| Total Complexity | 8 |
| Total Lines | 63 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 13 | class WebhookCreatorEventBridge implements WebhookCreatorInterface |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var ShopifyApiFactory |
||
| 17 | */ |
||
| 18 | private $apis; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | private $eventBridgeArn; |
||
| 24 | |||
| 25 | public function __construct(ShopifyApiFactory $apis, string $eventBridgeArn) |
||
| 26 | { |
||
| 27 | $this->apis = $apis; |
||
| 28 | $this->eventBridgeArn = $eventBridgeArn; |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * {@inheritdoc} |
||
| 33 | */ |
||
| 34 | public function createWebhooks(string $storeName, array $topics) |
||
| 35 | { |
||
| 36 | $api = $this->apis->getForStore($storeName); |
||
| 37 | |||
| 38 | foreach ($topics as $topic) { |
||
| 39 | $webhook = GenericResource::create([ |
||
| 40 | 'topic' => $topic, |
||
| 41 | 'address' => $this->eventBridgeArn, |
||
| 42 | 'format' => 'json', |
||
| 43 | ]); |
||
| 44 | |||
| 45 | try { |
||
| 46 | $api->Webhook->create($webhook); |
||
| 47 | } catch (ClientException $e) { |
||
| 48 | if ($e->getResponse()->getStatusCode() == 422) { |
||
| 49 | continue; |
||
| 50 | } |
||
| 51 | |||
| 52 | throw $e; |
||
| 53 | } |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * {@inheritdoc} |
||
| 59 | */ |
||
| 60 | public function listWebhooks(string $storeName) |
||
| 61 | { |
||
| 62 | $api = $this->apis->getForStore($storeName); |
||
| 63 | |||
| 64 | return $api->Webhook->findAll(); |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * {@inheritdoc} |
||
| 69 | */ |
||
| 70 | public function deleteAllWebhooks(string $storeName) |
||
| 76 | } |
||
| 77 | } |
||
| 78 | } |
||
| 79 |