-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from brandinarsenault/channel-points-v2
Add Channel Points API
- Loading branch information
Showing
4 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace spec\NewTwitchApi\Resources; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Psr7\Request; | ||
use GuzzleHttp\Psr7\Response; | ||
use PhpSpec\ObjectBehavior; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class ChannelPointsApiSpec extends ObjectBehavior | ||
{ | ||
function let(Client $guzzleClient) | ||
{ | ||
$this->beConstructedWith($guzzleClient); | ||
} | ||
|
||
function it_should_get_custom_reward(Client $guzzleClient, Response $response) | ||
{ | ||
$guzzleClient->send(new Request('GET', 'channel_points/custom_rewards?broadcaster_id=123', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); | ||
$this->getCustomReward('TEST_TOKEN', '123')->shouldBeAnInstanceOf(ResponseInterface::class); | ||
} | ||
|
||
function it_should_get_custom_reward_with_everything(Client $guzzleClient, Response $response) | ||
{ | ||
$guzzleClient->send(new Request('GET', 'channel_points/custom_rewards?broadcaster_id=123&id=321&only_manageable_rewards=1', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); | ||
$this->getCustomReward('TEST_TOKEN', '123', ['321'], true)->shouldBeAnInstanceOf(ResponseInterface::class); | ||
} | ||
|
||
function it_should_get_custom_reward_redemption(Client $guzzleClient, Response $response) | ||
{ | ||
$guzzleClient->send(new Request('GET', 'channel_points/custom_rewards/redemptions?broadcaster_id=123&reward_id=321', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); | ||
$this->getCustomRewardRedemption('TEST_TOKEN', '123', '321')->shouldBeAnInstanceOf(ResponseInterface::class); | ||
} | ||
|
||
function it_should_get_custom_reward_redemption_with_reward_everything(Client $guzzleClient, Response $response) | ||
{ | ||
$guzzleClient->send(new Request('GET', 'channel_points/custom_rewards/redemptions?broadcaster_id=123&reward_id=321&status=UNFULFILLED&sort=OLDEST&after=abc&first=50', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); | ||
$this->getCustomRewardRedemption('TEST_TOKEN', '123', '321', [], 'UNFULFILLED', 'OLDEST', 'abc', '50')->shouldBeAnInstanceOf(ResponseInterface::class); | ||
} | ||
|
||
function it_should_get_custom_reward_redemption_with_id_everything(Client $guzzleClient, Response $response) | ||
{ | ||
$guzzleClient->send(new Request('GET', 'channel_points/custom_rewards/redemptions?broadcaster_id=123&id=321&id=333&status=UNFULFILLED&sort=OLDEST&after=abc&first=50', ['Authorization' => 'Bearer TEST_TOKEN']))->willReturn($response); | ||
$this->getCustomRewardRedemption('TEST_TOKEN', '123', null, ['321', '333'], 'UNFULFILLED', 'OLDEST', 'abc', '50')->shouldBeAnInstanceOf(ResponseInterface::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NewTwitchApi\Resources; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class ChannelPointsApi extends AbstractResource | ||
{ | ||
/** | ||
* @throws GuzzleException | ||
*/ | ||
public function getCustomRewardById(string $bearer, string $broadcasterId, string $id, bool $onlyManageableRewards = null): ResponseInterface | ||
{ | ||
return $this->getCustomReward($bearer, $broadcasterId, [$id], $onlyManageableRewards); | ||
} | ||
|
||
/** | ||
* @throws GuzzleException | ||
* @link https://dev.twitch.tv/docs/api/reference#get-custom-reward | ||
*/ | ||
public function getCustomReward(string $bearer, string $broadcasterId, array $ids = [], bool $onlyManageableRewards = null): ResponseInterface | ||
{ | ||
$queryParamsMap = []; | ||
|
||
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; | ||
|
||
foreach ($ids as $id) { | ||
$queryParamsMap[] = ['key' => 'id', 'value' => $id]; | ||
} | ||
|
||
if ($onlyManageableRewards) { | ||
$queryParamsMap[] = ['key' => 'only_manageable_rewards', 'value' => $onlyManageableRewards]; | ||
} | ||
|
||
return $this->callApi('channel_points/custom_rewards', $bearer, $queryParamsMap); | ||
} | ||
|
||
/** | ||
* @throws GuzzleException | ||
* @link https://dev.twitch.tv/docs/api/reference#get-custom-reward-redemption | ||
*/ | ||
public function getCustomRewardRedemption(string $bearer, string $broadcasterId, string $rewardId = null, array $ids = [], string $status = null, string $sort = null, string $after = null, string $first = null): ResponseInterface | ||
{ | ||
$queryParamsMap = []; | ||
|
||
$queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; | ||
|
||
if ($rewardId) { | ||
$queryParamsMap[] = ['key' => 'reward_id', 'value' => $rewardId]; | ||
} | ||
|
||
foreach ($ids as $id) { | ||
$queryParamsMap[] = ['key' => 'id', 'value' => $id]; | ||
} | ||
|
||
if ($status) { | ||
$queryParamsMap[] = ['key' => 'status', 'value' => $status]; | ||
} | ||
|
||
if ($sort) { | ||
$queryParamsMap[] = ['key' => 'sort', 'value' => $sort]; | ||
} | ||
|
||
if ($after) { | ||
$queryParamsMap[] = ['key' => 'after', 'value' => $after]; | ||
} | ||
|
||
if ($first) { | ||
$queryParamsMap[] = ['key' => 'first', 'value' => $first]; | ||
} | ||
|
||
return $this->callApi('channel_points/custom_rewards/redemptions', $bearer, $queryParamsMap); | ||
} | ||
|
||
/** | ||
* @throws GuzzleException | ||
* @link https://dev.twitch.tv/docs/api/reference#get-bits-leaderboard | ||
*/ | ||
public function getBitsLeaderboard(string $bearer, int $count = null, string $period = null, string $startedAt = null, string $userId = null): ResponseInterface | ||
{ | ||
$queryParamsMap = []; | ||
|
||
if ($count) { | ||
$queryParamsMap[] = ['key' => 'count', 'value' => $count]; | ||
} | ||
|
||
if ($period) { | ||
$queryParamsMap[] = ['key' => 'period', 'value' => $period]; | ||
} | ||
|
||
if ($startedAt) { | ||
$queryParamsMap[] = ['key' => 'started_at', 'value' => $startedAt]; | ||
} | ||
|
||
if ($userId) { | ||
$queryParamsMap[] = ['key' => 'user_id', 'value' => $userId]; | ||
} | ||
|
||
return $this->callApi('bits/leaderboard', $bearer, $queryParamsMap); | ||
} | ||
|
||
/** | ||
* @throws GuzzleException | ||
* @link https://dev.twitch.tv/docs/api/reference#get-extension-transactions | ||
*/ | ||
public function getExtensionTransactions(string $bearer, string $extensionId, array $transactionIds = [], int $first = null, string $after = null): ResponseInterface | ||
{ | ||
$queryParamsMap = []; | ||
|
||
$queryParamsMap[] = ['key' => 'extension_id', 'value' => $extensionId]; | ||
|
||
foreach ($transactionIds as $transactionId) { | ||
$queryParamsMap[] = ['key' => 'id', 'value' => $transactionId]; | ||
} | ||
|
||
if ($first) { | ||
$queryParamsMap[] = ['key' => 'first', 'value' => $first]; | ||
} | ||
|
||
if ($after) { | ||
$queryParamsMap[] = ['key' => 'after', 'value' => $after]; | ||
} | ||
|
||
return $this->callApi('extensions/transactions', $bearer, $queryParamsMap); | ||
} | ||
} |