Skip to content

Commit

Permalink
Change to v3 sdk paginator and exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfedr committed Sep 29, 2015
1 parent bb75f15 commit 1059d93
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 32 deletions.
8 changes: 3 additions & 5 deletions src/Mcfedr/AwsPushBundle/Command/EnableAllCommand.php
Expand Up @@ -61,11 +61,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
*/
private function enablePlatform($platform)
{
foreach ($this->sns->getListEndpointsByPlatformApplicationIterator(
[
'PlatformApplicationArn' => $this->arns[$platform]
]
) as $endpoint) {
foreach ($this->sns->getPaginator('ListEndpointsByPlatformApplication', [
'PlatformApplicationArn' => $this->arns[$platform]
]) as $endpoint) {
if ($endpoint['Attributes']['Enabled'] == "false") {
try {
$this->sns->setEndpointAttributes(
Expand Down
8 changes: 3 additions & 5 deletions src/Mcfedr/AwsPushBundle/Command/RemoveDisabledCommand.php
Expand Up @@ -61,11 +61,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
*/
private function removeFromPlatform($platform)
{
foreach ($this->sns->getListEndpointsByPlatformApplicationIterator(
[
'PlatformApplicationArn' => $this->arns[$platform]
]
) as $endpoint) {
foreach ($this->sns->getPaginator('ListEndpointsByPlatformApplication', [
'PlatformApplicationArn' => $this->arns[$platform]
]) as $endpoint) {
if ($endpoint['Attributes']['Enabled'] == "false") {
try {
$this->sns->deleteEndpoint(
Expand Down
20 changes: 5 additions & 15 deletions src/Mcfedr/AwsPushBundle/Command/SubscribeTopicsCommand.php
@@ -1,8 +1,7 @@
<?php
namespace Mcfedr\AwsPushBundle\Command;

use Aws\Sns\Exception\SubscriptionLimitExceededException;
use Aws\Sns\Exception\TopicLimitExceededException;
use Aws\Sns\Exception\SnsException;
use Aws\Sns\SnsClient;
use Mcfedr\AwsPushBundle\Service\Topics;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -77,14 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
foreach ($this->arns as $platform => $arn) {
$this->subscribePlatform($platform, $input->getOption('topic'));
}
} catch (SubscriptionLimitExceededException $e) {
$this->logger && $this->logger->error(
'Failed to subscription to topic',
[
'exception' => $e
]
);
} catch (TopicLimitExceededException $e) {
} catch (SnsException $e) {
$this->logger && $this->logger->error(
'Failed to create topic',
[
Expand All @@ -96,11 +88,9 @@ protected function execute(InputInterface $input, OutputInterface $output)

private function subscribePlatform($platform, $topic)
{
foreach ($this->sns->getListEndpointsByPlatformApplicationIterator(
[
'PlatformApplicationArn' => $this->arns[$platform]
]
) as $endpoint) {
foreach ($this->sns->getPaginator('ListEndpointsByPlatformApplication', [
'PlatformApplicationArn' => $this->arns[$platform]
]) as $endpoint) {
$this->logger && $this->logger->info(
'Subscribing device to topic',
[
Expand Down
4 changes: 2 additions & 2 deletions src/Mcfedr/AwsPushBundle/Service/Devices.php
Expand Up @@ -2,7 +2,7 @@

namespace Mcfedr\AwsPushBundle\Service;

use Aws\Sns\Exception\InvalidParameterException;
use Aws\Sns\Exception\SnsException;
use Aws\Sns\SnsClient;
use Mcfedr\AwsPushBundle\Exception\PlatformNotConfiguredException;

Expand Down Expand Up @@ -53,7 +53,7 @@ public function registerDevice($deviceId, $platform)
]
]
);
} catch (InvalidParameterException $e) {
} catch (SnsException $e) {
preg_match('/Endpoint (.+?) already/', $e->getMessage(), $matches);
if (isset($matches[1])) {
$this->sns->setEndpointAttributes(
Expand Down
8 changes: 3 additions & 5 deletions src/Mcfedr/AwsPushBundle/Service/Messages.php
Expand Up @@ -136,11 +136,9 @@ private function broadcastToPlatform($message, $platform)
return;
}

foreach ($this->sns->getListEndpointsByPlatformApplicationIterator(
[
'PlatformApplicationArn' => $this->arns[$platform]
]
) as $endpoint) {
foreach ($this->sns->getPaginator('ListEndpointsByPlatformApplication', [
'PlatformApplicationArn' => $this->arns[$platform]
]) as $endpoint) {
if ($endpoint['Attributes']['Enabled'] == "true") {
try {
$this->send($message, $endpoint['EndpointArn']);
Expand Down

0 comments on commit 1059d93

Please sign in to comment.