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); }