Skip to content

Commit

Permalink
set null as default param
Browse files Browse the repository at this point in the history
  • Loading branch information
alexschastny committed May 12, 2023
1 parent d0f17e8 commit 591bcc8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
19 changes: 12 additions & 7 deletions spec/TwitchApi/Resources/EventSubApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 5 additions & 2 deletions src/Resources/EventSubApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand All @@ -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);
}

Expand Down

0 comments on commit 591bcc8

Please sign in to comment.