diff --git a/spec/TwitchApi/Resources/EventSubApiSpec.php b/spec/TwitchApi/Resources/EventSubApiSpec.php index 8a11339..a3b9c5a 100644 --- a/spec/TwitchApi/Resources/EventSubApiSpec.php +++ b/spec/TwitchApi/Resources/EventSubApiSpec.php @@ -14,20 +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) + 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' => '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); } @@ -291,13 +297,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..a1faae0 100644 --- a/src/Resources/EventSubApi.php +++ b/src/Resources/EventSubApi.php @@ -40,7 +40,7 @@ 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 = null): ResponseInterface { $bodyParams = []; @@ -56,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); } @@ -511,6 +515,7 @@ public function subscribeToDropEntitlementGrant(string $bearer, string $secret, 'drop.entitlement.grant', '1', $condition, + true ); }