diff --git a/spec/NewTwitchApi/NewTwitchApiSpec.php b/spec/NewTwitchApi/NewTwitchApiSpec.php index b9d926d..eb43ff2 100644 --- a/spec/NewTwitchApi/NewTwitchApiSpec.php +++ b/spec/NewTwitchApi/NewTwitchApiSpec.php @@ -6,6 +6,7 @@ use NewTwitchApi\Auth\OauthApi; use NewTwitchApi\Resources\AnalyticsApi; use NewTwitchApi\Resources\BitsApi; +use NewTwitchApi\Resources\ChannelPointsApi; use NewTwitchApi\Resources\EntitlementsApi; use NewTwitchApi\Resources\GamesApi; use NewTwitchApi\Resources\StreamsApi; @@ -37,6 +38,11 @@ function it_should_provide_bits_api() $this->getBitsApi()->shouldBeAnInstanceOf(BitsApi::class); } + function it_should_provide_channel_points_api() + { + $this->getChannelPointsApi()->shouldBeAnInstanceOf(ChannelPointsApi::class); + } + function it_should_provide_entitlements_api() { $this->getEntitlementsApi()->shouldBeAnInstanceOf(EntitlementsApi::class); diff --git a/spec/NewTwitchApi/Resources/ChannelPointsApiSpec.php b/spec/NewTwitchApi/Resources/ChannelPointsApiSpec.php new file mode 100644 index 0000000..c902ac7 --- /dev/null +++ b/spec/NewTwitchApi/Resources/ChannelPointsApiSpec.php @@ -0,0 +1,47 @@ +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); + } +} diff --git a/src/NewTwitchApi/NewTwitchApi.php b/src/NewTwitchApi/NewTwitchApi.php index 96893be..f0e55e4 100644 --- a/src/NewTwitchApi/NewTwitchApi.php +++ b/src/NewTwitchApi/NewTwitchApi.php @@ -9,6 +9,7 @@ use NewTwitchApi\Resources\AdsApi; use NewTwitchApi\Resources\AnalyticsApi; use NewTwitchApi\Resources\BitsApi; +use NewTwitchApi\Resources\ChannelPointsApi; use NewTwitchApi\Resources\ClipsApi; use NewTwitchApi\Resources\EntitlementsApi; use NewTwitchApi\Resources\GamesApi; @@ -29,6 +30,7 @@ class NewTwitchApi private $adsApi; private $analyticsApi; private $bitsApi; + private $channelPointsApi; private $clipsApi; private $entitlementsApi; private $gamesApi; @@ -49,6 +51,7 @@ public function __construct(Client $helixGuzzleClient, string $clientId, string $this->adsApi = new AdsApi($helixGuzzleClient); $this->analyticsApi = new AnalyticsApi($helixGuzzleClient); $this->bitsApi = new BitsApi($helixGuzzleClient); + $this->channelPointsApi = new ChannelPointsApi($helixGuzzleClient); $this->clipsApi = new ClipsApi($helixGuzzleClient); $this->entitlementsApi = new EntitlementsApi($helixGuzzleClient); $this->gamesApi = new GamesApi($helixGuzzleClient); @@ -84,6 +87,11 @@ public function getBitsApi(): BitsApi return $this->bitsApi; } + public function getChannelPointsApi(): ChannelPointsApi + { + return $this->channelPointsApi; + } + public function getClipsApi(): ClipsApi { return $this->clipsApi; diff --git a/src/NewTwitchApi/Resources/ChannelPointsApi.php b/src/NewTwitchApi/Resources/ChannelPointsApi.php new file mode 100644 index 0000000..a4cbb6f --- /dev/null +++ b/src/NewTwitchApi/Resources/ChannelPointsApi.php @@ -0,0 +1,129 @@ +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); + } +}