Skip to content

Commit 07449c3

Browse files
committed
Add TagsApi->replaceStreamTags
1 parent b2837a7 commit 07449c3

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

spec/NewTwitchApi/Resources/TagsApiSpec.php

+18
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,22 @@ function it_should_get_stream_tags(RequestGenerator $requestGenerator, Request $
4646
$requestGenerator->generate('GET', 'streams/tags', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request);
4747
$this->getStreamTags('TEST_TOKEN', '123')->shouldBe($response);
4848
}
49+
50+
function it_should_replace_stream_tags(RequestGenerator $requestGenerator, Request $request, Response $response)
51+
{
52+
$requestGenerator->generate('PUT', 'streams/tags', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request);
53+
$this->replaceStreamTags('TEST_TOKEN', '123')->shouldBe($response);
54+
}
55+
56+
function it_should_replace_stream_tags_with_one_tag(RequestGenerator $requestGenerator, Request $request, Response $response)
57+
{
58+
$requestGenerator->generate('PUT', 'streams/tags', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'tag_ids', 'value' => ['456']]])->willReturn($request);
59+
$this->replaceStreamTags('TEST_TOKEN', '123', ['456'])->shouldBe($response);
60+
}
61+
62+
function it_should_replace_stream_tags_with_multiple_tags(RequestGenerator $requestGenerator, Request $request, Response $response)
63+
{
64+
$requestGenerator->generate('PUT', 'streams/tags', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'tag_ids', 'value' => ['456', '789']]])->willReturn($request);
65+
$this->replaceStreamTags('TEST_TOKEN', '123', ['456', '789'])->shouldBe($response);
66+
}
4967
}

src/NewTwitchApi/Resources/TagsApi.php

+17
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,21 @@ public function getStreamTags(string $bearer, string $broadcasterId): ResponseIn
4343

4444
return $this->getApi('streams/tags', $bearer, $queryParamsMap);
4545
}
46+
47+
/**
48+
* @throws GuzzleException
49+
* @link https://dev.twitch.tv/docs/api/reference#replace-stream-tags
50+
*/
51+
public function replaceStreamTags(string $bearer, string $broadcasterId, $tags = []): ResponseInterface
52+
{
53+
$queryParamsMap = $bodyParamsMap = [];
54+
55+
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];
56+
57+
if (count($tags) > 0) {
58+
$bodyParamsMap[] = ['key' => 'tag_ids', 'value' => $tags];
59+
}
60+
61+
return $this->putApi('streams/tags', $bearer, $queryParamsMap, $bodyParamsMap);
62+
}
4663
}

0 commit comments

Comments
 (0)