Skip to content

Commit

Permalink
drop.entitlement.grant subscription must have is_batching_enabled param
Browse files Browse the repository at this point in the history
  • Loading branch information
alexschastny committed May 12, 2023
1 parent 201c00d commit d0f17e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions spec/TwitchApi/Resources/EventSubApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 3 additions & 1 deletion src/Resources/EventSubApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down Expand Up @@ -511,6 +512,7 @@ public function subscribeToDropEntitlementGrant(string $bearer, string $secret,
'drop.entitlement.grant',
'1',
$condition,
true
);
}

Expand Down

0 comments on commit d0f17e8

Please sign in to comment.