Skip to content

Commit

Permalink
Add Add/Remove for Moderators/VIPs and GET VIPs
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandin committed Aug 29, 2022
1 parent 3976f35 commit 338c5d1
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
48 changes: 48 additions & 0 deletions spec/TwitchApi/Resources/ModerationApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,52 @@ function it_should_delete_chat_messages_with_message_id(RequestGenerator $reques
$requestGenerator->generate('DELETE', 'moderation/chat', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'moderator_id', 'value' => '456'], ['key' => 'message_id', 'value' => '789']], [])->willReturn($request);
$this->deleteChatMessages('TEST_TOKEN', '123', '456', '789')->shouldBe($response);
}

function it_should_add_a_channel_moderator(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('POST', 'moderation/moderators', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => '456']], [])->willReturn($request);
$this->addChannelModerator('TEST_TOKEN', '123', '456')->shouldBe($response);
}

function it_should_remove_a_channel_moderator(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('DELETE', 'moderation/moderators', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => '456']], [])->willReturn($request);
$this->removeChannelModerator('TEST_TOKEN', '123', '456')->shouldBe($response);
}

function it_should_get_vips_for_a_channel(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'channels/vips', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request);
$this->getVips('TEST_TOKEN', '123')->shouldBe($response);
}

function it_should_get_vips_for_a_channel_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'channels/vips', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'first', 'value' => 100], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request);
$this->getVips('TEST_TOKEN', '123', [], 100, 'abc')->shouldBe($response);
}

function it_should_get_vips_for_a_channel_with_one_id(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'channels/vips', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => '456']], [])->willReturn($request);
$this->getVips('TEST_TOKEN', '123', ['456'])->shouldBe($response);
}

function it_should_get_vips_for_a_channel_with_multipe_ids(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('GET', 'channels/vips', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => '456'], ['key' => 'user_id', 'value' => '789']], [])->willReturn($request);
$this->getVips('TEST_TOKEN', '123', ['456', '789'])->shouldBe($response);
}

function it_should_add_vip_for_a_channel(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('POST', 'channels/vips', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => '456']], [])->willReturn($request);
$this->addChannelVip('TEST_TOKEN', '123', '456')->shouldBe($response);
}

function it_should_remove_vip_for_a_channel(RequestGenerator $requestGenerator, Request $request, Response $response)
{
$requestGenerator->generate('DELETE', 'channels/vips', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => '456']], [])->willReturn($request);
$this->removeChannelVip('TEST_TOKEN', '123', '456')->shouldBe($response);
}
}
78 changes: 78 additions & 0 deletions src/Resources/ModerationApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,32 @@ public function getModerators(string $bearer, string $broadcasterId, array $ids
return $this->getApi('moderation/moderators', $bearer, $queryParamsMap);
}

/**
* @throws GuzzleException
* @link https://dev.twitch.tv/docs/api/reference#add-channel-moderator
*/
public function addChannelModerator(string $bearer, string $broadcasterId, string $userId): ResponseInterface
{
$queryParamsMap = [];
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];
$queryParamsMap[] = ['key' => 'user_id', 'value' => $userId];

return $this->postApi('moderation/moderators', $bearer, $queryParamsMap);
}

/**
* @throws GuzzleException
* @link https://dev.twitch.tv/docs/api/reference#remove-channel-moderator
*/
public function removeChannelModerator(string $bearer, string $broadcasterId, string $userId): ResponseInterface
{
$queryParamsMap = [];
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];
$queryParamsMap[] = ['key' => 'user_id', 'value' => $userId];

return $this->deleteApi('moderation/moderators', $bearer, $queryParamsMap);
}

/**
* @throws GuzzleException
* @link https://dev.twitch.tv/docs/api/reference#check-automod-status
Expand Down Expand Up @@ -221,4 +247,56 @@ public function deleteChatMessages(string $bearer, string $broadcasterId, string

return $this->deleteApi('moderation/chat', $bearer, $queryParamsMap);
}

/**
* @throws GuzzleException
* @link https://dev.twitch.tv/docs/api/reference#get-vips
*/
public function getVips(string $bearer, string $broadcasterId, array $users = [], int $first = null, string $after = null): ResponseInterface
{
$queryParamsMap = [];
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];

foreach($users as $user) {
$queryParamsMap[] = ['key' => 'user_id', 'value' => $user];
}

if ($first) {
$queryParamsMap[] = ['key' => 'first', 'value' => $first];
}

if ($after) {
$queryParamsMap[] = ['key' => 'after', 'value' => $after];
}

return $this->getApi('channels/vips', $bearer, $queryParamsMap);
}

/**
* @throws GuzzleException
* @link https://dev.twitch.tv/docs/api/reference#add-channel-vip
*/
public function addChannelVip(string $bearer, string $broadcasterId, string $userId): ResponseInterface
{
$queryParamsMap = [];

$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];
$queryParamsMap[] = ['key' => 'user_id', 'value' => $userId];

return $this->postApi('channels/vips', $bearer, $queryParamsMap);
}

/**
* @throws GuzzleException
* @link https://dev.twitch.tv/docs/api/reference#remove-channel-vip
*/
public function removeChannelVip(string $bearer, string $broadcasterId, string $userId): ResponseInterface
{
$queryParamsMap = [];

$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId];
$queryParamsMap[] = ['key' => 'user_id', 'value' => $userId];

return $this->deleteApi('channels/vips', $bearer, $queryParamsMap);
}
}

0 comments on commit 338c5d1

Please sign in to comment.