Skip to content

Commit 0d6ddb0

Browse files
authored
Merge pull request #154 from nicklaw5/v7.2.0
2 parents 4ed365e + 44312ed commit 0d6ddb0

File tree

7 files changed

+158
-15
lines changed

7 files changed

+158
-15
lines changed

spec/TwitchApi/Resources/ChannelsApiSpec.php

+24
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,28 @@ function it_should_modify_channel_with_opts(RequestGenerator $requestGenerator,
5757
$requestGenerator->generate('PATCH', 'channels', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'game_id', 'value' => '0'], ['key' => 'broadcaster_language', 'value' => 'en'], ['key' => 'title', 'value' => 'test 123'], ['key' => 'delay', 'value' => 5]])->willReturn($request);
5858
$this->modifyChannelInfo('TEST_TOKEN', '123', ['game_id' => '0', 'broadcaster_language' => 'en', 'title' => 'test 123', 'delay' => 5])->shouldBe($response);
5959
}
60+
61+
function it_should_get_followed_channels(RequestGenerator $requestGenerator, Request $request, Response $response)
62+
{
63+
$requestGenerator->generate('GET', 'channels/followed', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123']], [])->willReturn($request);
64+
$this->getFollowedChannels('TEST_TOKEN', '123')->shouldBe($response);
65+
}
66+
67+
function it_should_get_followed_channels_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response)
68+
{
69+
$requestGenerator->generate('GET', 'channels/followed', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'broadcaster_id', 'value' => '456'], ['key' => 'first', 'value' => 100], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request);
70+
$this->getFollowedChannels('TEST_TOKEN', '123', '456', 100, 'abc')->shouldBe($response);
71+
}
72+
73+
function it_should_get_channel_followers(RequestGenerator $requestGenerator, Request $request, Response $response)
74+
{
75+
$requestGenerator->generate('GET', 'channels/followers', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request);
76+
$this->getChannelFollowers('TEST_TOKEN', '123')->shouldBe($response);
77+
}
78+
79+
function it_should_get_channel_followers_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response)
80+
{
81+
$requestGenerator->generate('GET', 'channels/followers', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => '456'], ['key' => 'first', 'value' => 100], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request);
82+
$this->getChannelFollowers('TEST_TOKEN', '123', '456', 100, 'abc')->shouldBe($response);
83+
}
6084
}

spec/TwitchApi/Resources/ChatApiSpec.php

+6
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,10 @@ function it_should_get_chatters_with_opts(RequestGenerator $requestGenerator, Re
117117
$requestGenerator->generate('GET', 'chat/chatters', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'moderator_id', 'value' => '456'],['key' => 'first', 'value' => 100], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request);
118118
$this->getChatters('TEST_TOKEN', '123', '456', 100, 'abc')->shouldBe($response);
119119
}
120+
121+
function it_should_send_a_shoutout(RequestGenerator $requestGenerator, Request $request, Response $response)
122+
{
123+
$requestGenerator->generate('POST', 'chat/shoutouts', 'TEST_TOKEN', [['key' => 'from_broadcaster_id', 'value' => '123'], ['key' => 'to_broadcaster_id', 'value' => '456'], ['key' => 'moderator_id', 'value' => '789']], [])->willReturn($request);
124+
$this->sendShoutout('TEST_TOKEN', '123', '456', '789')->shouldBe($response);
125+
}
120126
}

spec/TwitchApi/Resources/EventSubApiSpec.php

+20-8
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ function it_should_subscribe_to_channel_update(RequestGenerator $requestGenerato
8787

8888
function it_should_subscribe_to_channel_follow(RequestGenerator $requestGenerator, Request $request, Response $response)
8989
{
90-
$this->createEventSubSubscription('channel.follow', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request);
91-
$this->subscribeToChannelFollow($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response);
90+
$this->createEventSubSubscription('channel.follow', '2', ['broadcaster_user_id' => '12345', 'moderator_user_id' => '54321'], $requestGenerator)->willReturn($request);
91+
$this->subscribeToChannelFollow($this->bearer, $this->secret, $this->callback, '12345', '54321')->shouldBe($response);
9292
}
9393

9494
function it_should_subscribe_to_channel_subscribe(RequestGenerator $requestGenerator, Request $request, Response $response)
@@ -309,37 +309,49 @@ function it_should_subscribe_to_drop_entitelement_grant_with_opts(RequestGenerat
309309

310310
function it_should_subscribe_to_channel_charity_campaign_start(RequestGenerator $requestGenerator, Request $request, Response $response)
311311
{
312-
$this->createEventSubSubscription('channel.charity_campaign.start', 'beta', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request);
312+
$this->createEventSubSubscription('channel.charity_campaign.start', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request);
313313
$this->subscribeToChannelCharityCampaignStart($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response);
314314
}
315315

316316
function it_should_subscribe_to_channel_charity_campaign_progress(RequestGenerator $requestGenerator, Request $request, Response $response)
317317
{
318-
$this->createEventSubSubscription('channel.charity_campaign.progress', 'beta', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request);
318+
$this->createEventSubSubscription('channel.charity_campaign.progress', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request);
319319
$this->subscribeToChannelCharityCampaignProgress($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response);
320320
}
321321

322322
function it_should_subscribe_to_channel_charity_campaign_stop(RequestGenerator $requestGenerator, Request $request, Response $response)
323323
{
324-
$this->createEventSubSubscription('channel.charity_campaign.stop', 'beta', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request);
324+
$this->createEventSubSubscription('channel.charity_campaign.stop', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request);
325325
$this->subscribeToChannelCharityCampaignStop($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response);
326326
}
327327

328328
function it_should_subscribe_to_channel_charity_campaign_donate(RequestGenerator $requestGenerator, Request $request, Response $response)
329329
{
330-
$this->createEventSubSubscription('channel.charity_campaign.donate', 'beta', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request);
330+
$this->createEventSubSubscription('channel.charity_campaign.donate', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request);
331331
$this->subscribeToChannelCharityCampaignDonate($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response);
332332
}
333333

334334
function it_should_subscribe_to_channel_shield_mode_begin(RequestGenerator $requestGenerator, Request $request, Response $response)
335335
{
336-
$this->createEventSubSubscription('channel.shield_mode.begin', 'beta', ['broadcaster_user_id' => '12345', 'moderator_user_id' => '54321'], $requestGenerator)->willReturn($request);
336+
$this->createEventSubSubscription('channel.shield_mode.begin', '1', ['broadcaster_user_id' => '12345', 'moderator_user_id' => '54321'], $requestGenerator)->willReturn($request);
337337
$this->subscribeToChannelShieldModeBegin($this->bearer, $this->secret, $this->callback, '12345', '54321')->shouldBe($response);
338338
}
339339

340340
function it_should_subscribe_to_channel_shield_mode_end(RequestGenerator $requestGenerator, Request $request, Response $response)
341341
{
342-
$this->createEventSubSubscription('channel.shield_mode.end', 'beta', ['broadcaster_user_id' => '12345', 'moderator_user_id' => '54321'], $requestGenerator)->willReturn($request);
342+
$this->createEventSubSubscription('channel.shield_mode.end', '1', ['broadcaster_user_id' => '12345', 'moderator_user_id' => '54321'], $requestGenerator)->willReturn($request);
343343
$this->subscribeToChannelShieldModeEnd($this->bearer, $this->secret, $this->callback, '12345', '54321')->shouldBe($response);
344344
}
345+
346+
function it_should_subscribe_to_channel_shoutout_create(RequestGenerator $requestGenerator, Request $request, Response $response)
347+
{
348+
$this->createEventSubSubscription('channel.shoutout.create', '1', ['broadcaster_user_id' => '12345', 'moderator_user_id' => '54321'], $requestGenerator)->willReturn($request);
349+
$this->subscribeToChannelShoutoutCreate($this->bearer, $this->secret, $this->callback, '12345', '54321')->shouldBe($response);
350+
}
351+
352+
function it_should_subscribe_to_channel_shoutout_receive(RequestGenerator $requestGenerator, Request $request, Response $response)
353+
{
354+
$this->createEventSubSubscription('channel.shoutout.receive', '1', ['broadcaster_user_id' => '12345', 'moderator_user_id' => '54321'], $requestGenerator)->willReturn($request);
355+
$this->subscribeToChannelShoutoutReceive($this->bearer, $this->secret, $this->callback, '12345', '54321')->shouldBe($response);
356+
}
345357
}

spec/TwitchApi/Resources/GoalsApiSpec.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator
1919
function it_should_get_goals_by_broadcaster_id(RequestGenerator $requestGenerator, Request $request, Response $response)
2020
{
2121
$requestGenerator->generate('GET', 'goals', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request);
22-
$this->getGoals('TEST_TOKEN', ['123'])->shouldBe($response);
22+
$this->getGoals('TEST_TOKEN', '123')->shouldBe($response);
2323
}
2424

2525
}

src/Resources/ChannelsApi.php

+50
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,54 @@ public function modifyChannelInfo(string $bearer, string $broadcasterId, $bodyPa
5252

5353
return $this->patchApi('channels', $bearer, $queryParamsMap, $bodyParamsMap);
5454
}
55+
56+
/**
57+
* @throws GuzzleException
58+
* @link https://dev.twitch.tv/docs/api/reference/#get-followed-channels
59+
*/
60+
public function getFollowedChannels(string $bearer, string $userId, string $broadcasterId = null, int $first = null, string $after = null): ResponseInterface
61+
{
62+
$queryParamsMap = [];
63+
64+
$queryParamsMap[] = ['key' => 'user_id', 'value' => $userId];
65+
66+
if ($broadcasterId) {
67+
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];
68+
}
69+
70+
if ($first) {
71+
$queryParamsMap[] = ['key' => 'first', 'value' => $first];
72+
}
73+
74+
if ($after) {
75+
$queryParamsMap[] = ['key' => 'after', 'value' => $after];
76+
}
77+
78+
return $this->getApi('channels/followed', $bearer, $queryParamsMap);
79+
}
80+
81+
/**
82+
* @throws GuzzleException
83+
* @link https://dev.twitch.tv/docs/api/reference/#get-channel-followers
84+
*/
85+
public function getChannelFollowers(string $bearer, string $broadcasterId, string $userId = null, int $first = null, string $after = null): ResponseInterface
86+
{
87+
$queryParamsMap = [];
88+
89+
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];
90+
91+
if ($userId) {
92+
$queryParamsMap[] = ['key' => 'user_id', 'value' => $userId];
93+
}
94+
95+
if ($first) {
96+
$queryParamsMap[] = ['key' => 'first', 'value' => $first];
97+
}
98+
99+
if ($after) {
100+
$queryParamsMap[] = ['key' => 'after', 'value' => $after];
101+
}
102+
103+
return $this->getApi('channels/followers', $bearer, $queryParamsMap);
104+
}
55105
}

src/Resources/ChatApi.php

+17
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,21 @@ public function getChatters(string $bearer, string $broadcasterId, string $moder
179179

180180
return $this->getApi('chat/chatters', $bearer, $queryParamsMap);
181181
}
182+
183+
/**
184+
* @throws GuzzleException
185+
* @link https://dev.twitch.tv/docs/api/reference/#send-a-shoutout
186+
*/
187+
public function sendShoutout(string $bearer, string $fromBroadcasterId, string $toBroadcasterId, string $moderatorId): ResponseInterface
188+
{
189+
$queryParamsMap = [];
190+
191+
$queryParamsMap[] = ['key' => 'from_broadcaster_id', 'value' => $fromBroadcasterId];
192+
193+
$queryParamsMap[] = ['key' => 'to_broadcaster_id', 'value' => $toBroadcasterId];
194+
195+
$queryParamsMap[] = ['key' => 'moderator_id', 'value' => $moderatorId];
196+
197+
return $this->postApi('chat/shoutouts', $bearer, $queryParamsMap);
198+
}
182199
}

src/Resources/EventSubApi.php

+40-6
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,20 @@ public function subscribeToChannelUpdate(string $bearer, string $secret, string
9191
}
9292

9393
/**
94-
* @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelfollow
94+
* @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/#channelfollow
9595
*/
96-
public function subscribeToChannelFollow(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface
96+
public function subscribeToChannelFollow(string $bearer, string $secret, string $callback, string $twitchId, string $moderatorId): ResponseInterface
9797
{
9898
return $this->createEventSubSubscription(
9999
$bearer,
100100
$secret,
101101
$callback,
102102
'channel.follow',
103-
'1',
104-
['broadcaster_user_id' => $twitchId],
103+
'2',
104+
[
105+
'broadcaster_user_id' => $twitchId,
106+
'moderator_user_id' => $moderatorId,
107+
],
105108
);
106109
}
107110

@@ -495,6 +498,22 @@ public function subscribeToChannelShieldModeEnd(string $bearer, string $secret,
495498
return $this->subscribeToChannelShieldMode($bearer, $secret, $callback, $twitchId, $moderatorId, 'end');
496499
}
497500

501+
/**
502+
* @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/#channelshoutoutcreate
503+
*/
504+
public function subscribeToChannelShoutoutCreate(string $bearer, string $secret, string $callback, string $twitchId, string $moderatorId): ResponseInterface
505+
{
506+
return $this->subscribeToChannelShoutout($bearer, $secret, $callback, $twitchId, $moderatorId, 'create');
507+
}
508+
509+
/**
510+
* @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/#channelshoutoutreceive
511+
*/
512+
public function subscribeToChannelShoutoutReceive(string $bearer, string $secret, string $callback, string $twitchId, string $moderatorId): ResponseInterface
513+
{
514+
return $this->subscribeToChannelShoutout($bearer, $secret, $callback, $twitchId, $moderatorId, 'receive');
515+
}
516+
498517
/**
499518
* @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/#dropentitlementgrant
500519
*/
@@ -661,7 +680,7 @@ private function subscribeToChannelCharityCampaign(string $bearer, string $secre
661680
$secret,
662681
$callback,
663682
sprintf('channel.charity_campaign.%s', $eventType),
664-
'beta',
683+
'1',
665684
['broadcaster_user_id' => $twitchId],
666685
);
667686
}
@@ -673,7 +692,22 @@ private function subscribeToChannelShieldMode(string $bearer, string $secret, st
673692
$secret,
674693
$callback,
675694
sprintf('channel.shield_mode.%s', $eventType),
676-
'beta',
695+
'1',
696+
[
697+
'broadcaster_user_id' => $twitchId,
698+
'moderator_user_id' => $moderatorId,
699+
],
700+
);
701+
}
702+
703+
private function subscribeToChannelShoutout(string $bearer, string $secret, string $callback, string $twitchId, string $moderatorId, string $eventType): ResponseInterface
704+
{
705+
return $this->createEventSubSubscription(
706+
$bearer,
707+
$secret,
708+
$callback,
709+
sprintf('channel.shoutout.%s', $eventType),
710+
'1',
677711
[
678712
'broadcaster_user_id' => $twitchId,
679713
'moderator_user_id' => $moderatorId,

0 commit comments

Comments
 (0)