|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace NewTwitchApi\Resources; |
| 6 | + |
| 7 | +use GuzzleHttp\Exception\GuzzleException; |
| 8 | +use Psr\Http\Message\ResponseInterface; |
| 9 | + |
| 10 | +class ChannelPointsApi extends AbstractResource |
| 11 | +{ |
| 12 | + /** |
| 13 | + * @throws GuzzleException |
| 14 | + */ |
| 15 | + public function getCustomRewardById(string $bearer, string $broadcasterId, string $id, bool $onlyManageableRewards = null): ResponseInterface |
| 16 | + { |
| 17 | + return $this->getCustomReward($bearer, $broadcasterId, [$id], $onlyManageableRewards); |
| 18 | + } |
| 19 | + |
| 20 | + /** |
| 21 | + * @throws GuzzleException |
| 22 | + * @link https://dev.twitch.tv/docs/api/reference#get-custom-reward |
| 23 | + */ |
| 24 | + public function getCustomReward(string $bearer, string $broadcasterId, array $ids = [], bool $onlyManageableRewards = null): ResponseInterface |
| 25 | + { |
| 26 | + $queryParamsMap = []; |
| 27 | + |
| 28 | + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; |
| 29 | + |
| 30 | + foreach ($ids as $id) { |
| 31 | + $queryParamsMap[] = ['key' => 'id', 'value' => $id]; |
| 32 | + } |
| 33 | + |
| 34 | + if ($onlyManageableRewards) { |
| 35 | + $queryParamsMap[] = ['key' => 'only_manageable_rewards', 'value' => $onlyManageableRewards]; |
| 36 | + } |
| 37 | + |
| 38 | + return $this->callApi('channel_points/custom_rewards', $bearer, $queryParamsMap); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @throws GuzzleException |
| 43 | + * @link https://dev.twitch.tv/docs/api/reference#get-custom-reward-redemption |
| 44 | + */ |
| 45 | + 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 |
| 46 | + { |
| 47 | + $queryParamsMap = []; |
| 48 | + |
| 49 | + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; |
| 50 | + |
| 51 | + if ($rewardId) { |
| 52 | + $queryParamsMap[] = ['key' => 'reward_id', 'value' => $rewardId]; |
| 53 | + } |
| 54 | + |
| 55 | + foreach ($ids as $id) { |
| 56 | + $queryParamsMap[] = ['key' => 'id', 'value' => $id]; |
| 57 | + } |
| 58 | + |
| 59 | + if ($status) { |
| 60 | + $queryParamsMap[] = ['key' => 'status', 'value' => $status]; |
| 61 | + } |
| 62 | + |
| 63 | + if ($sort) { |
| 64 | + $queryParamsMap[] = ['key' => 'sort', 'value' => $sort]; |
| 65 | + } |
| 66 | + |
| 67 | + if ($after) { |
| 68 | + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; |
| 69 | + } |
| 70 | + |
| 71 | + if ($first) { |
| 72 | + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; |
| 73 | + } |
| 74 | + |
| 75 | + return $this->callApi('channel_points/custom_rewards/redemptions', $bearer, $queryParamsMap); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * @throws GuzzleException |
| 80 | + * @link https://dev.twitch.tv/docs/api/reference#get-bits-leaderboard |
| 81 | + */ |
| 82 | + public function getBitsLeaderboard(string $bearer, int $count = null, string $period = null, string $startedAt = null, string $userId = null): ResponseInterface |
| 83 | + { |
| 84 | + $queryParamsMap = []; |
| 85 | + |
| 86 | + if ($count) { |
| 87 | + $queryParamsMap[] = ['key' => 'count', 'value' => $count]; |
| 88 | + } |
| 89 | + |
| 90 | + if ($period) { |
| 91 | + $queryParamsMap[] = ['key' => 'period', 'value' => $period]; |
| 92 | + } |
| 93 | + |
| 94 | + if ($startedAt) { |
| 95 | + $queryParamsMap[] = ['key' => 'started_at', 'value' => $startedAt]; |
| 96 | + } |
| 97 | + |
| 98 | + if ($userId) { |
| 99 | + $queryParamsMap[] = ['key' => 'user_id', 'value' => $userId]; |
| 100 | + } |
| 101 | + |
| 102 | + return $this->callApi('bits/leaderboard', $bearer, $queryParamsMap); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * @throws GuzzleException |
| 107 | + * @link https://dev.twitch.tv/docs/api/reference#get-extension-transactions |
| 108 | + */ |
| 109 | + public function getExtensionTransactions(string $bearer, string $extensionId, array $transactionIds = [], int $first = null, string $after = null): ResponseInterface |
| 110 | + { |
| 111 | + $queryParamsMap = []; |
| 112 | + |
| 113 | + $queryParamsMap[] = ['key' => 'extension_id', 'value' => $extensionId]; |
| 114 | + |
| 115 | + foreach ($transactionIds as $transactionId) { |
| 116 | + $queryParamsMap[] = ['key' => 'id', 'value' => $transactionId]; |
| 117 | + } |
| 118 | + |
| 119 | + if ($first) { |
| 120 | + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; |
| 121 | + } |
| 122 | + |
| 123 | + if ($after) { |
| 124 | + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; |
| 125 | + } |
| 126 | + |
| 127 | + return $this->callApi('extensions/transactions', $bearer, $queryParamsMap); |
| 128 | + } |
| 129 | +} |
0 commit comments