From d0f17e88c0ad6be975821d7da53827d076b88d2a Mon Sep 17 00:00:00 2001 From: alexschastny Date: Fri, 12 May 2023 21:00:47 +0200 Subject: [PATCH 1/2] drop.entitlement.grant subscription must have is_batching_enabled param --- spec/TwitchApi/Resources/EventSubApiSpec.php | 7 ++++--- src/Resources/EventSubApi.php | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/spec/TwitchApi/Resources/EventSubApiSpec.php b/spec/TwitchApi/Resources/EventSubApiSpec.php index 8a11339..d6e469d 100644 --- a/spec/TwitchApi/Resources/EventSubApiSpec.php +++ b/spec/TwitchApi/Resources/EventSubApiSpec.php @@ -14,13 +14,14 @@ class EventSubApiSpec extends ObjectBehavior private string $secret = 'SECRET'; private string $callback = 'https://example.com/'; - private function createEventSubSubscription(string $type, string $version, array $condition, RequestGenerator $requestGenerator) + private function createEventSubSubscription(string $type, string $version, array $condition, RequestGenerator $requestGenerator, bool $isBatchingEnabled = false) { $bodyParams = []; $bodyParams[] = ['key' => 'type', 'value' => $type]; $bodyParams[] = ['key' => 'version', 'value' => $version]; $bodyParams[] = ['key' => 'condition', 'value' => $condition]; + $bodyParams[] = ['key' => 'is_batching_enabled', 'value' => $isBatchingEnabled]; $bodyParams[] = ['key' => 'transport', 'value' => [ 'method' => 'webhook', 'callback' => $this->callback, @@ -291,13 +292,13 @@ function it_should_subscribe_to_channel_goal_end(RequestGenerator $requestGenera function it_should_subscribe_to_drop_entitelement_grant(RequestGenerator $requestGenerator, Request $request, Response $response) { - $this->createEventSubSubscription('drop.entitlement.grant', '1', ['organization_id' => '12345'], $requestGenerator)->willReturn($request); + $this->createEventSubSubscription('drop.entitlement.grant', '1', ['organization_id' => '12345'], $requestGenerator, true)->willReturn($request); $this->subscribeToDropEntitlementGrant($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); } function it_should_subscribe_to_drop_entitelement_grant_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) { - $this->createEventSubSubscription('drop.entitlement.grant', '1', ['organization_id' => '123', 'category_id' => '456', 'campaign_id' => '789'], $requestGenerator)->willReturn($request); + $this->createEventSubSubscription('drop.entitlement.grant', '1', ['organization_id' => '123', 'category_id' => '456', 'campaign_id' => '789'], $requestGenerator, true)->willReturn($request); $this->subscribeToDropEntitlementGrant($this->bearer, $this->secret, $this->callback, '123', '456', '789')->shouldBe($response); } diff --git a/src/Resources/EventSubApi.php b/src/Resources/EventSubApi.php index 89a05e6..6a13244 100644 --- a/src/Resources/EventSubApi.php +++ b/src/Resources/EventSubApi.php @@ -40,13 +40,14 @@ public function getEventSubSubscription(string $bearer, string $status = null, s * @throws GuzzleException * @link https://dev.twitch.tv/docs/api/reference#create-eventsub-subscription */ - public function createEventSubSubscription(string $bearer, string $secret, string $callback, string $type, string $version, array $condition): ResponseInterface + public function createEventSubSubscription(string $bearer, string $secret, string $callback, string $type, string $version, array $condition, bool $isBatchingEnabled = false): ResponseInterface { $bodyParams = []; $bodyParams[] = ['key' => 'type', 'value' => $type]; $bodyParams[] = ['key' => 'version', 'value' => $version]; $bodyParams[] = ['key' => 'condition', 'value' => $condition]; + $bodyParams[] = ['key' => 'is_batching_enabled', 'value' => $isBatchingEnabled]; $bodyParams[] = [ 'key' => 'transport', 'value' => [ @@ -511,6 +512,7 @@ public function subscribeToDropEntitlementGrant(string $bearer, string $secret, 'drop.entitlement.grant', '1', $condition, + true ); } From 591bcc83001836abe641bb813dc91feb93c13cb4 Mon Sep 17 00:00:00 2001 From: alexschastny Date: Fri, 12 May 2023 23:17:53 +0200 Subject: [PATCH 2/2] set null as default param --- spec/TwitchApi/Resources/EventSubApiSpec.php | 19 ++++++++++++------- src/Resources/EventSubApi.php | 7 +++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/spec/TwitchApi/Resources/EventSubApiSpec.php b/spec/TwitchApi/Resources/EventSubApiSpec.php index d6e469d..a3b9c5a 100644 --- a/spec/TwitchApi/Resources/EventSubApiSpec.php +++ b/spec/TwitchApi/Resources/EventSubApiSpec.php @@ -14,21 +14,26 @@ class EventSubApiSpec extends ObjectBehavior private string $secret = 'SECRET'; private string $callback = 'https://example.com/'; - private function createEventSubSubscription(string $type, string $version, array $condition, RequestGenerator $requestGenerator, bool $isBatchingEnabled = false) + private function createEventSubSubscription(string $type, string $version, array $condition, RequestGenerator $requestGenerator, bool $isBatchingEnabled = null) { $bodyParams = []; $bodyParams[] = ['key' => 'type', 'value' => $type]; $bodyParams[] = ['key' => 'version', 'value' => $version]; $bodyParams[] = ['key' => 'condition', 'value' => $condition]; - $bodyParams[] = ['key' => 'is_batching_enabled', 'value' => $isBatchingEnabled]; - $bodyParams[] = ['key' => 'transport', 'value' => [ - 'method' => 'webhook', - 'callback' => $this->callback, - 'secret' => $this->secret, - ] + $bodyParams[] = [ + 'key' => 'transport', + 'value' => [ + 'method' => 'webhook', + 'callback' => $this->callback, + 'secret' => $this->secret, + ], ]; + if (null !== $isBatchingEnabled) { + $bodyParams[] = ['key' => 'is_batching_enabled', 'value' => $isBatchingEnabled]; + } + return $requestGenerator->generate('POST', 'eventsub/subscriptions', $this->bearer, [], $bodyParams); } diff --git a/src/Resources/EventSubApi.php b/src/Resources/EventSubApi.php index 6a13244..a1faae0 100644 --- a/src/Resources/EventSubApi.php +++ b/src/Resources/EventSubApi.php @@ -40,14 +40,13 @@ public function getEventSubSubscription(string $bearer, string $status = null, s * @throws GuzzleException * @link https://dev.twitch.tv/docs/api/reference#create-eventsub-subscription */ - public function createEventSubSubscription(string $bearer, string $secret, string $callback, string $type, string $version, array $condition, bool $isBatchingEnabled = false): ResponseInterface + public function createEventSubSubscription(string $bearer, string $secret, string $callback, string $type, string $version, array $condition, bool $isBatchingEnabled = null): ResponseInterface { $bodyParams = []; $bodyParams[] = ['key' => 'type', 'value' => $type]; $bodyParams[] = ['key' => 'version', 'value' => $version]; $bodyParams[] = ['key' => 'condition', 'value' => $condition]; - $bodyParams[] = ['key' => 'is_batching_enabled', 'value' => $isBatchingEnabled]; $bodyParams[] = [ 'key' => 'transport', 'value' => [ @@ -57,6 +56,10 @@ public function createEventSubSubscription(string $bearer, string $secret, strin ], ]; + if (null !== $isBatchingEnabled) { + $bodyParams[] = ['key' => 'is_batching_enabled', 'value' => $isBatchingEnabled]; + } + return $this->postApi('eventsub/subscriptions', $bearer, [], $bodyParams); }