예제 #1
0
 /**
  * Enable all devices registered on platform
  *
  * @param string $platform
  */
 private function enablePlatform($platform)
 {
     foreach ($this->sns->getPaginator('ListEndpointsByPlatformApplication', ['PlatformApplicationArn' => $this->arns[$platform]]) as $endpoint) {
         if ($endpoint['Attributes']['Enabled'] == "false") {
             try {
                 $this->sns->setEndpointAttributes(['EndpointArn' => $endpoint['EndpointArn'], 'Attributes' => ['Enabled' => "true"]]);
                 $this->logger && $this->logger->info("Enabled {$endpoint['EndpointArn']}");
             } catch (\Exception $e) {
                 $this->logger && $this->logger->error("Failed to push set attributes on {$endpoint['EndpointArn']}", ['exception' => $e, 'endpoint' => $endpoint]);
             }
         }
     }
 }
예제 #2
0
 /**
  * Register a device token
  *
  * @param string $deviceId device token
  * @param string $platform platform on which to register
  * @return string the endpoint ARN for this device
  * @throws PlatformNotConfiguredException
  */
 public function registerDevice($deviceId, $platform)
 {
     if (!isset($this->arns[$platform])) {
         throw new PlatformNotConfiguredException("There is no configured ARN for {$platform}");
     }
     try {
         $res = $this->sns->createPlatformEndpoint(['PlatformApplicationArn' => $this->arns[$platform], 'Token' => $deviceId, 'Attributes' => ['Enabled' => 'true']]);
     } catch (InvalidParameterException $e) {
         preg_match('/Endpoint (.+?) already/', $e->getMessage(), $matches);
         if (isset($matches[1])) {
             $this->sns->setEndpointAttributes(['EndpointArn' => $matches[1], 'Attributes' => ['Enabled' => 'true']]);
             return $matches[1];
         } else {
             throw $e;
         }
     }
     return $res['EndpointArn'];
 }