From de6e0d6cf1f1fa48cda2f77b7bfcd494f029a787 Mon Sep 17 00:00:00 2001 From: Brandin Arsenault Date: Wed, 28 Jul 2021 15:03:38 -0300 Subject: [PATCH 1/6] Drop v5, rename NewTwitchApi to TwitchApi, Add Legacy Support --- README.md | 30 +- composer.json | 84 +-- spec/TwitchApi/Auth/AuthGuzzleClientSpec.php | 28 + spec/TwitchApi/Auth/OauthApiSpec.php | 118 ++++ spec/TwitchApi/HelixGuzzleClientSpec.php | 45 ++ spec/TwitchApi/Resources/AdsApiSpec.php | 24 + spec/TwitchApi/Resources/AnalyticsApiSpec.php | 102 ++++ spec/TwitchApi/Resources/BitsApiSpec.php | 54 ++ .../Resources/ChannelPointsApiSpec.php | 120 ++++ spec/TwitchApi/Resources/ChannelsApiSpec.php | 60 ++ spec/TwitchApi/Resources/ChatApiSpec.php | 60 ++ .../Resources/EntitlementsApiSpec.php | 84 +++ spec/TwitchApi/Resources/EventSubApiSpec.php | 249 +++++++++ spec/TwitchApi/Resources/GamesApiSpec.php | 60 ++ .../TwitchApi/Resources/ModerationApiSpec.php | 30 + spec/TwitchApi/Resources/PollsApiSpec.php | 60 ++ .../Resources/PredictionsApiSpec.php | 60 ++ spec/TwitchApi/Resources/ScheduleApiSpec.php | 84 +++ spec/TwitchApi/Resources/StreamsApiSpec.php | 156 ++++++ .../Resources/SubscriptionsApiSpec.php | 54 ++ spec/TwitchApi/Resources/TagsApiSpec.php | 66 +++ spec/TwitchApi/Resources/TeamsApiSpec.php | 54 ++ spec/TwitchApi/Resources/UsersApiSpec.php | 162 ++++++ spec/TwitchApi/Resources/VideosApiSpec.php | 102 ++++ spec/TwitchApi/Resources/WebhooksApiSpec.php | 42 ++ spec/TwitchApi/TwitchApiSpec.php | 136 +++++ src/Auth/AuthGuzzleClient.php | 19 + src/Auth/OauthApi.php | 149 +++++ src/HelixGuzzleClient.php | 48 ++ src/NewTwitchApi.php | 7 + src/NewTwitchApi/HelixGuzzleClient.php | 41 +- src/NewTwitchApi/NewTwitchApi.php | 211 +------ src/RequestGenerator.php | 81 +++ src/Resources/AbstractResource.php | 75 +++ src/Resources/AdsApi.php | 25 + src/Resources/AnalyticsApi.php | 81 +++ src/Resources/BitsApi.php | 78 +++ src/Resources/ChannelPointsApi.php | 149 +++++ src/Resources/ChannelsApi.php | 55 ++ src/Resources/ChatApi.php | 76 +++ src/Resources/ClipsApi.php | 87 +++ src/Resources/EntitlementsApi.php | 89 +++ src/Resources/EventSubApi.php | 523 ++++++++++++++++++ src/Resources/GamesApi.php | 51 ++ src/Resources/HypeTrainApi.php | 36 ++ src/Resources/ModerationApi.php | 135 +++++ src/Resources/PollsApi.php | 71 +++ src/Resources/PredictionsApi.php | 71 +++ src/Resources/ScheduleApi.php | 145 +++++ src/Resources/SearchApi.php | 57 ++ src/Resources/StreamsApi.php | 156 ++++++ src/Resources/SubscriptionsApi.php | 63 +++ src/Resources/TagsApi.php | 63 +++ src/Resources/TeamsApi.php | 59 ++ src/Resources/UsersApi.php | 207 +++++++ src/Resources/VideosApi.php | 77 +++ src/Resources/WebhooksApi.php | 28 + src/TwitchApi.php | 386 +++++-------- src/Webhooks/WebhooksSubscriptionApi.php | 161 ++++++ test/TwitchApi/Resources/UsersTest.php | 68 +++ 60 files changed, 5210 insertions(+), 542 deletions(-) create mode 100644 spec/TwitchApi/Auth/AuthGuzzleClientSpec.php create mode 100644 spec/TwitchApi/Auth/OauthApiSpec.php create mode 100644 spec/TwitchApi/HelixGuzzleClientSpec.php create mode 100644 spec/TwitchApi/Resources/AdsApiSpec.php create mode 100644 spec/TwitchApi/Resources/AnalyticsApiSpec.php create mode 100644 spec/TwitchApi/Resources/BitsApiSpec.php create mode 100644 spec/TwitchApi/Resources/ChannelPointsApiSpec.php create mode 100644 spec/TwitchApi/Resources/ChannelsApiSpec.php create mode 100644 spec/TwitchApi/Resources/ChatApiSpec.php create mode 100644 spec/TwitchApi/Resources/EntitlementsApiSpec.php create mode 100644 spec/TwitchApi/Resources/EventSubApiSpec.php create mode 100644 spec/TwitchApi/Resources/GamesApiSpec.php create mode 100644 spec/TwitchApi/Resources/ModerationApiSpec.php create mode 100644 spec/TwitchApi/Resources/PollsApiSpec.php create mode 100644 spec/TwitchApi/Resources/PredictionsApiSpec.php create mode 100644 spec/TwitchApi/Resources/ScheduleApiSpec.php create mode 100644 spec/TwitchApi/Resources/StreamsApiSpec.php create mode 100644 spec/TwitchApi/Resources/SubscriptionsApiSpec.php create mode 100644 spec/TwitchApi/Resources/TagsApiSpec.php create mode 100644 spec/TwitchApi/Resources/TeamsApiSpec.php create mode 100644 spec/TwitchApi/Resources/UsersApiSpec.php create mode 100644 spec/TwitchApi/Resources/VideosApiSpec.php create mode 100644 spec/TwitchApi/Resources/WebhooksApiSpec.php create mode 100644 spec/TwitchApi/TwitchApiSpec.php create mode 100644 src/Auth/AuthGuzzleClient.php create mode 100644 src/Auth/OauthApi.php create mode 100644 src/HelixGuzzleClient.php create mode 100644 src/NewTwitchApi.php create mode 100644 src/RequestGenerator.php create mode 100644 src/Resources/AbstractResource.php create mode 100644 src/Resources/AdsApi.php create mode 100644 src/Resources/AnalyticsApi.php create mode 100644 src/Resources/BitsApi.php create mode 100644 src/Resources/ChannelPointsApi.php create mode 100644 src/Resources/ChannelsApi.php create mode 100644 src/Resources/ChatApi.php create mode 100644 src/Resources/ClipsApi.php create mode 100644 src/Resources/EntitlementsApi.php create mode 100644 src/Resources/EventSubApi.php create mode 100644 src/Resources/GamesApi.php create mode 100644 src/Resources/HypeTrainApi.php create mode 100644 src/Resources/ModerationApi.php create mode 100644 src/Resources/PollsApi.php create mode 100644 src/Resources/PredictionsApi.php create mode 100644 src/Resources/ScheduleApi.php create mode 100644 src/Resources/SearchApi.php create mode 100644 src/Resources/StreamsApi.php create mode 100644 src/Resources/SubscriptionsApi.php create mode 100644 src/Resources/TagsApi.php create mode 100644 src/Resources/TeamsApi.php create mode 100644 src/Resources/UsersApi.php create mode 100644 src/Resources/VideosApi.php create mode 100644 src/Resources/WebhooksApi.php create mode 100644 src/Webhooks/WebhooksSubscriptionApi.php create mode 100644 test/TwitchApi/Resources/UsersTest.php diff --git a/README.md b/README.md index c48bb67..bf65f87 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,9 @@ $twitch_client_id = 'TWITCH_CLIENT_ID'; $twitch_client_secret = 'TWITCH_CLIENT_SECRET'; $twitch_scopes = ''; -$helixGuzzleClient = new \NewTwitchApi\HelixGuzzleClient($twitch_client_id); -$newTwitchApi = new \NewTwitchApi\NewTwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); -$oauth = $newTwitchApi->getOauthApi(); +$helixGuzzleClient = new \TwitchApi\HelixGuzzleClient($twitch_client_id); +$TwitchApi = new \TwitchApi\TwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); +$oauth = $TwitchApi->getOauthApi(); try { $token = $oauth->getAppAccessToken($twitch_scopes ?? ''); @@ -62,9 +62,9 @@ $twitch_client_id = 'TWITCH_CLIENT_ID'; $twitch_client_secret = 'TWITCH_CLIENT_SECRET'; $twitch_scopes = ''; -$helixGuzzleClient = new \NewTwitchApi\HelixGuzzleClient($twitch_client_id); -$newTwitchApi = new \NewTwitchApi\NewTwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); -$oauth = $newTwitchApi->getOauthApi(); +$helixGuzzleClient = new \TwitchApi\HelixGuzzleClient($twitch_client_id); +$TwitchApi = new \TwitchApi\TwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); +$oauth = $TwitchApi->getOauthApi(); // Get the code from URI $code = $_GET['code']; @@ -104,9 +104,9 @@ $twitch_client_secret = 'TWITCH_CLIENT_SECRET'; $twitch_scopes = ''; $user_refresh_token = 'REFRESH_TOKEN'; -$helixGuzzleClient = new \NewTwitchApi\HelixGuzzleClient($twitch_client_id); -$newTwitchApi = new \NewTwitchApi\NewTwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); -$oauth = $newTwitchApi->getOauthApi(); +$helixGuzzleClient = new \TwitchApi\HelixGuzzleClient($twitch_client_id); +$TwitchApi = new \TwitchApi\TwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); +$oauth = $TwitchApi->getOauthApi(); try { $token = $oauth->getAppAccessToken($twitch_scopes ?? ''); @@ -124,11 +124,11 @@ try { ### Usage of the API Classes -Everything stems from the `NewTwitchApi` class. However, if you want to individually instantiate `UsersApi`, `OauthApi`, etc. you are free to do so. +Everything stems from the `TwitchApi` class. However, if you want to individually instantiate `UsersApi`, `OauthApi`, etc. you are free to do so. The API calls generally return an object implementing `ResponseInterface`. Since you are getting the full `Response` object, you'll need to handle its contents, e.g. by decoding then into an object with `json_decode()`. This library does not assume this is what you want to do, so it does not do this for you automatically. This library simply acts as a middleman between your code and Twitch, providing you with the raw responses the Twitch API returns. -The individual API classes that can be called from `NewTwitchApi` correspond to the [Twitch API documentation](https://dev.twitch.tv/docs/api/). The rest of the API classes are based on the resources listed [here](https://dev.twitch.tv/docs/api/reference/). The methods in the classes generally correspond to the endpoints for each resource. The naming convention was chosen to try and match the Twitch documentation. Each primary endpoint method (not convenience or helper methods) should have an `@link` annotation with a URL to that endpoint's specific documentation. +The individual API classes that can be called from `TwitchApi` correspond to the [Twitch API documentation](https://dev.twitch.tv/docs/api/). The rest of the API classes are based on the resources listed [here](https://dev.twitch.tv/docs/api/reference/). The methods in the classes generally correspond to the endpoints for each resource. The naming convention was chosen to try and match the Twitch documentation. Each primary endpoint method (not convenience or helper methods) should have an `@link` annotation with a URL to that endpoint's specific documentation. Here is a sample of retrieving a users table from their access token: @@ -140,14 +140,14 @@ $twitch_access_token = 'the token'; // The Guzzle client used can be the included `HelixGuzzleClient` class, for convenience. // You can also use a mock, fake, or other double for testing, of course. -$helixGuzzleClient = new \NewTwitchApi\HelixGuzzleClient($twitch_client_id); +$helixGuzzleClient = new \TwitchApi\HelixGuzzleClient($twitch_client_id); -// Instantiate NewTwitchApi. Can be done in a service layer and injected as well. -$newTwitchApi = new NewTwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); +// Instantiate TwitchApi. Can be done in a service layer and injected as well. +$TwitchApi = new TwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); try { // Make the API call. A ResponseInterface object is returned. - $response = $newTwitchApi->getUsersApi()->getUserByAccessToken($twitch_access_token); + $response = $TwitchApi->getUsersApi()->getUserByAccessToken($twitch_access_token); // Get and decode the actual content sent by Twitch. $responseContent = json_decode($response->getBody()->getContents()); diff --git a/composer.json b/composer.json index a4521f8..e61c81c 100644 --- a/composer.json +++ b/composer.json @@ -1,44 +1,50 @@ { - "name": "nicklaw5/twitch-api-php", - "type": "library", - "description": "A Twitch API client for PHP.", - "keywords": ["twitch", "twitch.tv", "twitch-tv", "twitch-api", "api"], - "homepage": "http://github.com/nicklaw5/twitch-api-php", - "license": "MIT", - "authors": [ - { - "name": "Nicholas Law", - "homepage": "https://github.com/nicklaw5" - }, - { - "name": "Brian Zwahr", - "homepage": "https://github.com/echosa" - }, - { - "name": "Brandin Arsenault", - "homepage": "https://github.com/brandinarsenault" - } - ], - "require": { - "php": ">=7.4.0", - "ext-json": "*", - "guzzlehttp/guzzle": "~6.0|~7.0" + "name": "nicklaw5/twitch-api-php", + "type": "library", + "description": "A Twitch API client for PHP.", + "keywords": [ + "twitch", + "twitch.tv", + "twitch-tv", + "twitch-api", + "api" + ], + "homepage": "http://github.com/nicklaw5/twitch-api-php", + "license": "MIT", + "authors": [ + { + "name": "Nicholas Law", + "homepage": "https://github.com/nicklaw5" }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^2.13", - "phpspec/phpspec": "^6.1", - "phpunit/phpunit": "^8.5" + { + "name": "Brian Zwahr", + "homepage": "https://github.com/echosa" }, - "autoload": { - "psr-4": { - "TwitchApi\\": "src/", - "NewTwitchApi\\": "src/NewTwitchApi", - "NewTwitchApi\\Tests\\": "test/NewTwitchApi" - } - }, - "autoload-dev": { - "psr-4": { - "Tests\\": "test/" - } + { + "name": "Brandin Arsenault", + "homepage": "https://github.com/brandinarsenault" + } + ], + "require": { + "php": ">=7.4.0", + "ext-json": "*", + "guzzlehttp/guzzle": "~6.0|~7.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.13", + "phpspec/phpspec": "^6.1", + "phpunit/phpunit": "^8.5" + }, + "autoload": { + "psr-4": { + "TwitchApi\\": "src/", + "TwitchApi\\Tests\\": "test/TwitchApi", + "NewTwitchApi\\": "src/NewTwitchApi" + } + }, + "autoload-dev": { + "psr-4": { + "Tests\\": "test/" } + } } diff --git a/spec/TwitchApi/Auth/AuthGuzzleClientSpec.php b/spec/TwitchApi/Auth/AuthGuzzleClientSpec.php new file mode 100644 index 0000000..47169b0 --- /dev/null +++ b/spec/TwitchApi/Auth/AuthGuzzleClientSpec.php @@ -0,0 +1,28 @@ +beConstructedThrough('getClient'); + $this->shouldHaveType('\GuzzleHttp\Client'); + + /** @var Uri $uri */ + $uri = $this->getConfig('base_uri'); + $uri->getScheme()->shouldBe('https'); + $uri->getHost()->shouldBe('id.twitch.tv'); + $uri->getPath()->shouldBe('/oauth2/'); + } + + function it_should_have_passed_in_config_params_instead_of_defaults() + { + $this->beConstructedThrough('getClient', [['base_uri' => 'https://different.url']]); + $this->shouldHaveType('\GuzzleHttp\Client'); + $this->getConfig('base_uri')->getHost()->shouldBe('different.url'); + } +} diff --git a/spec/TwitchApi/Auth/OauthApiSpec.php b/spec/TwitchApi/Auth/OauthApiSpec.php new file mode 100644 index 0000000..bc41dde --- /dev/null +++ b/spec/TwitchApi/Auth/OauthApiSpec.php @@ -0,0 +1,118 @@ +beConstructedWith('client-id', 'client-secret', $guzzleClient); + } + + function it_should_get_auth_url(Client $guzzleClient) + { + $guzzleClient->getConfig('base_uri')->willReturn('https://id.twitch.tv/oauth2/'); + $this->getAuthUrl('https://redirect.url')->shouldReturn( + 'https://id.twitch.tv/oauth2/authorize?client_id=client-id&redirect_uri=https://redirect.url&response_type=code&scope=' + ); + } + + function it_should_get_access_token(Client $guzzleClient, Response $response) + { + $request = new Request( + 'POST', + 'token' + ); + $guzzleClient->send($request, ['json' => [ + 'client_id' => 'client-id', + 'client_secret' => 'client-secret', + 'grant_type' => 'authorization_code', + 'redirect_uri' => 'https://redirect.url', + 'code' => 'user-code-from-twitch', + 'state' => null, + ]])->willReturn($response); + + $this->getUserAccessToken('user-code-from-twitch', 'https://redirect.url')->shouldBe($response); + } + + function it_should_get_refresh_token(Client $guzzleClient, Response $response) + { + $request = new Request( + 'POST', + 'token' + ); + $guzzleClient->send($request, ['json' => [ + 'client_id' => 'client-id', + 'client_secret' => 'client-secret', + 'grant_type' => 'refresh_token', + 'refresh_token' => 'user-refresh-token', + ]])->willReturn($response); + + $this->refreshToken('user-refresh-token')->shouldBe($response); + } + + function it_should_validate_access_token(Client $guzzleClient, Response $response) + { + $request = new Request( + 'GET', + 'validate', + [ + 'Authorization' => 'OAuth user-access-token', + ] + ); + $guzzleClient->send($request, [])->willReturn($response); + + $this->validateAccessToken('user-access-token')->shouldBe($response); + } + + function it_should_return_true_if_access_token_is_valid(Client $guzzleClient, Response $response) + { + $request = new Request( + 'GET', + 'validate', + [ + 'Authorization' => 'OAuth user-access-token', + ] + ); + $response->getStatusCode()->willReturn(200); + $guzzleClient->send($request, [])->willReturn($response); + + $this->isValidAccessToken('user-access-token')->shouldReturn(true); + } + + function it_should_return_false_if_access_token_is_invalid(Client $guzzleClient, Response $response) + { + $request = new Request( + 'GET', + 'validate', + [ + 'Authorization' => 'OAuth invalid-user-access-token', + ] + ); + $response->getStatusCode()->willReturn(401); + $guzzleClient->send($request, [])->willReturn($response); + + $this->isValidAccessToken('invalid-user-access-token')->shouldReturn(false); + } + + function it_should_get_app_access_token(Client $guzzleClient, Response $response) + { + $request = new Request( + 'POST', + 'token' + ); + $guzzleClient->send($request, ['json' => [ + 'client_id' => 'client-id', + 'client_secret' => 'client-secret', + 'grant_type' => 'client_credentials', + 'scope' => '', + ]])->willReturn($response); + + $this->getAppAccessToken()->shouldBe($response); + } +} diff --git a/spec/TwitchApi/HelixGuzzleClientSpec.php b/spec/TwitchApi/HelixGuzzleClientSpec.php new file mode 100644 index 0000000..bb2195a --- /dev/null +++ b/spec/TwitchApi/HelixGuzzleClientSpec.php @@ -0,0 +1,45 @@ +beConstructedWith('TEST_CLIENT_ID'); + } + + function it_should_have_correct_base_uri() + { + $this->shouldHaveType('\TwitchApi\HelixGuzzleClient'); + + /** @var Uri $uri */ + $uri = $this->getConfig('base_uri'); + $uri->getScheme()->shouldBe('https'); + $uri->getHost()->shouldBe('api.twitch.tv'); + $uri->getPath()->shouldBe('/helix/'); + } + + function it_should_have_client_id_header() + { + $this->shouldHaveType('\TwitchApi\HelixGuzzleClient'); + $this->getConfig('headers')->shouldHaveKeyWithValue('Client-ID', 'TEST_CLIENT_ID'); + } + + function it_should_have_json_content_type_header() + { + + $this->shouldHaveType('\TwitchApi\HelixGuzzleClient'); + $this->getConfig('headers')->shouldHaveKeyWithValue('Content-Type', 'application/json'); + } + + function it_should_have_passed_in_config_params_instead_of_defaults() + { + $this->beConstructedWith('TEST_CLIENT_ID', ['base_uri' => 'https://different.url']); + $this->shouldHaveType('\TwitchApi\HelixGuzzleClient'); + $this->getConfig('base_uri')->getHost()->shouldBe('different.url'); + } +} diff --git a/spec/TwitchApi/Resources/AdsApiSpec.php b/spec/TwitchApi/Resources/AdsApiSpec.php new file mode 100644 index 0000000..4a0e6a8 --- /dev/null +++ b/spec/TwitchApi/Resources/AdsApiSpec.php @@ -0,0 +1,24 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_start_commercial(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'channels/commercial', 'TEST_TOKEN', [], [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'length', 'value' => 30]])->willReturn($request); + $this->startCommercial('TEST_TOKEN', '123', 30)->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/AnalyticsApiSpec.php b/spec/TwitchApi/Resources/AnalyticsApiSpec.php new file mode 100644 index 0000000..640c0ff --- /dev/null +++ b/spec/TwitchApi/Resources/AnalyticsApiSpec.php @@ -0,0 +1,102 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_get_extension_analytics(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'analytics/extensions', 'TEST_TOKEN', [], [])->willReturn($request); + $this->getExtensionAnalytics('TEST_TOKEN')->shouldBe($response); + } + + function it_should_get_extension_analytics_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'analytics/extensions', 'TEST_TOKEN', [['key' => 'extension_id', 'value' => '1']], [])->willReturn($request); + $this->getExtensionAnalytics('TEST_TOKEN', '1')->shouldBe($response); + } + + function it_should_get_extension_analytics_with_type(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'analytics/extensions', 'TEST_TOKEN', [['key' => 'type', 'value' => 'overview_v1']], [])->willReturn($request); + $this->getExtensionAnalytics('TEST_TOKEN', null, 'overview_v1')->shouldBe($response); + } + + function it_should_get_extension_analytics_with_first(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'analytics/extensions', 'TEST_TOKEN', [['key' => 'first', 'value' => '100']], [])->willReturn($request); + $this->getExtensionAnalytics('TEST_TOKEN', null, null, 100)->shouldBe($response); + } + + function it_should_get_extension_analytics_with_after(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'analytics/extensions', 'TEST_TOKEN', [['key' => 'after', 'value' => 'abc']], [])->willReturn($request); + $this->getExtensionAnalytics('TEST_TOKEN', null, null, null, 'abc')->shouldBe($response); + } + + function it_should_get_extension_analytics_with_started_at(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'analytics/extensions', 'TEST_TOKEN', [['key' => 'started_at', 'value' => '2020-01-01T00:00:00Z']], [])->willReturn($request); + $this->getExtensionAnalytics('TEST_TOKEN', null, null, null, null, '2020-01-01T00:00:00Z')->shouldBe($response); + } + + function it_should_get_extension_analytics_with_ended_at(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'analytics/extensions', 'TEST_TOKEN', [['key' => 'ended_at', 'value' => '2020-01-01T00:00:00Z']], [])->willReturn($request); + $this->getExtensionAnalytics('TEST_TOKEN', null, null, null, null, null, '2020-01-01T00:00:00Z')->shouldBe($response); + } + + function it_should_get_game_analytics(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'analytics/games', 'TEST_TOKEN', [], [])->willReturn($request); + $this->getGameAnalytics('TEST_TOKEN')->shouldBe($response); + } + + function it_should_get_game_analytics_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'analytics/games', 'TEST_TOKEN', [['key' => 'game_id', 'value' => '1']], [])->willReturn($request); + $this->getGameAnalytics('TEST_TOKEN', '1')->shouldBe($response); + } + + function it_should_get_game_analytics_with_type(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'analytics/games', 'TEST_TOKEN', [['key' => 'type', 'value' => 'overview_v1']], [])->willReturn($request); + $this->getGameAnalytics('TEST_TOKEN', null, 'overview_v1')->shouldBe($response); + } + + function it_should_get_game_analytics_with_first(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'analytics/games', 'TEST_TOKEN', [['key' => 'first', 'value' => '100']], [])->willReturn($request); + $this->getGameAnalytics('TEST_TOKEN', null, null, 100)->shouldBe($response); + } + + function it_should_get_game_analytics_with_after(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'analytics/games', 'TEST_TOKEN', [['key' => 'after', 'value' => 'abc']], [])->willReturn($request); + $this->getGameAnalytics('TEST_TOKEN', null, null, null, 'abc')->shouldBe($response); + } + + function it_should_get_game_analytics_with_started_at(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'analytics/games', 'TEST_TOKEN', [['key' => 'started_at', 'value' => '2020-01-01T00:00:00Z']], [])->willReturn($request); + $this->getGameAnalytics('TEST_TOKEN', null, null, null, null, '2020-01-01T00:00:00Z')->shouldBe($response); + } + + function it_should_get_game_analytics_with_ended_at(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'analytics/games', 'TEST_TOKEN', [['key' => 'ended_at', 'value' => '2020-01-01T00:00:00Z']], [])->willReturn($request); + $this->getGameAnalytics('TEST_TOKEN', null, null, null, null, null, '2020-01-01T00:00:00Z')->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/BitsApiSpec.php b/spec/TwitchApi/Resources/BitsApiSpec.php new file mode 100644 index 0000000..aa6d952 --- /dev/null +++ b/spec/TwitchApi/Resources/BitsApiSpec.php @@ -0,0 +1,54 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_getcheermotes(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'bits/cheermotes', 'TEST_TOKEN', [], [])->willReturn($request); + $this->getCheermotes('TEST_TOKEN')->shouldBe($response); + } + + function it_should_getcheermotes_by_broadcaster_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'bits/cheermotes', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getCheermotes('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_extension_transactions(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'extensions/transactions', 'TEST_TOKEN', [['key' => 'extension_id', 'value' => '1']], [])->willReturn($request); + $this->getExtensionTransactions('TEST_TOKEN', '1')->shouldBe($response); + } + + function it_should_extension_transactions_with_transaction_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'extensions/transactions', 'TEST_TOKEN', [['key' => 'extension_id', 'value' => '1'], ['key' => 'id', 'value' => '321']], [])->willReturn($request); + $this->getExtensionTransactions('TEST_TOKEN', '1', ['321'])->shouldBe($response); + } + + function it_should_extension_transactions_with_first(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'extensions/transactions', 'TEST_TOKEN', [['key' => 'extension_id', 'value' => '1'], ['key' => 'first', 'value' => '100']], [])->willReturn($request); + $this->getExtensionTransactions('TEST_TOKEN', '1', [], 100)->shouldBe($response); + } + + function it_should_extension_transactions_with_after(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'extensions/transactions', 'TEST_TOKEN', [['key' => 'extension_id', 'value' => '1'], ['key' => 'after', 'value' => '100']], [])->willReturn($request); + $this->getExtensionTransactions('TEST_TOKEN', '1', [], null, 100)->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/ChannelPointsApiSpec.php b/spec/TwitchApi/Resources/ChannelPointsApiSpec.php new file mode 100644 index 0000000..6a4928a --- /dev/null +++ b/spec/TwitchApi/Resources/ChannelPointsApiSpec.php @@ -0,0 +1,120 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_get_custom_reward(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getCustomReward('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_custom_reward_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321']], [])->willReturn($request); + $this->getCustomReward('TEST_TOKEN', '123', ['321'])->shouldBe($response); + } + + function it_should_get_custom_reward_by_ids(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321'], ['key' => 'id', 'value' => '456']], [])->willReturn($request); + $this->getCustomReward('TEST_TOKEN', '123', ['321', '456'])->shouldBe($response); + } + + function it_should_get_custom_reward_by_id_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321'], ['key' => 'only_manageable_rewards', 'value' => 1]], [])->willReturn($request); + $this->getCustomReward('TEST_TOKEN', '123', ['321'], true)->shouldBe($response); + } + + function it_should_get_custom_reward_by_ids_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321'], ['key' => 'id', 'value' => '456'], ['key' => 'only_manageable_rewards', 'value' => 1]], [])->willReturn($request); + $this->getCustomReward('TEST_TOKEN', '123', ['321', '456'], true)->shouldBe($response); + } + + function it_should_get_custom_reward_redemption(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'channel_points/custom_rewards/redemptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'reward_id', 'value' => '321']], [])->willReturn($request); + $this->getCustomRewardRedemption('TEST_TOKEN', '123', '321')->shouldBe($response); + } + + function it_should_get_custom_reward_redemption_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'channel_points/custom_rewards/redemptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'reward_id', 'value' => '321'], ['key' => 'status', 'value' => 'UNFULFILLED'], ['key' => 'sort', 'value' => 'NEWEST'], ['key' => 'after', 'value' => 'abc'], ['key' => 'first', 'value' => 100]], [])->willReturn($request); + $this->getCustomRewardRedemption('TEST_TOKEN', '123', '321', [], 'UNFULFILLED', 'NEWEST', 'abc', 100)->shouldBe($response); + } + + function it_should_get_custom_reward_redemption_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'channel_points/custom_rewards/redemptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'reward_id', 'value' => '321'], ['key' => 'id', 'value' => '111']], [])->willReturn($request); + $this->getCustomRewardRedemption('TEST_TOKEN', '123', '321', ['111'])->shouldBe($response); + } + + function it_should_get_custom_reward_redemption_by_ids(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'channel_points/custom_rewards/redemptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'reward_id', 'value' => '321'], ['key' => 'id', 'value' => '111'], ['key' => 'id', 'value' => '222']], [])->willReturn($request); + $this->getCustomRewardRedemption('TEST_TOKEN', '123', '321', ['111', '222'])->shouldBe($response); + } + + function it_should_create_custom_reward(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'title', 'value' => 'test 123'], ['key' => 'cost', 'value' => 100]])->willReturn($request); + $this->createCustomReward('TEST_TOKEN', '123', 'test 123', 100)->shouldBe($response); + } + + function it_should_create_custom_reward_with_one_opt(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'title', 'value' => 'test 123'], ['key' => 'cost', 'value' => 100], ['key' => 'prompt', 'value' => 'What is your name?']])->willReturn($request); + $this->createCustomReward('TEST_TOKEN', '123', 'test 123', 100, ['prompt' => 'What is your name?'])->shouldBe($response); + } + + function it_should_create_custom_reward_with_multiple_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'title', 'value' => 'test 123'], ['key' => 'cost', 'value' => 100], ['key' => 'prompt', 'value' => 'What is your name?'], ['key' => 'is_enabled', 'value' => 1]])->willReturn($request); + $this->createCustomReward('TEST_TOKEN', '123', 'test 123', 100, ['prompt' => 'What is your name?', 'is_enabled' => 1])->shouldBe($response); + } + + function it_should_update_custom_reward(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PATCH', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321']], [])->willReturn($request); + $this->updateCustomReward('TEST_TOKEN', '123', '321')->shouldBe($response); + } + + function it_should_update_custom_reward_with_one_opt(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PATCH', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321']], [['key' => 'prompt', 'value' => 'What is your name?']])->willReturn($request); + $this->updateCustomReward('TEST_TOKEN', '123', '321', ['prompt' => 'What is your name?'])->shouldBe($response); + } + + function it_should_update_custom_reward_with_multiple_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PATCH', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321']], [['key' => 'prompt', 'value' => 'What is your name?'], ['key' => 'is_enabled', 'value' => 1]])->willReturn($request); + $this->updateCustomReward('TEST_TOKEN', '123', '321', ['prompt' => 'What is your name?', 'is_enabled' => 1])->shouldBe($response); + } + + function it_should_delete_custom_reward(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('DELETE', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321']], [])->willReturn($request); + $this->deleteCustomReward('TEST_TOKEN', '123', '321')->shouldBe($response); + } + + function it_should_update_redemption_status(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PATCH', 'channel_points/custom_rewards/redemptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'reward_id', 'value' => '456'], ['key' => 'id', 'value' => '789']], [['key' => 'status', 'value' => 'FULFILLED']])->willReturn($request); + $this->updateRedemptionStatus('TEST_TOKEN', '123', '456', '789', 'FULFILLED')->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/ChannelsApiSpec.php b/spec/TwitchApi/Resources/ChannelsApiSpec.php new file mode 100644 index 0000000..d99245b --- /dev/null +++ b/spec/TwitchApi/Resources/ChannelsApiSpec.php @@ -0,0 +1,60 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_get_channel_info(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'channels', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getChannelInfo('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_channel_editors(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'channels/editors', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getChannelEditors('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_modify_channel_with_game_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PATCH', 'channels', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'game_id', 'value' => '0']])->willReturn($request); + $this->modifyChannelInfo('TEST_TOKEN', '123', ['game_id' => '0'])->shouldBe($response); + } + + function it_should_modify_channel_with_language(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PATCH', 'channels', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'broadcaster_language', 'value' => 'en']])->willReturn($request); + $this->modifyChannelInfo('TEST_TOKEN', '123', ['broadcaster_language' => 'en'])->shouldBe($response); + } + + function it_should_modify_channel_with_title(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PATCH', 'channels', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'title', 'value' => 'test 123']])->willReturn($request); + $this->modifyChannelInfo('TEST_TOKEN', '123', ['title' => 'test 123'])->shouldBe($response); + } + + function it_should_modify_channel_with_delay(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PATCH', 'channels', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'delay', 'value' => 5]])->willReturn($request); + $this->modifyChannelInfo('TEST_TOKEN', '123', ['delay' => 5])->shouldBe($response); + } + + function it_should_modify_channel_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PATCH', 'channels', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'game_id', 'value' => '0'], ['key' => 'broadcaster_language', 'value' => 'en'], ['key' => 'title', 'value' => 'test 123'], ['key' => 'delay', 'value' => 5]])->willReturn($request); + $this->modifyChannelInfo('TEST_TOKEN', '123', ['game_id' => '0', 'broadcaster_language' => 'en', 'title' => 'test 123', 'delay' => 5])->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/ChatApiSpec.php b/spec/TwitchApi/Resources/ChatApiSpec.php new file mode 100644 index 0000000..ca7f2c7 --- /dev/null +++ b/spec/TwitchApi/Resources/ChatApiSpec.php @@ -0,0 +1,60 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_get_channel_emotes(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'chat/emotes', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getChannelEmotes('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_global_emotes(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'chat/emotes/global', 'TEST_TOKEN', [], [])->willReturn($request); + $this->getGlobalEmotes('TEST_TOKEN')->shouldBe($response); + } + + function it_should_get_one_emote_set(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'chat/emotes/set', 'TEST_TOKEN', [['key' => 'emote_set_id', 'value' => '123']], [])->willReturn($request); + $this->getEmoteSets('TEST_TOKEN', ['123'])->shouldBe($response); + } + + function it_should_get_one_emote_set_with_helper_function(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'chat/emotes/set', 'TEST_TOKEN', [['key' => 'emote_set_id', 'value' => '123']], [])->willReturn($request); + $this->getEmoteSet('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_multiple_emote_sets(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'chat/emotes/set', 'TEST_TOKEN', [['key' => 'emote_set_id', 'value' => '123'], ['key' => 'emote_set_id', 'value' => '456']], [])->willReturn($request); + $this->getEmoteSets('TEST_TOKEN', ['123', '456'])->shouldBe($response); + } + + function it_should_get_channel_chat_badges(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'chat/badges', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getChannelChatBadges('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_global_chat_badges(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'chat/badges/global', 'TEST_TOKEN', [], [])->willReturn($request); + $this->getGlobalChatBadges('TEST_TOKEN')->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/EntitlementsApiSpec.php b/spec/TwitchApi/Resources/EntitlementsApiSpec.php new file mode 100644 index 0000000..f86b34b --- /dev/null +++ b/spec/TwitchApi/Resources/EntitlementsApiSpec.php @@ -0,0 +1,84 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_create_entitlement_grants_upload_url(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'entitlements/upload', 'TEST_TOKEN', [['key' => 'manifest_id', 'value' => '123'], ['key' => 'type', 'value' => 'bulk_drops_grant']], [])->willReturn($request); + $this->createEntitlementGrantsUploadURL('TEST_TOKEN', '123', 'bulk_drops_grant')->shouldBe($response); + } + + function it_should_create_entitlement_grants_upload_url_shorthand(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'entitlements/upload', 'TEST_TOKEN', [['key' => 'manifest_id', 'value' => '123'], ['key' => 'type', 'value' => 'bulk_drops_grant']], [])->willReturn($request); + $this->createEntitlementGrantsUploadURL('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_code_status(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'entitlements/codes', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'code', 'value' => 'abc']], [])->willReturn($request); + $this->getCodeStatus('TEST_TOKEN', '123', ['abc'])->shouldBe($response); + } + + function it_should_get_codes_status(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'entitlements/codes', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'code', 'value' => 'abc'], ['key' => 'code', 'value' => 'def']], [])->willReturn($request); + $this->getCodeStatus('TEST_TOKEN', '123', ['abc', 'def'])->shouldBe($response); + } + + function it_should_get_drop_entitlements_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'entitlements/drops', 'TEST_TOKEN', [['key' => 'id', 'value' => '123']], [])->willReturn($request); + $this->getDropsEntitlements('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_drop_entitlements_by_user_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'entitlements/drops', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123']], [])->willReturn($request); + $this->getDropsEntitlements('TEST_TOKEN', null, '123')->shouldBe($response); + } + + function it_should_get_drop_entitlements_by_user_id_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'entitlements/drops', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'after', 'value' => 'abc'], ['key' => 'first', 'value' => 100]], [])->willReturn($request); + $this->getDropsEntitlements('TEST_TOKEN', null, '123', null, 'abc', 100)->shouldBe($response); + } + + function it_should_get_drop_entitlements_by_game_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'entitlements/drops', 'TEST_TOKEN', [['key' => 'game_id', 'value' => '123']], [])->willReturn($request); + $this->getDropsEntitlements('TEST_TOKEN', null, null, '123')->shouldBe($response); + } + + function it_should_get_drop_entitlements_by_game_id_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'entitlements/drops', 'TEST_TOKEN', [['key' => 'game_id', 'value' => '123'], ['key' => 'after', 'value' => 'abc'], ['key' => 'first', 'value' => 100]], [])->willReturn($request); + $this->getDropsEntitlements('TEST_TOKEN', null, null, '123', 'abc', 100)->shouldBe($response); + } + + function it_should_redeem_code(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'entitlements/code', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'code', 'value' => 'abc']], [])->willReturn($request); + $this->redeemCode('TEST_TOKEN', '123', ['abc'])->shouldBe($response); + } + + function it_should_redeem_codes(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'entitlements/code', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'code', 'value' => 'abc'], ['key' => 'code', 'value' => 'def']], [])->willReturn($request); + $this->redeemCode('TEST_TOKEN', '123', ['abc', 'def'])->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/EventSubApiSpec.php b/spec/TwitchApi/Resources/EventSubApiSpec.php new file mode 100644 index 0000000..4b56d63 --- /dev/null +++ b/spec/TwitchApi/Resources/EventSubApiSpec.php @@ -0,0 +1,249 @@ + 'type', 'value' => $type]; + $bodyParams[] = ['key' => 'version', 'value' => $version]; + $bodyParams[] = ['key' => 'condition', 'value' => $condition]; + $bodyParams[] = ['key' => 'transport', 'value' => [ + 'method' => 'webhook', + 'callback' => $this->callback, + 'secret' => $this->secret, + ] + ]; + + return $requestGenerator->generate('POST', 'eventsub/subscriptions', $this->bearer, [], $bodyParams); + } + + function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_get_event_sub_subscription(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'eventsub/subscriptions', 'TEST_TOKEN', [], [])->willReturn($request); + $this->getEventSubSubscription('TEST_TOKEN')->shouldBe($response); + } + + function it_should_get_event_sub_subscription_with_status(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'eventsub/subscriptions', 'TEST_TOKEN', [['key' => 'status', 'value' => 'enabled']], [])->willReturn($request); + $this->getEventSubSubscription('TEST_TOKEN', 'enabled')->shouldBe($response); + } + + function it_should_get_event_sub_subscription_with_type(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'eventsub/subscriptions', 'TEST_TOKEN', [['key' => 'type', 'value' => 'channel.update']], [])->willReturn($request); + $this->getEventSubSubscription('TEST_TOKEN', null, 'channel.update')->shouldBe($response); + } + + function it_should_delete_event_sub_subscription(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('DELETE', 'eventsub/subscriptions', 'TEST_TOKEN', [['key' => 'id', 'value' => '123']], [])->willReturn($request); + $this->deleteEventSubSubscription('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_subscribe_to_channel_update(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.update', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelUpdate($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_follow(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.follow', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelFollow($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_subscribe(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.subscribe', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelSubscribe($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_subscription_end(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.subscription.end', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelSubscriptionEnd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_subscription_gift(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.subscription.gift', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelSubscriptionGift($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_subscription_message(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.subscription.message', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelSubscriptionMessage($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_cheer(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.cheer', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelCheer($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_raid(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.raid', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelRaid($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_ban(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.ban', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelBan($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_unban(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.unban', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelUnban($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_moderator_add(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.moderator.add', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelModeratorAdd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_moderator_remove(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.moderator.remove', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelModeratorRemove($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_points_custom_reward_add(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.channel_points_custom_reward.add', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelPointsCustomRewardAdd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_points_custom_reward_update(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.channel_points_custom_reward.update', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelPointsCustomRewardUpdate($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_points_custom_reward_remove(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.channel_points_custom_reward.remove', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelPointsCustomRewardRemove($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_points_custom_reward_redemption_add(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.channel_points_custom_reward_redemption.add', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelPointsCustomRewardRedemptionAdd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_points_custom_reward_redemption_update(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.channel_points_custom_reward_redemption.update', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelPointsCustomRewardRedemptionUpdate($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_poll_begin(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.poll.begin', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelPollBegin($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_poll_progress(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.poll.progress', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelPollProgress($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_poll_endn(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.poll.end', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelPollEnd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_prediction_begin(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.prediction.begin', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelPredictionBegin($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_prediction_progress(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.prediction.progress', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelPredictionProgress($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_prediction_lock(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.prediction.lock', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelPredictionLock($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_prediction_endn(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.prediction.end', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelPredictionEnd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_hype_train_begin(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.hype_train.begin', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelHypeTrainBegin($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_hype_train_progress(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.hype_train.progress', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelHypeTrainProgress($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_channel_hype_train_end(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('channel.hype_train.end', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToChannelHypeTrainEnd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_stream_online(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('stream.online', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToStreamOnline($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_stream_offline(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('stream.offline', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToStreamOffline($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_user_update(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('user.update', '1', ['user_id' => '12345'], $requestGenerator)->willReturn($request); + $this->subscribeToUserUpdate($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); + } + + function it_should_subscribe_to_extension_bits_transaction_create(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $this->createEventSubSubscription('extension.bits_transaction.create', 'beta', ['extension_client_id' => 'deadbeef'], $requestGenerator)->willReturn($request); + $this->subscribeToExtensionBitsTransactionCreate($this->bearer, $this->secret, $this->callback, 'deadbeef')->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/GamesApiSpec.php b/spec/TwitchApi/Resources/GamesApiSpec.php new file mode 100644 index 0000000..e71b760 --- /dev/null +++ b/spec/TwitchApi/Resources/GamesApiSpec.php @@ -0,0 +1,60 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_get_games_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'games', 'TEST_TOKEN', [['key' => 'id', 'value' => '123']], [])->willReturn($request); + $this->getGames('TEST_TOKEN', ['123'])->shouldBe($response); + } + + function it_should_get_games_by_ids(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'games', 'TEST_TOKEN', [['key' => 'id', 'value' => '123'], ['key' => 'id', 'value' => '456']], [])->willReturn($request); + $this->getGames('TEST_TOKEN', ['123', '456'])->shouldBe($response); + } + + function it_should_get_games_by_name(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'games', 'TEST_TOKEN', [['key' => 'name', 'value' => 'abc']], [])->willReturn($request); + $this->getGames('TEST_TOKEN', [], ['abc'])->shouldBe($response); + } + + function it_should_get_games_by_names(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'games', 'TEST_TOKEN', [['key' => 'name', 'value' => 'abc'], ['key' => 'name', 'value' => 'def']], [])->willReturn($request); + $this->getGames('TEST_TOKEN', [], ['abc', 'def'])->shouldBe($response); + } + + function it_should_get_games_by_ids_and_names(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'games', 'TEST_TOKEN', [['key' => 'id', 'value' => '123'], ['key' => 'id', 'value' => '456'], ['key' => 'name', 'value' => 'abc'], ['key' => 'name', 'value' => 'def']], [])->willReturn($request); + $this->getGames('TEST_TOKEN', ['123', '456'], ['abc', 'def'])->shouldBe($response); + } + + function it_should_get_top_games(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'games/top', 'TEST_TOKEN', [], [])->willReturn($request); + $this->getTopGames('TEST_TOKEN')->shouldBe($response); + } + + function it_should_get_top_games_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'games/top', 'TEST_TOKEN', [['key' => 'first', 'value' => 100], ['key' => 'before', 'value' => 'abc'], ['key' => 'after', 'value' => 'def']], [])->willReturn($request); + $this->getTopGames('TEST_TOKEN', 100, 'abc', 'def')->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/ModerationApiSpec.php b/spec/TwitchApi/Resources/ModerationApiSpec.php new file mode 100644 index 0000000..95b4ce8 --- /dev/null +++ b/spec/TwitchApi/Resources/ModerationApiSpec.php @@ -0,0 +1,30 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_check_automod_status(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'moderation/enforcements/status', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'msg_id', 'value' => '456'], ['key' => 'msg_text', 'value' => 'test 123'], ['key' => 'user_id', 'value' => '789']])->willReturn($request); + $this->checkAutoModStatus('TEST_TOKEN', '123', '456', 'test 123', '789')->shouldBe($response); + } + + function it_should_release_held_message(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'moderation/automod/message', 'TEST_TOKEN', [], [['key' => 'user_id', 'value' => '123'], ['key' => 'msg_id', 'value' => '456'], ['key' => 'action', 'value' => 'ALLOW']])->willReturn($request); + $this->manageHeldAutoModMessage('TEST_TOKEN', '123', '456', 'ALLOW')->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/PollsApiSpec.php b/spec/TwitchApi/Resources/PollsApiSpec.php new file mode 100644 index 0000000..17310f1 --- /dev/null +++ b/spec/TwitchApi/Resources/PollsApiSpec.php @@ -0,0 +1,60 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_get_polls(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'polls', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getPolls('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_polls_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'polls', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321']], [])->willReturn($request); + $this->getPolls('TEST_TOKEN', '123', ['321'])->shouldBe($response); + } + + function it_should_get_polls_by_ids(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'polls', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321'], ['key' => 'id', 'value' => '456']], [])->willReturn($request); + $this->getPolls('TEST_TOKEN', '123', ['321', '456'])->shouldBe($response); + } + + function it_should_get_polls_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'polls', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'after', 'value' => 'abc'], ['key' => 'first', 'value' => 100]], [])->willReturn($request); + $this->getPolls('TEST_TOKEN', '123', [], 'abc', 100)->shouldBe($response); + } + + function it_should_create_a_poll(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'polls', 'TEST_TOKEN', [], [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'title', 'value' => 'What is my name?'], ['key' => 'choices', 'value' => [['title' => 'John'], ['title' => 'Doe']]], ['key' => 'duration', 'value' => 15]])->willReturn($request); + $this->createPoll('TEST_TOKEN', '123', 'What is my name?', [['title' => 'John'], ['title' => 'Doe']], 15)->shouldBe($response); + } + + function it_should_create_a_poll_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'polls', 'TEST_TOKEN', [], [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'title', 'value' => 'What is my name?'], ['key' => 'choices', 'value' => [['title' => 'John'], ['title' => 'Doe']]], ['key' => 'duration', 'value' => 15], ['key' => 'bits_voting_enabled', 'value' => 1]])->willReturn($request); + $this->createPoll('TEST_TOKEN', '123', 'What is my name?', [['title' => 'John'], ['title' => 'Doe']], 15, ['bits_voting_enabled' => 1])->shouldBe($response); + } + + function it_should_end_a_poll(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PATCH', 'polls', 'TEST_TOKEN', [], [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '456'], ['key' => 'status', 'value' => 'TERMINATED']])->willReturn($request); + $this->endPoll('TEST_TOKEN', '123', '456', 'TERMINATED')->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/PredictionsApiSpec.php b/spec/TwitchApi/Resources/PredictionsApiSpec.php new file mode 100644 index 0000000..3e02a27 --- /dev/null +++ b/spec/TwitchApi/Resources/PredictionsApiSpec.php @@ -0,0 +1,60 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_get_predictions(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'predictions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getPredictions('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_predictions_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'predictions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321']], [])->willReturn($request); + $this->getPredictions('TEST_TOKEN', '123', ['321'])->shouldBe($response); + } + + function it_should_get_predictions_by_ids(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'predictions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321'], ['key' => 'id', 'value' => '456']], [])->willReturn($request); + $this->getPredictions('TEST_TOKEN', '123', ['321', '456'])->shouldBe($response); + } + + function it_should_get_predictions_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'predictions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'after', 'value' => 'abc'], ['key' => 'first', 'value' => 100]], [])->willReturn($request); + $this->getPredictions('TEST_TOKEN', '123', [], 'abc', 100)->shouldBe($response); + } + + function it_should_create_a_prediction(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'predictions', 'TEST_TOKEN', [], [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'title', 'value' => 'Will the coin land on heads or tails?'], ['key' => 'outcomes', 'value' => [['title' => 'Heads'], ['title' => 'Tails']]], ['key' => 'prediction_window', 'value' => 15]])->willReturn($request); + $this->createPrediction('TEST_TOKEN', '123', 'Will the coin land on heads or tails?', [['title' => 'Heads'], ['title' => 'Tails']], 15)->shouldBe($response); + } + + function it_should_end_a_prediction(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PATCH', 'predictions', 'TEST_TOKEN', [], [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '456'], ['key' => 'status', 'value' => 'CANCELLED']])->willReturn($request); + $this->endPrediction('TEST_TOKEN', '123', '456', 'CANCELLED')->shouldBe($response); + } + + function it_should_resolve_a_prediction(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PATCH', 'predictions', 'TEST_TOKEN', [], [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '456'], ['key' => 'status', 'value' => 'RESOLVED'], ['key' => 'winning_outcome_id', 'value' => '1']])->willReturn($request); + $this->endPrediction('TEST_TOKEN', '123', '456', 'RESOLVED', '1')->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/ScheduleApiSpec.php b/spec/TwitchApi/Resources/ScheduleApiSpec.php new file mode 100644 index 0000000..914c981 --- /dev/null +++ b/spec/TwitchApi/Resources/ScheduleApiSpec.php @@ -0,0 +1,84 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_get_channel_stream_schedule(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'schedule', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getChannelStreamSchedule('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_channel_stream_schedule_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'schedule', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'start_time', 'value' => '2021-06-15T23:08:20+00:00'], ['key' => 'utc_offset', 'value' => '240'], ['key' => 'first', 'value' => 25], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request); + $this->getChannelStreamSchedule('TEST_TOKEN', '123', [], '2021-06-15T23:08:20+00:00', '240', 25, 'abc')->shouldBe($response); + } + + function it_should_get_a_channel_stream_schedule(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'schedule', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '456']], [])->willReturn($request); + $this->getChannelStreamSchedule('TEST_TOKEN', '123', ['456'])->shouldBe($response); + } + + function it_should_get_multiple_channel_stream_schedules(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'schedule', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '456'], ['key' => 'id', 'value' => '789']], [])->willReturn($request); + $this->getChannelStreamSchedule('TEST_TOKEN', '123', ['456', '789'])->shouldBe($response); + } + + function it_should_get_channel_icalendar_with_no_auth(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'schedule/icalendar', null, [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getChanneliCalendar(null, '123')->shouldBe($response); + } + + function it_should_get_channel_icalendar_with_auth(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'schedule/icalendar', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getChanneliCalendar('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_update_channel_stream_schedule(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PATCH', 'schedule/settings', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'is_vacation_enabled', 'value' => true], ['key' => 'vacation_start_time', 'value' => '2021-06-15T23:08:20+00:00'], ['key' => 'vacation_end_time', 'value' => '2021-06-22T23:08:20+00:00'], ['key' => 'timezone', 'value' => 'America/New_York']], [])->willReturn($request); + $this->updateChannelStreamSchedule('TEST_TOKEN', '123', true, '2021-06-15T23:08:20+00:00', '2021-06-22T23:08:20+00:00', 'America/New_York')->shouldBe($response); + } + + function it_should_create_channel_stream_schedule_segment(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'schedule/segment', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'start_time', 'value' => '2021-06-15T23:08:20+00:00'], ['key' => 'timezone', 'value' => 'America/New_York'], ['key' => 'is_recurring', 'value' => true]])->willReturn($request); + $this->createChannelStreamScheduleSegment('TEST_TOKEN', '123', '2021-06-15T23:08:20+00:00', 'America/New_York', true)->shouldBe($response); + } + + function it_should_create_channel_stream_schedule_segment_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'schedule/segment', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'start_time', 'value' => '2021-06-15T23:08:20+00:00'], ['key' => 'timezone', 'value' => 'America/New_York'], ['key' => 'is_recurring', 'value' => true], ['key' => 'duration', 'value' => '240']])->willReturn($request); + $this->createChannelStreamScheduleSegment('TEST_TOKEN', '123', '2021-06-15T23:08:20+00:00', 'America/New_York', true, ['duration' => '240'])->shouldBe($response); + } + + function it_should_update_channel_stream_schedule_segment(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PATCH', 'schedule/segment', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '456']], [['key' => 'start_time', 'value' => '2021-06-15T23:08:20+00:00'], ['key' => 'timezone', 'value' => 'America/New_York'], ['key' => 'is_canceled', 'value' => true], ['key' => 'duration', 'value' => '240']])->willReturn($request); + $this->updateChannelStreamScheduleSegment('TEST_TOKEN', '123', '456', ['start_time' => '2021-06-15T23:08:20+00:00', 'timezone' => 'America/New_York', 'is_canceled' => true, 'duration' => '240'])->shouldBe($response); + } + + function it_should_delete_channel_stream_schedule_segment(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('DELETE', 'schedule/segment', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '456']], [])->willReturn($request); + $this->deleteChannelStreamScheduleSegment('TEST_TOKEN', '123', '456')->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/StreamsApiSpec.php b/spec/TwitchApi/Resources/StreamsApiSpec.php new file mode 100644 index 0000000..ea1afee --- /dev/null +++ b/spec/TwitchApi/Resources/StreamsApiSpec.php @@ -0,0 +1,156 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_get_streams_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123']], [])->willReturn($request); + $this->getStreams('TEST_TOKEN', ['123'])->shouldBe($response); + } + + function it_should_get_streams_by_id_with_helper(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123']], [])->willReturn($request); + $this->getStreamForUserId('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_streams_by_ids(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'user_id', 'value' => '321']], [])->willReturn($request); + $this->getStreams('TEST_TOKEN', ['123', '321'])->shouldBe($response); + } + + function it_should_get_streams_by_username(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'user_login', 'value' => 'test']], [])->willReturn($request); + $this->getStreams('TEST_TOKEN', [], ['test'])->shouldBe($response); + } + + function it_should_get_streams_by_username_with_helper(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'user_login', 'value' => 'test']], [])->willReturn($request); + $this->getStreamForUsername('TEST_TOKEN', 'test')->shouldBe($response); + } + + function it_should_get_streams_by_usernames(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'user_login', 'value' => 'test'], ['key' => 'user_login', 'value' => 'user']], [])->willReturn($request); + $this->getStreams('TEST_TOKEN', [], ['test', 'user'])->shouldBe($response); + } + + function it_should_get_streams_by_id_and_username(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'user_login', 'value' => 'test']], [])->willReturn($request); + $this->getStreams('TEST_TOKEN', ['123'], ['test'])->shouldBe($response); + } + + function it_should_get_streams_by_game_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'game_id', 'value' => '123']], [])->willReturn($request); + $this->getStreams('TEST_TOKEN', [], [], ['123'])->shouldBe($response); + } + + function it_should_get_streams_by_game_id_with_helper(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'game_id', 'value' => '123']], [])->willReturn($request); + $this->getStreamsByGameId('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_streams_by_game_ids(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'game_id', 'value' => '123'], ['key' => 'game_id', 'value' => '456']], [])->willReturn($request); + $this->getStreams('TEST_TOKEN', [], [], ['123', '456'])->shouldBe($response); + } + + function it_should_get_streams_by_language(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'language', 'value' => 'en']], [])->willReturn($request); + $this->getStreams('TEST_TOKEN', [], [], [], ['en'])->shouldBe($response); + } + + function it_should_get_streams_by_language_with_helper(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'language', 'value' => 'en']], [])->willReturn($request); + $this->getStreamsByLanguage('TEST_TOKEN', 'en')->shouldBe($response); + } + + function it_should_get_streams_by_languages(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'language', 'value' => 'en'], ['key' => 'language', 'value' => 'fr']], [])->willReturn($request); + $this->getStreams('TEST_TOKEN', [], [], [], ['en', 'fr'])->shouldBe($response); + } + + function it_should_get_streams_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'first', 'value' => 100], ['key' => 'before', 'value' => 'abc'], ['key' => 'after', 'value' => 'def']], [])->willReturn($request); + $this->getStreams('TEST_TOKEN', [], [], [], [], 100, 'abc', 'def')->shouldBe($response); + } + + function it_should_get_stream_key(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams/key', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getStreamKey('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_stream_markers_by_user_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams/markers', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123']], [])->willReturn($request); + $this->getStreamMarkers('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_stream_markers_by_user_id_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams/markers', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'first', 'value' => 100], ['key' => 'before', 'value' => 'abc'], ['key' => 'after', 'value' => 'def']], [])->willReturn($request); + $this->getStreamMarkers('TEST_TOKEN', '123', null, 100, 'abc', 'def')->shouldBe($response); + } + + function it_should_get_stream_markers_by_video_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams/markers', 'TEST_TOKEN', [['key' => 'video_id', 'value' => '123']], [])->willReturn($request); + $this->getStreamMarkers('TEST_TOKEN', null, '123')->shouldBe($response); + } + + function it_should_get_stream_markers_by_video_id_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams/markers', 'TEST_TOKEN', [['key' => 'video_id', 'value' => '123'], ['key' => 'first', 'value' => 100], ['key' => 'before', 'value' => 'abc'], ['key' => 'after', 'value' => 'def']], [])->willReturn($request); + $this->getStreamMarkers('TEST_TOKEN', null, '123', 100, 'abc', 'def')->shouldBe($response); + } + + function it_should_get_followed_streams(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams/followed', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123']], [])->willReturn($request); + $this->getFollowedStreams('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_followed_streams_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams/followed', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'first', 'value' => 100], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request); + $this->getFollowedStreams('TEST_TOKEN', '123', 100, 'abc')->shouldBe($response); + } + + function it_should_create_stream_marker(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'streams/markers', 'TEST_TOKEN', [], [['key' => 'user_id', 'value' => '123']])->willReturn($request); + $this->createStreamMarker('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_create_stream_marker_with_description(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'streams/markers', 'TEST_TOKEN', [], [['key' => 'user_id', 'value' => '123'], ['key' => 'description', 'value' => 'This is a marker']])->willReturn($request); + $this->createStreamMarker('TEST_TOKEN', '123', 'This is a marker')->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/SubscriptionsApiSpec.php b/spec/TwitchApi/Resources/SubscriptionsApiSpec.php new file mode 100644 index 0000000..9851174 --- /dev/null +++ b/spec/TwitchApi/Resources/SubscriptionsApiSpec.php @@ -0,0 +1,54 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_get_broadcaster_subscriptions(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'subscriptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getBroadcasterSubscriptions('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_broadcaster_subscriptions_with_all(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'subscriptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'first', 'value' => 100], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request); + $this->getBroadcasterSubscriptions('TEST_TOKEN', '123', 100, 'abc')->shouldBe($response); + } + + function it_should_get_broadcaster_subscribers(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'subscriptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getBroadcasterSubscribers('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_broadcaster_subscribers_with_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'subscriptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => '321']], [])->willReturn($request); + $this->getBroadcasterSubscribers('TEST_TOKEN', '123', ['321'])->shouldBe($response); + } + + function it_should_get_broadcaster_subscribers_with_ids(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'subscriptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => '321'], ['key' => 'user_id', 'value' => '456']], [])->willReturn($request); + $this->getBroadcasterSubscribers('TEST_TOKEN', '123', ['321', '456'])->shouldBe($response); + } + + function it_should_check_user_subscriptions(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'subscriptions/user', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => '456']], [])->willReturn($request); + $this->checkUserSubscription('TEST_TOKEN', '123', '456')->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/TagsApiSpec.php b/spec/TwitchApi/Resources/TagsApiSpec.php new file mode 100644 index 0000000..004f522 --- /dev/null +++ b/spec/TwitchApi/Resources/TagsApiSpec.php @@ -0,0 +1,66 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_get_all_tags(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'tags/streams', 'TEST_TOKEN', [], [])->willReturn($request); + $this->getAllStreamTags('TEST_TOKEN')->shouldBe($response); + } + + function it_should_get_all_tags_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'tags/streams', 'TEST_TOKEN', [['key' => 'tag_id', 'value' => '123']], [])->willReturn($request); + $this->getAllStreamTags('TEST_TOKEN', ['123'])->shouldBe($response); + } + + function it_should_get_all_tags_with_first(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'tags/streams', 'TEST_TOKEN', [['key' => 'first', 'value' => 100]], [])->willReturn($request); + $this->getAllStreamTags('TEST_TOKEN', [], 100)->shouldBe($response); + } + + function it_should_get_all_tags_with_after(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'tags/streams', 'TEST_TOKEN', [['key' => 'after', 'value' => 'abc']], [])->willReturn($request); + $this->getAllStreamTags('TEST_TOKEN', [], null, 'abc')->shouldBe($response); + } + + function it_should_get_stream_tags(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'streams/tags', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getStreamTags('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_replace_stream_tags(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PUT', 'streams/tags', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->replaceStreamTags('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_replace_stream_tags_with_one_tag(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PUT', 'streams/tags', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'tag_ids', 'value' => ['456']]])->willReturn($request); + $this->replaceStreamTags('TEST_TOKEN', '123', ['456'])->shouldBe($response); + } + + function it_should_replace_stream_tags_with_multiple_tags(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PUT', 'streams/tags', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'tag_ids', 'value' => ['456', '789']]])->willReturn($request); + $this->replaceStreamTags('TEST_TOKEN', '123', ['456', '789'])->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/TeamsApiSpec.php b/spec/TwitchApi/Resources/TeamsApiSpec.php new file mode 100644 index 0000000..8356751 --- /dev/null +++ b/spec/TwitchApi/Resources/TeamsApiSpec.php @@ -0,0 +1,54 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_get_channel_teams(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'teams/channel', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getChannelTeams('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_teams(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'teams', 'TEST_TOKEN', [], [])->willReturn($request); + $this->getTeams('TEST_TOKEN')->shouldBe($response); + } + + function it_should_get_teams_by_name(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'teams', 'TEST_TOKEN', [['key' => 'name', 'value' => 'abc']], [])->willReturn($request); + $this->getTeams('TEST_TOKEN', 'abc')->shouldBe($response); + } + + function it_should_get_teams_by_name_with_helper_function(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'teams', 'TEST_TOKEN', [['key' => 'name', 'value' => 'abc']], [])->willReturn($request); + $this->getTeamsByName('TEST_TOKEN', 'abc')->shouldBe($response); + } + + function it_should_get_teams_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'teams', 'TEST_TOKEN', [['key' => 'id', 'value' => '123']], [])->willReturn($request); + $this->getTeams('TEST_TOKEN', null, '123')->shouldBe($response); + } + + function it_should_get_teams_by_id_with_helper_function(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'teams', 'TEST_TOKEN', [['key' => 'id', 'value' => '123']], [])->willReturn($request); + $this->getTeamsById('TEST_TOKEN', '123')->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/UsersApiSpec.php b/spec/TwitchApi/Resources/UsersApiSpec.php new file mode 100644 index 0000000..c988648 --- /dev/null +++ b/spec/TwitchApi/Resources/UsersApiSpec.php @@ -0,0 +1,162 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_get_user_with_access_token(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'users', 'TEST_TOKEN', [], [])->willReturn($request); + $this->getUsers('TEST_TOKEN')->shouldBe($response); + } + + function it_should_get_user_with_access_token_convenience_method(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'users', 'TEST_TOKEN', [], [])->willReturn($request); + $this->getUserByAccessToken('TEST_TOKEN')->shouldBe($response); + } + + function it_should_get_users_by_ids(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'users', 'TEST_TOKEN', [['key' => 'id', 'value' => '12345'], ['key' => 'id', 'value' => '98765']], [])->willReturn($request); + $this->getUsers('TEST_TOKEN', ['12345', '98765'])->shouldBe($response); + } + + function it_should_get_users_by_usernames(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'users', 'TEST_TOKEN', [['key' => 'login', 'value' => 'twitchuser'], ['key' => 'login', 'value' => 'anotheruser']], [])->willReturn($request); + $this->getUsers('TEST_TOKEN', [], ['twitchuser', 'anotheruser'])->shouldBe($response); + } + + function it_should_get_users_by_id_and_username(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'users', 'TEST_TOKEN', [['key' => 'id', 'value' => '12345'], ['key' => 'id', 'value' => '98765'], ['key' => 'login', 'value' => 'twitchuser'], ['key' => 'login', 'value' => 'anotheruser']], [])->willReturn($request); + $this->getUsers('TEST_TOKEN', ['12345', '98765'], ['twitchuser', 'anotheruser'])->shouldBe($response); + } + + function it_should_get_a_single_user_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'users', 'TEST_TOKEN', [['key' => 'id', 'value' => '12345']], [])->willReturn($request); + $this->getUserById('TEST_TOKEN', '12345')->shouldBe($response); + } + + function it_should_get_a_single_user_by_username(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'users', 'TEST_TOKEN', [['key' => 'login', 'value' => 'twitchuser']], [])->willReturn($request); + $this->getUserByUsername('TEST_TOKEN', 'twitchuser')->shouldBe($response); + } + + function it_should_get_users_follows_by_follower_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'users/follows', 'TEST_TOKEN', [['key' => 'from_id', 'value' => '12345']], [])->willReturn($request); + $this->getUsersFollows('TEST_TOKEN', '12345')->shouldBe($response); + } + + function it_should_get_users_follows_by_followed_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'users/follows', 'TEST_TOKEN', [['key' => 'to_id', 'value' => '12345']], [])->willReturn($request); + $this->getUsersFollows('TEST_TOKEN', null, '12345')->shouldBe($response); + } + + function it_should_get_users_follows_by_follower_id_and_followed_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'users/follows', 'TEST_TOKEN', [['key' => 'from_id', 'value' => '12345'], ['key' => 'to_id', 'value' => '98765']], [])->willReturn($request); + $this->getUsersFollows('TEST_TOKEN', '12345', '98765')->shouldBe($response); + } + + function it_should_get_users_follows_page_by_first(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'users/follows', 'TEST_TOKEN', [['key' => 'first', 'value' => 42]], [])->willReturn($request); + $this->getUsersFollows('TEST_TOKEN', null, null, 42)->shouldBe($response); + } + + function it_should_get_users_follows_page_by_after(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'users/follows', 'TEST_TOKEN', [['key' => 'after', 'value' => '42']], [])->willReturn($request); + $this->getUsersFollows('TEST_TOKEN', null, null, null, '42')->shouldBe($response); + } + + function it_should_get_users_follows_by_everything(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'users/follows', 'TEST_TOKEN', [['key' => 'from_id', 'value' => '12345'], ['key' => 'to_id', 'value' => '98765'], ['key' => 'first', 'value' => 42], ['key' => 'after', 'value' => '99']], [])->willReturn($request); + $this->getUsersFollows('TEST_TOKEN', '12345', '98765', 42, '99')->shouldBe($response); + } + + function it_should_create_a_follow(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'users/follows', 'TEST_TOKEN', [['key' => 'from_id', 'value' => '123'], ['key' => 'to_id', 'value' => '321']], [])->willReturn($request); + $this->createUserFollow('TEST_TOKEN', '123', '321')->shouldBe($response); + } + + function it_should_create_a_follow_with_notifications(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'users/follows', 'TEST_TOKEN', [['key' => 'from_id', 'value' => '123'], ['key' => 'to_id', 'value' => '321'], ['key' => 'allow_notifications', 'value' => 1]], [])->willReturn($request); + $this->createUserFollow('TEST_TOKEN', '123', '321', true)->shouldBe($response); + } + + function it_should_create_a_follow_without_notifications(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('POST', 'users/follows', 'TEST_TOKEN', [['key' => 'from_id', 'value' => '123'], ['key' => 'to_id', 'value' => '321'], ['key' => 'allow_notifications', 'value' => 0]], [])->willReturn($request); + $this->createUserFollow('TEST_TOKEN', '123', '321', false)->shouldBe($response); + } + + function it_should_delete_a_follow(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('DELETE', 'users/follows', 'TEST_TOKEN', [['key' => 'from_id', 'value' => '123'], ['key' => 'to_id', 'value' => '321']], [])->willReturn($request); + $this->deleteUserFollow('TEST_TOKEN', '123', '321')->shouldBe($response); + } + + function it_should_update_user(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PUT', 'users', 'TEST_TOKEN', [], [])->willReturn($request); + $this->updateUser('TEST_TOKEN')->shouldBe($response); + } + + function it_should_update_user_description(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PUT', 'users', 'TEST_TOKEN', [['key' => 'description', 'value' => 'test']], [])->willReturn($request); + $this->updateUser('TEST_TOKEN', 'test')->shouldBe($response); + } + + function it_should_get_user_block_list(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'users/blocks', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); + $this->getUserBlockList('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_get_user_block_list_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'users/blocks', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'first', 'value' => 100], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request); + $this->getUserBlockList('TEST_TOKEN', '123', 100, 'abc')->shouldBe($response); + } + + function it_should_block_user(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PUT', 'users/blocks', 'TEST_TOKEN', [['key' => 'target_user_id', 'value' => '123']], [])->willReturn($request); + $this->blockUser('TEST_TOKEN', '123')->shouldBe($response); + } + + function it_should_block_user_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('PUT', 'users/blocks', 'TEST_TOKEN', [['key' => 'target_user_id', 'value' => '123'], ['key' => 'source_context', 'value' => 'chat'], ['key' => 'reason', 'value' => 'spam']], [])->willReturn($request); + $this->blockUser('TEST_TOKEN', '123', 'chat', 'spam')->shouldBe($response); + } + + function it_should_unblock_user(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('DELETE', 'users/blocks', 'TEST_TOKEN', [['key' => 'target_user_id', 'value' => '123']], [])->willReturn($request); + $this->unblockUser('TEST_TOKEN', '123')->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/VideosApiSpec.php b/spec/TwitchApi/Resources/VideosApiSpec.php new file mode 100644 index 0000000..7d3fa20 --- /dev/null +++ b/spec/TwitchApi/Resources/VideosApiSpec.php @@ -0,0 +1,102 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_get_video_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'id', 'value' => '123']], [])->willReturn($request); + $this->getVideos('TEST_TOKEN', ['123'])->shouldBe($response); + } + + function it_should_get_videos_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'id', 'value' => '123'], ['key' => 'id', 'value' => '321']], [])->willReturn($request); + $this->getVideos('TEST_TOKEN', ['123', '321'])->shouldBe($response); + } + + function it_should_get_videos_by_user_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123']], [])->willReturn($request); + $this->getVideos('TEST_TOKEN', [], '123')->shouldBe($response); + } + + function it_should_get_videos_by_game_id(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'game_id', 'value' => '123']], [])->willReturn($request); + $this->getVideos('TEST_TOKEN', [], null, '123')->shouldBe($response); + } + + function it_should_get_videos_with_first(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'first', 'value' => 100]], [])->willReturn($request); + $this->getVideos('TEST_TOKEN', [], null, null, 100)->shouldBe($response); + } + + function it_should_get_videos_with_before(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'before', 'value' => 'abc']], [])->willReturn($request); + $this->getVideos('TEST_TOKEN', [], null, null, null, 'abc')->shouldBe($response); + } + + function it_should_get_videos_with_after(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'after', 'value' => 'cba']], [])->willReturn($request); + $this->getVideos('TEST_TOKEN', [], null, null, null, null, 'cba')->shouldBe($response); + } + + function it_should_get_videos_with_language(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'language', 'value' => 'en']], [])->willReturn($request); + $this->getVideos('TEST_TOKEN', [], null, null, null, null, null, 'en')->shouldBe($response); + } + + function it_should_get_videos_with_period(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'period', 'value' => 'all']], [])->willReturn($request); + $this->getVideos('TEST_TOKEN', [], null, null, null, null, null, null, 'all')->shouldBe($response); + } + + function it_should_get_videos_with_sort(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'sort', 'value' => 'trending']], [])->willReturn($request); + $this->getVideos('TEST_TOKEN', [], null, null, null, null, null, null, null, 'trending')->shouldBe($response); + } + + function it_should_get_videos_with_type(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'type', 'value' => 'all']], [])->willReturn($request); + $this->getVideos('TEST_TOKEN', [], null, null, null, null, null, null, null, null, 'all')->shouldBe($response); + } + + function it_should_get_videos_with_everything(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'game_id', 'value' => '321'], ['key' => 'first', 'value' => 100], ['key' => 'before', 'value' => 'abc'], ['key' => 'after', 'value' => 'def'], ['key' => 'language', 'value' => 'en'], ['key' => 'period', 'value' => 'all'], ['key' => 'sort', 'value' => 'trending'], ['key' => 'type', 'value' => 'all']], [])->willReturn($request); + $this->getVideos('TEST_TOKEN', [], '123', '321', 100, 'abc', 'def', 'en', 'all', 'trending', 'all')->shouldBe($response); + } + + function it_should_delete_videos(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('DELETE', 'videos', 'TEST_TOKEN', [['key' => 'id', 'value' => '123']], [])->willReturn($request); + $this->deleteVideos('TEST_TOKEN', ['123'])->shouldBe($response); + } + + function it_should_delete_multiple_videos(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('DELETE', 'videos', 'TEST_TOKEN', [['key' => 'id', 'value' => '123'], ['key' => 'id', 'value' => '321']], [])->willReturn($request); + $this->deleteVideos('TEST_TOKEN', ['123', '321'])->shouldBe($response); + } +} diff --git a/spec/TwitchApi/Resources/WebhooksApiSpec.php b/spec/TwitchApi/Resources/WebhooksApiSpec.php new file mode 100644 index 0000000..f15438c --- /dev/null +++ b/spec/TwitchApi/Resources/WebhooksApiSpec.php @@ -0,0 +1,42 @@ +beConstructedWith($guzzleClient, $requestGenerator); + $guzzleClient->send($request)->willReturn($response); + } + + function it_should_get_webhooks_subscriptions(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'webhooks/subscriptions', 'TEST_TOKEN', [], [])->willReturn($request); + $this->getWebhookSubscriptions('TEST_TOKEN')->shouldBe($response); + } + + function it_should_get_webhooks_subscriptions_with_first(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'webhooks/subscriptions', 'TEST_TOKEN', [['key' => 'first', 'value' => 100]], [])->willReturn($request); + $this->getWebhookSubscriptions('TEST_TOKEN', 100)->shouldBe($response); + } + + function it_should_get_webhooks_subscriptions_with_after(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'webhooks/subscriptions', 'TEST_TOKEN', [['key' => 'after', 'value' => 'abc']], [])->willReturn($request); + $this->getWebhookSubscriptions('TEST_TOKEN', null, 'abc')->shouldBe($response); + } + + function it_should_get_webhooks_subscriptions_with_everything(RequestGenerator $requestGenerator, Request $request, Response $response) + { + $requestGenerator->generate('GET', 'webhooks/subscriptions', 'TEST_TOKEN', [['key' => 'first', 'value' => 100], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request); + $this->getWebhookSubscriptions('TEST_TOKEN', 100, 'abc')->shouldBe($response); + } +} diff --git a/spec/TwitchApi/TwitchApiSpec.php b/spec/TwitchApi/TwitchApiSpec.php new file mode 100644 index 0000000..40cecbc --- /dev/null +++ b/spec/TwitchApi/TwitchApiSpec.php @@ -0,0 +1,136 @@ +beConstructedWith($guzzleClient, 'client-id', 'client-secret'); + } + + function it_should_provide_oauth_api() + { + $this->getOauthApi()->shouldBeAnInstanceOf(OauthApi::class); + } + + function it_should_provide_ads_api() + { + $this->getAdsApi()->shouldBeAnInstanceOf(AdsApi::class); + } + + function it_should_provide_analytics_api() + { + $this->getAnalyticsApi()->shouldBeAnInstanceOf(AnalyticsApi::class); + } + + 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_channels_api() + { + $this->getChannelsApi()->shouldBeAnInstanceOf(ChannelsApi::class); + } + + function it_should_provide_entitlements_api() + { + $this->getEntitlementsApi()->shouldBeAnInstanceOf(EntitlementsApi::class); + } + + function it_should_provide_event_sub_api() + { + $this->getEventSubApi()->shouldBeAnInstanceOf(EventSubApi::class); + } + + function it_should_provide_games_api() + { + $this->getGamesApi()->shouldBeAnInstanceOf(GamesApi::class); + } + + function it_should_provide_polls_api() + { + $this->getPollsApi()->shouldBeAnInstanceOf(PollsApi::class); + } + + function it_should_provide_predictions_api() + { + $this->getPredictionsApi()->shouldBeAnInstanceOf(PredictionsApi::class); + } + + function it_should_provide_schedule_api() + { + $this->getScheduleApi()->shouldBeAnInstanceOf(ScheduleApi::class); + } + + function it_should_provide_subscriptions_api() + { + $this->getSubscriptionsApi()->shouldBeAnInstanceOf(SubscriptionsApi::class); + } + + function it_should_provide_streams_api() + { + $this->getStreamsApi()->shouldBeAnInstanceOf(StreamsApi::class); + } + + function it_should_provide_tags_api() + { + $this->getTagsApi()->shouldBeAnInstanceOf(TagsApi::class); + } + + function it_should_provide_teams_api() + { + $this->getTeamsApi()->shouldBeAnInstanceOf(TeamsApi::class); + } + + function it_should_provide_users_api() + { + $this->getUsersApi()->shouldBeAnInstanceOf(UsersApi::class); + } + + function it_should_provide_videos_api() + { + $this->getVideosApi()->shouldBeAnInstanceOf(VideosApi::class); + } + + function it_should_provide_webhooks_api() + { + $this->getWebhooksApi()->shouldBeAnInstanceOf(WebhooksApi::class); + } + + function it_should_provide_webhooks_subscription_api() + { + $this->getWebhooksSubscriptionApi()->shouldBeAnInstanceOf(WebhooksSubscriptionApi::class); + } +} diff --git a/src/Auth/AuthGuzzleClient.php b/src/Auth/AuthGuzzleClient.php new file mode 100644 index 0000000..03e9e8d --- /dev/null +++ b/src/Auth/AuthGuzzleClient.php @@ -0,0 +1,19 @@ + self::BASE_URI, + ]); + } +} diff --git a/src/Auth/OauthApi.php b/src/Auth/OauthApi.php new file mode 100644 index 0000000..7ec02e2 --- /dev/null +++ b/src/Auth/OauthApi.php @@ -0,0 +1,149 @@ +clientId = $clientId; + $this->clientSecret = $clientSecret; + $this->guzzleClient = $guzzleClient ?? AuthGuzzleClient::getClient(); + } + + /** + * @return string A full authentication URL, including the Guzzle client's base URI. + */ + public function getAuthUrl(string $redirectUri, string $responseType = 'code', string $scope = '', bool $forceVerify = false, string $state = null): string + { + return sprintf( + '%s%s', + $this->guzzleClient->getConfig('base_uri'), + $this->getPartialAuthUrl($redirectUri, $responseType, $scope, $forceVerify, $state) + ); + } + + /** + * @throws GuzzleException + */ + public function getUserAccessToken($code, string $redirectUri, $state = null): ResponseInterface + { + return $this->makeRequest( + new Request('POST', 'token'), + [ + RequestOptions::JSON => [ + 'client_id' => $this->clientId, + 'client_secret' => $this->clientSecret, + 'grant_type' => 'authorization_code', + 'redirect_uri' => $redirectUri, + 'code' => $code, + 'state' => $state, + ], + ] + ); + } + + /** + * @throws GuzzleException + */ + public function refreshToken(string $refeshToken, string $scope = ''): ResponseInterface + { + $requestOptions = [ + 'client_id' => $this->clientId, + 'client_secret' => $this->clientSecret, + 'grant_type' => 'refresh_token', + 'refresh_token' => $refeshToken, + ]; + if ($scope) { + $requestOptions['scope'] = $scope; + } + + return $this->makeRequest( + new Request('POST', 'token'), + [ + RequestOptions::JSON => $requestOptions, + ] + ); + } + + /** + * @throws GuzzleException + */ + public function validateAccessToken(string $accessToken): ResponseInterface + { + return $this->makeRequest( + new Request( + 'GET', + 'validate', + [ + 'Authorization' => sprintf('OAuth %s', $accessToken), + ] + ) + ); + } + + /** + * @throws GuzzleException + */ + public function isValidAccessToken(string $accessToken): bool + { + return $this->validateAccessToken($accessToken)->getStatusCode() === 200; + } + + /** + * @throws GuzzleException + */ + public function getAppAccessToken(string $scope = ''): ResponseInterface + { + return $this->makeRequest( + new Request('POST', 'token'), + [ + RequestOptions::JSON => [ + 'client_id' => $this->clientId, + 'client_secret' => $this->clientSecret, + 'grant_type' => 'client_credentials', + 'scope' => $scope, + ], + ] + ); + } + + /** + * @throws GuzzleException + */ + private function makeRequest(Request $request, array $options = []): ResponseInterface + { + return $this->guzzleClient->send($request, $options); + } + + /** + * @return string A partial authentication URL, excluding the Guzzle client's base URI. + */ + private function getPartialAuthUrl(string $redirectUri, string $responseType = 'code', string $scope = '', bool $forceVerify = false, string $state = null): string + { + $optionalParameters = ''; + $optionalParameters .= $forceVerify ? '&force_verify=true' : ''; + $optionalParameters .= $state ? sprintf('&state=%s', $state) : ''; + + return sprintf( + 'authorize?client_id=%s&redirect_uri=%s&response_type=%s&scope=%s%s', + $this->clientId, + $redirectUri, + $responseType, + $scope, + $optionalParameters + ); + } +} diff --git a/src/HelixGuzzleClient.php b/src/HelixGuzzleClient.php new file mode 100644 index 0000000..5af0bcd --- /dev/null +++ b/src/HelixGuzzleClient.php @@ -0,0 +1,48 @@ + $clientId, + 'Content-Type' => 'application/json', + ]; + + $client_config = [ + 'base_uri' => $baseUri, + 'headers' => $headers, + ]; + + if (isset($config['handler'])) { + $client_config = []; + } + + $client_config = array_merge($client_config, $config); + + $this->client = new Client($client_config); + } + + public function getConfig($option = null) + { + return $this->client->getConfig($option); + } + + public function send($request) + { + return $this->client->send($request); + } +} diff --git a/src/NewTwitchApi.php b/src/NewTwitchApi.php new file mode 100644 index 0000000..283c0f7 --- /dev/null +++ b/src/NewTwitchApi.php @@ -0,0 +1,7 @@ + $clientId, - 'Content-Type' => 'application/json', - ]; - - $client_config = [ - 'base_uri' => $baseUri, - 'headers' => $headers, - ]; - - if (isset($config['handler'])) { - $client_config = []; - } - - $client_config = array_merge($client_config, $config); - - $this->client = new Client($client_config); - } - - public function getConfig($option = null) - { - return $this->client->getConfig($option); - } - - public function send($request) - { - return $this->client->send($request); - } } diff --git a/src/NewTwitchApi/NewTwitchApi.php b/src/NewTwitchApi/NewTwitchApi.php index bea409b..40e9407 100644 --- a/src/NewTwitchApi/NewTwitchApi.php +++ b/src/NewTwitchApi/NewTwitchApi.php @@ -1,216 +1,9 @@ oauthApi = new OauthApi($clientId, $clientSecret, $authGuzzleClient); - $this->adsApi = new AdsApi($helixGuzzleClient, $requestGenerator); - $this->analyticsApi = new AnalyticsApi($helixGuzzleClient, $requestGenerator); - $this->bitsApi = new BitsApi($helixGuzzleClient, $requestGenerator); - $this->channelPointsApi = new ChannelPointsApi($helixGuzzleClient, $requestGenerator); - $this->channelsApi = new ChannelsApi($helixGuzzleClient, $requestGenerator); - $this->chatApi = new ChatApi($helixGuzzleClient, $requestGenerator); - $this->clipsApi = new ClipsApi($helixGuzzleClient, $requestGenerator); - $this->entitlementsApi = new EntitlementsApi($helixGuzzleClient, $requestGenerator); - $this->eventSubApi = new EventSubApi($helixGuzzleClient, $requestGenerator); - $this->gamesApi = new GamesApi($helixGuzzleClient, $requestGenerator); - $this->hypeTrainApi = new HypeTrainApi($helixGuzzleClient, $requestGenerator); - $this->moderationApi = new ModerationApi($helixGuzzleClient, $requestGenerator); - $this->pollsApi = new PollsApi($helixGuzzleClient, $requestGenerator); - $this->predictionsApi = new PredictionsApi($helixGuzzleClient, $requestGenerator); - $this->scheduleApi = new ScheduleApi($helixGuzzleClient, $requestGenerator); - $this->searchApi = new SearchApi($helixGuzzleClient, $requestGenerator); - $this->streamsApi = new StreamsApi($helixGuzzleClient, $requestGenerator); - $this->subscriptionsApi = new SubscriptionsApi($helixGuzzleClient, $requestGenerator); - $this->tagsApi = new TagsApi($helixGuzzleClient, $requestGenerator); - $this->teamsApi = new TeamsApi($helixGuzzleClient, $requestGenerator); - $this->usersApi = new UsersApi($helixGuzzleClient, $requestGenerator); - $this->videosApi = new VideosApi($helixGuzzleClient, $requestGenerator); - $this->webhooksApi = new WebhooksApi($helixGuzzleClient, $requestGenerator); - $this->webhooksSubscriptionApi = new WebhooksSubscriptionApi($clientId, $clientSecret, $helixGuzzleClient); - } - - public function getOauthApi(): OauthApi - { - return $this->oauthApi; - } - - public function getAdsApi(): AdsApi - { - return $this->adsApi; - } - - public function getAnalyticsApi(): AnalyticsApi - { - return $this->analyticsApi; - } - - public function getBitsApi(): BitsApi - { - return $this->bitsApi; - } - - public function getChannelPointsApi(): ChannelPointsApi - { - return $this->channelPointsApi; - } - - public function getChannelsApi(): ChannelsApi - { - return $this->channelsApi; - } - - public function getChatApi(): ChatApi - { - return $this->chatApi; - } - - public function getClipsApi(): ClipsApi - { - return $this->clipsApi; - } - - public function getEntitlementsApi(): EntitlementsApi - { - return $this->entitlementsApi; - } - - public function getEventSubApi(): EventSubApi - { - return $this->eventSubApi; - } - - public function getGamesApi(): GamesApi - { - return $this->gamesApi; - } - - public function getHypeTrainApi(): HypeTrainApi - { - return $this->hypeTrainApi; - } - - public function getModerationApi(): ModerationApi - { - return $this->moderationApi; - } - - public function getPollsApi(): PollsApi - { - return $this->pollsApi; - } - - public function getPredictionsApi(): PredictionsApi - { - return $this->predictionsApi; - } - - public function getScheduleApi(): ScheduleApi - { - return $this->scheduleApi; - } - - public function getSearchApi(): SearchApi - { - return $this->searchApi; - } - - public function getStreamsApi(): StreamsApi - { - return $this->streamsApi; - } - - public function getSubscriptionsApi(): SubscriptionsApi - { - return $this->subscriptionsApi; - } - - public function getTagsApi(): TagsApi - { - return $this->tagsApi; - } - - public function getTeamsApi(): TeamsApi - { - return $this->teamsApi; - } - - public function getUsersApi(): UsersApi - { - return $this->usersApi; - } - - public function getVideosApi(): VideosApi - { - return $this->videosApi; - } - - public function getWebhooksApi(): WebhooksApi - { - return $this->webhooksApi; - } - - public function getWebhooksSubscriptionApi(): WebhooksSubscriptionApi - { - return $this->webhooksSubscriptionApi; - } } diff --git a/src/RequestGenerator.php b/src/RequestGenerator.php new file mode 100644 index 0000000..8a52048 --- /dev/null +++ b/src/RequestGenerator.php @@ -0,0 +1,81 @@ + 'application/json', + ]; + + if ($bearer) { + $headers['Authorization'] = sprintf('Bearer %s', $bearer); + } + + if (count($bodyParams) > 0) { + $request = new Request( + $httpMethod, + sprintf( + '%s%s', + $uriEndpoint, + $this->generateQueryParams($queryParamsMap) + ), + $headers, + $this->generateBodyParams($bodyParams) + ); + } else { + $request = new Request( + $httpMethod, + sprintf( + '%s%s', + $uriEndpoint, + $this->generateQueryParams($queryParamsMap) + ), + $headers + ); + } + + return $request; + } + + /** + * $queryParamsMap should be a mapping of the param key expected in the API call URL, + * and the value to be sent for that key. + * + * [['key' => 'param_key', 'value' => 42],['key' => 'other_key', 'value' => 'asdf']] + * would result in + * ?param_key=42&other_key=asdf + */ + protected function generateQueryParams(array $queryParamsMap): string + { + $queryStringParams = ''; + foreach ($queryParamsMap as $paramMap) { + if ($paramMap['value'] !== null) { + if (is_bool($paramMap['value'])) { + $paramMap['value'] = (int) $paramMap['value']; + } + $format = is_int($paramMap['value']) ? '%d' : '%s'; + $queryStringParams .= sprintf('&%s='.$format, $paramMap['key'], $paramMap['value']); + } + } + + return $queryStringParams ? '?'.substr($queryStringParams, 1) : ''; + } + + protected function generateBodyParams(array $bodyParamsMap): string + { + $bodyParams = []; + foreach ($bodyParamsMap as $bodyParam) { + if ($bodyParam['value'] !== null) { + $bodyParams[$bodyParam['key']] = $bodyParam['value']; + } + } + + return json_encode($bodyParams); + } +} diff --git a/src/Resources/AbstractResource.php b/src/Resources/AbstractResource.php new file mode 100644 index 0000000..0e1dc59 --- /dev/null +++ b/src/Resources/AbstractResource.php @@ -0,0 +1,75 @@ +guzzleClient = $guzzleClient; + $this->requestGenerator = $requestGenerator; + } + + /** + * @throws GuzzleException + */ + protected function getApi(string $uriEndpoint, string $bearer, array $queryParamsMap = [], array $bodyParams = []): ResponseInterface + { + return $this->sendToApi('GET', $uriEndpoint, $bearer, $queryParamsMap, $bodyParams); + } + + /** + * @throws GuzzleException + */ + protected function getApiWithOptionalAuth(string $uriEndpoint, string $bearer = null, array $queryParamsMap = [], array $bodyParams = []): ResponseInterface + { + return $this->sendToApi('GET', $uriEndpoint, $bearer, $queryParamsMap, $bodyParams); + } + + /** + * @throws GuzzleException + */ + protected function deleteApi(string $uriEndpoint, string $bearer, array $queryParamsMap = [], array $bodyParams = []): ResponseInterface + { + return $this->sendToApi('DELETE', $uriEndpoint, $bearer, $queryParamsMap, $bodyParams); + } + + /** + * @throws GuzzleException + */ + protected function patchApi(string $uriEndpoint, string $bearer, array $queryParamsMap = [], array $bodyParams = []): ResponseInterface + { + return $this->sendToApi('PATCH', $uriEndpoint, $bearer, $queryParamsMap, $bodyParams); + } + + /** + * @throws GuzzleException + */ + protected function postApi(string $uriEndpoint, string $bearer, array $queryParamsMap = [], array $bodyParams = []): ResponseInterface + { + return $this->sendToApi('POST', $uriEndpoint, $bearer, $queryParamsMap, $bodyParams); + } + + /** + * @throws GuzzleException + */ + protected function putApi(string $uriEndpoint, string $bearer, array $queryParamsMap = [], array $bodyParams = []): ResponseInterface + { + return $this->sendToApi('PUT', $uriEndpoint, $bearer, $queryParamsMap, $bodyParams); + } + + private function sendToApi(string $httpMethod, string $uriEndpoint, string $bearer = null, array $queryParamsMap = [], array $bodyParams = []): ResponseInterface + { + return $this->guzzleClient->send($this->requestGenerator->generate($httpMethod, $uriEndpoint, $bearer, $queryParamsMap, $bodyParams)); + } +} diff --git a/src/Resources/AdsApi.php b/src/Resources/AdsApi.php new file mode 100644 index 0000000..1803e5c --- /dev/null +++ b/src/Resources/AdsApi.php @@ -0,0 +1,25 @@ + 'broadcaster_id', 'value' => $broadcasterId]; + $bodyParamsMap[] = ['key' => 'length', 'value' => $length]; + + return $this->postApi('channels/commercial', $bearer, [], $bodyParamsMap); + } +} diff --git a/src/Resources/AnalyticsApi.php b/src/Resources/AnalyticsApi.php new file mode 100644 index 0000000..90cccaf --- /dev/null +++ b/src/Resources/AnalyticsApi.php @@ -0,0 +1,81 @@ + 'extension_id', 'value' => $extensionId]; + } + + if ($type) { + $queryParamsMap[] = ['key' => 'type', 'value' => $type]; + } + + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + if ($startedAt) { + $queryParamsMap[] = ['key' => 'started_at', 'value' => $startedAt]; + } + + if ($endedAt) { + $queryParamsMap[] = ['key' => 'ended_at', 'value' => $endedAt]; + } + + return $this->getApi('analytics/extensions', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#get-game-analytics + */ + public function getGameAnalytics(string $bearer, string $gameId = null, string $type = null, int $first = null, string $after = null, string $startedAt = null, string $endedAt = null): ResponseInterface + { + $queryParamsMap = []; + + if ($gameId) { + $queryParamsMap[] = ['key' => 'game_id', 'value' => $gameId]; + } + + if ($type) { + $queryParamsMap[] = ['key' => 'type', 'value' => $type]; + } + + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + if ($startedAt) { + $queryParamsMap[] = ['key' => 'started_at', 'value' => $startedAt]; + } + + if ($endedAt) { + $queryParamsMap[] = ['key' => 'ended_at', 'value' => $endedAt]; + } + + return $this->getApi('analytics/games', $bearer, $queryParamsMap); + } +} diff --git a/src/Resources/BitsApi.php b/src/Resources/BitsApi.php new file mode 100644 index 0000000..d0b2c50 --- /dev/null +++ b/src/Resources/BitsApi.php @@ -0,0 +1,78 @@ + 'broadcaster_id', 'value' => $broadcasterId]; + } + + return $this->getApi('bits/cheermotes', $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->getApi('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->getApi('extensions/transactions', $bearer, $queryParamsMap); + } +} diff --git a/src/Resources/ChannelPointsApi.php b/src/Resources/ChannelPointsApi.php new file mode 100644 index 0000000..a1fac78 --- /dev/null +++ b/src/Resources/ChannelPointsApi.php @@ -0,0 +1,149 @@ +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->getApi('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->getApi('channel_points/custom_rewards/redemptions', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#create-custom-rewards + */ + public function createCustomReward(string $bearer, string $broadcasterId, string $title, int $cost, $additionalBodyParams = []): ResponseInterface + { + // $additionalBodyParams should be a standard key => value format, eg. ['game_id' => '1']; + $queryParamsMap = $bodyParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + $bodyParamsMap[] = ['key' => 'title', 'value' => $title]; + $bodyParamsMap[] = ['key' => 'cost', 'value' => $cost]; + + foreach ($additionalBodyParams as $key => $value) { + $bodyParamsMap[] = ['key' => $key, 'value' => $value]; + } + + return $this->postApi('channel_points/custom_rewards', $bearer, $queryParamsMap, $bodyParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#update-custom-reward + */ + public function updateCustomReward(string $bearer, string $broadcasterId, string $rewardId, $bodyParams = []): ResponseInterface + { + // $bodyParams should be a standard key => value format, eg. ['game_id' => '1']; + $queryParamsMap = $bodyParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + $queryParamsMap[] = ['key' => 'id', 'value' => $rewardId]; + + foreach ($bodyParams as $key => $value) { + $bodyParamsMap[] = ['key' => $key, 'value' => $value]; + } + + return $this->patchApi('channel_points/custom_rewards', $bearer, $queryParamsMap, $bodyParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#delete-custom-reward + */ + public function deleteCustomReward(string $bearer, string $broadcasterId, string $id): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + $queryParamsMap[] = ['key' => 'id', 'value' => $id]; + + return $this->deleteApi('channel_points/custom_rewards', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#update-redemption-status + */ + public function updateRedemptionStatus(string $bearer, string $broadcasterId, string $rewardId, string $redemptionId, string $status): ResponseInterface + { + $queryParamsMap = $bodyParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + $queryParamsMap[] = ['key' => 'reward_id', 'value' => $rewardId]; + $queryParamsMap[] = ['key' => 'id', 'value' => $redemptionId]; + + $bodyParamsMap[] = ['key' => 'status', 'value' => $status]; + + return $this->patchApi('channel_points/custom_rewards/redemptions', $bearer, $queryParamsMap, $bodyParamsMap); + } +} diff --git a/src/Resources/ChannelsApi.php b/src/Resources/ChannelsApi.php new file mode 100644 index 0000000..323d590 --- /dev/null +++ b/src/Resources/ChannelsApi.php @@ -0,0 +1,55 @@ + 'broadcaster_id', 'value' => $broadcasterId]; + + return $this->getApi('channels', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#get-channel-editors + */ + public function getChannelEditors(string $bearer, string $broadcasterId): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + return $this->getApi('channels/editors', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#modify-channel-information + */ + public function modifyChannelInfo(string $bearer, string $broadcasterId, $bodyParams = []): ResponseInterface + { + // $bodyParams should be a standard key => value format, eg. ['game_id' => '1']; + $queryParamsMap = $bodyParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + foreach ($bodyParams as $key => $value) { + $bodyParamsMap[] = ['key' => $key, 'value' => $value]; + } + + return $this->patchApi('channels', $bearer, $queryParamsMap, $bodyParamsMap); + } +} diff --git a/src/Resources/ChatApi.php b/src/Resources/ChatApi.php new file mode 100644 index 0000000..62f4212 --- /dev/null +++ b/src/Resources/ChatApi.php @@ -0,0 +1,76 @@ + 'broadcaster_id', 'value' => $broadcasterId]; + + return $this->getApi('chat/emotes', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#get-global-emotes + */ + public function getGlobalEmotes(string $bearer): ResponseInterface + { + return $this->getApi('chat/emotes/global', $bearer); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#get-emote-sets + */ + public function getEmoteSets(string $bearer, array $emoteSetIds = []): ResponseInterface + { + $queryParamsMap = []; + + foreach ($emoteSetIds as $emoteSetId) { + $queryParamsMap[] = ['key' => 'emote_set_id', 'value' => $emoteSetId]; + } + + return $this->getApi('chat/emotes/set', $bearer, $queryParamsMap); + } + + public function getEmoteSet(string $bearer, string $emoteSetId): ResponseInterface + { + $queryParamsMap = []; + $queryParamsMap[] = ['key' => 'emote_set_id', 'value' => $emoteSetId]; + + return $this->getApi('chat/emotes/set', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#get-channel-chat-badges + */ + public function getChannelChatBadges(string $bearer, string $broadcasterId): ResponseInterface + { + $queryParamsMap = []; + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + return $this->getApi('chat/badges', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#get-global-chat-badges + */ + public function getGlobalChatBadges(string $bearer): ResponseInterface + { + return $this->getApi('chat/badges/global', $bearer); + } +} diff --git a/src/Resources/ClipsApi.php b/src/Resources/ClipsApi.php new file mode 100644 index 0000000..d0c6d78 --- /dev/null +++ b/src/Resources/ClipsApi.php @@ -0,0 +1,87 @@ +getClips($bearer, $broadcasterId, null, null, $first, $before, $after, $startedAt, $endedAt); + } + + /** + * @throws GuzzleException + */ + public function getClipsByGameId(string $bearer, string $gameId, int $first = null, string $before = null, string $after = null, string $startedAt = null, string $endedAt = null): ResponseInterface + { + return $this->getClips($bearer, null, $gameId, null, $first, $before, $after, $startedAt, $endedAt); + } + + /** + * @throws GuzzleException + */ + public function getClipsByIds(string $bearer, string $clipIds, string $startedAt = null, string $endedAt = null): ResponseInterface + { + return $this->getClips($bearer, null, null, $clipIds, null, null, null, $startedAt, $endedAt); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#get-clips + */ + public function getClips(string $bearer, string $broadcasterId = null, string $gameId = null, string $clipIds = null, int $first = null, string $before = null, string $after = null, string $startedAt = null, string $endedAt = null): ResponseInterface + { + $queryParamsMap = []; + if ($broadcasterId) { + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + } + if ($gameId) { + $queryParamsMap[] = ['key' => 'game_id', 'value' => $gameId]; + } + if ($clipIds) { + $queryParamsMap[] = ['key' => 'id', 'value' => $clipIds]; + } + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + if ($before) { + $queryParamsMap[] = ['key' => 'before', 'value' => $before]; + } + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + if ($startedAt) { + $queryParamsMap[] = ['key' => 'started_at', 'value' => $startedAt]; + } + if ($endedAt) { + $queryParamsMap[] = ['key' => 'ended_at', 'value' => $endedAt]; + } + + return $this->getApi('clips', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#create-clip + */ + public function createClip(string $bearer, string $broadcasterId, bool $hasDelay = null): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + if ($hasDelay) { + $queryParamsMap[] = ['key' => 'has_delay', 'value' => $hasDelay]; + } + + return $this->postApi('clips', $bearer, $queryParamsMap); + } +} diff --git a/src/Resources/EntitlementsApi.php b/src/Resources/EntitlementsApi.php new file mode 100644 index 0000000..5f33c76 --- /dev/null +++ b/src/Resources/EntitlementsApi.php @@ -0,0 +1,89 @@ + 'manifest_id', 'value' => $manifestId]; + $queryParamsMap[] = ['key' => 'type', 'value' => $type]; + + return $this->postApi('entitlements/upload', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#get-code-status + */ + public function getCodeStatus(string $bearer, int $userId, array $codes = []): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'user_id', 'value' => $userId]; + + foreach ($codes as $code) { + $queryParamsMap[] = ['key' => 'code', 'value' => $code]; + } + + return $this->getApi('entitlements/codes', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#get-drops-entitlements + */ + public function getDropsEntitlements(string $bearer, string $id = null, string $userId = null, string $gameId = null, string $after = null, int $first = null): ResponseInterface + { + $queryParamsMap = []; + + if ($id) { + $queryParamsMap[] = ['key' => 'id', 'value' => $id]; + } + + if ($userId) { + $queryParamsMap[] = ['key' => 'user_id', 'value' => $userId]; + } + + if ($gameId) { + $queryParamsMap[] = ['key' => 'game_id', 'value' => $gameId]; + } + + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + + return $this->getApi('entitlements/drops', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#redeem-code + */ + public function redeemCode(string $bearer, int $userId, array $codes = []): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'user_id', 'value' => $userId]; + + foreach ($codes as $code) { + $queryParamsMap[] = ['key' => 'code', 'value' => $code]; + } + + return $this->postApi('entitlements/code', $bearer, $queryParamsMap); + } +} diff --git a/src/Resources/EventSubApi.php b/src/Resources/EventSubApi.php new file mode 100644 index 0000000..b2736fa --- /dev/null +++ b/src/Resources/EventSubApi.php @@ -0,0 +1,523 @@ + 'status', 'value' => $status]; + } + + if ($type) { + $queryParamsMap[] = ['key' => 'type', 'value' => $type]; + } + + return $this->getApi('eventsub/subscriptions', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#create-eventsub-subscription + */ + public function createEventSubSubscription(string $bearer, string $secret, string $callback, string $type, string $version, array $condition): ResponseInterface + { + $bodyParams = []; + + $bodyParams[] = ['key' => 'type', 'value' => $type]; + $bodyParams[] = ['key' => 'version', 'value' => $version]; + $bodyParams[] = ['key' => 'condition', 'value' => $condition]; + $bodyParams[] = [ + 'key' => 'transport', + 'value' => [ + 'method' => 'webhook', + 'callback' => $callback, + 'secret' => $secret, + ], + ]; + + return $this->postApi('eventsub/subscriptions', $bearer, [], $bodyParams); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#delete-eventsub-subscription + */ + public function deleteEventSubSubscription(string $bearer, string $id): ResponseInterface + { + $queryParamsMap = []; + $queryParamsMap[] = ['key' => 'id', 'value' => $id]; + + return $this->deleteApi('eventsub/subscriptions', $bearer, $queryParamsMap); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelupdate + */ + public function subscribeToChannelUpdate(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + 'channel.update', + '1', + ['broadcaster_user_id' => $twitchId], + ); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelfollow + */ + public function subscribeToChannelFollow(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + 'channel.follow', + '1', + ['broadcaster_user_id' => $twitchId], + ); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelsubscribe + */ + public function subscribeToChannelSubscribe(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + 'channel.subscribe', + '1', + ['broadcaster_user_id' => $twitchId], + ); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/#channelsubscriptionend + */ + public function subscribeToChannelSubscriptionEnd(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + 'channel.subscription.end', + '1', + ['broadcaster_user_id' => $twitchId], + ); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/#channelsubscriptiongift + */ + public function subscribeToChannelSubscriptionGift(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + 'channel.subscription.gift', + '1', + ['broadcaster_user_id' => $twitchId], + ); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelsubscriptionmessage-beta + */ + public function subscribeToChannelSubscriptionMessage(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + 'channel.subscription.message', + '1', + ['broadcaster_user_id' => $twitchId], + ); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelcheer + */ + public function subscribeToChannelCheer(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + 'channel.cheer', + '1', + ['broadcaster_user_id' => $twitchId], + ); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelraid + */ + public function subscribeToChannelRaid(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + 'channel.raid', + '1', + ['broadcaster_user_id' => $twitchId], + ); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelban + */ + public function subscribeToChannelBan(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + 'channel.ban', + '1', + ['broadcaster_user_id' => $twitchId], + ); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelunban + */ + public function subscribeToChannelUnban(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + 'channel.unban', + '1', + ['broadcaster_user_id' => $twitchId], + ); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelmoderatoradd + */ + public function subscribeToChannelModeratorAdd(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->subscribeToChannelModerator($bearer, $secret, $callback, $twitchId, 'add'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelmoderatorremove + */ + public function subscribeToChannelModeratorRemove(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->subscribeToChannelModerator($bearer, $secret, $callback, $twitchId, 'remove'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelchannel_points_custom_rewardadd + */ + public function subscribeToChannelPointsCustomRewardAdd(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->subscribeToChannelPointsCustomReward($bearer, $secret, $callback, $twitchId, null, 'add'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelchannel_points_custom_rewardupdate + */ + public function subscribeToChannelPointsCustomRewardUpdate(string $bearer, string $secret, string $callback, string $twitchId, string $rewardId = null): ResponseInterface + { + return $this->subscribeToChannelPointsCustomReward($bearer, $secret, $callback, $twitchId, $rewardId, 'update'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelchannel_points_custom_rewardremove + */ + public function subscribeToChannelPointsCustomRewardRemove(string $bearer, string $secret, string $callback, string $twitchId, string $rewardId = null): ResponseInterface + { + return $this->subscribeToChannelPointsCustomReward($bearer, $secret, $callback, $twitchId, $rewardId, 'remove'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelchannel_points_custom_reward_redemptionadd + */ + public function subscribeToChannelPointsCustomRewardRedemptionAdd(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->subscribeToChannelPointsCustomRewardRedemption($bearer, $secret, $callback, $twitchId, null, 'add'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelchannel_points_custom_reward_redemptionupdate + */ + public function subscribeToChannelPointsCustomRewardRedemptionUpdate(string $bearer, string $secret, string $callback, string $twitchId, string $rewardId = null): ResponseInterface + { + return $this->subscribeToChannelPointsCustomRewardRedemption($bearer, $secret, $callback, $twitchId, $rewardId, 'update'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelpollbegin + */ + public function subscribeToChannelPollBegin(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->subscribeToChannelPoll($bearer, $secret, $callback, $twitchId, 'begin'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelpollprogress + */ + public function subscribeToChannelPollProgress(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->subscribeToChannelPoll($bearer, $secret, $callback, $twitchId, 'progress'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelpollend + */ + public function subscribeToChannelPollEnd(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->subscribeToChannelPoll($bearer, $secret, $callback, $twitchId, 'end'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelpredictionbegin + */ + public function subscribeToChannelPredictionBegin(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->subscribeToChannelPrediction($bearer, $secret, $callback, $twitchId, 'begin'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelpredictionprogress + */ + public function subscribeToChannelPredictionProgress(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->subscribeToChannelPrediction($bearer, $secret, $callback, $twitchId, 'progress'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelpredictionprogress + */ + public function subscribeToChannelPredictionLock(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->subscribeToChannelPrediction($bearer, $secret, $callback, $twitchId, 'lock'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelpredictionend + */ + public function subscribeToChannelPredictionEnd(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->subscribeToChannelPrediction($bearer, $secret, $callback, $twitchId, 'end'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelhype_trainbegin + */ + public function subscribeToChannelHypeTrainBegin(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->subscribeToChannelHypeTrain($bearer, $secret, $callback, $twitchId, 'begin'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelhype_trainprogress + */ + public function subscribeToChannelHypeTrainProgress(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->subscribeToChannelHypeTrain($bearer, $secret, $callback, $twitchId, 'progress'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelhype_trainend + */ + public function subscribeToChannelHypeTrainEnd(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->subscribeToChannelHypeTrain($bearer, $secret, $callback, $twitchId, 'end'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#streamonline + */ + public function subscribeToStreamOnline(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->subscribeToStream($bearer, $secret, $callback, $twitchId, 'online'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#streamoffline + */ + public function subscribeToStreamOffline(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->subscribeToStream($bearer, $secret, $callback, $twitchId, 'offline'); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#userauthorizationrevoke + */ + public function subscribeToUserAuthorizationRevoke(string $bearer, string $secret, string $callback, string $clientId): ResponseInterface + { + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + 'user.authorization.revoke', + '1', + ['client_id' => $clientId], + ); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#userupdate + */ + public function subscribeToUserUpdate(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface + { + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + 'user.update', + '1', + ['user_id' => $twitchId], + ); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#extensionbits_transactioncreate-beta + */ + public function subscribeToExtensionBitsTransactionCreate(string $bearer, string $secret, string $callback, string $extensionClientId): ResponseInterface + { + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + 'extension.bits_transaction.create', + 'beta', + ['extension_client_id' => $extensionClientId], + ); + } + + /** + * @link https://dev.twitch.tv/docs/eventsub#verify-a-signature + */ + public function verifySignature(string $signature, string $secret, string $messageId, string $timestamp, string $body): bool + { + [$hashAlgorithm, $expectedHash] = explode('=', $signature); + $generatedHash = hash_hmac($hashAlgorithm, $messageId.$timestamp.$body, $secret); + + return $expectedHash === $generatedHash; + } + + private function subscribeToChannelModerator(string $bearer, string $secret, string $callback, string $twitchId, string $eventType): ResponseInterface + { + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + sprintf('channel.moderator.%s', $eventType), + '1', + ['broadcaster_user_id' => $twitchId], + ); + } + + private function subscribeToChannelPointsCustomReward(string $bearer, string $secret, string $callback, string $twitchId, string $rewardId = null, string $eventType): ResponseInterface + { + $condition = ['broadcaster_user_id' => $twitchId]; + + if ($rewardId) { + $condition['reward_id'] = $rewardId; + } + + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + sprintf('channel.channel_points_custom_reward.%s', $eventType), + '1', + $condition, + ); + } + + private function subscribeToChannelPointsCustomRewardRedemption(string $bearer, string $secret, string $callback, string $twitchId, string $rewardId = null, string $eventType): ResponseInterface + { + $condition = ['broadcaster_user_id' => $twitchId]; + + if ($rewardId) { + $condition['reward_id'] = $rewardId; + } + + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + sprintf('channel.channel_points_custom_reward_redemption.%s', $eventType), + '1', + $condition, + ); + } + + private function subscribeToChannelPoll(string $bearer, string $secret, string $callback, string $twitchId, string $eventType): ResponseInterface + { + $condition = ['broadcaster_user_id' => $twitchId]; + + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + sprintf('channel.poll.%s', $eventType), + '1', + $condition, + ); + } + + private function subscribeToChannelPrediction(string $bearer, string $secret, string $callback, string $twitchId, string $eventType): ResponseInterface + { + $condition = ['broadcaster_user_id' => $twitchId]; + + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + sprintf('channel.prediction.%s', $eventType), + '1', + $condition, + ); + } + + private function subscribeToChannelHypeTrain(string $bearer, string $secret, string $callback, string $twitchId, string $eventType): ResponseInterface + { + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + sprintf('channel.hype_train.%s', $eventType), + '1', + ['broadcaster_user_id' => $twitchId], + ); + } + + private function subscribeToStream(string $bearer, string $secret, string $callback, string $twitchId, string $eventType): ResponseInterface + { + return $this->createEventSubSubscription( + $bearer, + $secret, + $callback, + sprintf('stream.%s', $eventType), + '1', + ['broadcaster_user_id' => $twitchId], + ); + } +} diff --git a/src/Resources/GamesApi.php b/src/Resources/GamesApi.php new file mode 100644 index 0000000..6a850b2 --- /dev/null +++ b/src/Resources/GamesApi.php @@ -0,0 +1,51 @@ + 'id', 'value' => $id]; + } + foreach ($names as $name) { + $queryParamsMap[] = ['key' => 'name', 'value' => $name]; + } + + return $this->getApi('games', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference/#get-top-games + */ + public function getTopGames(string $bearer, int $first = null, string $before = null, string $after = null): ResponseInterface + { + $queryParamsMap = []; + + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + + if ($before) { + $queryParamsMap[] = ['key' => 'before', 'value' => $before]; + } + + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + return $this->getApi('games/top', $bearer, $queryParamsMap); + } +} diff --git a/src/Resources/HypeTrainApi.php b/src/Resources/HypeTrainApi.php new file mode 100644 index 0000000..7e0fb37 --- /dev/null +++ b/src/Resources/HypeTrainApi.php @@ -0,0 +1,36 @@ + 'broadcaster_id', 'value' => $broadcasterId]; + + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + + if ($id) { + $queryParamsMap[] = ['key' => 'id', 'value' => $id]; + } + + if ($cursor) { + $queryParamsMap[] = ['key' => 'cursor', 'value' => $cursor]; + } + + return $this->getApi('bits/cheermotes', $bearer, $queryParamsMap); + } +} diff --git a/src/Resources/ModerationApi.php b/src/Resources/ModerationApi.php new file mode 100644 index 0000000..57b72a4 --- /dev/null +++ b/src/Resources/ModerationApi.php @@ -0,0 +1,135 @@ + 'broadcaster_id', 'value' => $broadcasterId]; + + foreach ($ids as $id) { + $queryParamsMap[] = ['key' => 'user_id', 'value' => $id]; + } + + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + return $this->getApi('moderation/banned/events', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference/#get-banned-users + */ + public function getBannedUsers(string $bearer, string $broadcasterId, array $ids = [], string $before = null, string $after = null): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + foreach ($ids as $id) { + $queryParamsMap[] = ['key' => 'user_id', 'value' => $id]; + } + + if ($before) { + $queryParamsMap[] = ['key' => 'before', 'value' => $before]; + } + + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + return $this->getApi('moderation/banned', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference/#get-moderators + */ + public function getModerators(string $bearer, string $broadcasterId, array $ids = [], string $after = null): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + foreach ($ids as $id) { + $queryParamsMap[] = ['key' => 'user_id', 'value' => $id]; + } + + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + return $this->getApi('moderation/moderators', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference/#get-moderator-events + */ + public function getModeratorEvents(string $bearer, string $broadcasterId, array $ids = [], string $after = null): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + foreach ($ids as $id) { + $queryParamsMap[] = ['key' => 'user_id', 'value' => $id]; + } + + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + return $this->getApi('moderation/moderators/events', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#check-automod-status + */ + public function checkAutoModStatus(string $bearer, string $broadcasterId, string $msgId, string $msgText, string $userId): ResponseInterface + { + $queryParamsMap = $bodyParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + $bodyParamsMap[] = ['key' => 'msg_id', 'value' => $msgId]; + $bodyParamsMap[] = ['key' => 'msg_text', 'value' => $msgText]; + $bodyParamsMap[] = ['key' => 'user_id', 'value' => $userId]; + + return $this->postApi('moderation/enforcements/status', $bearer, $queryParamsMap, $bodyParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#manage-held-automod-messages + */ + public function manageHeldAutoModMessage(string $bearer, string $userId, string $msgId, string $action): ResponseInterface + { + $bodyParamsMap = []; + + $bodyParamsMap[] = ['key' => 'user_id', 'value' => $userId]; + $bodyParamsMap[] = ['key' => 'msg_id', 'value' => $msgId]; + $bodyParamsMap[] = ['key' => 'action', 'value' => $action]; + + return $this->postApi('moderation/automod/message', $bearer, [], $bodyParamsMap); + } +} diff --git a/src/Resources/PollsApi.php b/src/Resources/PollsApi.php new file mode 100644 index 0000000..d4ac2fb --- /dev/null +++ b/src/Resources/PollsApi.php @@ -0,0 +1,71 @@ + 'broadcaster_id', 'value' => $broadcasterId]; + + foreach ($ids as $id) { + $queryParamsMap[] = ['key' => 'id', 'value' => $id]; + } + + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + + return $this->getApi('polls', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#create-poll + */ + public function createPoll(string $bearer, string $broadcasterId, string $title, array $choices, int $duration, $optionalBodyParams = []): ResponseInterface + { + $bodyParamsMap = []; + + $bodyParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + $bodyParamsMap[] = ['key' => 'title', 'value' => $title]; + $bodyParamsMap[] = ['key' => 'choices', 'value' => $choices]; + $bodyParamsMap[] = ['key' => 'duration', 'value' => $duration]; + + foreach ($optionalBodyParams as $key => $value) { + $bodyParamsMap[] = ['key' => $key, 'value' => $value]; + } + + return $this->postApi('polls', $bearer, [], $bodyParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#end-poll + */ + public function endPoll(string $bearer, string $broadcasterId, string $pollId, string $status): ResponseInterface + { + $bodyParamsMap = []; + + $bodyParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + $bodyParamsMap[] = ['key' => 'id', 'value' => $pollId]; + $bodyParamsMap[] = ['key' => 'status', 'value' => $status]; + + return $this->patchApi('polls', $bearer, [], $bodyParamsMap); + } +} diff --git a/src/Resources/PredictionsApi.php b/src/Resources/PredictionsApi.php new file mode 100644 index 0000000..cb2c810 --- /dev/null +++ b/src/Resources/PredictionsApi.php @@ -0,0 +1,71 @@ + 'broadcaster_id', 'value' => $broadcasterId]; + + foreach ($ids as $id) { + $queryParamsMap[] = ['key' => 'id', 'value' => $id]; + } + + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + + return $this->getApi('predictions', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#create-prediction + */ + public function createPrediction(string $bearer, string $broadcasterId, string $title, array $outcomes, int $predictionWindow): ResponseInterface + { + $bodyParamsMap = []; + + $bodyParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + $bodyParamsMap[] = ['key' => 'title', 'value' => $title]; + $bodyParamsMap[] = ['key' => 'outcomes', 'value' => $outcomes]; + $bodyParamsMap[] = ['key' => 'prediction_window', 'value' => $predictionWindow]; + + return $this->postApi('predictions', $bearer, [], $bodyParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#end-prediction + */ + public function endPrediction(string $bearer, string $broadcasterId, string $pollId, string $status, string $winningOutcomeId = null): ResponseInterface + { + $bodyParamsMap = []; + + $bodyParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + $bodyParamsMap[] = ['key' => 'id', 'value' => $pollId]; + $bodyParamsMap[] = ['key' => 'status', 'value' => $status]; + + if ($winningOutcomeId) { + $bodyParamsMap[] = ['key' => 'winning_outcome_id', 'value' => $winningOutcomeId]; + } + + return $this->patchApi('predictions', $bearer, [], $bodyParamsMap); + } +} diff --git a/src/Resources/ScheduleApi.php b/src/Resources/ScheduleApi.php new file mode 100644 index 0000000..ec4157b --- /dev/null +++ b/src/Resources/ScheduleApi.php @@ -0,0 +1,145 @@ + 'broadcaster_id', 'value' => $broadcasterId]; + + foreach ($ids as $id) { + $queryParamsMap[] = ['key' => 'id', 'value' => $id]; + } + + if ($startTime) { + $queryParamsMap[] = ['key' => 'start_time', 'value' => $startTime]; + } + + if ($utcOffset) { + $queryParamsMap[] = ['key' => 'utc_offset', 'value' => $utcOffset]; + } + + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + return $this->getApi('schedule', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference/#get-channel-icalendar + */ + public function getChanneliCalendar(string $bearer = null, string $broadcasterId): ResponseInterface + { + // This endpoint at the time of addition does not require any authorization, so the bearer is null. + // However, to prevent a breaking update in the future, it will remain the first function parameter. + // You may simple pass NULL to this to bypass authentication. + + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + return $this->getApiWithOptionalAuth('schedule/icalendar', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference/#update-channel-stream-schedule + */ + public function updateChannelStreamSchedule(string $bearer, string $broadcasterId, bool $isVacationEnabled = null, $vacationStartTime = null, $vacationEndTime = null, $timezone = null): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + if ($isVacationEnabled) { + $queryParamsMap[] = ['key' => 'is_vacation_enabled', 'value' => $isVacationEnabled]; + } + + if ($vacationStartTime) { + $queryParamsMap[] = ['key' => 'vacation_start_time', 'value' => $vacationStartTime]; + } + + if ($vacationEndTime) { + $queryParamsMap[] = ['key' => 'vacation_end_time', 'value' => $vacationEndTime]; + } + + if ($timezone) { + $queryParamsMap[] = ['key' => 'timezone', 'value' => $timezone]; + } + + return $this->patchApi('schedule/settings', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference/#create-channel-stream-schedule-segment + */ + public function createChannelStreamScheduleSegment(string $bearer, string $broadcasterId, string $startTime, string $timezone, bool $isRecurring, array $additionalBodyParams = []): ResponseInterface + { + // $additionalBodyParams should be a standard key => value format, eg. ['duration' => '240']; + $queryParamsMap = $bodyParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + $bodyParamsMap[] = ['key' => 'start_time', 'value' => $startTime]; + $bodyParamsMap[] = ['key' => 'timezone', 'value' => $timezone]; + $bodyParamsMap[] = ['key' => 'is_recurring', 'value' => $isRecurring]; + + foreach ($additionalBodyParams as $key => $value) { + $bodyParamsMap[] = ['key' => $key, 'value' => $value]; + } + + return $this->postApi('schedule/segment', $bearer, $queryParamsMap, $bodyParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference/#update-channel-stream-schedule-segment + */ + public function updateChannelStreamScheduleSegment(string $bearer, string $broadcasterId, string $segmentId, array $updateValues = []): ResponseInterface + { + // $updateValues should be a standard key => value format based on the values available on the documentation, eg. ['duration' => '240']; + $queryParamsMap = $bodyParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + $queryParamsMap[] = ['key' => 'id', 'value' => $segmentId]; + + foreach ($updateValues as $key => $value) { + $bodyParamsMap[] = ['key' => $key, 'value' => $value]; + } + + return $this->patchApi('schedule/segment', $bearer, $queryParamsMap, $bodyParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference/#delete-channel-stream-schedule-segment + */ + public function deleteChannelStreamScheduleSegment(string $bearer, string $broadcasterId, string $segmentId): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + $queryParamsMap[] = ['key' => 'id', 'value' => $segmentId]; + + return $this->deleteApi('schedule/segment', $bearer, $queryParamsMap); + } +} diff --git a/src/Resources/SearchApi.php b/src/Resources/SearchApi.php new file mode 100644 index 0000000..55c43d5 --- /dev/null +++ b/src/Resources/SearchApi.php @@ -0,0 +1,57 @@ + 'query', 'value' => $query]; + + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + return $this->getApi('search/categories', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#search-channels + */ + public function searchChannels(string $bearer, string $query, $liveOnly = null, string $first = null, string $after = null): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'query', 'value' => $query]; + + if ($liveOnly) { + $queryParamsMap[] = ['key' => 'live_only', 'value' => $liveOnly]; + } + + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + return $this->getApi('search/channels', $bearer, $queryParamsMap); + } +} diff --git a/src/Resources/StreamsApi.php b/src/Resources/StreamsApi.php new file mode 100644 index 0000000..545e541 --- /dev/null +++ b/src/Resources/StreamsApi.php @@ -0,0 +1,156 @@ +getStreams($bearer, [$userId]); + } + + /** + * @throws GuzzleException + */ + public function getStreamForUsername(string $bearer, string $username): ResponseInterface + { + return $this->getStreams($bearer, [], [$username]); + } + + /** + * @throws GuzzleException + */ + public function getStreamsByGameId(string $bearer, string $gameId, int $first = null, string $before = null, string $after = null): ResponseInterface + { + return $this->getStreams($bearer, [], [], [$gameId]); + } + + /** + * @throws GuzzleException + */ + public function getStreamsByLanguage(string $bearer, string $language, int $first = null, string $before = null, string $after = null): ResponseInterface + { + return $this->getStreams($bearer, [], [], [], [$language]); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#get-stream-key + */ + public function getStreamKey(string $bearer, string $broadcasterId): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + return $this->getApi('streams/key', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference/#get-streams + */ + public function getStreams(string $bearer, array $userIds = [], array $usernames = [], array $gameIds = [], array $languages = [], int $first = null, string $before = null, string $after = null): ResponseInterface + { + $queryParamsMap = []; + foreach ($userIds as $id) { + $queryParamsMap[] = ['key' => 'user_id', 'value' => $id]; + } + foreach ($usernames as $username) { + $queryParamsMap[] = ['key' => 'user_login', 'value' => $username]; + } + foreach ($gameIds as $gameId) { + $queryParamsMap[] = ['key' => 'game_id', 'value' => $gameId]; + } + foreach ($languages as $language) { + $queryParamsMap[] = ['key' => 'language', 'value' => $language]; + } + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + if ($before) { + $queryParamsMap[] = ['key' => 'before', 'value' => $before]; + } + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + return $this->getApi('streams', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference/#get-stream-markers + */ + public function getStreamMarkers(string $bearer, string $userId = null, string $videoId = null, string $first = null, string $before = null, string $after = null): ResponseInterface + { + $queryParamsMap = []; + + if ($userId) { + $queryParamsMap[] = ['key' => 'user_id', 'value' => $userId]; + } + + if ($videoId) { + $queryParamsMap[] = ['key' => 'video_id', 'value' => $videoId]; + } + + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + + if ($before) { + $queryParamsMap[] = ['key' => 'before', 'value' => $before]; + } + + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + return $this->getApi('streams/markers', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference/#get-followed-streams + */ + public function getFollowedStreams(string $bearer, string $userId, int $first = null, string $after = null): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'user_id', 'value' => $userId]; + + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + return $this->getApi('streams/followed', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#create-stream-marker + */ + public function createStreamMarker(string $bearer, string $userId, string $description = null): ResponseInterface + { + $bodyParamsMap = []; + + $bodyParamsMap[] = ['key' => 'user_id', 'value' => $userId]; + if ($description) { + $bodyParamsMap[] = ['key' => 'description', 'value' => $description]; + } + + return $this->postApi('streams/markers', $bearer, [], $bodyParamsMap); + } +} diff --git a/src/Resources/SubscriptionsApi.php b/src/Resources/SubscriptionsApi.php new file mode 100644 index 0000000..7422cbf --- /dev/null +++ b/src/Resources/SubscriptionsApi.php @@ -0,0 +1,63 @@ + 'broadcaster_id', 'value' => $broadcasterId]; + + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + return $this->getApi('subscriptions', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference/#get-broadcaster-subscriptions + */ + public function getBroadcasterSubscribers(string $bearer, string $broadcasterId, array $ids = []): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + foreach ($ids as $id) { + $queryParamsMap[] = ['key' => 'user_id', 'value' => $id]; + } + + return $this->getApi('subscriptions', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#check-user-subscription + */ + public function checkUserSubscription(string $bearer, string $broadcasterId, string $userId): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + $queryParamsMap[] = ['key' => 'user_id', 'value' => $userId]; + + return $this->getApi('subscriptions/user', $bearer, $queryParamsMap); + } +} diff --git a/src/Resources/TagsApi.php b/src/Resources/TagsApi.php new file mode 100644 index 0000000..0c14d11 --- /dev/null +++ b/src/Resources/TagsApi.php @@ -0,0 +1,63 @@ + 'tag_id', 'value' => $tagId]; + } + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + return $this->getApi('tags/streams', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#get-stream-tags + */ + public function getStreamTags(string $bearer, string $broadcasterId): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + return $this->getApi('streams/tags', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#replace-stream-tags + */ + public function replaceStreamTags(string $bearer, string $broadcasterId, $tags = []): ResponseInterface + { + $queryParamsMap = $bodyParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + if (count($tags) > 0) { + $bodyParamsMap[] = ['key' => 'tag_ids', 'value' => $tags]; + } + + return $this->putApi('streams/tags', $bearer, $queryParamsMap, $bodyParamsMap); + } +} diff --git a/src/Resources/TeamsApi.php b/src/Resources/TeamsApi.php new file mode 100644 index 0000000..3830fa8 --- /dev/null +++ b/src/Resources/TeamsApi.php @@ -0,0 +1,59 @@ + 'broadcaster_id', 'value' => $broadcasterId]; + + return $this->getApi('teams/channel', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#get-teams + */ + public function getTeams(string $bearer, string $name = null, string $id = null): ResponseInterface + { + $queryParamsMap = []; + + if ($name) { + $queryParamsMap[] = ['key' => 'name', 'value' => $name]; + } + + if ($id) { + $queryParamsMap[] = ['key' => 'id', 'value' => $id]; + } + + return $this->getApi('teams', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + */ + public function getTeamsByName(string $bearer, string $name): ResponseInterface + { + return $this->getTeams($bearer, $name, null); + } + + /** + * @throws GuzzleException + */ + public function getTeamsById(string $bearer, string $id): ResponseInterface + { + return $this->getTeams($bearer, null, $id); + } +} diff --git a/src/Resources/UsersApi.php b/src/Resources/UsersApi.php new file mode 100644 index 0000000..ca8d407 --- /dev/null +++ b/src/Resources/UsersApi.php @@ -0,0 +1,207 @@ +getUsers($userAccessToken, [], [], $includeEmail); + } + + /** + * @throws GuzzleException + */ + public function getUserById(string $bearer, string $id, bool $includeEmail = false): ResponseInterface + { + return $this->getUsers($bearer, [$id], [], $includeEmail); + } + + /** + * @throws GuzzleException + */ + public function getUserByUsername(string $bearer, string $username, bool $includeEmail = false): ResponseInterface + { + return $this->getUsers($bearer, [], [$username], $includeEmail); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference/#get-users + */ + public function getUsers(string $bearer, array $ids = [], array $usernames = [], bool $includeEmail = false): ResponseInterface + { + $queryParamsMap = []; + foreach ($ids as $id) { + $queryParamsMap[] = ['key' => 'id', 'value' => $id]; + } + foreach ($usernames as $username) { + $queryParamsMap[] = ['key' => 'login', 'value' => $username]; + } + if ($includeEmail) { + $queryParamsMap[] = ['key' => 'scope', 'value' => 'user:read:email']; + } + + return $this->getApi('users', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference/#get-users-follows + */ + public function getUsersFollows(string $bearer, string $followerId = null, string $followedUserId = null, int $first = null, string $after = null): ResponseInterface + { + $queryParamsMap = []; + if ($followerId) { + $queryParamsMap[] = ['key' => 'from_id', 'value' => $followerId]; + } + if ($followedUserId) { + $queryParamsMap[] = ['key' => 'to_id', 'value' => $followedUserId]; + } + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + return $this->getApi('users/follows', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference/#get-user-extensions + */ + public function getUserExtensions(string $bearer): ResponseInterface + { + $queryParamsMap = []; + + return $this->getApi('users/extensions/list', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference/#get-user-active-extensions + */ + public function getActiveUserExtensions(string $bearer, string $userId = null): ResponseInterface + { + $queryParamsMap = []; + + if ($userId) { + $queryParamsMap[] = ['key' => 'user_id', 'value' => $userId]; + } + + return $this->getApi('users/extensions', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#create-user-follows + */ + public function createUserFollow(string $bearer, string $fromId, string $toId, bool $notifications = null): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'from_id', 'value' => $fromId]; + + $queryParamsMap[] = ['key' => 'to_id', 'value' => $toId]; + + if ($notifications !== null) { + $queryParamsMap[] = ['key' => 'allow_notifications', 'value' => $notifications]; + } + + return $this->postApi('users/follows', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#delete-user-follows + */ + public function deleteUserFollow(string $bearer, string $fromId, string $toId): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'from_id', 'value' => $fromId]; + + $queryParamsMap[] = ['key' => 'to_id', 'value' => $toId]; + + return $this->deleteApi('users/follows', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#update-user + */ + public function updateUser(string $bearer, string $description = null): ResponseInterface + { + $queryParamsMap = []; + + if ($description) { + $queryParamsMap[] = ['key' => 'description', 'value' => $description]; + } + + return $this->putApi('users', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#get-user-block-list + */ + public function getUserBlockList(string $bearer, string $broadcasterId, int $first = null, string $after = null): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; + + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + return $this->getApi('users/blocks', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#block-user + */ + public function blockUser(string $bearer, string $targetUserId, string $sourceContext = null, string $reason = null): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'target_user_id', 'value' => $targetUserId]; + + if ($sourceContext) { + $queryParamsMap[] = ['key' => 'source_context', 'value' => $sourceContext]; + } + + if ($reason) { + $queryParamsMap[] = ['key' => 'reason', 'value' => $reason]; + } + + return $this->putApi('users/blocks', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#unblock-user + */ + public function unblockUser(string $bearer, string $targetUserId): ResponseInterface + { + $queryParamsMap = []; + + $queryParamsMap[] = ['key' => 'target_user_id', 'value' => $targetUserId]; + + return $this->deleteApi('users/blocks', $bearer, $queryParamsMap); + } +} diff --git a/src/Resources/VideosApi.php b/src/Resources/VideosApi.php new file mode 100644 index 0000000..17e4d00 --- /dev/null +++ b/src/Resources/VideosApi.php @@ -0,0 +1,77 @@ + 'id', 'value' => $id]; + } + + if ($userId) { + $queryParamsMap[] = ['key' => 'user_id', 'value' => $userId]; + } + + if ($gameId) { + $queryParamsMap[] = ['key' => 'game_id', 'value' => $gameId]; + } + + if ($first) { + $queryParamsMap[] = ['key' => 'first', 'value' => $first]; + } + + if ($before) { + $queryParamsMap[] = ['key' => 'before', 'value' => $before]; + } + + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + if ($language) { + $queryParamsMap[] = ['key' => 'language', 'value' => $language]; + } + + if ($period) { + $queryParamsMap[] = ['key' => 'period', 'value' => $period]; + } + + if ($sort) { + $queryParamsMap[] = ['key' => 'sort', 'value' => $sort]; + } + + if ($type) { + $queryParamsMap[] = ['key' => 'type', 'value' => $type]; + } + + return $this->getApi('videos', $bearer, $queryParamsMap); + } + + /** + * @throws GuzzleException + * @link https://dev.twitch.tv/docs/api/reference#delete-videos + */ + public function deleteVideos(string $bearer, array $ids = []): ResponseInterface + { + $queryParamsMap = []; + + foreach ($ids as $id) { + $queryParamsMap[] = ['key' => 'id', 'value' => $id]; + } + + return $this->deleteApi('videos', $bearer, $queryParamsMap); + } +} diff --git a/src/Resources/WebhooksApi.php b/src/Resources/WebhooksApi.php new file mode 100644 index 0000000..b933ef2 --- /dev/null +++ b/src/Resources/WebhooksApi.php @@ -0,0 +1,28 @@ + 'first', 'value' => $first]; + } + if ($after) { + $queryParamsMap[] = ['key' => 'after', 'value' => $after]; + } + + return $this->getApi('webhooks/subscriptions', $bearer, $queryParamsMap); + } +} diff --git a/src/TwitchApi.php b/src/TwitchApi.php index 8cc662e..20c86c5 100644 --- a/src/TwitchApi.php +++ b/src/TwitchApi.php @@ -1,310 +1,216 @@ oauthApi = new OauthApi($clientId, $clientSecret, $authGuzzleClient); + $this->adsApi = new AdsApi($helixGuzzleClient, $requestGenerator); + $this->analyticsApi = new AnalyticsApi($helixGuzzleClient, $requestGenerator); + $this->bitsApi = new BitsApi($helixGuzzleClient, $requestGenerator); + $this->channelPointsApi = new ChannelPointsApi($helixGuzzleClient, $requestGenerator); + $this->channelsApi = new ChannelsApi($helixGuzzleClient, $requestGenerator); + $this->chatApi = new ChatApi($helixGuzzleClient, $requestGenerator); + $this->clipsApi = new ClipsApi($helixGuzzleClient, $requestGenerator); + $this->entitlementsApi = new EntitlementsApi($helixGuzzleClient, $requestGenerator); + $this->eventSubApi = new EventSubApi($helixGuzzleClient, $requestGenerator); + $this->gamesApi = new GamesApi($helixGuzzleClient, $requestGenerator); + $this->hypeTrainApi = new HypeTrainApi($helixGuzzleClient, $requestGenerator); + $this->moderationApi = new ModerationApi($helixGuzzleClient, $requestGenerator); + $this->pollsApi = new PollsApi($helixGuzzleClient, $requestGenerator); + $this->predictionsApi = new PredictionsApi($helixGuzzleClient, $requestGenerator); + $this->scheduleApi = new ScheduleApi($helixGuzzleClient, $requestGenerator); + $this->searchApi = new SearchApi($helixGuzzleClient, $requestGenerator); + $this->streamsApi = new StreamsApi($helixGuzzleClient, $requestGenerator); + $this->subscriptionsApi = new SubscriptionsApi($helixGuzzleClient, $requestGenerator); + $this->tagsApi = new TagsApi($helixGuzzleClient, $requestGenerator); + $this->teamsApi = new TeamsApi($helixGuzzleClient, $requestGenerator); + $this->usersApi = new UsersApi($helixGuzzleClient, $requestGenerator); + $this->videosApi = new VideosApi($helixGuzzleClient, $requestGenerator); + $this->webhooksApi = new WebhooksApi($helixGuzzleClient, $requestGenerator); + $this->webhooksSubscriptionApi = new WebhooksSubscriptionApi($clientId, $clientSecret, $helixGuzzleClient); + } - /** - * @var string - */ - protected $accessToken; + public function getOauthApi(): OauthApi + { + return $this->oauthApi; + } - /** - * Instantiate a new TwitchApi instance - * - * @param array $options - */ - public function __construct(array $options) + public function getAdsApi(): AdsApi { - if (!isset($options['client_id'])) { - throw new ClientIdRequiredException(); - } + return $this->adsApi; + } - $this->setClientId($options['client_id']); - $this->setClientSecret(isset($options['client_secret']) ? $options['client_secret'] : null); - $this->setRedirectUri(isset($options['redirect_uri']) ? $options['redirect_uri'] : null); - $this->setApiVersion(isset($options['api_version']) ? $options['api_version'] : $this->getDefaultApiVersion()); - $this->setScope(isset($options['scope']) ? $options['scope'] : []); + public function getAnalyticsApi(): AnalyticsApi + { + return $this->analyticsApi; } - /** - * Get defaultApiVersion - * - * @return int - */ - public function getDefaultApiVersion() + public function getBitsApi(): BitsApi { - return $this->defaultApiVersion; + return $this->bitsApi; } - /** - * Get supportedApiVersions - * - * @return array - */ - public function getSupportedApiVersions() + public function getChannelPointsApi(): ChannelPointsApi { - return $this->supportedApiVersions; + return $this->channelPointsApi; } - /** - * Set client ID - * - * @param string - */ - public function setClientId($clientId) + public function getChannelsApi(): ChannelsApi { - $this->clientId = (string) $clientId; + return $this->channelsApi; } - /** - * Get client ID - * - * @return string - */ - public function getClientId() + public function getChatApi(): ChatApi { - return $this->clientId; + return $this->chatApi; } - /** - * Set client secret - * - * @param string $clientSecret - */ - public function setClientSecret($clientSecret) + public function getClipsApi(): ClipsApi { - $this->clientSecret = (string) $clientSecret; + return $this->clipsApi; } - /** - * Get client secret - * - * @return string - */ - public function getClientSecret() + public function getEntitlementsApi(): EntitlementsApi { - return $this->clientSecret; + return $this->entitlementsApi; } - /** - * Set API version - * - * @param string|int $apiVersion - * @throws UnsupportedApiVersionException - */ - public function setApiVersion($apiVersion) + public function getEventSubApi(): EventSubApi { - if (!in_array($apiVersion = intval($apiVersion), $this->getSupportedApiVersions())) { - throw new UnsupportedApiVersionException(); - } + return $this->eventSubApi; + } - $this->apiVersion = $apiVersion; + public function getGamesApi(): GamesApi + { + return $this->gamesApi; } - /** - * Get API version - * - * @return int - */ - public function getApiVersion() + public function getHypeTrainApi(): HypeTrainApi { - return $this->apiVersion; + return $this->hypeTrainApi; } - /** - * Set redirect URI - * - * @param string $redirectUri - */ - public function setRedirectUri($redirectUri) + public function getModerationApi(): ModerationApi { - $this->redirectUri = (string) $redirectUri; + return $this->moderationApi; } - /** - * Get redirect URI - * - * @return string - */ - public function getRedirectUri() + public function getPollsApi(): PollsApi { - return $this->redirectUri; + return $this->pollsApi; } - /** - * Set scope - * - * @param array $scope - * @throws InvalidTypeException - */ - public function setScope($scope) + public function getPredictionsApi(): PredictionsApi { - if (!is_array($scope)) { - throw new InvalidTypeException('Scope', 'array', gettype($scope)); - } + return $this->predictionsApi; + } - $this->scope = $scope; + public function getScheduleApi(): ScheduleApi + { + return $this->scheduleApi; } - /** - * Get scope - * - * @return array - */ - public function getScope() + public function getSearchApi(): SearchApi { - return $this->scope; + return $this->searchApi; } - /** - * Returns true if the set API version is greater than v3 - * - * @return bool - */ - protected function apiVersionIsGreaterThanV3() + public function getStreamsApi(): StreamsApi { - return $this->getApiVersion() > 3; + return $this->streamsApi; } - /** - * Return true if the provided limit is valid - * - * @param string|int $limit - * @return bool - */ - protected function isValidLimit($limit) + public function getSubscriptionsApi(): SubscriptionsApi { - return is_numeric($limit) && $limit > 0; + return $this->subscriptionsApi; } - /** - * Return true if the provided offset is valid - * - * @param string|int $offset - * @return bool - */ - protected function isValidOffset($offset) + public function getTagsApi(): TagsApi { - return is_numeric($offset) && $offset > -1; + return $this->tagsApi; } - /** - * Return true if the provided direction is valid - * - * @param string $direction - * @return bool - */ - protected function isValidDirection($direction) + public function getTeamsApi(): TeamsApi { - return in_array(strtolower($direction), ['asc', 'desc']); + return $this->teamsApi; } - /** - * Return true if the provided broadcast type is valid - * - * @param string $broadcastType - * @return bool - */ - protected function isValidBroadcastType($broadcastType) + public function getUsersApi(): UsersApi { - $validBroadcastTypes = ['archive', 'highlight', 'upload']; + return $this->usersApi; + } - $broadcastTypeArray = explode(',', $broadcastType); - foreach ($broadcastTypeArray as $type) { - if (!in_array($type, $validBroadcastTypes)) { - return false; - } - } + public function getVideosApi(): VideosApi + { + return $this->videosApi; + } - return true; + public function getWebhooksApi(): WebhooksApi + { + return $this->webhooksApi; } - /** - * Return true if the provided stream type is valid - * - * @param string $streamType - * @return bool - */ - protected function isValidStreamType($streamType) + public function getWebhooksSubscriptionApi(): WebhooksSubscriptionApi { - return in_array(strtolower($streamType), ['live', 'playlist', 'all']); + return $this->webhooksSubscriptionApi; } } diff --git a/src/Webhooks/WebhooksSubscriptionApi.php b/src/Webhooks/WebhooksSubscriptionApi.php new file mode 100644 index 0000000..980f0eb --- /dev/null +++ b/src/Webhooks/WebhooksSubscriptionApi.php @@ -0,0 +1,161 @@ +clientId = $clientId; + $this->secret = $secret; + $this->guzzleClient = $guzzleClient ?? HelixGuzzleClient::getClient($clientId); + } + + public function subscribeToStream(string $twitchId, string $callback, string $bearer, int $leaseSeconds = 0): void + { + $this->subscribe( + sprintf('https://api.twitch.tv/helix/streams?user_id=%s', $twitchId), + $callback, + $bearer, + $leaseSeconds + ); + } + + public function subscribeToSubscriptionEvents(string $twitchId, string $callback, string $bearer, int $leaseSeconds = 0): void + { + $this->subscribe( + sprintf('https://api.twitch.tv/helix/subscriptions/events?broadcaster_id=%s&first=1', $twitchId), + $callback, + $bearer, + $leaseSeconds + ); + } + + public function subscribeToUser(string $twitchId, string $callback, string $bearer, int $leaseSeconds = 0): void + { + $this->subscribe( + sprintf('https://api.twitch.tv/helix/users?id=%s', $twitchId), + $callback, + $bearer, + $leaseSeconds + ); + } + + public function subscribeToUserFollows(string $followerId, string $followedUserId, int $first, string $callback, string $bearer, int $leaseSeconds = 0): void + { + $queryParams = []; + if ($followerId) { + $queryParams['from_id'] = $followerId; + } + if ($followedUserId) { + $queryParams['to_id'] = $followedUserId; + } + if ($first) { + $queryParams['first'] = $first; + } + $this->subscribe( + sprintf('https://api.twitch.tv/helix/users/follows?%s', http_build_query($queryParams)), + $callback, + $bearer, + $leaseSeconds + ); + } + + public function unsubscribeFromStream(string $twitchId, string $callback, string $bearer): void + { + $this->unsubscribe( + sprintf('https://api.twitch.tv/helix/streams?user_id=%s', $twitchId), + $callback, + $bearer + ); + } + + public function unsubscribeFromUser(string $twitchId, string $callback, string $bearer) + { + $this->unsubscribe( + sprintf('https://api.twitch.tv/helix/users?id=%s', $twitchId), + $callback, + $bearer + ); + } + + public function unsubscribeFromUserFollows(string $followerId, string $followedUserId, int $first, string $callback, string $bearer) + { + $queryParams = []; + if ($followerId) { + $queryParams['from_id'] = $followerId; + } + if ($followedUserId) { + $queryParams['to_id'] = $followedUserId; + } + if ($first) { + $queryParams['first'] = $first; + } + $this->unsubscribe( + sprintf('https://api.twitch.tv/helix/users/follows?%s', http_build_query($queryParams)), + $callback, + $bearer + ); + } + + public function validateWebhookEventCallback(string $xHubSignature, string $content): bool + { + [$hashAlgorithm, $expectedHash] = explode('=', $xHubSignature); + $generatedHash = hash_hmac($hashAlgorithm, $content, $this->secret); + + return $expectedHash === $generatedHash; + } + + private function subscribe(string $topic, string $callback, string $bearer, int $leaseSeconds = 0): void + { + $headers = [ + 'Client-ID' => $this->clientId, + ]; + + $headers['Authorization'] = sprintf('Bearer %s', $bearer); + + $body = [ + 'hub.callback' => $callback, + 'hub.mode' => self::SUBSCRIBE, + 'hub.topic' => $topic, + 'hub.lease_seconds' => $leaseSeconds, + 'hub.secret' => $this->secret, + ]; + + $this->guzzleClient->post('webhooks/hub', [ + 'headers' => $headers, + 'body' => json_encode($body), + ]); + } + + private function unsubscribe(string $topic, string $callback, string $bearer): void + { + $headers = [ + 'Client-ID' => $this->clientId, + ]; + + $headers['Authorization'] = sprintf('Bearer %s', $bearer); + + $body = [ + 'hub.callback' => $callback, + 'hub.mode' => self::UNSUBSCRIBE, + 'hub.topic' => $topic, + ]; + + $this->guzzleClient->post('webhooks/hub', [ + 'headers' => $headers, + 'body' => json_encode($body), + ]); + } +} diff --git a/test/TwitchApi/Resources/UsersTest.php b/test/TwitchApi/Resources/UsersTest.php new file mode 100644 index 0000000..fab45e6 --- /dev/null +++ b/test/TwitchApi/Resources/UsersTest.php @@ -0,0 +1,68 @@ +getHelixGuzzleClientWithMockUserResponse(), $this->getRequestGenerator()); + $response = $users->getUserById('TEST_APP_ACCESS_TOKEN', '44322889'); + + $this->assertEquals(200, $response->getStatusCode()); + $contents = json_decode($response->getBody()->getContents()); + $this->assertEquals('dallas', $contents->data[0]->login); + } + + public function testGetUserByUsernameShouldReturnSuccessfulResponseWithUserData(): void + { + $users = new UsersApi($this->getHelixGuzzleClientWithMockUserResponse(), $this->getRequestGenerator()); + $response = $users->getUserByUsername('TEST_APP_ACCESS_TOKEN', 'dallas'); + + $this->assertEquals(200, $response->getStatusCode()); + $contents = json_decode($response->getBody()->getContents()); + $this->assertEquals(44322889, $contents->data[0]->id); + } + + private function getHelixGuzzleClientWithMockUserResponse(): HelixGuzzleClient + { + // Example response from https://dev.twitch.tv/docs/api/reference/#get-users + $getUserReponseJson = << $handler]); + } + + private function getRequestGenerator(): RequestGenerator + { + return new RequestGenerator(); + } +} From f27dfdff9f02c8afdddf82e1826d967e2c0c4dea Mon Sep 17 00:00:00 2001 From: Brandin Arsenault Date: Wed, 28 Jul 2021 15:04:51 -0300 Subject: [PATCH 2/6] Drop v5, rename NewTwitchApi to TwitchApi, Add Legacy Support --- .../Auth/AuthGuzzleClientSpec.php | 28 - spec/NewTwitchApi/Auth/OauthApiSpec.php | 118 ---- spec/NewTwitchApi/HelixGuzzleClientSpec.php | 45 -- spec/NewTwitchApi/NewTwitchApiSpec.php | 136 ----- spec/NewTwitchApi/Resources/AdsApiSpec.php | 24 - .../Resources/AnalyticsApiSpec.php | 102 ---- spec/NewTwitchApi/Resources/BitsApiSpec.php | 54 -- .../Resources/ChannelPointsApiSpec.php | 120 ---- .../Resources/ChannelsApiSpec.php | 60 -- spec/NewTwitchApi/Resources/ChatApiSpec.php | 60 -- .../Resources/EntitlementsApiSpec.php | 84 --- .../Resources/EventSubApiSpec.php | 249 -------- spec/NewTwitchApi/Resources/GamesApiSpec.php | 60 -- .../Resources/ModerationApiSpec.php | 30 - spec/NewTwitchApi/Resources/PollsApiSpec.php | 60 -- .../Resources/PredictionsApiSpec.php | 60 -- .../Resources/ScheduleApiSpec.php | 84 --- .../NewTwitchApi/Resources/StreamsApiSpec.php | 156 ----- .../Resources/SubscriptionsApiSpec.php | 54 -- spec/NewTwitchApi/Resources/TagsApiSpec.php | 66 --- spec/NewTwitchApi/Resources/TeamsApiSpec.php | 54 -- spec/NewTwitchApi/Resources/UsersApiSpec.php | 162 ------ spec/NewTwitchApi/Resources/VideosApiSpec.php | 102 ---- .../Resources/WebhooksApiSpec.php | 42 -- src/Api/Authentication.php | 75 --- src/Api/Bits.php | 34 -- src/Api/ChannelFeed.php | 355 ------------ src/Api/Channels.php | 409 ------------- src/Api/Chat.php | 53 -- src/Api/Clips.php | 143 ----- src/Api/Collections.php | 290 ---------- src/Api/Communities.php | 537 ------------------ src/Api/Games.php | 37 -- src/Api/Ingests.php | 16 - src/Api/Root.php | 17 - src/Api/Search.php | 116 ---- src/Api/Streams.php | 182 ------ src/Api/Teams.php | 53 -- src/Api/Users.php | 355 ------------ src/Api/Videos.php | 113 ---- src/Exceptions/ClientIdRequiredException.php | 11 - ...pointNotSupportedByApiVersionException.php | 14 - src/Exceptions/InvalidDirectionException.php | 11 - .../InvalidEmailAddressException.php | 11 - src/Exceptions/InvalidIdentifierException.php | 14 - src/Exceptions/InvalidLimitException.php | 11 - src/Exceptions/InvalidOffsetException.php | 11 - .../InvalidParameterLengthException.php | 14 - src/Exceptions/InvalidStreamTypeException.php | 11 - src/Exceptions/InvalidTypeException.php | 16 - src/Exceptions/TwitchApiException.php | 15 - .../UnsupportedApiVersionException.php | 11 - src/Exceptions/UnsupportedOptionException.php | 15 - src/NewTwitchApi/Auth/AuthGuzzleClient.php | 19 - src/NewTwitchApi/Auth/OauthApi.php | 149 ----- src/NewTwitchApi/RequestGenerator.php | 81 --- .../Resources/AbstractResource.php | 75 --- src/NewTwitchApi/Resources/AdsApi.php | 25 - src/NewTwitchApi/Resources/AnalyticsApi.php | 81 --- src/NewTwitchApi/Resources/BitsApi.php | 78 --- .../Resources/ChannelPointsApi.php | 149 ----- src/NewTwitchApi/Resources/ChannelsApi.php | 55 -- src/NewTwitchApi/Resources/ChatApi.php | 76 --- src/NewTwitchApi/Resources/ClipsApi.php | 87 --- .../Resources/EntitlementsApi.php | 89 --- src/NewTwitchApi/Resources/EventSubApi.php | 523 ----------------- src/NewTwitchApi/Resources/GamesApi.php | 51 -- src/NewTwitchApi/Resources/HypeTrainApi.php | 36 -- src/NewTwitchApi/Resources/ModerationApi.php | 135 ----- src/NewTwitchApi/Resources/PollsApi.php | 71 --- src/NewTwitchApi/Resources/PredictionsApi.php | 71 --- src/NewTwitchApi/Resources/ScheduleApi.php | 145 ----- src/NewTwitchApi/Resources/SearchApi.php | 57 -- src/NewTwitchApi/Resources/StreamsApi.php | 156 ----- .../Resources/SubscriptionsApi.php | 63 -- src/NewTwitchApi/Resources/TagsApi.php | 63 -- src/NewTwitchApi/Resources/TeamsApi.php | 59 -- src/NewTwitchApi/Resources/UsersApi.php | 207 ------- src/NewTwitchApi/Resources/VideosApi.php | 77 --- src/NewTwitchApi/Resources/WebhooksApi.php | 28 - .../Webhooks/WebhooksSubscriptionApi.php | 161 ------ src/TwitchRequest.php | 220 ------- test/NewTwitchApi/Resources/UsersTest.php | 68 --- test/TwitchApiTest.php | 81 --- 84 files changed, 8196 deletions(-) delete mode 100644 spec/NewTwitchApi/Auth/AuthGuzzleClientSpec.php delete mode 100644 spec/NewTwitchApi/Auth/OauthApiSpec.php delete mode 100644 spec/NewTwitchApi/HelixGuzzleClientSpec.php delete mode 100644 spec/NewTwitchApi/NewTwitchApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/AdsApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/AnalyticsApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/BitsApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/ChannelPointsApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/ChannelsApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/ChatApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/EntitlementsApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/EventSubApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/GamesApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/ModerationApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/PollsApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/PredictionsApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/ScheduleApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/StreamsApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/SubscriptionsApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/TagsApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/TeamsApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/UsersApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/VideosApiSpec.php delete mode 100644 spec/NewTwitchApi/Resources/WebhooksApiSpec.php delete mode 100644 src/Api/Authentication.php delete mode 100644 src/Api/Bits.php delete mode 100644 src/Api/ChannelFeed.php delete mode 100644 src/Api/Channels.php delete mode 100644 src/Api/Chat.php delete mode 100644 src/Api/Clips.php delete mode 100644 src/Api/Collections.php delete mode 100644 src/Api/Communities.php delete mode 100644 src/Api/Games.php delete mode 100644 src/Api/Ingests.php delete mode 100644 src/Api/Root.php delete mode 100644 src/Api/Search.php delete mode 100644 src/Api/Streams.php delete mode 100644 src/Api/Teams.php delete mode 100644 src/Api/Users.php delete mode 100644 src/Api/Videos.php delete mode 100644 src/Exceptions/ClientIdRequiredException.php delete mode 100644 src/Exceptions/EndpointNotSupportedByApiVersionException.php delete mode 100644 src/Exceptions/InvalidDirectionException.php delete mode 100644 src/Exceptions/InvalidEmailAddressException.php delete mode 100644 src/Exceptions/InvalidIdentifierException.php delete mode 100644 src/Exceptions/InvalidLimitException.php delete mode 100644 src/Exceptions/InvalidOffsetException.php delete mode 100644 src/Exceptions/InvalidParameterLengthException.php delete mode 100644 src/Exceptions/InvalidStreamTypeException.php delete mode 100644 src/Exceptions/InvalidTypeException.php delete mode 100644 src/Exceptions/TwitchApiException.php delete mode 100644 src/Exceptions/UnsupportedApiVersionException.php delete mode 100644 src/Exceptions/UnsupportedOptionException.php delete mode 100644 src/NewTwitchApi/Auth/AuthGuzzleClient.php delete mode 100644 src/NewTwitchApi/Auth/OauthApi.php delete mode 100644 src/NewTwitchApi/RequestGenerator.php delete mode 100644 src/NewTwitchApi/Resources/AbstractResource.php delete mode 100644 src/NewTwitchApi/Resources/AdsApi.php delete mode 100644 src/NewTwitchApi/Resources/AnalyticsApi.php delete mode 100644 src/NewTwitchApi/Resources/BitsApi.php delete mode 100644 src/NewTwitchApi/Resources/ChannelPointsApi.php delete mode 100644 src/NewTwitchApi/Resources/ChannelsApi.php delete mode 100644 src/NewTwitchApi/Resources/ChatApi.php delete mode 100644 src/NewTwitchApi/Resources/ClipsApi.php delete mode 100644 src/NewTwitchApi/Resources/EntitlementsApi.php delete mode 100644 src/NewTwitchApi/Resources/EventSubApi.php delete mode 100644 src/NewTwitchApi/Resources/GamesApi.php delete mode 100644 src/NewTwitchApi/Resources/HypeTrainApi.php delete mode 100644 src/NewTwitchApi/Resources/ModerationApi.php delete mode 100644 src/NewTwitchApi/Resources/PollsApi.php delete mode 100644 src/NewTwitchApi/Resources/PredictionsApi.php delete mode 100644 src/NewTwitchApi/Resources/ScheduleApi.php delete mode 100644 src/NewTwitchApi/Resources/SearchApi.php delete mode 100644 src/NewTwitchApi/Resources/StreamsApi.php delete mode 100644 src/NewTwitchApi/Resources/SubscriptionsApi.php delete mode 100644 src/NewTwitchApi/Resources/TagsApi.php delete mode 100644 src/NewTwitchApi/Resources/TeamsApi.php delete mode 100644 src/NewTwitchApi/Resources/UsersApi.php delete mode 100644 src/NewTwitchApi/Resources/VideosApi.php delete mode 100644 src/NewTwitchApi/Resources/WebhooksApi.php delete mode 100644 src/NewTwitchApi/Webhooks/WebhooksSubscriptionApi.php delete mode 100644 src/TwitchRequest.php delete mode 100644 test/NewTwitchApi/Resources/UsersTest.php delete mode 100644 test/TwitchApiTest.php diff --git a/spec/NewTwitchApi/Auth/AuthGuzzleClientSpec.php b/spec/NewTwitchApi/Auth/AuthGuzzleClientSpec.php deleted file mode 100644 index 500934e..0000000 --- a/spec/NewTwitchApi/Auth/AuthGuzzleClientSpec.php +++ /dev/null @@ -1,28 +0,0 @@ -beConstructedThrough('getClient'); - $this->shouldHaveType('\GuzzleHttp\Client'); - - /** @var Uri $uri */ - $uri = $this->getConfig('base_uri'); - $uri->getScheme()->shouldBe('https'); - $uri->getHost()->shouldBe('id.twitch.tv'); - $uri->getPath()->shouldBe('/oauth2/'); - } - - function it_should_have_passed_in_config_params_instead_of_defaults() - { - $this->beConstructedThrough('getClient', [['base_uri' => 'https://different.url']]); - $this->shouldHaveType('\GuzzleHttp\Client'); - $this->getConfig('base_uri')->getHost()->shouldBe('different.url'); - } -} diff --git a/spec/NewTwitchApi/Auth/OauthApiSpec.php b/spec/NewTwitchApi/Auth/OauthApiSpec.php deleted file mode 100644 index 810a1f5..0000000 --- a/spec/NewTwitchApi/Auth/OauthApiSpec.php +++ /dev/null @@ -1,118 +0,0 @@ -beConstructedWith('client-id', 'client-secret', $guzzleClient); - } - - function it_should_get_auth_url(Client $guzzleClient) - { - $guzzleClient->getConfig('base_uri')->willReturn('https://id.twitch.tv/oauth2/'); - $this->getAuthUrl('https://redirect.url')->shouldReturn( - 'https://id.twitch.tv/oauth2/authorize?client_id=client-id&redirect_uri=https://redirect.url&response_type=code&scope=' - ); - } - - function it_should_get_access_token(Client $guzzleClient, Response $response) - { - $request = new Request( - 'POST', - 'token' - ); - $guzzleClient->send($request, ['json' => [ - 'client_id' => 'client-id', - 'client_secret' => 'client-secret', - 'grant_type' => 'authorization_code', - 'redirect_uri' => 'https://redirect.url', - 'code' => 'user-code-from-twitch', - 'state' => null, - ]])->willReturn($response); - - $this->getUserAccessToken('user-code-from-twitch', 'https://redirect.url')->shouldBe($response); - } - - function it_should_get_refresh_token(Client $guzzleClient, Response $response) - { - $request = new Request( - 'POST', - 'token' - ); - $guzzleClient->send($request, ['json' => [ - 'client_id' => 'client-id', - 'client_secret' => 'client-secret', - 'grant_type' => 'refresh_token', - 'refresh_token' => 'user-refresh-token', - ]])->willReturn($response); - - $this->refreshToken('user-refresh-token')->shouldBe($response); - } - - function it_should_validate_access_token(Client $guzzleClient, Response $response) - { - $request = new Request( - 'GET', - 'validate', - [ - 'Authorization' => 'OAuth user-access-token', - ] - ); - $guzzleClient->send($request, [])->willReturn($response); - - $this->validateAccessToken('user-access-token')->shouldBe($response); - } - - function it_should_return_true_if_access_token_is_valid(Client $guzzleClient, Response $response) - { - $request = new Request( - 'GET', - 'validate', - [ - 'Authorization' => 'OAuth user-access-token', - ] - ); - $response->getStatusCode()->willReturn(200); - $guzzleClient->send($request, [])->willReturn($response); - - $this->isValidAccessToken('user-access-token')->shouldReturn(true); - } - - function it_should_return_false_if_access_token_is_invalid(Client $guzzleClient, Response $response) - { - $request = new Request( - 'GET', - 'validate', - [ - 'Authorization' => 'OAuth invalid-user-access-token', - ] - ); - $response->getStatusCode()->willReturn(401); - $guzzleClient->send($request, [])->willReturn($response); - - $this->isValidAccessToken('invalid-user-access-token')->shouldReturn(false); - } - - function it_should_get_app_access_token(Client $guzzleClient, Response $response) - { - $request = new Request( - 'POST', - 'token' - ); - $guzzleClient->send($request, ['json' => [ - 'client_id' => 'client-id', - 'client_secret' => 'client-secret', - 'grant_type' => 'client_credentials', - 'scope' => '', - ]])->willReturn($response); - - $this->getAppAccessToken()->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/HelixGuzzleClientSpec.php b/spec/NewTwitchApi/HelixGuzzleClientSpec.php deleted file mode 100644 index 31366e6..0000000 --- a/spec/NewTwitchApi/HelixGuzzleClientSpec.php +++ /dev/null @@ -1,45 +0,0 @@ -beConstructedWith('TEST_CLIENT_ID'); - } - - function it_should_have_correct_base_uri() - { - $this->shouldHaveType('\NewTwitchApi\HelixGuzzleClient'); - - /** @var Uri $uri */ - $uri = $this->getConfig('base_uri'); - $uri->getScheme()->shouldBe('https'); - $uri->getHost()->shouldBe('api.twitch.tv'); - $uri->getPath()->shouldBe('/helix/'); - } - - function it_should_have_client_id_header() - { - $this->shouldHaveType('\NewTwitchApi\HelixGuzzleClient'); - $this->getConfig('headers')->shouldHaveKeyWithValue('Client-ID', 'TEST_CLIENT_ID'); - } - - function it_should_have_json_content_type_header() - { - - $this->shouldHaveType('\NewTwitchApi\HelixGuzzleClient'); - $this->getConfig('headers')->shouldHaveKeyWithValue('Content-Type', 'application/json'); - } - - function it_should_have_passed_in_config_params_instead_of_defaults() - { - $this->beConstructedWith('TEST_CLIENT_ID', ['base_uri' => 'https://different.url']); - $this->shouldHaveType('\NewTwitchApi\HelixGuzzleClient'); - $this->getConfig('base_uri')->getHost()->shouldBe('different.url'); - } -} diff --git a/spec/NewTwitchApi/NewTwitchApiSpec.php b/spec/NewTwitchApi/NewTwitchApiSpec.php deleted file mode 100644 index d97ce42..0000000 --- a/spec/NewTwitchApi/NewTwitchApiSpec.php +++ /dev/null @@ -1,136 +0,0 @@ -beConstructedWith($guzzleClient, 'client-id', 'client-secret'); - } - - function it_should_provide_oauth_api() - { - $this->getOauthApi()->shouldBeAnInstanceOf(OauthApi::class); - } - - function it_should_provide_ads_api() - { - $this->getAdsApi()->shouldBeAnInstanceOf(AdsApi::class); - } - - function it_should_provide_analytics_api() - { - $this->getAnalyticsApi()->shouldBeAnInstanceOf(AnalyticsApi::class); - } - - 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_channels_api() - { - $this->getChannelsApi()->shouldBeAnInstanceOf(ChannelsApi::class); - } - - function it_should_provide_entitlements_api() - { - $this->getEntitlementsApi()->shouldBeAnInstanceOf(EntitlementsApi::class); - } - - function it_should_provide_event_sub_api() - { - $this->getEventSubApi()->shouldBeAnInstanceOf(EventSubApi::class); - } - - function it_should_provide_games_api() - { - $this->getGamesApi()->shouldBeAnInstanceOf(GamesApi::class); - } - - function it_should_provide_polls_api() - { - $this->getPollsApi()->shouldBeAnInstanceOf(PollsApi::class); - } - - function it_should_provide_predictions_api() - { - $this->getPredictionsApi()->shouldBeAnInstanceOf(PredictionsApi::class); - } - - function it_should_provide_schedule_api() - { - $this->getScheduleApi()->shouldBeAnInstanceOf(ScheduleApi::class); - } - - function it_should_provide_subscriptions_api() - { - $this->getSubscriptionsApi()->shouldBeAnInstanceOf(SubscriptionsApi::class); - } - - function it_should_provide_streams_api() - { - $this->getStreamsApi()->shouldBeAnInstanceOf(StreamsApi::class); - } - - function it_should_provide_tags_api() - { - $this->getTagsApi()->shouldBeAnInstanceOf(TagsApi::class); - } - - function it_should_provide_teams_api() - { - $this->getTeamsApi()->shouldBeAnInstanceOf(TeamsApi::class); - } - - function it_should_provide_users_api() - { - $this->getUsersApi()->shouldBeAnInstanceOf(UsersApi::class); - } - - function it_should_provide_videos_api() - { - $this->getVideosApi()->shouldBeAnInstanceOf(VideosApi::class); - } - - function it_should_provide_webhooks_api() - { - $this->getWebhooksApi()->shouldBeAnInstanceOf(WebhooksApi::class); - } - - function it_should_provide_webhooks_subscription_api() - { - $this->getWebhooksSubscriptionApi()->shouldBeAnInstanceOf(WebhooksSubscriptionApi::class); - } -} diff --git a/spec/NewTwitchApi/Resources/AdsApiSpec.php b/spec/NewTwitchApi/Resources/AdsApiSpec.php deleted file mode 100644 index bd7232e..0000000 --- a/spec/NewTwitchApi/Resources/AdsApiSpec.php +++ /dev/null @@ -1,24 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_start_commercial(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'channels/commercial', 'TEST_TOKEN', [], [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'length', 'value' => 30]])->willReturn($request); - $this->startCommercial('TEST_TOKEN', '123', 30)->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/AnalyticsApiSpec.php b/spec/NewTwitchApi/Resources/AnalyticsApiSpec.php deleted file mode 100644 index c1d7ccf..0000000 --- a/spec/NewTwitchApi/Resources/AnalyticsApiSpec.php +++ /dev/null @@ -1,102 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_get_extension_analytics(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'analytics/extensions', 'TEST_TOKEN', [], [])->willReturn($request); - $this->getExtensionAnalytics('TEST_TOKEN')->shouldBe($response); - } - - function it_should_get_extension_analytics_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'analytics/extensions', 'TEST_TOKEN', [['key' => 'extension_id', 'value' => '1']], [])->willReturn($request); - $this->getExtensionAnalytics('TEST_TOKEN', '1')->shouldBe($response); - } - - function it_should_get_extension_analytics_with_type(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'analytics/extensions', 'TEST_TOKEN', [['key' => 'type', 'value' => 'overview_v1']], [])->willReturn($request); - $this->getExtensionAnalytics('TEST_TOKEN', null, 'overview_v1')->shouldBe($response); - } - - function it_should_get_extension_analytics_with_first(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'analytics/extensions', 'TEST_TOKEN', [['key' => 'first', 'value' => '100']], [])->willReturn($request); - $this->getExtensionAnalytics('TEST_TOKEN', null, null, 100)->shouldBe($response); - } - - function it_should_get_extension_analytics_with_after(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'analytics/extensions', 'TEST_TOKEN', [['key' => 'after', 'value' => 'abc']], [])->willReturn($request); - $this->getExtensionAnalytics('TEST_TOKEN', null, null, null, 'abc')->shouldBe($response); - } - - function it_should_get_extension_analytics_with_started_at(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'analytics/extensions', 'TEST_TOKEN', [['key' => 'started_at', 'value' => '2020-01-01T00:00:00Z']], [])->willReturn($request); - $this->getExtensionAnalytics('TEST_TOKEN', null, null, null, null, '2020-01-01T00:00:00Z')->shouldBe($response); - } - - function it_should_get_extension_analytics_with_ended_at(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'analytics/extensions', 'TEST_TOKEN', [['key' => 'ended_at', 'value' => '2020-01-01T00:00:00Z']], [])->willReturn($request); - $this->getExtensionAnalytics('TEST_TOKEN', null, null, null, null, null, '2020-01-01T00:00:00Z')->shouldBe($response); - } - - function it_should_get_game_analytics(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'analytics/games', 'TEST_TOKEN', [], [])->willReturn($request); - $this->getGameAnalytics('TEST_TOKEN')->shouldBe($response); - } - - function it_should_get_game_analytics_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'analytics/games', 'TEST_TOKEN', [['key' => 'game_id', 'value' => '1']], [])->willReturn($request); - $this->getGameAnalytics('TEST_TOKEN', '1')->shouldBe($response); - } - - function it_should_get_game_analytics_with_type(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'analytics/games', 'TEST_TOKEN', [['key' => 'type', 'value' => 'overview_v1']], [])->willReturn($request); - $this->getGameAnalytics('TEST_TOKEN', null, 'overview_v1')->shouldBe($response); - } - - function it_should_get_game_analytics_with_first(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'analytics/games', 'TEST_TOKEN', [['key' => 'first', 'value' => '100']], [])->willReturn($request); - $this->getGameAnalytics('TEST_TOKEN', null, null, 100)->shouldBe($response); - } - - function it_should_get_game_analytics_with_after(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'analytics/games', 'TEST_TOKEN', [['key' => 'after', 'value' => 'abc']], [])->willReturn($request); - $this->getGameAnalytics('TEST_TOKEN', null, null, null, 'abc')->shouldBe($response); - } - - function it_should_get_game_analytics_with_started_at(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'analytics/games', 'TEST_TOKEN', [['key' => 'started_at', 'value' => '2020-01-01T00:00:00Z']], [])->willReturn($request); - $this->getGameAnalytics('TEST_TOKEN', null, null, null, null, '2020-01-01T00:00:00Z')->shouldBe($response); - } - - function it_should_get_game_analytics_with_ended_at(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'analytics/games', 'TEST_TOKEN', [['key' => 'ended_at', 'value' => '2020-01-01T00:00:00Z']], [])->willReturn($request); - $this->getGameAnalytics('TEST_TOKEN', null, null, null, null, null, '2020-01-01T00:00:00Z')->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/BitsApiSpec.php b/spec/NewTwitchApi/Resources/BitsApiSpec.php deleted file mode 100644 index e81275c..0000000 --- a/spec/NewTwitchApi/Resources/BitsApiSpec.php +++ /dev/null @@ -1,54 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_getcheermotes(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'bits/cheermotes', 'TEST_TOKEN', [], [])->willReturn($request); - $this->getCheermotes('TEST_TOKEN')->shouldBe($response); - } - - function it_should_getcheermotes_by_broadcaster_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'bits/cheermotes', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); - $this->getCheermotes('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_extension_transactions(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'extensions/transactions', 'TEST_TOKEN', [['key' => 'extension_id', 'value' => '1']], [])->willReturn($request); - $this->getExtensionTransactions('TEST_TOKEN', '1')->shouldBe($response); - } - - function it_should_extension_transactions_with_transaction_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'extensions/transactions', 'TEST_TOKEN', [['key' => 'extension_id', 'value' => '1'], ['key' => 'id', 'value' => '321']], [])->willReturn($request); - $this->getExtensionTransactions('TEST_TOKEN', '1', ['321'])->shouldBe($response); - } - - function it_should_extension_transactions_with_first(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'extensions/transactions', 'TEST_TOKEN', [['key' => 'extension_id', 'value' => '1'], ['key' => 'first', 'value' => '100']], [])->willReturn($request); - $this->getExtensionTransactions('TEST_TOKEN', '1', [], 100)->shouldBe($response); - } - - function it_should_extension_transactions_with_after(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'extensions/transactions', 'TEST_TOKEN', [['key' => 'extension_id', 'value' => '1'], ['key' => 'after', 'value' => '100']], [])->willReturn($request); - $this->getExtensionTransactions('TEST_TOKEN', '1', [], null, 100)->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/ChannelPointsApiSpec.php b/spec/NewTwitchApi/Resources/ChannelPointsApiSpec.php deleted file mode 100644 index d3e7eaf..0000000 --- a/spec/NewTwitchApi/Resources/ChannelPointsApiSpec.php +++ /dev/null @@ -1,120 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_get_custom_reward(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); - $this->getCustomReward('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_custom_reward_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321']], [])->willReturn($request); - $this->getCustomReward('TEST_TOKEN', '123', ['321'])->shouldBe($response); - } - - function it_should_get_custom_reward_by_ids(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321'], ['key' => 'id', 'value' => '456']], [])->willReturn($request); - $this->getCustomReward('TEST_TOKEN', '123', ['321', '456'])->shouldBe($response); - } - - function it_should_get_custom_reward_by_id_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321'], ['key' => 'only_manageable_rewards', 'value' => 1]], [])->willReturn($request); - $this->getCustomReward('TEST_TOKEN', '123', ['321'], true)->shouldBe($response); - } - - function it_should_get_custom_reward_by_ids_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321'], ['key' => 'id', 'value' => '456'], ['key' => 'only_manageable_rewards', 'value' => 1]], [])->willReturn($request); - $this->getCustomReward('TEST_TOKEN', '123', ['321', '456'], true)->shouldBe($response); - } - - function it_should_get_custom_reward_redemption(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'channel_points/custom_rewards/redemptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'reward_id', 'value' => '321']], [])->willReturn($request); - $this->getCustomRewardRedemption('TEST_TOKEN', '123', '321')->shouldBe($response); - } - - function it_should_get_custom_reward_redemption_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'channel_points/custom_rewards/redemptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'reward_id', 'value' => '321'], ['key' => 'status', 'value' => 'UNFULFILLED'], ['key' => 'sort', 'value' => 'NEWEST'], ['key' => 'after', 'value' => 'abc'], ['key' => 'first', 'value' => 100]], [])->willReturn($request); - $this->getCustomRewardRedemption('TEST_TOKEN', '123', '321', [], 'UNFULFILLED', 'NEWEST', 'abc', 100)->shouldBe($response); - } - - function it_should_get_custom_reward_redemption_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'channel_points/custom_rewards/redemptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'reward_id', 'value' => '321'], ['key' => 'id', 'value' => '111']], [])->willReturn($request); - $this->getCustomRewardRedemption('TEST_TOKEN', '123', '321', ['111'])->shouldBe($response); - } - - function it_should_get_custom_reward_redemption_by_ids(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'channel_points/custom_rewards/redemptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'reward_id', 'value' => '321'], ['key' => 'id', 'value' => '111'], ['key' => 'id', 'value' => '222']], [])->willReturn($request); - $this->getCustomRewardRedemption('TEST_TOKEN', '123', '321', ['111', '222'])->shouldBe($response); - } - - function it_should_create_custom_reward(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'title', 'value' => 'test 123'], ['key' => 'cost', 'value' => 100]])->willReturn($request); - $this->createCustomReward('TEST_TOKEN', '123', 'test 123', 100)->shouldBe($response); - } - - function it_should_create_custom_reward_with_one_opt(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'title', 'value' => 'test 123'], ['key' => 'cost', 'value' => 100], ['key' => 'prompt', 'value' => 'What is your name?']])->willReturn($request); - $this->createCustomReward('TEST_TOKEN', '123', 'test 123', 100, ['prompt' => 'What is your name?'])->shouldBe($response); - } - - function it_should_create_custom_reward_with_multiple_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'title', 'value' => 'test 123'], ['key' => 'cost', 'value' => 100], ['key' => 'prompt', 'value' => 'What is your name?'], ['key' => 'is_enabled', 'value' => 1]])->willReturn($request); - $this->createCustomReward('TEST_TOKEN', '123', 'test 123', 100, ['prompt' => 'What is your name?', 'is_enabled' => 1])->shouldBe($response); - } - - function it_should_update_custom_reward(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PATCH', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321']], [])->willReturn($request); - $this->updateCustomReward('TEST_TOKEN', '123', '321')->shouldBe($response); - } - - function it_should_update_custom_reward_with_one_opt(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PATCH', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321']], [['key' => 'prompt', 'value' => 'What is your name?']])->willReturn($request); - $this->updateCustomReward('TEST_TOKEN', '123', '321', ['prompt' => 'What is your name?'])->shouldBe($response); - } - - function it_should_update_custom_reward_with_multiple_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PATCH', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321']], [['key' => 'prompt', 'value' => 'What is your name?'], ['key' => 'is_enabled', 'value' => 1]])->willReturn($request); - $this->updateCustomReward('TEST_TOKEN', '123', '321', ['prompt' => 'What is your name?', 'is_enabled' => 1])->shouldBe($response); - } - - function it_should_delete_custom_reward(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('DELETE', 'channel_points/custom_rewards', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321']], [])->willReturn($request); - $this->deleteCustomReward('TEST_TOKEN', '123', '321')->shouldBe($response); - } - - function it_should_update_redemption_status(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PATCH', 'channel_points/custom_rewards/redemptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'reward_id', 'value' => '456'], ['key' => 'id', 'value' => '789']], [['key' => 'status', 'value' => 'FULFILLED']])->willReturn($request); - $this->updateRedemptionStatus('TEST_TOKEN', '123', '456', '789', 'FULFILLED')->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/ChannelsApiSpec.php b/spec/NewTwitchApi/Resources/ChannelsApiSpec.php deleted file mode 100644 index a192304..0000000 --- a/spec/NewTwitchApi/Resources/ChannelsApiSpec.php +++ /dev/null @@ -1,60 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_get_channel_info(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'channels', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); - $this->getChannelInfo('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_channel_editors(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'channels/editors', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); - $this->getChannelEditors('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_modify_channel_with_game_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PATCH', 'channels', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'game_id', 'value' => '0']])->willReturn($request); - $this->modifyChannelInfo('TEST_TOKEN', '123', ['game_id' => '0'])->shouldBe($response); - } - - function it_should_modify_channel_with_language(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PATCH', 'channels', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'broadcaster_language', 'value' => 'en']])->willReturn($request); - $this->modifyChannelInfo('TEST_TOKEN', '123', ['broadcaster_language' => 'en'])->shouldBe($response); - } - - function it_should_modify_channel_with_title(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PATCH', 'channels', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'title', 'value' => 'test 123']])->willReturn($request); - $this->modifyChannelInfo('TEST_TOKEN', '123', ['title' => 'test 123'])->shouldBe($response); - } - - function it_should_modify_channel_with_delay(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PATCH', 'channels', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'delay', 'value' => 5]])->willReturn($request); - $this->modifyChannelInfo('TEST_TOKEN', '123', ['delay' => 5])->shouldBe($response); - } - - function it_should_modify_channel_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PATCH', 'channels', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'game_id', 'value' => '0'], ['key' => 'broadcaster_language', 'value' => 'en'], ['key' => 'title', 'value' => 'test 123'], ['key' => 'delay', 'value' => 5]])->willReturn($request); - $this->modifyChannelInfo('TEST_TOKEN', '123', ['game_id' => '0', 'broadcaster_language' => 'en', 'title' => 'test 123', 'delay' => 5])->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/ChatApiSpec.php b/spec/NewTwitchApi/Resources/ChatApiSpec.php deleted file mode 100644 index e0c4bfe..0000000 --- a/spec/NewTwitchApi/Resources/ChatApiSpec.php +++ /dev/null @@ -1,60 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_get_channel_emotes(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'chat/emotes', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); - $this->getChannelEmotes('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_global_emotes(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'chat/emotes/global', 'TEST_TOKEN', [], [])->willReturn($request); - $this->getGlobalEmotes('TEST_TOKEN')->shouldBe($response); - } - - function it_should_get_one_emote_set(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'chat/emotes/set', 'TEST_TOKEN', [['key' => 'emote_set_id', 'value' => '123']], [])->willReturn($request); - $this->getEmoteSets('TEST_TOKEN', ['123'])->shouldBe($response); - } - - function it_should_get_one_emote_set_with_helper_function(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'chat/emotes/set', 'TEST_TOKEN', [['key' => 'emote_set_id', 'value' => '123']], [])->willReturn($request); - $this->getEmoteSet('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_multiple_emote_sets(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'chat/emotes/set', 'TEST_TOKEN', [['key' => 'emote_set_id', 'value' => '123'], ['key' => 'emote_set_id', 'value' => '456']], [])->willReturn($request); - $this->getEmoteSets('TEST_TOKEN', ['123', '456'])->shouldBe($response); - } - - function it_should_get_channel_chat_badges(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'chat/badges', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); - $this->getChannelChatBadges('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_global_chat_badges(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'chat/badges/global', 'TEST_TOKEN', [], [])->willReturn($request); - $this->getGlobalChatBadges('TEST_TOKEN')->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/EntitlementsApiSpec.php b/spec/NewTwitchApi/Resources/EntitlementsApiSpec.php deleted file mode 100644 index 942603c..0000000 --- a/spec/NewTwitchApi/Resources/EntitlementsApiSpec.php +++ /dev/null @@ -1,84 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_create_entitlement_grants_upload_url(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'entitlements/upload', 'TEST_TOKEN', [['key' => 'manifest_id', 'value' => '123'], ['key' => 'type', 'value' => 'bulk_drops_grant']], [])->willReturn($request); - $this->createEntitlementGrantsUploadURL('TEST_TOKEN', '123', 'bulk_drops_grant')->shouldBe($response); - } - - function it_should_create_entitlement_grants_upload_url_shorthand(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'entitlements/upload', 'TEST_TOKEN', [['key' => 'manifest_id', 'value' => '123'], ['key' => 'type', 'value' => 'bulk_drops_grant']], [])->willReturn($request); - $this->createEntitlementGrantsUploadURL('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_code_status(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'entitlements/codes', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'code', 'value' => 'abc']], [])->willReturn($request); - $this->getCodeStatus('TEST_TOKEN', '123', ['abc'])->shouldBe($response); - } - - function it_should_get_codes_status(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'entitlements/codes', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'code', 'value' => 'abc'], ['key' => 'code', 'value' => 'def']], [])->willReturn($request); - $this->getCodeStatus('TEST_TOKEN', '123', ['abc', 'def'])->shouldBe($response); - } - - function it_should_get_drop_entitlements_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'entitlements/drops', 'TEST_TOKEN', [['key' => 'id', 'value' => '123']], [])->willReturn($request); - $this->getDropsEntitlements('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_drop_entitlements_by_user_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'entitlements/drops', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123']], [])->willReturn($request); - $this->getDropsEntitlements('TEST_TOKEN', null, '123')->shouldBe($response); - } - - function it_should_get_drop_entitlements_by_user_id_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'entitlements/drops', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'after', 'value' => 'abc'], ['key' => 'first', 'value' => 100]], [])->willReturn($request); - $this->getDropsEntitlements('TEST_TOKEN', null, '123', null, 'abc', 100)->shouldBe($response); - } - - function it_should_get_drop_entitlements_by_game_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'entitlements/drops', 'TEST_TOKEN', [['key' => 'game_id', 'value' => '123']], [])->willReturn($request); - $this->getDropsEntitlements('TEST_TOKEN', null, null, '123')->shouldBe($response); - } - - function it_should_get_drop_entitlements_by_game_id_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'entitlements/drops', 'TEST_TOKEN', [['key' => 'game_id', 'value' => '123'], ['key' => 'after', 'value' => 'abc'], ['key' => 'first', 'value' => 100]], [])->willReturn($request); - $this->getDropsEntitlements('TEST_TOKEN', null, null, '123', 'abc', 100)->shouldBe($response); - } - - function it_should_redeem_code(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'entitlements/code', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'code', 'value' => 'abc']], [])->willReturn($request); - $this->redeemCode('TEST_TOKEN', '123', ['abc'])->shouldBe($response); - } - - function it_should_redeem_codes(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'entitlements/code', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'code', 'value' => 'abc'], ['key' => 'code', 'value' => 'def']], [])->willReturn($request); - $this->redeemCode('TEST_TOKEN', '123', ['abc', 'def'])->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/EventSubApiSpec.php b/spec/NewTwitchApi/Resources/EventSubApiSpec.php deleted file mode 100644 index 3649624..0000000 --- a/spec/NewTwitchApi/Resources/EventSubApiSpec.php +++ /dev/null @@ -1,249 +0,0 @@ - 'type', 'value' => $type]; - $bodyParams[] = ['key' => 'version', 'value' => $version]; - $bodyParams[] = ['key' => 'condition', 'value' => $condition]; - $bodyParams[] = ['key' => 'transport', 'value' => [ - 'method' => 'webhook', - 'callback' => $this->callback, - 'secret' => $this->secret, - ] - ]; - - return $requestGenerator->generate('POST', 'eventsub/subscriptions', $this->bearer, [], $bodyParams); - } - - function let(HelixGuzzleClient $guzzleClient, RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_get_event_sub_subscription(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'eventsub/subscriptions', 'TEST_TOKEN', [], [])->willReturn($request); - $this->getEventSubSubscription('TEST_TOKEN')->shouldBe($response); - } - - function it_should_get_event_sub_subscription_with_status(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'eventsub/subscriptions', 'TEST_TOKEN', [['key' => 'status', 'value' => 'enabled']], [])->willReturn($request); - $this->getEventSubSubscription('TEST_TOKEN', 'enabled')->shouldBe($response); - } - - function it_should_get_event_sub_subscription_with_type(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'eventsub/subscriptions', 'TEST_TOKEN', [['key' => 'type', 'value' => 'channel.update']], [])->willReturn($request); - $this->getEventSubSubscription('TEST_TOKEN', null, 'channel.update')->shouldBe($response); - } - - function it_should_delete_event_sub_subscription(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('DELETE', 'eventsub/subscriptions', 'TEST_TOKEN', [['key' => 'id', 'value' => '123']], [])->willReturn($request); - $this->deleteEventSubSubscription('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_subscribe_to_channel_update(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.update', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelUpdate($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_follow(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.follow', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelFollow($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_subscribe(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.subscribe', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelSubscribe($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_subscription_end(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.subscription.end', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelSubscriptionEnd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_subscription_gift(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.subscription.gift', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelSubscriptionGift($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_subscription_message(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.subscription.message', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelSubscriptionMessage($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_cheer(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.cheer', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelCheer($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_raid(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.raid', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelRaid($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_ban(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.ban', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelBan($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_unban(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.unban', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelUnban($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_moderator_add(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.moderator.add', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelModeratorAdd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_moderator_remove(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.moderator.remove', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelModeratorRemove($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_points_custom_reward_add(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.channel_points_custom_reward.add', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelPointsCustomRewardAdd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_points_custom_reward_update(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.channel_points_custom_reward.update', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelPointsCustomRewardUpdate($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_points_custom_reward_remove(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.channel_points_custom_reward.remove', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelPointsCustomRewardRemove($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_points_custom_reward_redemption_add(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.channel_points_custom_reward_redemption.add', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelPointsCustomRewardRedemptionAdd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_points_custom_reward_redemption_update(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.channel_points_custom_reward_redemption.update', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelPointsCustomRewardRedemptionUpdate($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_poll_begin(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.poll.begin', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelPollBegin($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_poll_progress(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.poll.progress', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelPollProgress($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_poll_endn(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.poll.end', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelPollEnd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_prediction_begin(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.prediction.begin', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelPredictionBegin($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_prediction_progress(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.prediction.progress', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelPredictionProgress($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_prediction_lock(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.prediction.lock', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelPredictionLock($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_prediction_endn(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.prediction.end', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelPredictionEnd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_hype_train_begin(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.hype_train.begin', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelHypeTrainBegin($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_hype_train_progress(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.hype_train.progress', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelHypeTrainProgress($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_channel_hype_train_end(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('channel.hype_train.end', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToChannelHypeTrainEnd($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_stream_online(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('stream.online', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToStreamOnline($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_stream_offline(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('stream.offline', '1', ['broadcaster_user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToStreamOffline($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_user_update(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('user.update', '1', ['user_id' => '12345'], $requestGenerator)->willReturn($request); - $this->subscribeToUserUpdate($this->bearer, $this->secret, $this->callback, '12345')->shouldBe($response); - } - - function it_should_subscribe_to_extension_bits_transaction_create(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $this->createEventSubSubscription('extension.bits_transaction.create', 'beta', ['extension_client_id' => 'deadbeef'], $requestGenerator)->willReturn($request); - $this->subscribeToExtensionBitsTransactionCreate($this->bearer, $this->secret, $this->callback, 'deadbeef')->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/GamesApiSpec.php b/spec/NewTwitchApi/Resources/GamesApiSpec.php deleted file mode 100644 index e7e9124..0000000 --- a/spec/NewTwitchApi/Resources/GamesApiSpec.php +++ /dev/null @@ -1,60 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_get_games_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'games', 'TEST_TOKEN', [['key' => 'id', 'value' => '123']], [])->willReturn($request); - $this->getGames('TEST_TOKEN', ['123'])->shouldBe($response); - } - - function it_should_get_games_by_ids(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'games', 'TEST_TOKEN', [['key' => 'id', 'value' => '123'], ['key' => 'id', 'value' => '456']], [])->willReturn($request); - $this->getGames('TEST_TOKEN', ['123', '456'])->shouldBe($response); - } - - function it_should_get_games_by_name(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'games', 'TEST_TOKEN', [['key' => 'name', 'value' => 'abc']], [])->willReturn($request); - $this->getGames('TEST_TOKEN', [], ['abc'])->shouldBe($response); - } - - function it_should_get_games_by_names(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'games', 'TEST_TOKEN', [['key' => 'name', 'value' => 'abc'], ['key' => 'name', 'value' => 'def']], [])->willReturn($request); - $this->getGames('TEST_TOKEN', [], ['abc', 'def'])->shouldBe($response); - } - - function it_should_get_games_by_ids_and_names(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'games', 'TEST_TOKEN', [['key' => 'id', 'value' => '123'], ['key' => 'id', 'value' => '456'], ['key' => 'name', 'value' => 'abc'], ['key' => 'name', 'value' => 'def']], [])->willReturn($request); - $this->getGames('TEST_TOKEN', ['123', '456'], ['abc', 'def'])->shouldBe($response); - } - - function it_should_get_top_games(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'games/top', 'TEST_TOKEN', [], [])->willReturn($request); - $this->getTopGames('TEST_TOKEN')->shouldBe($response); - } - - function it_should_get_top_games_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'games/top', 'TEST_TOKEN', [['key' => 'first', 'value' => 100], ['key' => 'before', 'value' => 'abc'], ['key' => 'after', 'value' => 'def']], [])->willReturn($request); - $this->getTopGames('TEST_TOKEN', 100, 'abc', 'def')->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/ModerationApiSpec.php b/spec/NewTwitchApi/Resources/ModerationApiSpec.php deleted file mode 100644 index ccd4fb9..0000000 --- a/spec/NewTwitchApi/Resources/ModerationApiSpec.php +++ /dev/null @@ -1,30 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_check_automod_status(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'moderation/enforcements/status', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'msg_id', 'value' => '456'], ['key' => 'msg_text', 'value' => 'test 123'], ['key' => 'user_id', 'value' => '789']])->willReturn($request); - $this->checkAutoModStatus('TEST_TOKEN', '123', '456', 'test 123', '789')->shouldBe($response); - } - - function it_should_release_held_message(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'moderation/automod/message', 'TEST_TOKEN', [], [['key' => 'user_id', 'value' => '123'], ['key' => 'msg_id', 'value' => '456'], ['key' => 'action', 'value' => 'ALLOW']])->willReturn($request); - $this->manageHeldAutoModMessage('TEST_TOKEN', '123', '456', 'ALLOW')->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/PollsApiSpec.php b/spec/NewTwitchApi/Resources/PollsApiSpec.php deleted file mode 100644 index 088ed4e..0000000 --- a/spec/NewTwitchApi/Resources/PollsApiSpec.php +++ /dev/null @@ -1,60 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_get_polls(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'polls', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); - $this->getPolls('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_polls_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'polls', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321']], [])->willReturn($request); - $this->getPolls('TEST_TOKEN', '123', ['321'])->shouldBe($response); - } - - function it_should_get_polls_by_ids(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'polls', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321'], ['key' => 'id', 'value' => '456']], [])->willReturn($request); - $this->getPolls('TEST_TOKEN', '123', ['321', '456'])->shouldBe($response); - } - - function it_should_get_polls_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'polls', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'after', 'value' => 'abc'], ['key' => 'first', 'value' => 100]], [])->willReturn($request); - $this->getPolls('TEST_TOKEN', '123', [], 'abc', 100)->shouldBe($response); - } - - function it_should_create_a_poll(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'polls', 'TEST_TOKEN', [], [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'title', 'value' => 'What is my name?'], ['key' => 'choices', 'value' => [['title' => 'John'], ['title' => 'Doe']]], ['key' => 'duration', 'value' => 15]])->willReturn($request); - $this->createPoll('TEST_TOKEN', '123', 'What is my name?', [['title' => 'John'], ['title' => 'Doe']], 15)->shouldBe($response); - } - - function it_should_create_a_poll_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'polls', 'TEST_TOKEN', [], [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'title', 'value' => 'What is my name?'], ['key' => 'choices', 'value' => [['title' => 'John'], ['title' => 'Doe']]], ['key' => 'duration', 'value' => 15], ['key' => 'bits_voting_enabled', 'value' => 1]])->willReturn($request); - $this->createPoll('TEST_TOKEN', '123', 'What is my name?', [['title' => 'John'], ['title' => 'Doe']], 15, ['bits_voting_enabled' => 1])->shouldBe($response); - } - - function it_should_end_a_poll(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PATCH', 'polls', 'TEST_TOKEN', [], [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '456'], ['key' => 'status', 'value' => 'TERMINATED']])->willReturn($request); - $this->endPoll('TEST_TOKEN', '123', '456', 'TERMINATED')->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/PredictionsApiSpec.php b/spec/NewTwitchApi/Resources/PredictionsApiSpec.php deleted file mode 100644 index f08757f..0000000 --- a/spec/NewTwitchApi/Resources/PredictionsApiSpec.php +++ /dev/null @@ -1,60 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_get_predictions(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'predictions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); - $this->getPredictions('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_predictions_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'predictions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321']], [])->willReturn($request); - $this->getPredictions('TEST_TOKEN', '123', ['321'])->shouldBe($response); - } - - function it_should_get_predictions_by_ids(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'predictions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '321'], ['key' => 'id', 'value' => '456']], [])->willReturn($request); - $this->getPredictions('TEST_TOKEN', '123', ['321', '456'])->shouldBe($response); - } - - function it_should_get_predictions_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'predictions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'after', 'value' => 'abc'], ['key' => 'first', 'value' => 100]], [])->willReturn($request); - $this->getPredictions('TEST_TOKEN', '123', [], 'abc', 100)->shouldBe($response); - } - - function it_should_create_a_prediction(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'predictions', 'TEST_TOKEN', [], [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'title', 'value' => 'Will the coin land on heads or tails?'], ['key' => 'outcomes', 'value' => [['title' => 'Heads'], ['title' => 'Tails']]], ['key' => 'prediction_window', 'value' => 15]])->willReturn($request); - $this->createPrediction('TEST_TOKEN', '123', 'Will the coin land on heads or tails?', [['title' => 'Heads'], ['title' => 'Tails']], 15)->shouldBe($response); - } - - function it_should_end_a_prediction(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PATCH', 'predictions', 'TEST_TOKEN', [], [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '456'], ['key' => 'status', 'value' => 'CANCELLED']])->willReturn($request); - $this->endPrediction('TEST_TOKEN', '123', '456', 'CANCELLED')->shouldBe($response); - } - - function it_should_resolve_a_prediction(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PATCH', 'predictions', 'TEST_TOKEN', [], [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '456'], ['key' => 'status', 'value' => 'RESOLVED'], ['key' => 'winning_outcome_id', 'value' => '1']])->willReturn($request); - $this->endPrediction('TEST_TOKEN', '123', '456', 'RESOLVED', '1')->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/ScheduleApiSpec.php b/spec/NewTwitchApi/Resources/ScheduleApiSpec.php deleted file mode 100644 index 18064e5..0000000 --- a/spec/NewTwitchApi/Resources/ScheduleApiSpec.php +++ /dev/null @@ -1,84 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_get_channel_stream_schedule(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'schedule', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); - $this->getChannelStreamSchedule('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_channel_stream_schedule_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'schedule', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'start_time', 'value' => '2021-06-15T23:08:20+00:00'], ['key' => 'utc_offset', 'value' => '240'], ['key' => 'first', 'value' => 25], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request); - $this->getChannelStreamSchedule('TEST_TOKEN', '123', [], '2021-06-15T23:08:20+00:00', '240', 25, 'abc')->shouldBe($response); - } - - function it_should_get_a_channel_stream_schedule(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'schedule', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '456']], [])->willReturn($request); - $this->getChannelStreamSchedule('TEST_TOKEN', '123', ['456'])->shouldBe($response); - } - - function it_should_get_multiple_channel_stream_schedules(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'schedule', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '456'], ['key' => 'id', 'value' => '789']], [])->willReturn($request); - $this->getChannelStreamSchedule('TEST_TOKEN', '123', ['456', '789'])->shouldBe($response); - } - - function it_should_get_channel_icalendar_with_no_auth(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'schedule/icalendar', null, [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); - $this->getChanneliCalendar(null, '123')->shouldBe($response); - } - - function it_should_get_channel_icalendar_with_auth(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'schedule/icalendar', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); - $this->getChanneliCalendar('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_update_channel_stream_schedule(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PATCH', 'schedule/settings', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'is_vacation_enabled', 'value' => true], ['key' => 'vacation_start_time', 'value' => '2021-06-15T23:08:20+00:00'], ['key' => 'vacation_end_time', 'value' => '2021-06-22T23:08:20+00:00'], ['key' => 'timezone', 'value' => 'America/New_York']], [])->willReturn($request); - $this->updateChannelStreamSchedule('TEST_TOKEN', '123', true, '2021-06-15T23:08:20+00:00', '2021-06-22T23:08:20+00:00', 'America/New_York')->shouldBe($response); - } - - function it_should_create_channel_stream_schedule_segment(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'schedule/segment', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'start_time', 'value' => '2021-06-15T23:08:20+00:00'], ['key' => 'timezone', 'value' => 'America/New_York'], ['key' => 'is_recurring', 'value' => true]])->willReturn($request); - $this->createChannelStreamScheduleSegment('TEST_TOKEN', '123', '2021-06-15T23:08:20+00:00', 'America/New_York', true)->shouldBe($response); - } - - function it_should_create_channel_stream_schedule_segment_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'schedule/segment', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'start_time', 'value' => '2021-06-15T23:08:20+00:00'], ['key' => 'timezone', 'value' => 'America/New_York'], ['key' => 'is_recurring', 'value' => true], ['key' => 'duration', 'value' => '240']])->willReturn($request); - $this->createChannelStreamScheduleSegment('TEST_TOKEN', '123', '2021-06-15T23:08:20+00:00', 'America/New_York', true, ['duration' => '240'])->shouldBe($response); - } - - function it_should_update_channel_stream_schedule_segment(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PATCH', 'schedule/segment', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '456']], [['key' => 'start_time', 'value' => '2021-06-15T23:08:20+00:00'], ['key' => 'timezone', 'value' => 'America/New_York'], ['key' => 'is_canceled', 'value' => true], ['key' => 'duration', 'value' => '240']])->willReturn($request); - $this->updateChannelStreamScheduleSegment('TEST_TOKEN', '123', '456', ['start_time' => '2021-06-15T23:08:20+00:00', 'timezone' => 'America/New_York', 'is_canceled' => true, 'duration' => '240'])->shouldBe($response); - } - - function it_should_delete_channel_stream_schedule_segment(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('DELETE', 'schedule/segment', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'id', 'value' => '456']], [])->willReturn($request); - $this->deleteChannelStreamScheduleSegment('TEST_TOKEN', '123', '456')->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/StreamsApiSpec.php b/spec/NewTwitchApi/Resources/StreamsApiSpec.php deleted file mode 100644 index da4e7ca..0000000 --- a/spec/NewTwitchApi/Resources/StreamsApiSpec.php +++ /dev/null @@ -1,156 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_get_streams_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123']], [])->willReturn($request); - $this->getStreams('TEST_TOKEN', ['123'])->shouldBe($response); - } - - function it_should_get_streams_by_id_with_helper(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123']], [])->willReturn($request); - $this->getStreamForUserId('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_streams_by_ids(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'user_id', 'value' => '321']], [])->willReturn($request); - $this->getStreams('TEST_TOKEN', ['123', '321'])->shouldBe($response); - } - - function it_should_get_streams_by_username(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'user_login', 'value' => 'test']], [])->willReturn($request); - $this->getStreams('TEST_TOKEN', [], ['test'])->shouldBe($response); - } - - function it_should_get_streams_by_username_with_helper(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'user_login', 'value' => 'test']], [])->willReturn($request); - $this->getStreamForUsername('TEST_TOKEN', 'test')->shouldBe($response); - } - - function it_should_get_streams_by_usernames(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'user_login', 'value' => 'test'], ['key' => 'user_login', 'value' => 'user']], [])->willReturn($request); - $this->getStreams('TEST_TOKEN', [], ['test', 'user'])->shouldBe($response); - } - - function it_should_get_streams_by_id_and_username(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'user_login', 'value' => 'test']], [])->willReturn($request); - $this->getStreams('TEST_TOKEN', ['123'], ['test'])->shouldBe($response); - } - - function it_should_get_streams_by_game_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'game_id', 'value' => '123']], [])->willReturn($request); - $this->getStreams('TEST_TOKEN', [], [], ['123'])->shouldBe($response); - } - - function it_should_get_streams_by_game_id_with_helper(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'game_id', 'value' => '123']], [])->willReturn($request); - $this->getStreamsByGameId('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_streams_by_game_ids(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'game_id', 'value' => '123'], ['key' => 'game_id', 'value' => '456']], [])->willReturn($request); - $this->getStreams('TEST_TOKEN', [], [], ['123', '456'])->shouldBe($response); - } - - function it_should_get_streams_by_language(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'language', 'value' => 'en']], [])->willReturn($request); - $this->getStreams('TEST_TOKEN', [], [], [], ['en'])->shouldBe($response); - } - - function it_should_get_streams_by_language_with_helper(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'language', 'value' => 'en']], [])->willReturn($request); - $this->getStreamsByLanguage('TEST_TOKEN', 'en')->shouldBe($response); - } - - function it_should_get_streams_by_languages(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'language', 'value' => 'en'], ['key' => 'language', 'value' => 'fr']], [])->willReturn($request); - $this->getStreams('TEST_TOKEN', [], [], [], ['en', 'fr'])->shouldBe($response); - } - - function it_should_get_streams_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams', 'TEST_TOKEN', [['key' => 'first', 'value' => 100], ['key' => 'before', 'value' => 'abc'], ['key' => 'after', 'value' => 'def']], [])->willReturn($request); - $this->getStreams('TEST_TOKEN', [], [], [], [], 100, 'abc', 'def')->shouldBe($response); - } - - function it_should_get_stream_key(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams/key', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); - $this->getStreamKey('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_stream_markers_by_user_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams/markers', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123']], [])->willReturn($request); - $this->getStreamMarkers('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_stream_markers_by_user_id_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams/markers', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'first', 'value' => 100], ['key' => 'before', 'value' => 'abc'], ['key' => 'after', 'value' => 'def']], [])->willReturn($request); - $this->getStreamMarkers('TEST_TOKEN', '123', null, 100, 'abc', 'def')->shouldBe($response); - } - - function it_should_get_stream_markers_by_video_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams/markers', 'TEST_TOKEN', [['key' => 'video_id', 'value' => '123']], [])->willReturn($request); - $this->getStreamMarkers('TEST_TOKEN', null, '123')->shouldBe($response); - } - - function it_should_get_stream_markers_by_video_id_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams/markers', 'TEST_TOKEN', [['key' => 'video_id', 'value' => '123'], ['key' => 'first', 'value' => 100], ['key' => 'before', 'value' => 'abc'], ['key' => 'after', 'value' => 'def']], [])->willReturn($request); - $this->getStreamMarkers('TEST_TOKEN', null, '123', 100, 'abc', 'def')->shouldBe($response); - } - - function it_should_get_followed_streams(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams/followed', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123']], [])->willReturn($request); - $this->getFollowedStreams('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_followed_streams_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams/followed', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'first', 'value' => 100], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request); - $this->getFollowedStreams('TEST_TOKEN', '123', 100, 'abc')->shouldBe($response); - } - - function it_should_create_stream_marker(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'streams/markers', 'TEST_TOKEN', [], [['key' => 'user_id', 'value' => '123']])->willReturn($request); - $this->createStreamMarker('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_create_stream_marker_with_description(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'streams/markers', 'TEST_TOKEN', [], [['key' => 'user_id', 'value' => '123'], ['key' => 'description', 'value' => 'This is a marker']])->willReturn($request); - $this->createStreamMarker('TEST_TOKEN', '123', 'This is a marker')->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/SubscriptionsApiSpec.php b/spec/NewTwitchApi/Resources/SubscriptionsApiSpec.php deleted file mode 100644 index 8d09a74..0000000 --- a/spec/NewTwitchApi/Resources/SubscriptionsApiSpec.php +++ /dev/null @@ -1,54 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_get_broadcaster_subscriptions(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'subscriptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); - $this->getBroadcasterSubscriptions('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_broadcaster_subscriptions_with_all(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'subscriptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'first', 'value' => 100], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request); - $this->getBroadcasterSubscriptions('TEST_TOKEN', '123', 100, 'abc')->shouldBe($response); - } - - function it_should_get_broadcaster_subscribers(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'subscriptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); - $this->getBroadcasterSubscribers('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_broadcaster_subscribers_with_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'subscriptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => '321']], [])->willReturn($request); - $this->getBroadcasterSubscribers('TEST_TOKEN', '123', ['321'])->shouldBe($response); - } - - function it_should_get_broadcaster_subscribers_with_ids(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'subscriptions', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => '321'], ['key' => 'user_id', 'value' => '456']], [])->willReturn($request); - $this->getBroadcasterSubscribers('TEST_TOKEN', '123', ['321', '456'])->shouldBe($response); - } - - function it_should_check_user_subscriptions(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'subscriptions/user', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'user_id', 'value' => '456']], [])->willReturn($request); - $this->checkUserSubscription('TEST_TOKEN', '123', '456')->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/TagsApiSpec.php b/spec/NewTwitchApi/Resources/TagsApiSpec.php deleted file mode 100644 index 0f5fc88..0000000 --- a/spec/NewTwitchApi/Resources/TagsApiSpec.php +++ /dev/null @@ -1,66 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_get_all_tags(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'tags/streams', 'TEST_TOKEN', [], [])->willReturn($request); - $this->getAllStreamTags('TEST_TOKEN')->shouldBe($response); - } - - function it_should_get_all_tags_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'tags/streams', 'TEST_TOKEN', [['key' => 'tag_id', 'value' => '123']], [])->willReturn($request); - $this->getAllStreamTags('TEST_TOKEN', ['123'])->shouldBe($response); - } - - function it_should_get_all_tags_with_first(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'tags/streams', 'TEST_TOKEN', [['key' => 'first', 'value' => 100]], [])->willReturn($request); - $this->getAllStreamTags('TEST_TOKEN', [], 100)->shouldBe($response); - } - - function it_should_get_all_tags_with_after(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'tags/streams', 'TEST_TOKEN', [['key' => 'after', 'value' => 'abc']], [])->willReturn($request); - $this->getAllStreamTags('TEST_TOKEN', [], null, 'abc')->shouldBe($response); - } - - function it_should_get_stream_tags(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'streams/tags', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); - $this->getStreamTags('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_replace_stream_tags(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PUT', 'streams/tags', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); - $this->replaceStreamTags('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_replace_stream_tags_with_one_tag(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PUT', 'streams/tags', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'tag_ids', 'value' => ['456']]])->willReturn($request); - $this->replaceStreamTags('TEST_TOKEN', '123', ['456'])->shouldBe($response); - } - - function it_should_replace_stream_tags_with_multiple_tags(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PUT', 'streams/tags', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [['key' => 'tag_ids', 'value' => ['456', '789']]])->willReturn($request); - $this->replaceStreamTags('TEST_TOKEN', '123', ['456', '789'])->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/TeamsApiSpec.php b/spec/NewTwitchApi/Resources/TeamsApiSpec.php deleted file mode 100644 index 0fd592f..0000000 --- a/spec/NewTwitchApi/Resources/TeamsApiSpec.php +++ /dev/null @@ -1,54 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_get_channel_teams(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'teams/channel', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); - $this->getChannelTeams('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_teams(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'teams', 'TEST_TOKEN', [], [])->willReturn($request); - $this->getTeams('TEST_TOKEN')->shouldBe($response); - } - - function it_should_get_teams_by_name(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'teams', 'TEST_TOKEN', [['key' => 'name', 'value' => 'abc']], [])->willReturn($request); - $this->getTeams('TEST_TOKEN', 'abc')->shouldBe($response); - } - - function it_should_get_teams_by_name_with_helper_function(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'teams', 'TEST_TOKEN', [['key' => 'name', 'value' => 'abc']], [])->willReturn($request); - $this->getTeamsByName('TEST_TOKEN', 'abc')->shouldBe($response); - } - - function it_should_get_teams_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'teams', 'TEST_TOKEN', [['key' => 'id', 'value' => '123']], [])->willReturn($request); - $this->getTeams('TEST_TOKEN', null, '123')->shouldBe($response); - } - - function it_should_get_teams_by_id_with_helper_function(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'teams', 'TEST_TOKEN', [['key' => 'id', 'value' => '123']], [])->willReturn($request); - $this->getTeamsById('TEST_TOKEN', '123')->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/UsersApiSpec.php b/spec/NewTwitchApi/Resources/UsersApiSpec.php deleted file mode 100644 index 9861910..0000000 --- a/spec/NewTwitchApi/Resources/UsersApiSpec.php +++ /dev/null @@ -1,162 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_get_user_with_access_token(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'users', 'TEST_TOKEN', [], [])->willReturn($request); - $this->getUsers('TEST_TOKEN')->shouldBe($response); - } - - function it_should_get_user_with_access_token_convenience_method(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'users', 'TEST_TOKEN', [], [])->willReturn($request); - $this->getUserByAccessToken('TEST_TOKEN')->shouldBe($response); - } - - function it_should_get_users_by_ids(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'users', 'TEST_TOKEN', [['key' => 'id', 'value' => '12345'], ['key' => 'id', 'value' => '98765']], [])->willReturn($request); - $this->getUsers('TEST_TOKEN', ['12345', '98765'])->shouldBe($response); - } - - function it_should_get_users_by_usernames(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'users', 'TEST_TOKEN', [['key' => 'login', 'value' => 'twitchuser'], ['key' => 'login', 'value' => 'anotheruser']], [])->willReturn($request); - $this->getUsers('TEST_TOKEN', [], ['twitchuser', 'anotheruser'])->shouldBe($response); - } - - function it_should_get_users_by_id_and_username(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'users', 'TEST_TOKEN', [['key' => 'id', 'value' => '12345'], ['key' => 'id', 'value' => '98765'], ['key' => 'login', 'value' => 'twitchuser'], ['key' => 'login', 'value' => 'anotheruser']], [])->willReturn($request); - $this->getUsers('TEST_TOKEN', ['12345', '98765'], ['twitchuser', 'anotheruser'])->shouldBe($response); - } - - function it_should_get_a_single_user_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'users', 'TEST_TOKEN', [['key' => 'id', 'value' => '12345']], [])->willReturn($request); - $this->getUserById('TEST_TOKEN', '12345')->shouldBe($response); - } - - function it_should_get_a_single_user_by_username(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'users', 'TEST_TOKEN', [['key' => 'login', 'value' => 'twitchuser']], [])->willReturn($request); - $this->getUserByUsername('TEST_TOKEN', 'twitchuser')->shouldBe($response); - } - - function it_should_get_users_follows_by_follower_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'users/follows', 'TEST_TOKEN', [['key' => 'from_id', 'value' => '12345']], [])->willReturn($request); - $this->getUsersFollows('TEST_TOKEN', '12345')->shouldBe($response); - } - - function it_should_get_users_follows_by_followed_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'users/follows', 'TEST_TOKEN', [['key' => 'to_id', 'value' => '12345']], [])->willReturn($request); - $this->getUsersFollows('TEST_TOKEN', null, '12345')->shouldBe($response); - } - - function it_should_get_users_follows_by_follower_id_and_followed_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'users/follows', 'TEST_TOKEN', [['key' => 'from_id', 'value' => '12345'], ['key' => 'to_id', 'value' => '98765']], [])->willReturn($request); - $this->getUsersFollows('TEST_TOKEN', '12345', '98765')->shouldBe($response); - } - - function it_should_get_users_follows_page_by_first(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'users/follows', 'TEST_TOKEN', [['key' => 'first', 'value' => 42]], [])->willReturn($request); - $this->getUsersFollows('TEST_TOKEN', null, null, 42)->shouldBe($response); - } - - function it_should_get_users_follows_page_by_after(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'users/follows', 'TEST_TOKEN', [['key' => 'after', 'value' => '42']], [])->willReturn($request); - $this->getUsersFollows('TEST_TOKEN', null, null, null, '42')->shouldBe($response); - } - - function it_should_get_users_follows_by_everything(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'users/follows', 'TEST_TOKEN', [['key' => 'from_id', 'value' => '12345'], ['key' => 'to_id', 'value' => '98765'], ['key' => 'first', 'value' => 42], ['key' => 'after', 'value' => '99']], [])->willReturn($request); - $this->getUsersFollows('TEST_TOKEN', '12345', '98765', 42, '99')->shouldBe($response); - } - - function it_should_create_a_follow(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'users/follows', 'TEST_TOKEN', [['key' => 'from_id', 'value' => '123'], ['key' => 'to_id', 'value' => '321']], [])->willReturn($request); - $this->createUserFollow('TEST_TOKEN', '123', '321')->shouldBe($response); - } - - function it_should_create_a_follow_with_notifications(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'users/follows', 'TEST_TOKEN', [['key' => 'from_id', 'value' => '123'], ['key' => 'to_id', 'value' => '321'], ['key' => 'allow_notifications', 'value' => 1]], [])->willReturn($request); - $this->createUserFollow('TEST_TOKEN', '123', '321', true)->shouldBe($response); - } - - function it_should_create_a_follow_without_notifications(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'users/follows', 'TEST_TOKEN', [['key' => 'from_id', 'value' => '123'], ['key' => 'to_id', 'value' => '321'], ['key' => 'allow_notifications', 'value' => 0]], [])->willReturn($request); - $this->createUserFollow('TEST_TOKEN', '123', '321', false)->shouldBe($response); - } - - function it_should_delete_a_follow(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('DELETE', 'users/follows', 'TEST_TOKEN', [['key' => 'from_id', 'value' => '123'], ['key' => 'to_id', 'value' => '321']], [])->willReturn($request); - $this->deleteUserFollow('TEST_TOKEN', '123', '321')->shouldBe($response); - } - - function it_should_update_user(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PUT', 'users', 'TEST_TOKEN', [], [])->willReturn($request); - $this->updateUser('TEST_TOKEN')->shouldBe($response); - } - - function it_should_update_user_description(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PUT', 'users', 'TEST_TOKEN', [['key' => 'description', 'value' => 'test']], [])->willReturn($request); - $this->updateUser('TEST_TOKEN', 'test')->shouldBe($response); - } - - function it_should_get_user_block_list(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'users/blocks', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123']], [])->willReturn($request); - $this->getUserBlockList('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_get_user_block_list_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'users/blocks', 'TEST_TOKEN', [['key' => 'broadcaster_id', 'value' => '123'], ['key' => 'first', 'value' => 100], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request); - $this->getUserBlockList('TEST_TOKEN', '123', 100, 'abc')->shouldBe($response); - } - - function it_should_block_user(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PUT', 'users/blocks', 'TEST_TOKEN', [['key' => 'target_user_id', 'value' => '123']], [])->willReturn($request); - $this->blockUser('TEST_TOKEN', '123')->shouldBe($response); - } - - function it_should_block_user_with_opts(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('PUT', 'users/blocks', 'TEST_TOKEN', [['key' => 'target_user_id', 'value' => '123'], ['key' => 'source_context', 'value' => 'chat'], ['key' => 'reason', 'value' => 'spam']], [])->willReturn($request); - $this->blockUser('TEST_TOKEN', '123', 'chat', 'spam')->shouldBe($response); - } - - function it_should_unblock_user(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('DELETE', 'users/blocks', 'TEST_TOKEN', [['key' => 'target_user_id', 'value' => '123']], [])->willReturn($request); - $this->unblockUser('TEST_TOKEN', '123')->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/VideosApiSpec.php b/spec/NewTwitchApi/Resources/VideosApiSpec.php deleted file mode 100644 index 4245edf..0000000 --- a/spec/NewTwitchApi/Resources/VideosApiSpec.php +++ /dev/null @@ -1,102 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_get_video_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'id', 'value' => '123']], [])->willReturn($request); - $this->getVideos('TEST_TOKEN', ['123'])->shouldBe($response); - } - - function it_should_get_videos_by_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'id', 'value' => '123'], ['key' => 'id', 'value' => '321']], [])->willReturn($request); - $this->getVideos('TEST_TOKEN', ['123', '321'])->shouldBe($response); - } - - function it_should_get_videos_by_user_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123']], [])->willReturn($request); - $this->getVideos('TEST_TOKEN', [], '123')->shouldBe($response); - } - - function it_should_get_videos_by_game_id(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'game_id', 'value' => '123']], [])->willReturn($request); - $this->getVideos('TEST_TOKEN', [], null, '123')->shouldBe($response); - } - - function it_should_get_videos_with_first(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'first', 'value' => 100]], [])->willReturn($request); - $this->getVideos('TEST_TOKEN', [], null, null, 100)->shouldBe($response); - } - - function it_should_get_videos_with_before(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'before', 'value' => 'abc']], [])->willReturn($request); - $this->getVideos('TEST_TOKEN', [], null, null, null, 'abc')->shouldBe($response); - } - - function it_should_get_videos_with_after(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'after', 'value' => 'cba']], [])->willReturn($request); - $this->getVideos('TEST_TOKEN', [], null, null, null, null, 'cba')->shouldBe($response); - } - - function it_should_get_videos_with_language(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'language', 'value' => 'en']], [])->willReturn($request); - $this->getVideos('TEST_TOKEN', [], null, null, null, null, null, 'en')->shouldBe($response); - } - - function it_should_get_videos_with_period(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'period', 'value' => 'all']], [])->willReturn($request); - $this->getVideos('TEST_TOKEN', [], null, null, null, null, null, null, 'all')->shouldBe($response); - } - - function it_should_get_videos_with_sort(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'sort', 'value' => 'trending']], [])->willReturn($request); - $this->getVideos('TEST_TOKEN', [], null, null, null, null, null, null, null, 'trending')->shouldBe($response); - } - - function it_should_get_videos_with_type(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'type', 'value' => 'all']], [])->willReturn($request); - $this->getVideos('TEST_TOKEN', [], null, null, null, null, null, null, null, null, 'all')->shouldBe($response); - } - - function it_should_get_videos_with_everything(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'videos', 'TEST_TOKEN', [['key' => 'user_id', 'value' => '123'], ['key' => 'game_id', 'value' => '321'], ['key' => 'first', 'value' => 100], ['key' => 'before', 'value' => 'abc'], ['key' => 'after', 'value' => 'def'], ['key' => 'language', 'value' => 'en'], ['key' => 'period', 'value' => 'all'], ['key' => 'sort', 'value' => 'trending'], ['key' => 'type', 'value' => 'all']], [])->willReturn($request); - $this->getVideos('TEST_TOKEN', [], '123', '321', 100, 'abc', 'def', 'en', 'all', 'trending', 'all')->shouldBe($response); - } - - function it_should_delete_videos(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('DELETE', 'videos', 'TEST_TOKEN', [['key' => 'id', 'value' => '123']], [])->willReturn($request); - $this->deleteVideos('TEST_TOKEN', ['123'])->shouldBe($response); - } - - function it_should_delete_multiple_videos(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('DELETE', 'videos', 'TEST_TOKEN', [['key' => 'id', 'value' => '123'], ['key' => 'id', 'value' => '321']], [])->willReturn($request); - $this->deleteVideos('TEST_TOKEN', ['123', '321'])->shouldBe($response); - } -} diff --git a/spec/NewTwitchApi/Resources/WebhooksApiSpec.php b/spec/NewTwitchApi/Resources/WebhooksApiSpec.php deleted file mode 100644 index 77020d4..0000000 --- a/spec/NewTwitchApi/Resources/WebhooksApiSpec.php +++ /dev/null @@ -1,42 +0,0 @@ -beConstructedWith($guzzleClient, $requestGenerator); - $guzzleClient->send($request)->willReturn($response); - } - - function it_should_get_webhooks_subscriptions(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'webhooks/subscriptions', 'TEST_TOKEN', [], [])->willReturn($request); - $this->getWebhookSubscriptions('TEST_TOKEN')->shouldBe($response); - } - - function it_should_get_webhooks_subscriptions_with_first(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'webhooks/subscriptions', 'TEST_TOKEN', [['key' => 'first', 'value' => 100]], [])->willReturn($request); - $this->getWebhookSubscriptions('TEST_TOKEN', 100)->shouldBe($response); - } - - function it_should_get_webhooks_subscriptions_with_after(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'webhooks/subscriptions', 'TEST_TOKEN', [['key' => 'after', 'value' => 'abc']], [])->willReturn($request); - $this->getWebhookSubscriptions('TEST_TOKEN', null, 'abc')->shouldBe($response); - } - - function it_should_get_webhooks_subscriptions_with_everything(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('GET', 'webhooks/subscriptions', 'TEST_TOKEN', [['key' => 'first', 'value' => 100], ['key' => 'after', 'value' => 'abc']], [])->willReturn($request); - $this->getWebhookSubscriptions('TEST_TOKEN', 100, 'abc')->shouldBe($response); - } -} diff --git a/src/Api/Authentication.php b/src/Api/Authentication.php deleted file mode 100644 index 4af07be..0000000 --- a/src/Api/Authentication.php +++ /dev/null @@ -1,75 +0,0 @@ -baseUri), - '?response_type=code', - sprintf('&client_id=%s', $this->getClientId()), - sprintf('&redirect_uri=%s', $this->getRedirectUri()), - sprintf('&scope=%s', implode('+', $this->getScope())), - sprintf('&state=%s', $state), - sprintf('&force_verify=%s', $forceVerify ? 'true' : 'false'), - ]); - } - - /** - * Get a user's access credentials, which includes the access token - * - * @param string $code - * @param string $state - * @return array|string - */ - public function getAccessCredentials($code, $state = null) - { - return $this->post('oauth2/token', [ - 'client_id' => $this->getClientId(), - 'client_secret' => $this->getClientSecret(), - 'grant_type' => 'authorization_code', - 'redirect_uri' => $this->getRedirectUri(), - 'code' => $code, - 'state' => $state, - ]); - } - - /** - * Get a new access token - * - * @param string $refreshToken - * @return array|string - */ - public function refreshToken($refreshToken) - { - return $this->post('oauth2/token', [ - 'grant_type' => 'refresh_token', - 'refresh_token' => $refreshToken, - 'client_id' => $this->getClientId(), - 'client_secret' => $this->getClientSecret(), - ]); - } - - /** - * Revoke an access token - * - * @param string $accessToken - * @return array|string - */ - public function revokeToken($accessToken) - { - return $this->post('oauth2/revoke', [ - 'client_id' => $this->getClientId(), - 'token' => $accessToken, - ]); - } -} diff --git a/src/Api/Bits.php b/src/Api/Bits.php deleted file mode 100644 index dc326e8..0000000 --- a/src/Api/Bits.php +++ /dev/null @@ -1,34 +0,0 @@ -apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if ($channelIdentifier && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - $params = [ - 'channel_id' => $channelIdentifier, - ]; - - return $this->get('bits/actions', $params); - } -} diff --git a/src/Api/ChannelFeed.php b/src/Api/ChannelFeed.php deleted file mode 100644 index 50e9d40..0000000 --- a/src/Api/ChannelFeed.php +++ /dev/null @@ -1,355 +0,0 @@ -apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if ($cursor && !is_string($cursor)) { - throw new InvalidTypeException('Cursor', 'string', gettype($cursor)); - } - - if (!is_int($comments)) { - throw new InvalidTypeException('Comments', 'integer', gettype($comments)); - } - - $params = [ - 'limit' => intval($limit), - 'cursor' => $cursor, - 'comments' => $comments, - ]; - - return $this->get(sprintf('feed/%s/posts', $channelIdentifier), $params, $accessToken); - } - - /** - * Get a feed post - * - * @param string|int $channelIdentifier - * @param string $postId - * @param string $accessToken - * @param int $comments - * @throws InvalidIdentifierException - * @throws InvalidTypeException - * @return array|string - */ - public function getFeedPost($channelIdentifier, $postId, $accessToken, $comments = 5) - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - if (!is_string($postId)) { - throw new InvalidTypeException('Post ID', 'string', gettype($postId)); - } - - if (!is_int($comments)) { - throw new InvalidTypeException('Comments', 'integer', gettype($comments)); - } - - $params = [ - 'comments' => $comments, - ]; - - return $this->get(sprintf('feed/%s/posts/%s', $channelIdentifier, $postId), $params, $accessToken); - } - - /** - * Create a fedd post - * - * @param string|int $channelIdentifier - * @param string $accessToken - * @param string $content - * @param boolean $share - * @throws InvalidIdentifierException - * @throws InvalidTypeException - * @return array|string - */ - public function createFeedPost($channelIdentifier, $accessToken, $content, $share = false) - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - if (!is_string($content)) { - throw new InvalidTypeException('Content', 'string', gettype($content)); - } - - if (!is_bool($share)) { - throw new InvalidTypeException('Share', 'boolean', gettype($share)); - } - - $params = [ - 'share' => $share, - 'content' => $content, - ]; - - return $this->post(sprintf('feed/%s/posts', $channelIdentifier), $params, $accessToken); - } - - /** - * Delete a feed post - * - * @param string|int $channelIdentifier - * @param string $postId - * @param string $accessToken - * @throws InvalidIdentifierException - * @throws InvalidTypeException - * @return array|string - */ - public function deleteFeedPost($channelIdentifier, $postId, $accessToken) - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - if (!is_string($postId)) { - throw new InvalidTypeException('Post ID', 'string', gettype($postId)); - } - - return $this->delete(sprintf('feed/%s/posts/%s', $channelIdentifier, $postId), [], $accessToken); - } - - /** - * Create a reaction to a feed post - * - * @param string|int $channelIdentifier - * @param string $postId - * @param string $accessToken - * @param string $emoteId - * @throws InvalidIdentifierException - * @throws InvalidTypeException - * @return array|string - */ - public function createFeedPostReaction($channelIdentifier, $postId, $accessToken, $emoteId) - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - if (!is_string($postId)) { - throw new InvalidTypeException('Post ID', 'string', gettype($postId)); - } - - if (!is_string($emoteId)) { - throw new InvalidTypeException('Reaction', 'string', gettype($emoteId)); - } - - $params = [ - 'emote_id' => $emoteId, - ]; - - return $this->post(sprintf('feed/%s/posts/%s/reactions', $channelIdentifier, $postId), $params, $accessToken); - } - - /** - * Delete a reaction to a feed post - * - * @param string|int $channelIdentifier - * @param string $postId - * @param string $accessToken - * @param string $emoteId - * @throws InvalidIdentifierException - * @throws InvalidTypeException - * @return array|string - */ - public function deleteFeedPostReaction($channelIdentifier, $postId, $accessToken, $emoteId) - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - if (!is_string($postId)) { - throw new InvalidTypeException('Post ID', 'string', gettype($postId)); - } - - if (!is_string($emoteId)) { - throw new InvalidTypeException('Reaction', 'string', gettype($emoteId)); - } - - $params = [ - 'emote_id' => $emoteId, - ]; - - return $this->delete(sprintf('feed/%s/posts/%s/reactions', $channelIdentifier, $postId), $params, $accessToken); - } - - /** - * Get comments from a feed post - * - * @param string|int $channelIdentifier - * @param string $postId - * @param string $accessToken - * @param int $limit - * @param string $cursor - * @throws InvalidIdentifierException - * @throws InvalidTypeException - * @throws InvalidLimitException - * @return array|string - */ - public function getFeedComments($channelIdentifier, $postId, $accessToken, $limit = 10, $cursor = null) - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - if (!is_string($postId)) { - throw new InvalidTypeException('Post ID', 'string', gettype($postId)); - } - - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if ($cursor && !is_string($cursor)) { - throw new InvalidTypeException('Cursor', 'string', gettype($cursor)); - } - - $params = [ - 'limit' => intval($limit), - 'cursor' => $cursor, - ]; - - return $this->get(sprintf('feed/%s/posts/%s/comments', $channelIdentifier, $postId), $params, $accessToken); - } - - /** - * Create a feed post comment - * - * @param string|int $channelIdentifier - * @param string $postId - * @param string $accessToken - * @param string $comment - * @throws InvalidIdentifierException - * @throws InvalidTypeException - * @return array|string - */ - public function createFeedComment($channelIdentifier, $postId, $accessToken, $comment) - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - if (!is_string($comment)) { - throw new InvalidTypeException('Comment', 'string', gettype($comment)); - } - - $params = [ - 'content' => $comment, - ]; - - return $this->post(sprintf('feed/%s/posts/%s/comments', $channelIdentifier, $postId), $params, $accessToken); - } - - /** - * Delete a feed post comment - * - * @param string|int $channelIdentifier - * @param string $postId - * @param string $accessToken - * @param string|int $commentId - * @throws InvalidIdentifierException - * @throws InvalidTypeException - * @return array|string - */ - public function deleteFeedComment($channelIdentifier, $postId, $commentId, $accessToken) - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - return $this->delete(sprintf('feed/%s/posts/%s/comments/%s', $channelIdentifier, $postId, $commentId), [], $accessToken); - } - - /** - * Create a reaction to a feed comment - * - * @param string|int $channelIdentifier - * @param string $postId - * @param string|int $commentId - * @param string $accessToken - * @param string $emoteId - * @throws InvalidIdentifierException - * @throws InvalidTypeException - * @return array|string - */ - public function createFeedCommentReaction($channelIdentifier, $postId, $commentId, $accessToken, $emoteId) - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - if (!is_string($postId)) { - throw new InvalidTypeException('Post ID', 'string', gettype($postId)); - } - - if (!is_string($emoteId)) { - throw new InvalidTypeException('Reaction', 'string', gettype($emoteId)); - } - - $params = [ - 'emote_id' => $emoteId, - ]; - - return $this->post(sprintf('feed/%s/posts/%s/comments/%s/reactions', $channelIdentifier, $postId, $commentId), $params, $accessToken); - } - - /** - * Delete a reaction to a feed comment - * - * @param string|int $channelIdentifier - * @param string $postId - * @param string|int $commentId - * @param string $accessToken - * @param string $emoteId - * @throws InvalidIdentifierException - * @throws InvalidTypeException - * @return array|string - */ - public function deleteFeedCommentReaction($channelIdentifier, $postId, $commentId, $accessToken, $emoteId) - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - if (!is_string($postId)) { - throw new InvalidTypeException('Post ID', 'string', gettype($postId)); - } - - if (!is_string($emoteId)) { - throw new InvalidTypeException('Reaction', 'string', gettype($emoteId)); - } - - $params = [ - 'emote_id' => $emoteId, - ]; - - return $this->delete(sprintf('feed/%s/posts/%s/comments/%s/reactions', $channelIdentifier, $postId, $commentId), $params, $accessToken); - } -} diff --git a/src/Api/Channels.php b/src/Api/Channels.php deleted file mode 100644 index ac2b6b2..0000000 --- a/src/Api/Channels.php +++ /dev/null @@ -1,409 +0,0 @@ -get('channel', [], $accessToken); - } - - /** - * Get a channel - * - * @param string|int $channelIdentifier - * @throws InvalidIdentifierException - * @return array|string - */ - public function getChannel($channelIdentifier) - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - return $this->get(sprintf('channels/%s', $channelIdentifier)); - } - - /** - * Update a user's channel - * - * @param string|int $channelIdentifier - * @param string $accessToken - * @param string $status - * @param string $game - * @param int $delay - * @param bool $channelFeedEnabled - * @throws InvalidIdentifierException - * @throws InvalidTypeException - * @throws TwitchApiException - * @return array|string - */ - public function updateChannel($channelIdentifier, $accessToken, $status = null, $game = null, $delay = null, $channelFeedEnabled = null) - { - $params = []; - $params['channel'] = []; - - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - if ($status) { - if (!is_string($status)) { - throw new InvalidTypeException('Status', 'string', gettype($status)); - } - $params['channel']['status'] = $status; - } - - if ($game) { - if (!is_string($game)) { - throw new InvalidTypeException('Game', 'string', gettype($game)); - } - $params['channel']['game'] = $game; - } - - if ($delay) { - if (!is_numeric($delay)) { - throw new InvalidTypeException('Delay', 'integer', gettype($delay)); - } - $params['channel']['delay'] = intval($delay); - } - - if ($channelFeedEnabled !== null) { - if (!is_bool($channelFeedEnabled)) { - throw new InvalidTypeException('ChannelFeedEnabled', 'boolean', gettype($channelFeedEnabled)); - } - $params['channel']['channel_feed_enabled'] = $channelFeedEnabled; - } - - if (empty($params['channel'])) { - throw new TwitchApiException('At least one of the following parameters must be set: status, game, delay or channelFeedEnabled.'); - } - - return $this->put(sprintf('channels/%s', $channelIdentifier), $params, $accessToken); - } - - /** - * Get channel editors - * - * @param string|int $channelIdentifier - * @param string $accessToken - * @throws InvalidIdentifierException - * @return array|string - */ - public function getChannelEditors($channelIdentifier, $accessToken) - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - return $this->get(sprintf('channels/%s/editors', $channelIdentifier), [], $accessToken); - } - - /** - * Get channel followers - * - * @param string|int $channelIdentifier - * @param int $limit - * @param int $offset - * @param string $cursor - * @param string $direction - * @throws InvalidIdentifierException - * @throws InvalidLimitException - * @throws InvalidOffsetException - * @throws InvalidTypeException - * @throws InvalidDirectionException - * @return array|string - */ - public function getChannelFollowers($channelIdentifier, $limit = 25, $offset = 0, $cursor = null, $direction = 'desc') - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if (!$this->isValidOffset($offset)) { - throw new InvalidOffsetException(); - } - - if ($cursor && !is_string($cursor)) { - throw new InvalidTypeException('Cursor', 'string', gettype($cursor)); - } - - if (!$this->isValidDirection($direction)) { - throw new InvalidDirectionException(); - } - - $params = [ - 'limit' => intval($limit), - 'offset' => intval($offset), - 'cursor' => $cursor, - 'direction' => $direction, - ]; - - return $this->get(sprintf('channels/%s/follows', $channelIdentifier), $params); - } - - /** - * Get channel teams - * - * @param string|int $channelIdentifier - * @throws InvalidIdentifierException - * @return array|string - */ - public function getChannelTeams($channelIdentifier) - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - return $this->get(sprintf('channels/%s/teams', $channelIdentifier)); - } - - /** - * Get channel subscribers - * - * @param string|int $channelIdentifier - * @param string $accessToken - * @param int $limit - * @param int $offset - * @param string $direction - * @throws InvalidIdentifierException - * @throws InvalidLimitException - * @throws InvalidOffsetException - * @throws InvalidDirectionException - * @return array|string - */ - public function getChannelSubscribers($channelIdentifier, $accessToken, $limit = 25, $offset = 0, $direction = 'desc') - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if (!$this->isValidOffset($offset)) { - throw new InvalidOffsetException(); - } - - if (!$this->isValidDirection($direction)) { - throw new InvalidDirectionException(); - } - - $params = [ - 'limit' => intval($limit), - 'offset' => intval($offset), - 'direction' => $direction, - ]; - - return $this->get(sprintf('channels/%s/subscriptions', $channelIdentifier), $params, $accessToken); - } - - /** - * Check a user's subscription to a channel - * - * @param string|int $channelIdentifier - * @param string|int $userIdentifier - * @param string $accessToken - * @throws InvalidIdentifierException - * @return array|string - */ - public function checkChannelSubscriptionByUser($channelIdentifier, $userIdentifier, $accessToken) - { - if ($this->apiVersionIsGreaterThanV3()) { - if (!is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - if (!is_numeric($userIdentifier)) { - throw new InvalidIdentifierException('user'); - } - } - - return $this->get(sprintf('channels/%s/subscriptions/%s', $channelIdentifier, $userIdentifier), [], $accessToken); - } - - /** - * Get channel videos - * - * @param string|int $channelIdentifier - * @param int $limit - * @param int $offset - * @param string $broadcastType (comma-seperated list) - * @param string $language (comma-seperated list) - * @param string $sort - * @throws InvalidIdentifierException - * @throws InvalidLimitException - * @throws InvalidOffsetException - * @throws UnsupportedOptionException - * @throws InvalidTypeException - * @return array|string - */ - public function getChannelVideos($channelIdentifier, $limit = 10, $offset = 0, $broadcastType = 'highlight', $language = null, $sort = 'time') - { - $validSort = ['views', 'time']; - - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if (!$this->isValidOffset($offset)) { - throw new InvalidOffsetException(); - } - - $broadcastType = trim($broadcastType, ', '); - if (!$this->isValidBroadcastType($broadcastType)) { - throw new UnsupportedOptionException('broadcastType', $validBroadcastTypes); - } - - if ($language && !is_string($language)) { - throw new InvalidTypeException('language', 'string', gettype($language)); - } - - if (!in_array($sort = strtolower($sort), $validSort)) { - throw new UnsupportedOptionException('sort', $validSort); - } - - $params = [ - 'limit' => intval($limit), - 'offset' => intval($offset), - 'broadcast_type' => $broadcastType, - 'language' => $language, - 'sort' => $sort, - ]; - - return $this->get(sprintf('channels/%s/videos', $channelIdentifier), $params); - } - - /** - * Run a channel commercial - * - * @param string|int $channelIdentifier - * @param string $accessToken - * @param int $length - * @throws InvalidIdentifierException - * @throws UnsupportedOptionException - * @return array|string - */ - public function startChannelCommercial($channelIdentifier, $accessToken, $length = 30) - { - $validLengths = [30, 60, 90, 120, 150, 180]; - - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - if (!in_array($length = intval($length), $validLengths)) { - throw new UnsupportedOptionException('length', $validLengths); - } - - return $this->post(sprintf('channels/%s/commercial', $channelIdentifier), ['length' => $length], $accessToken); - } - - /** - * Reset a channel's stream key - * - * @param string|int $channelIdentifier - * @param string $accessToken - * @throws InvalidIdentifierException - * @return array|string - */ - public function resetChannelStreamKey($channelIdentifier, $accessToken) - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - return $this->delete(sprintf('channels/%s/stream_key', $channelIdentifier), [], $accessToken); - } - - /** - * Get the community for a channel - * - * @param string|int $channelIdentifier - * @throws InvalidIdentifierException - * @throws EndpointNotSupportedByApiVersionException - * @return null|array|string - */ - public function getChannelCommunity($channelIdentifier) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - return $this->get(sprintf('channels/%s/community', $channelIdentifier)); - } - - /** - * Set the community for a channel - * - * @param string|int $channelIdentifier - * @param string $communityId - * @param string $accessToken - * @throws InvalidIdentifierException - * @throws EndpointNotSupportedByApiVersionException - * @return null - */ - public function setChannelCommunity($channelIdentifier, $communityId, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - return $this->put(sprintf('channels/%s/community/%s', $channelIdentifier, $communityId), [], $accessToken); - } - - /** - * Remove a channel form a community - * - * @param string|int $channelIdentifier - * @param string $accessToken - * @throws InvalidIdentifierException - * @throws EndpointNotSupportedByApiVersionException - * @return null - */ - public function deleteChannelFromCommunity($channelIdentifier, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - return $this->delete(sprintf('channels/%s/community', $channelIdentifier), [], $accessToken); - } -} diff --git a/src/Api/Chat.php b/src/Api/Chat.php deleted file mode 100644 index 47e7c72..0000000 --- a/src/Api/Chat.php +++ /dev/null @@ -1,53 +0,0 @@ -apiVersionIsGreaterThanV3() && !is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - return $this->get(sprintf('chat/%s/badges', $channelIdentifier)); - } - - /** - * Get chat emoticons by set - * - * @param string $emotesets (comma-seperated list) - * @throws InvalidTypeException - * @return array|string - */ - public function getChatEmoticonSets($emotesets = null) - { - if ($emotesets && !is_string($emotesets)) { - throw new InvalidTypeException('emotesets', 'string', gettype($emotesets)); - } - - $emotesets = trim($emotesets, ', '); - - return $this->get('chat/emoticon_images', ['emotesets' => $emotesets]); - } - - /** - * Get all chat emotes - * - * @return array|string - */ - public function getAllChatEmoticons() - { - return $this->get('chat/emoticons'); - } -} diff --git a/src/Api/Clips.php b/src/Api/Clips.php deleted file mode 100644 index 18b6a92..0000000 --- a/src/Api/Clips.php +++ /dev/null @@ -1,143 +0,0 @@ -get(sprintf('clips/%s', $slug)); - } - - /** - * Get top clips - * - * @param string $channel (comma-seperated list - 10 max) - * @param string $cursor - * @param string $game (comma-seperated list - 10 max) - * @param int $limit - * @param string $period - * @param boolean $trending - * @param string $language comma-seperated list - 28 max) - * @throws InvalidTypeException - * @throws TwitchApiException - * @throws InvalidLimitException - * @throws UnsupportedOptionException - * @return array|string - */ - public function getTopClips($channel = null, $cursor = null, $game = null, $limit = 10, $period = 'day', $trending = false, $language = null) - { - $validPeriods = ['day', 'week', 'month', 'all']; - - if ($channel) { - if (!is_string($channel)) { - throw new InvalidTypeException('channel', 'string', gettype($channel)); - } - - $channel = trim($channel, ', '); - if (($count = substr_count($channel, ',') + 1) > 10) { - throw new TwitchApiException(sprintf('Only a maximum of 10 channels can be queried. %d requested.', $count)); - } - } - - if ($cursor && !is_string($cursor)) { - throw new InvalidTypeException('cursor', 'string', gettype($cursor)); - } - - if ($game) { - if (!is_string($game)) { - throw new InvalidTypeException('game', 'string', gettype($game)); - } - - $game = trim($game, ', '); - if (($count = substr_count($game, ',') + 1) > 10) { - throw new TwitchApiException(sprintf('Only a maximum of 10 games can be queried. %d requested.', $count)); - } - } - - if ($language) { - if (!is_string($language)) { - throw new InvalidTypeException('language', 'string', gettype($language)); - } - - $language = trim($language, ', '); - if (($count = substr_count($language, ',') + 1) > 28) { - throw new TwitchApiException(sprintf('Only a maximum of 28 languages can be queried. %d requested.', $count)); - } - } - - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if (!in_array($period = strtolower($period), $validPeriods)) { - throw new UnsupportedOptionException('period', $validPeriods); - } - - if (!is_bool($trending)) { - throw new InvalidTypeException('trending', 'boolean', gettype($trending)); - } - - $params = [ - 'channel' => $channel, - 'cursor' => $cursor, - 'game' => $game, - 'language' => $language, - 'limit' => (int)$limit, - 'period' => $period, - 'trending' => $trending ? 'true' : 'false', - ]; - - return $this->get('clips/top', $params); - } - - /** - * Get clips from channels followed - * - * @param string $accessToken - * @param int $limit - * @param string $cursor - * @param boolean $trending - * @throws InvalidTypeException - * @throws InvalidLimitException - * @return array|string - */ - public function getFollowedClips($accessToken, $limit = 10, $cursor = null, $trending = false) - { - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if ($cursor && !is_string($cursor)) { - throw new InvalidTypeException('cursor', 'string', gettype($cursor)); - } - - if (!is_bool($trending)) { - throw new InvalidTypeException('trending', 'boolean', gettype($trending)); - } - - $params = [ - 'limit' => (int)$limit, - 'cursor' => $cursor, - 'trending' => $trending ? 'true' : 'false', - ]; - - return $this->get('clips/followed', $params, $accessToken); - } -} diff --git a/src/Api/Collections.php b/src/Api/Collections.php deleted file mode 100644 index d52a545..0000000 --- a/src/Api/Collections.php +++ /dev/null @@ -1,290 +0,0 @@ -apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - return $this->get(sprintf('collections/%s', $collectionId)); - } - - /** - * Gets all items (videos) in specified collection - * - * @param string $collectionId - * @param bool $includeAllItems - * @throws EndpointNotSupportedByApiVersionException - * @throws InvalidTypeException - * @return array|string - */ - public function getCollection($collectionId, $includeAllItems = false) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_bool($includeAllItems)) { - throw new InvalidTypeException('Include All Items', 'boolean', gettype($includeAllItems)); - } - - $params = [ - 'includeAllItems' => $includeAllItems, - ]; - - return $this->get(sprintf('collections/%s/items', $collectionId), $params); - } - - /** - * Get all collections owned by a channel - * - * @param int|string $channelIdentifier - * @param int $limit - * @param string $cursor - * @param string $containingItem - * @throws EndpointNotSupportedByApiVersionException - * @throws InvalidIdentifierException - * @throws InvalidLimitException - * @throws InvalidTypeException - * @return array|string - */ - public function getChannelCollection($channelIdentifier, $limit = 10, $cursor = null, $containingItem = null) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if ($cursor && !is_string($cursor)) { - throw new InvalidTypeException('Cursor', 'string', gettype($cursor)); - } - - if ($containingItem && !is_string($containingItem)) { - throw new InvalidTypeException('Containing Item', 'string', gettype($containingItem)); - } - - $params = [ - 'limit' => intval($limit), - 'cursor' => $cursor, - 'containingItem' => $containingItem, - ]; - - return $this->get(sprintf('channels/%s/collections', $channelIdentifier), $params); - } - - /** - * Create a new collection owned a channel - * - * @param int|string $channelIdentifier - * @param string $title - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @throws InvalidIdentifierException - * @throws InvalidTypeException - * @return array|string - */ - public function createCollection($channelIdentifier, $title, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - - if (!is_string($title)) { - throw new InvalidTypeException('Title', 'string', gettype($title)); - } - - $params = [ - 'title' => $title, - ]; - - return $this->post(sprintf('channels/%s/collections', $channelIdentifier), $params, $accessToken); - } - - /** - * Update a collection - * - * @param string $collectionId - * @param string $title - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @throws InvalidTypeException - * @return null - */ - public function updateCollection($collectionId, $title, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_string($title)) { - throw new InvalidTypeException('Title', 'string', gettype($title)); - } - - $params = [ - 'title' => $title, - ]; - - return $this->put(sprintf('collections/%s', $collectionId), $params, $accessToken); - } - - /** - * Create a collection thumbnail - * - * @param string $collectionId - * @param string $itemId - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @return null - */ - public function createCollectionThumbnail($collectionId, $itemId, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_string($itemId)) { - throw new InvalidTypeException('Item ID', 'string', gettype($itemId)); - } - - $params = [ - 'item_id' => $itemId, - ]; - - return $this->put(sprintf('collections/%s/thumbnail', $collectionId), $params, $accessToken); - } - - /** - * Delete a collection - * - * @param string $collectionId - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @throws InvalidTypeException - * @return null - */ - public function deleteCollection($collectionId, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - return $this->delete(sprintf('collections/%s', $collectionId), [], $accessToken); - } - - /** - * Add an item to a collection - * - * @param string $collectionId - * @param string $itemId - * @param string $itemType - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @throws InvalidTypeException - * @return array|string - */ - public function addCollectionItem($collectionId, $itemId, $itemType = 'video', $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_string($itemId)) { - throw new InvalidTypeException('Item ID', 'string', gettype($itemId)); - } - - if (!is_string($itemType)) { - throw new InvalidTypeException('Item ID', 'string', gettype($itemType)); - } - - $params = [ - 'item_id' => $itemId, - 'type' => $itemType, - ]; - - return $this->post(sprintf('collections/%s/items', $collectionId), $params, $accessToken); - } - - /** - * Delete an item from a collection - * - * @param string $collectionId - * @param string $itemId - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @throws InvalidTypeException - * @return null - */ - public function deleteCollectionItem($collectionId, $itemId, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_string($itemId)) { - throw new InvalidTypeException('Item ID', 'string', gettype($itemId)); - } - - return $this->delete(sprintf('collections/%s/items/%s', $collectionId, $itemId), [], $accessToken); - } - - /** - * Move a collection item - * - * @param string $collectionId - * @param string $itemId - * @param int $position - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @throws InvalidTypeException - * @throws TwitchApiException - * @return null - */ - public function moveCollectionThumbnail($collectionId, $itemId, $position, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_string($itemId)) { - throw new InvalidTypeException('Item ID', 'string', gettype($itemId)); - } - - if ($position < 1) { - throw new TwitchApiException('Collection position cannot be less than 1.'); - } - - $params = [ - 'position' => $position, - ]; - - return $this->put(sprintf('collections/%s/itmes/%s', $collectionId, $itemId), $params, $accessToken); - } -} diff --git a/src/Api/Communities.php b/src/Api/Communities.php deleted file mode 100644 index 281efc1..0000000 --- a/src/Api/Communities.php +++ /dev/null @@ -1,537 +0,0 @@ -apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_string($name)) { - throw new InvalidTypeException('Name', 'string', gettype($name)); - } - - return $this->get('communities', ['name' => $name]); - } - - /** - * Get community by ID - * - * @param string $communityId - * @throws InvalidTypeException - * @throws EndpointNotSupportedByApiVersionException - * @return array|string - */ - public function getCommunityById($communityId) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_string($communityId)) { - throw new InvalidTypeException('Community ID', 'string', gettype($communityId)); - } - - return $this->get(sprintf('communities/%s', $communityId)); - } - - /** - * Create a community - * - * @param string $name - * @param string $summary - * @param string $description - * @param string $rules - * @param string $accessToken - * @throws InvalidParameterLengthException - * @throws EndpointNotSupportedByApiVersionException - * @return array|string - */ - public function createCommunity($name, $summary, $description, $rules, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (strlen($name) < 3 || strlen($name) > 25) { - throw new InvalidParameterLengthException('name'); - } - - if (strlen($summary) > 160) { - throw new InvalidParameterLengthException('summary'); - } - - if (strlen($description) > 1572864) { // 1.5MB - throw new InvalidParameterLengthException('description'); - } - - if (strlen($rules) > 1572864) { // 1.5MB - throw new InvalidParameterLengthException('rules'); - } - - $params = [ - 'name' => $name, - 'summary' => $summary, - 'description' => $description, - 'rules' => $rules, - ]; - - return $this->post('communities', $params, $accessToken); - } - - /** - * Update a community - * - * @param string $communityId - * @param string $accessToken - * @param string $summary - * @param string $description - * @param string $rules - * @param string $email - * @throws InvalidParameterLengthException - * @throws EndpointNotSupportedByApiVersionException - * @throws InvalidEmailAddressException - * @return array|string - */ - public function updateCommunity($communityId, $accessToken, $summary = null, $description = null, $rules = null, $email = null) - { - $params = []; - - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if ($summary) { - if (strlen($summary) > 160) { - throw new InvalidParameterLengthException('summary'); - } - $params['summary'] = $summary; - } - - if ($description) { - if (strlen($description) > 1572864) { // 1.5MB - throw new InvalidParameterLengthException('description'); - } - $params['description'] = $description; - } - - if ($rules) { - if (strlen($rules) > 1572864) { // 1.5MB - throw new InvalidParameterLengthException('rules'); - } - $params['rules'] = $rules; - } - - if ($email) { - if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) { - throw new InvalidEmailAddressException(); - } - $params['email'] = $email; - } - - return $this->put(sprintf('communities/%s', $communityId), $params, $accessToken); - } - - /** - * Get top communities - * - * @param int $limit - * @param string $cursor - * @throws InvalidLimitException - * @throws InvalidTypeException - * @throws EndpointNotSupportedByApiVersionException - * @return array|string - */ - public function getTopCommunities($limit = 10, $cursor = null) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if ($cursor && !is_string($cursor)) { - throw new InvalidTypeException('Cursor', 'string', gettype($cursor)); - } - - $params = [ - 'limit' => intval($limit), - 'cursor' => $cursor, - ]; - - return $this->get('communities/top', $params); - } - - /** - * Get banned community users - * - * @param string $communityId - * @param string $accessToken - * @param int $limit - * @param string $cursor - * @throws InvalidLimitException - * @throws InvalidTypeException - * @throws EndpointNotSupportedByApiVersionException - * @return array|string - */ - public function getBannedCommunityUsers($communityId, $accessToken, $limit = 10, $cursor = null) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if ($cursor && !is_string($cursor)) { - throw new InvalidTypeException('Cursor', 'string', gettype($cursor)); - } - - $params = [ - 'limit' => intval($limit), - 'cursor' => $cursor, - ]; - - return $this->get(sprintf('communities/%s/bans', $communityId), $params, $accessToken); - } - - /** - * Ban a community user - * - * @param string $communityId - * @param string $userId - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @throws InvalidIdentifierException - * @return array|string - */ - public function banCommunityUser($communityId, $userId, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_numeric($userId)) { - throw new InvalidIdentifierException('user'); - } - - return $this->put(sprintf('communities/%s/bans/%s', $communityId, $userId), [], $accessToken); - } - - /** - * Un-ban a community user - * - * @param string $communityId - * @param string $userId - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @throws InvalidIdentifierException - * @return array|string - */ - public function unbanCommunityUser($communityId, $userId, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_numeric($userId)) { - throw new InvalidIdentifierException('user'); - } - - return $this->delete(sprintf('communities/%s/bans/%s', $communityId, $userId), [], $accessToken); - } - - /** - * Upload a community avatar image (600x800px) - * - * @param string $communityId - * @param string $avatar (base64 encoded) - * @param string $accessToken - * @throws InvalidTypeException - * @throws EndpointNotSupportedByApiVersionException - * @return null|array|string - */ - public function createCommunityAvatar($communityId, $avatar, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_string($avatar)) { - throw new InvalidTypeException('Avatar', 'string', gettype($avatar)); - } - - return $this->post(sprintf('communities/%s/images/avatar', $communityId), ['avatar_image' => $avatar], $accessToken); - } - - /** - * Delete a community avatar image - * - * @param string $communityId - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @return null|array|string - */ - public function deleteCommunityAvatar($communityId, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - return $this->delete(sprintf('communities/%s/images/avatar', $communityId), [], $accessToken); - } - - /** - * Upload a community cover image (1200x180px) - * - * @param string $communityId - * @param string $image (base64 encoded) - * @param string $accessToken - * @throws InvalidTypeException - * @throws EndpointNotSupportedByApiVersionException - * @return null|array|string - */ - public function createCommunityCoverImage($communityId, $image, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_string($image)) { - throw new InvalidTypeException('Cover image', 'string', gettype($image)); - } - - return $this->post(sprintf('communities/%s/images/cover', $communityId), ['cover_image' => $image], $accessToken); - } - - /** - * Delete a community cover image - * - * @param string $communityId - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @return null|array|string - */ - public function deleteCommunityCoverImage($communityId, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - return $this->delete(sprintf('communities/%s/images/cover', $communityId), [], $accessToken); - } - - /** - * Get community moderators - * - * @param string $communityId - * @throws EndpointNotSupportedByApiVersionException - * @return array|string - */ - public function getCommunityModerators($communityId) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - return $this->get(sprintf('communities/%s/moderators', $communityId)); - } - - /** - * Give a community user moderator permissions - * - * @param string $communityId - * @param int $userId - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @throws InvalidIdentifierException - * @return null|array|string - */ - public function addCommunityModerator($communityId, $userId, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_numeric($userId)) { - throw new InvalidIdentifierException('user'); - } - - return $this->put(sprintf('communities/%s/moderators/%s', $communityId, $userId), [], $accessToken); - } - - /** - * Remove moderator permission from a community user - * - * @param string $communityId - * @param int $userId - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @throws InvalidIdentifierException - * @return null|array|string - */ - public function removeCommunityModerator($communityId, $userId, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_numeric($userId)) { - throw new InvalidIdentifierException('user'); - } - - return $this->delete(sprintf('communities/%s/moderators/%s', $communityId, $userId), [], $accessToken); - } - - /** - * Get community permissions - * - * @param string $communityId - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @return array|string - */ - public function getCommunityPermissions($communityId, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - return $this->get(sprintf('communities/%s/permissions', $communityId), [], $accessToken); - } - - /** - * Report a community channel violation - * - * @param string $communityId - * @param int $channelId - * @throws EndpointNotSupportedByApiVersionException - * @throws InvalidIdentifierException - * @return null|array|string - */ - public function reportCommunityViolation($communityId, $channelId) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_numeric($channelId)) { - throw new InvalidIdentifierException('channel'); - } - - return $this->post(sprintf('communities/%s/report_channel', $communityId), ['channel_id' => $channelId]); - } - - /** - * Get timed-out community users - * - * @param string $communityId - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @throws InvalidLimitException - * @throws InvalidTypeException - * @return array|string - */ - public function getTimedOutCommunityUsers($communityId, $accessToken, $limit = 10, $cursor = null) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if ($cursor && !is_string($cursor)) { - throw new InvalidTypeException('Cursor', 'string', gettype($cursor)); - } - - $params = [ - 'limit' => intval($limit), - 'cursor' => $cursor, - ]; - - return $this->get(sprintf('communities/%s/timeouts', $communityId), $params, $accessToken); - } - - /** - * Timeout a community user - * - * @param string $communityId - * @param int $userId - * @param string $accessToken - * @param int $duration - * @param string $reason - * @throws EndpointNotSupportedByApiVersionException - * @throws InvalidTypeException - * @return null|array|string - */ - public function timeoutCommunityUser($communityId, $userId, $accessToken, $duration, $reason = null) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_numeric($userId)) { - throw new InvalidIdentifierException('user'); - } - - if (!is_numeric($duration)) { - throw new InvalidTypeException('Duration', 'integer', gettype($duration)); - } - - if ($reason && !is_string($reason)) { - throw new InvalidTypeException('Reason', 'string', gettype($reason)); - } - - $params = [ - 'duration' => intval($duration), - 'reason' => $reason, - ]; - - return $this->put(sprintf('communities/%s/timeouts/%s', $communityId, $userId), $params, $accessToken); - } - - /** - * Remove a timeout from a community user - * - * @param string $communityId - * @param int $userId - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @throws InvalidIdentifierException - * @return null|array|string - */ - public function removeCommunityUserTimeout($communityId, $userId, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - if (!is_numeric($userId)) { - throw new InvalidIdentifierException('user'); - } - - return $this->delete(sprintf('communities/%s/timeouts/%s', $communityId, $userId), [], $accessToken); - } -} diff --git a/src/Api/Games.php b/src/Api/Games.php deleted file mode 100644 index 4894489..0000000 --- a/src/Api/Games.php +++ /dev/null @@ -1,37 +0,0 @@ -isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if (!$this->isValidOffset($offset)) { - throw new InvalidOffsetException(); - } - - $params = [ - 'limit' => $limit, - 'offset' => $offset, - ]; - - return $this->get('games/top', $params); - } - -} diff --git a/src/Api/Ingests.php b/src/Api/Ingests.php deleted file mode 100644 index 618f668..0000000 --- a/src/Api/Ingests.php +++ /dev/null @@ -1,16 +0,0 @@ -get('ingests'); - } -} diff --git a/src/Api/Root.php b/src/Api/Root.php deleted file mode 100644 index 362b1d2..0000000 --- a/src/Api/Root.php +++ /dev/null @@ -1,17 +0,0 @@ -get('', [], $accessToken); - } -} diff --git a/src/Api/Search.php b/src/Api/Search.php deleted file mode 100644 index 59be908..0000000 --- a/src/Api/Search.php +++ /dev/null @@ -1,116 +0,0 @@ -isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if (!$this->isValidOffset($offset)) { - throw new InvalidOffsetException(); - } - - $params = [ - 'query' => $query, - 'limit' => intval($limit), - 'offset' => intval($offset), - ]; - - return $this->get('search/channels', $params); - } - - /** - * Search for games by name - * - * @param string $query - * @throws InvalidTypeException - * @throws TwitchApiException - * @return array|string - */ - public function searchGames($query) - { - if (!is_string($query)) { - throw new InvalidTypeException('Query', 'string', gettype($query)); - } - - if (empty($query)) { - throw new TwitchApiException('A \'query\' parameter is required.'); - } - - return $this->get('search/games', ['query' => $query]); - } - - /** - * Search for streams by channel description or game name - * - * @param string $query - * @param int $limit - * @param int $offset - * @param boolean $hls - * @throws InvalidTypeException - * @throws TwitchApiException - * @throws InvalidLimitException - * @throws InvalidOffsetException - * @return array|string - */ - public function searchStreams($query, $limit = 25, $offset = 0, $hls = null) - { - if (!is_string($query)) { - throw new InvalidTypeException('Query', 'string', gettype($query)); - } - - if (empty($query)) { - throw new TwitchApiException('A \'query\' parameter is required.'); - } - - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if (!$this->isValidOffset($offset)) { - throw new InvalidOffsetException(); - } - - if ($hls !== null && !is_bool($hls)) { - throw new InvalidTypeException('HLS', 'boolean', gettype($hls)); - } - - $params = [ - 'query' => $query, - 'limit' => intval($limit), - 'offset' => intval($offset), - 'hls' => $hls, - ]; - - return $this->get('search/streams', $params); - } -} diff --git a/src/Api/Streams.php b/src/Api/Streams.php deleted file mode 100644 index 885dd9e..0000000 --- a/src/Api/Streams.php +++ /dev/null @@ -1,182 +0,0 @@ -apiVersionIsGreaterThanV3() && !is_numeric($userIdendifier)) { - throw new InvalidIdentifierException('user'); - } - - if (!$this->isValidStreamType($streamType)) { - throw new InvalidStreamTypeException(); - } - - return $this->get(sprintf('streams/%s', $userIdendifier), ['stream_type' => $streamType]); - } - - /** - * Get live streams - * - * @param string $channel (comma-seperated list) - * @param string $game - * @param string $language - * @param string $streamType - * @param int $limit - * @param int $offset - * @param string $broadcaster_language - * @throws InvalidTypeException - * @throws InvalidIdentifierException - * @throws InvalidStreamTypeException - * @throws InvalidLimitException - * @throws InvalidOffsetException - * @return array|string - */ - public function getLiveStreams($channel = null, $game = null, $language = null, $streamType = 'live', $limit = 25, $offset = 0, $broadcaster_language = null) - { - if ($channel) { - if (!is_string($channel)) { - throw new InvalidTypeException('channel', 'string', gettype($channel)); - } - - $channel = trim($channel, ', '); - if ($this->apiVersionIsGreaterThanV3()) { - foreach (explode(',', $channel) as $chan) { - if (!is_numeric($chan)) { - throw new InvalidIdentifierException('channel'); - } - } - } - } - - if ($game && !is_string($game)) { - throw new InvalidTypeException('game', 'string', gettype($game)); - } - - if ($language && !is_string($language)) { - throw new InvalidTypeException('language', 'string', gettype($language)); - } - - if ($broadcaster_language && !is_string($broadcaster_language)) { - throw new InvalidTypeException('broadcaster_language', 'string', gettype($broadcaster_language)); - } - - if (!$this->isValidStreamType($streamType)) { - throw new InvalidStreamTypeException(); - } - - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if (!$this->isValidOffset($offset)) { - throw new InvalidOffsetException(); - } - - $params = [ - 'channel' => $channel, - 'game' => $game, - 'language' => $language, - 'broadcaster_language' => $broadcaster_language, - 'stream_type' => $streamType, - 'limit' => intval($limit), - 'offset' => intval($offset), - ]; - - return $this->get('streams', $params); - } - - /** - * Gets a summary of live streams - * - * @param string $game - * @throws InvalidTypeException - * @return array|string - */ - public function getStreamsSummary($game = null) - { - if ($game && !is_string($game)) { - throw new InvalidTypeException('game', 'string', gettype($game)); - } - - return $this->get('streams/summary', ['game' => $game]); - } - - /** - * Get a list of all featured live streams - * - * @param int $limit - * @param int $offset - * @throws InvalidLimitException - * @throws InvalidOffsetException - * @return array|string - */ - public function getFeaturedStreams($limit = 25, $offset = 0) - { - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if (!$this->isValidOffset($offset)) { - throw new InvalidOffsetException(); - } - - $params = [ - 'limit' => intval($limit), - 'offset' => intval($offset), - ]; - - return $this->get('streams/featured', $params); - } - - /** - * Get followed streams - * - * @param string $streamType - * @param int $limit - * @param int $offset - * @throws InvalidStreamTypeException - * @throws InvalidLimitException - * @throws InvalidOffsetException - * @return array|string - */ - public function getFollowedStreams($asccessToken, $streamType = 'live', $limit = 25, $offset = 0) - { - if (!$this->isValidStreamType($streamType)) { - throw new InvalidStreamTypeException(); - } - - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if (!$this->isValidOffset($offset)) { - throw new InvalidOffsetException(); - } - - $params = [ - 'stream_type' => $streamType, - 'limit' => intval($limit), - 'offset' => intval($offset), - ]; - - return $this->get('streams/followed', $params, $asccessToken); - } -} diff --git a/src/Api/Teams.php b/src/Api/Teams.php deleted file mode 100644 index cf375a8..0000000 --- a/src/Api/Teams.php +++ /dev/null @@ -1,53 +0,0 @@ -get(sprintf('teams/%s', $name)); - } - - /** - * Get all active teams - * - * @param int $limit - * @param int $offset - * @throws InvalidLimitException - * @throws InvalidOffsetException - * @return array|string - */ - public function getAllTeams($limit = 25, $offset = 0) - { - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if (!$this->isValidOffset($offset)) { - throw new InvalidOffsetException(); - } - - $params = [ - 'limit' => intval($limit), - 'offset' => intval($offset), - ]; - - return $this->get('teams', $params); - } -} diff --git a/src/Api/Users.php b/src/Api/Users.php deleted file mode 100644 index 8620a29..0000000 --- a/src/Api/Users.php +++ /dev/null @@ -1,355 +0,0 @@ -get('user', [], $accessToken); - } - - /** - * Get a user - * - * @param string|int $userIdentifier - * @throws InvalidIdentifierException - * @return array|string - */ - public function getUser($userIdentifier) - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($userIdentifier)) { - throw new InvalidIdentifierException('user'); - } - - return $this->get(sprintf('users/%s', $userIdentifier)); - } - - /** - * Get a user from their username - * - * @param string $username - * @throws EndpointNotSupportedByApiVersionException - * @return array|string - */ - public function getUserByUsername($username) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - $params = [ - 'login' => $username, - ]; - - return $this->get('users', $params); - } - - /** - * Get a user's emotes - * - * @param string|int $userIdentifier - * @param string $accessToken - * @throws InvalidIdentifierException - * @return array|string - */ - public function getUserEmotes($userIdentifier, $accessToken) - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($userIdentifier)) { - throw new InvalidIdentifierException('user'); - } - - return $this->get(sprintf('users/%s/emotes', $userIdentifier), [], $accessToken); - } - - /** - * Check if a user is subscribed to a channel - * - * @param string|int $userIdentifier - * @param string|int $channelIdentifier - * @param string $accessToken - * @throws InvalidIdentifierException - * @return array|string - */ - public function checkUserSubscriptionToChannel($userIdentifier, $channelIdentifier, $accessToken) - { - if ($this->apiVersionIsGreaterThanV3()) { - if (!is_numeric($userIdentifier)) { - throw new InvalidIdentifierException('user'); - } - - if (!is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - } - - return $this->get(sprintf('users/%s/subscriptions/%s', $userIdentifier, $channelIdentifier), [], $accessToken); - } - - /** - * Gets a list of all channels followed by a user - * - * @param string|int $userIdentifier - * @param int $limit - * @param int $offset - * @param string $direction - * @param string $sortby - * @throws InvalidIdentifierException - * @throws InvalidLimitException - * @throws InvalidOffsetException - * @throws UnsupportedOptionException - * @return array|string - */ - public function getUsersFollowedChannels($userIdentifier, $limit = 25, $offset = 0, $direction = 'desc', $sortby = 'created_at') - { - $availableSortBys = ['created_at', 'last_broadcast', 'login']; - - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($userIdentifier)) { - throw new InvalidIdentifierException('user'); - } - - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if (!$this->isValidOffset($offset)) { - throw new InvalidOffsetException(); - } - - if (!$this->isValidDirection($direction)) { - throw new InvalidDirectionException(); - } - - if (!in_array($sortby = strtolower($sortby), $availableSortBys)) { - throw new UnsupportedOptionException('sortby', $availableSortBys); - } - - return $this->get(sprintf('users/%s/follows/channels', $userIdentifier), [ - 'limit' => intval($limit), - 'offset' => intval($offset), - 'direction' => $direction, - 'sortby' => $sortby, - ]); - } - - /** - * Check if a user follows a channel - * - * @param string|int $userIdentifier - * @param string|int $channelIdentifier - * @throws InvalidIdentifierException - * @return array|string - */ - public function checkUserFollowsChannel($userIdentifier, $channelIdentifier) - { - if ($this->apiVersionIsGreaterThanV3()) { - if (!is_numeric($userIdentifier)) { - throw new InvalidIdentifierException('user'); - } - - if (!is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - } - - return $this->get(sprintf('users/%s/follows/channels/%s', $userIdentifier, $channelIdentifier)); - } - - /** - * Have a user follow a channel - * - * @param string|int $userIdentifier - * @param string|int $channelIdentifier - * @param string $accessToken - * @param bool $notifications - * @throws InvalidIdentifierException - * @throws InvalidTypeException - * @return array|string - */ - public function followChannel($userIdentifier, $channelIdentifier, $accessToken, $notifications = false) - { - if ($this->apiVersionIsGreaterThanV3()) { - if (!is_numeric($userIdentifier)) { - throw new InvalidIdentifierException('user'); - } - - if (!is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - } - - if (!is_bool($notifications)) { - throw new InvalidTypeException('Notifications', 'boolean', gettype($notifications)); - } - - return $this->put( - sprintf('users/%s/follows/channels/%s', $userIdentifier, $channelIdentifier), - ['notifications' => $notifications], - $accessToken - ); - } - - /** - * Have a user unfollow a channel - * - * @param string|int $userIdentifier - * @param string|int $channelIdentifier - * @param string $accessToken - * @throws InvalidIdentifierException - * @return null|array|string - */ - public function unfollowChannel($userIdentifier, $channelIdentifier, $accessToken) - { - if ($this->apiVersionIsGreaterThanV3()) { - if (!is_numeric($userIdentifier)) { - throw new InvalidIdentifierException('user'); - } - - if (!is_numeric($channelIdentifier)) { - throw new InvalidIdentifierException('channel'); - } - } - - return $this->delete(sprintf('users/%s/follows/channels/%s', $userIdentifier, $channelIdentifier), [], $accessToken); - } - - /** - * Get a user’s block list - * - * @param string|int $userIdentifier - * @param string $accessToken - * @param int $limit - * @param int $offset - * @throws InvalidIdentifierException - * @throws InvalidLimitException - * @throws InvalidOffsetException - * @return array|string - */ - public function getUserBlockList($userIdentifier, $accessToken, $limit = 25, $offset = 0) - { - if ($this->apiVersionIsGreaterThanV3() && !is_numeric($userIdentifier)) { - throw new InvalidIdentifierException('user'); - } - - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if (!$this->isValidOffset($offset)) { - throw new InvalidOffsetException(); - } - - $params = [ - 'limit' => intval($limit), - 'offset' => intval($offset), - ]; - - return $this->get(sprintf('users/%s/blocks', $userIdentifier), $params, $accessToken); - } - - /** - * Block a user - * - * @param string|int $userIdentifier - * @param string|int $userToBlockIdentifier - * @param string $accessToken - * @throws InvalidIdentifierException - * @return array|string - */ - public function blockUser($userIdentifier, $userToBlockIdentifier, $accessToken) - { - if ($this->apiVersionIsGreaterThanV3()) { - if (!is_numeric($userIdentifier) || !is_numeric($userToBlockIdentifier)) { - throw new InvalidIdentifierException('user'); - } - } - - return $this->put(sprintf('users/%s/blocks/%s', $userIdentifier, $userToBlockIdentifier), [], $accessToken); - } - - /** - * Unblock a user - * - * @param string|int $userIdentifier - * @param string|int $userToBlockIdentifier - * @param string $accessToken - * @throws InvalidIdentifierException - * @return null|array|string - */ - public function unblockUser($userIdentifier, $userToUnlockIdentifier, $accessToken) - { - if ($this->apiVersionIsGreaterThanV3()) { - if (!is_numeric($userIdentifier) || !is_numeric($userToUnlockIdentifier)) { - throw new InvalidIdentifierException('user'); - } - } - - return $this->delete(sprintf('users/%s/blocks/%s', $userIdentifier, $userToUnlockIdentifier), [], $accessToken); - } - - /** - * Creates a connection between a user and VHS - * - * @param string $identifier - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @return null|array|string - */ - public function createUserVHSConnection($identifier, $accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - $params = [ - 'identifier' => $identifier, - ]; - - return $this->put('user/vhs', $params, $accessToken); - } - - /** - * Check whether an authenticated Twitch user is connected to VHS - * - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @return array|string - */ - public function checkUserVHSConnection($accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - return $this->get('user/vhs', [], $accessToken); - } - - /** - * Delete the connection between an authenticated Twitch user and VHS - * - * @param string $accessToken - * @throws EndpointNotSupportedByApiVersionException - * @return null|array|string - */ - public function deleteUserVHSConnection($accessToken) - { - if (!$this->apiVersionIsGreaterThanV3()) { - throw new EndpointNotSupportedByApiVersionException(); - } - - return $this->delete('user/vhs', [], $accessToken); - } -} diff --git a/src/Api/Videos.php b/src/Api/Videos.php deleted file mode 100644 index 3140844..0000000 --- a/src/Api/Videos.php +++ /dev/null @@ -1,113 +0,0 @@ -apiVersionIsGreaterThanV3() && !is_numeric($videoIdentifier)) { - throw new InvalidIdentifierException('video'); - } - - return $this->get(sprintf('videos/%s', $videoIdentifier)); - } - - /** - * Get top videos - * - * @param int $limit - * @param int $offset - * @param string $gamme - * @param string $period - * @param string $broadcastType (comma-seperated list) - * @throws InvalidLimitException - * @throws InvalidOffsetException - * @throws InvalidTypeException - * @throws UnsupportedOptionException - * @return array|string - */ - public function getTopVideos($limit = 10, $offset = 0, $game = null, $period = 'week', $broadcastType = 'highlight') - { - $validPeriods = ['week', 'month', 'all']; - - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if (!$this->isValidOffset($offset)) { - throw new InvalidOffsetException(); - } - - if ($game && !is_string($game)) { - throw new InvalidTypeException('game', 'string', gettype($game)); - } - - if (!in_array($period = strtolower($period), $validPeriods)) { - throw new UnsupportedOptionException('period', $validPeriods); - } - - $broadcastType = trim($broadcastType, ', '); - if (!$this->isValidBroadcastType($broadcastType)) { - throw new UnsupportedOptionException('broadcastType', $validBroadcastTypes); - } - - $params = [ - 'limit' => intval($limit), - 'offset' => intval($offset), - 'game' => $game, - 'period' => $period, - 'broadcast_type' => $broadcastType, - ]; - - return $this->get('videos/top', $params); - } - - /** - * Get the videos from channels followed by the authenticated user - * - * @param string $accessToken - * @param int $limit - * @param int $offset - * @param string $broadcastType (comma-seperated list) - * @throws InvalidLimitException - * @throws InvalidOffsetException - * @throws UnsupportedOptionException - * @return array|string - */ - public function getFollowedChannelsVideos($accessToken, $limit = 10, $offset = 0, $broadcastType = 'highlight') - { - if (!$this->isValidLimit($limit)) { - throw new InvalidLimitException(); - } - - if (!$this->isValidOffset($offset)) { - throw new InvalidOffsetException(); - } - - $broadcastType = trim($broadcastType, ', '); - if (!$this->isValidBroadcastType($broadcastType)) { - throw new UnsupportedOptionException('broadcastType', $validBroadcastTypes); - } - - $params = [ - 'limit' => intval($limit), - 'offset' => intval($offset), - 'broadcast_type' => $broadcastType, - ]; - - return $this->get('videos/followed', $params, $accessToken); - } -} diff --git a/src/Exceptions/ClientIdRequiredException.php b/src/Exceptions/ClientIdRequiredException.php deleted file mode 100644 index 5bd8fbf..0000000 --- a/src/Exceptions/ClientIdRequiredException.php +++ /dev/null @@ -1,11 +0,0 @@ - self::BASE_URI, - ]); - } -} diff --git a/src/NewTwitchApi/Auth/OauthApi.php b/src/NewTwitchApi/Auth/OauthApi.php deleted file mode 100644 index 8672615..0000000 --- a/src/NewTwitchApi/Auth/OauthApi.php +++ /dev/null @@ -1,149 +0,0 @@ -clientId = $clientId; - $this->clientSecret = $clientSecret; - $this->guzzleClient = $guzzleClient ?? AuthGuzzleClient::getClient(); - } - - /** - * @return string A full authentication URL, including the Guzzle client's base URI. - */ - public function getAuthUrl(string $redirectUri, string $responseType = 'code', string $scope = '', bool $forceVerify = false, string $state = null): string - { - return sprintf( - '%s%s', - $this->guzzleClient->getConfig('base_uri'), - $this->getPartialAuthUrl($redirectUri, $responseType, $scope, $forceVerify, $state) - ); - } - - /** - * @throws GuzzleException - */ - public function getUserAccessToken($code, string $redirectUri, $state = null): ResponseInterface - { - return $this->makeRequest( - new Request('POST', 'token'), - [ - RequestOptions::JSON => [ - 'client_id' => $this->clientId, - 'client_secret' => $this->clientSecret, - 'grant_type' => 'authorization_code', - 'redirect_uri' => $redirectUri, - 'code' => $code, - 'state' => $state, - ], - ] - ); - } - - /** - * @throws GuzzleException - */ - public function refreshToken(string $refeshToken, string $scope = ''): ResponseInterface - { - $requestOptions = [ - 'client_id' => $this->clientId, - 'client_secret' => $this->clientSecret, - 'grant_type' => 'refresh_token', - 'refresh_token' => $refeshToken, - ]; - if ($scope) { - $requestOptions['scope'] = $scope; - } - - return $this->makeRequest( - new Request('POST', 'token'), - [ - RequestOptions::JSON => $requestOptions, - ] - ); - } - - /** - * @throws GuzzleException - */ - public function validateAccessToken(string $accessToken): ResponseInterface - { - return $this->makeRequest( - new Request( - 'GET', - 'validate', - [ - 'Authorization' => sprintf('OAuth %s', $accessToken), - ] - ) - ); - } - - /** - * @throws GuzzleException - */ - public function isValidAccessToken(string $accessToken): bool - { - return $this->validateAccessToken($accessToken)->getStatusCode() === 200; - } - - /** - * @throws GuzzleException - */ - public function getAppAccessToken(string $scope = ''): ResponseInterface - { - return $this->makeRequest( - new Request('POST', 'token'), - [ - RequestOptions::JSON => [ - 'client_id' => $this->clientId, - 'client_secret' => $this->clientSecret, - 'grant_type' => 'client_credentials', - 'scope' => $scope, - ], - ] - ); - } - - /** - * @throws GuzzleException - */ - private function makeRequest(Request $request, array $options = []): ResponseInterface - { - return $this->guzzleClient->send($request, $options); - } - - /** - * @return string A partial authentication URL, excluding the Guzzle client's base URI. - */ - private function getPartialAuthUrl(string $redirectUri, string $responseType = 'code', string $scope = '', bool $forceVerify = false, string $state = null): string - { - $optionalParameters = ''; - $optionalParameters .= $forceVerify ? '&force_verify=true' : ''; - $optionalParameters .= $state ? sprintf('&state=%s', $state) : ''; - - return sprintf( - 'authorize?client_id=%s&redirect_uri=%s&response_type=%s&scope=%s%s', - $this->clientId, - $redirectUri, - $responseType, - $scope, - $optionalParameters - ); - } -} diff --git a/src/NewTwitchApi/RequestGenerator.php b/src/NewTwitchApi/RequestGenerator.php deleted file mode 100644 index 96c8ab5..0000000 --- a/src/NewTwitchApi/RequestGenerator.php +++ /dev/null @@ -1,81 +0,0 @@ - 'application/json', - ]; - - if ($bearer) { - $headers['Authorization'] = sprintf('Bearer %s', $bearer); - } - - if (count($bodyParams) > 0) { - $request = new Request( - $httpMethod, - sprintf( - '%s%s', - $uriEndpoint, - $this->generateQueryParams($queryParamsMap) - ), - $headers, - $this->generateBodyParams($bodyParams) - ); - } else { - $request = new Request( - $httpMethod, - sprintf( - '%s%s', - $uriEndpoint, - $this->generateQueryParams($queryParamsMap) - ), - $headers - ); - } - - return $request; - } - - /** - * $queryParamsMap should be a mapping of the param key expected in the API call URL, - * and the value to be sent for that key. - * - * [['key' => 'param_key', 'value' => 42],['key' => 'other_key', 'value' => 'asdf']] - * would result in - * ?param_key=42&other_key=asdf - */ - protected function generateQueryParams(array $queryParamsMap): string - { - $queryStringParams = ''; - foreach ($queryParamsMap as $paramMap) { - if ($paramMap['value'] !== null) { - if (is_bool($paramMap['value'])) { - $paramMap['value'] = (int) $paramMap['value']; - } - $format = is_int($paramMap['value']) ? '%d' : '%s'; - $queryStringParams .= sprintf('&%s='.$format, $paramMap['key'], $paramMap['value']); - } - } - - return $queryStringParams ? '?'.substr($queryStringParams, 1) : ''; - } - - protected function generateBodyParams(array $bodyParamsMap): string - { - $bodyParams = []; - foreach ($bodyParamsMap as $bodyParam) { - if ($bodyParam['value'] !== null) { - $bodyParams[$bodyParam['key']] = $bodyParam['value']; - } - } - - return json_encode($bodyParams); - } -} diff --git a/src/NewTwitchApi/Resources/AbstractResource.php b/src/NewTwitchApi/Resources/AbstractResource.php deleted file mode 100644 index 5c7079b..0000000 --- a/src/NewTwitchApi/Resources/AbstractResource.php +++ /dev/null @@ -1,75 +0,0 @@ -guzzleClient = $guzzleClient; - $this->requestGenerator = $requestGenerator; - } - - /** - * @throws GuzzleException - */ - protected function getApi(string $uriEndpoint, string $bearer, array $queryParamsMap = [], array $bodyParams = []): ResponseInterface - { - return $this->sendToApi('GET', $uriEndpoint, $bearer, $queryParamsMap, $bodyParams); - } - - /** - * @throws GuzzleException - */ - protected function getApiWithOptionalAuth(string $uriEndpoint, string $bearer = null, array $queryParamsMap = [], array $bodyParams = []): ResponseInterface - { - return $this->sendToApi('GET', $uriEndpoint, $bearer, $queryParamsMap, $bodyParams); - } - - /** - * @throws GuzzleException - */ - protected function deleteApi(string $uriEndpoint, string $bearer, array $queryParamsMap = [], array $bodyParams = []): ResponseInterface - { - return $this->sendToApi('DELETE', $uriEndpoint, $bearer, $queryParamsMap, $bodyParams); - } - - /** - * @throws GuzzleException - */ - protected function patchApi(string $uriEndpoint, string $bearer, array $queryParamsMap = [], array $bodyParams = []): ResponseInterface - { - return $this->sendToApi('PATCH', $uriEndpoint, $bearer, $queryParamsMap, $bodyParams); - } - - /** - * @throws GuzzleException - */ - protected function postApi(string $uriEndpoint, string $bearer, array $queryParamsMap = [], array $bodyParams = []): ResponseInterface - { - return $this->sendToApi('POST', $uriEndpoint, $bearer, $queryParamsMap, $bodyParams); - } - - /** - * @throws GuzzleException - */ - protected function putApi(string $uriEndpoint, string $bearer, array $queryParamsMap = [], array $bodyParams = []): ResponseInterface - { - return $this->sendToApi('PUT', $uriEndpoint, $bearer, $queryParamsMap, $bodyParams); - } - - private function sendToApi(string $httpMethod, string $uriEndpoint, string $bearer = null, array $queryParamsMap = [], array $bodyParams = []): ResponseInterface - { - return $this->guzzleClient->send($this->requestGenerator->generate($httpMethod, $uriEndpoint, $bearer, $queryParamsMap, $bodyParams)); - } -} diff --git a/src/NewTwitchApi/Resources/AdsApi.php b/src/NewTwitchApi/Resources/AdsApi.php deleted file mode 100644 index 1a02608..0000000 --- a/src/NewTwitchApi/Resources/AdsApi.php +++ /dev/null @@ -1,25 +0,0 @@ - 'broadcaster_id', 'value' => $broadcasterId]; - $bodyParamsMap[] = ['key' => 'length', 'value' => $length]; - - return $this->postApi('channels/commercial', $bearer, [], $bodyParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/AnalyticsApi.php b/src/NewTwitchApi/Resources/AnalyticsApi.php deleted file mode 100644 index d115969..0000000 --- a/src/NewTwitchApi/Resources/AnalyticsApi.php +++ /dev/null @@ -1,81 +0,0 @@ - 'extension_id', 'value' => $extensionId]; - } - - if ($type) { - $queryParamsMap[] = ['key' => 'type', 'value' => $type]; - } - - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - if ($startedAt) { - $queryParamsMap[] = ['key' => 'started_at', 'value' => $startedAt]; - } - - if ($endedAt) { - $queryParamsMap[] = ['key' => 'ended_at', 'value' => $endedAt]; - } - - return $this->getApi('analytics/extensions', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#get-game-analytics - */ - public function getGameAnalytics(string $bearer, string $gameId = null, string $type = null, int $first = null, string $after = null, string $startedAt = null, string $endedAt = null): ResponseInterface - { - $queryParamsMap = []; - - if ($gameId) { - $queryParamsMap[] = ['key' => 'game_id', 'value' => $gameId]; - } - - if ($type) { - $queryParamsMap[] = ['key' => 'type', 'value' => $type]; - } - - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - if ($startedAt) { - $queryParamsMap[] = ['key' => 'started_at', 'value' => $startedAt]; - } - - if ($endedAt) { - $queryParamsMap[] = ['key' => 'ended_at', 'value' => $endedAt]; - } - - return $this->getApi('analytics/games', $bearer, $queryParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/BitsApi.php b/src/NewTwitchApi/Resources/BitsApi.php deleted file mode 100644 index 30252b1..0000000 --- a/src/NewTwitchApi/Resources/BitsApi.php +++ /dev/null @@ -1,78 +0,0 @@ - 'broadcaster_id', 'value' => $broadcasterId]; - } - - return $this->getApi('bits/cheermotes', $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->getApi('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->getApi('extensions/transactions', $bearer, $queryParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/ChannelPointsApi.php b/src/NewTwitchApi/Resources/ChannelPointsApi.php deleted file mode 100644 index 051b67c..0000000 --- a/src/NewTwitchApi/Resources/ChannelPointsApi.php +++ /dev/null @@ -1,149 +0,0 @@ -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->getApi('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->getApi('channel_points/custom_rewards/redemptions', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#create-custom-rewards - */ - public function createCustomReward(string $bearer, string $broadcasterId, string $title, int $cost, $additionalBodyParams = []): ResponseInterface - { - // $additionalBodyParams should be a standard key => value format, eg. ['game_id' => '1']; - $queryParamsMap = $bodyParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - - $bodyParamsMap[] = ['key' => 'title', 'value' => $title]; - $bodyParamsMap[] = ['key' => 'cost', 'value' => $cost]; - - foreach ($additionalBodyParams as $key => $value) { - $bodyParamsMap[] = ['key' => $key, 'value' => $value]; - } - - return $this->postApi('channel_points/custom_rewards', $bearer, $queryParamsMap, $bodyParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#update-custom-reward - */ - public function updateCustomReward(string $bearer, string $broadcasterId, string $rewardId, $bodyParams = []): ResponseInterface - { - // $bodyParams should be a standard key => value format, eg. ['game_id' => '1']; - $queryParamsMap = $bodyParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - $queryParamsMap[] = ['key' => 'id', 'value' => $rewardId]; - - foreach ($bodyParams as $key => $value) { - $bodyParamsMap[] = ['key' => $key, 'value' => $value]; - } - - return $this->patchApi('channel_points/custom_rewards', $bearer, $queryParamsMap, $bodyParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#delete-custom-reward - */ - public function deleteCustomReward(string $bearer, string $broadcasterId, string $id): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - - $queryParamsMap[] = ['key' => 'id', 'value' => $id]; - - return $this->deleteApi('channel_points/custom_rewards', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#update-redemption-status - */ - public function updateRedemptionStatus(string $bearer, string $broadcasterId, string $rewardId, string $redemptionId, string $status): ResponseInterface - { - $queryParamsMap = $bodyParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - $queryParamsMap[] = ['key' => 'reward_id', 'value' => $rewardId]; - $queryParamsMap[] = ['key' => 'id', 'value' => $redemptionId]; - - $bodyParamsMap[] = ['key' => 'status', 'value' => $status]; - - return $this->patchApi('channel_points/custom_rewards/redemptions', $bearer, $queryParamsMap, $bodyParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/ChannelsApi.php b/src/NewTwitchApi/Resources/ChannelsApi.php deleted file mode 100644 index e386548..0000000 --- a/src/NewTwitchApi/Resources/ChannelsApi.php +++ /dev/null @@ -1,55 +0,0 @@ - 'broadcaster_id', 'value' => $broadcasterId]; - - return $this->getApi('channels', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#get-channel-editors - */ - public function getChannelEditors(string $bearer, string $broadcasterId): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - - return $this->getApi('channels/editors', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#modify-channel-information - */ - public function modifyChannelInfo(string $bearer, string $broadcasterId, $bodyParams = []): ResponseInterface - { - // $bodyParams should be a standard key => value format, eg. ['game_id' => '1']; - $queryParamsMap = $bodyParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - - foreach ($bodyParams as $key => $value) { - $bodyParamsMap[] = ['key' => $key, 'value' => $value]; - } - - return $this->patchApi('channels', $bearer, $queryParamsMap, $bodyParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/ChatApi.php b/src/NewTwitchApi/Resources/ChatApi.php deleted file mode 100644 index 2a88f78..0000000 --- a/src/NewTwitchApi/Resources/ChatApi.php +++ /dev/null @@ -1,76 +0,0 @@ - 'broadcaster_id', 'value' => $broadcasterId]; - - return $this->getApi('chat/emotes', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#get-global-emotes - */ - public function getGlobalEmotes(string $bearer): ResponseInterface - { - return $this->getApi('chat/emotes/global', $bearer); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#get-emote-sets - */ - public function getEmoteSets(string $bearer, array $emoteSetIds = []): ResponseInterface - { - $queryParamsMap = []; - - foreach ($emoteSetIds as $emoteSetId) { - $queryParamsMap[] = ['key' => 'emote_set_id', 'value' => $emoteSetId]; - } - - return $this->getApi('chat/emotes/set', $bearer, $queryParamsMap); - } - - public function getEmoteSet(string $bearer, string $emoteSetId): ResponseInterface - { - $queryParamsMap = []; - $queryParamsMap[] = ['key' => 'emote_set_id', 'value' => $emoteSetId]; - - return $this->getApi('chat/emotes/set', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#get-channel-chat-badges - */ - public function getChannelChatBadges(string $bearer, string $broadcasterId): ResponseInterface - { - $queryParamsMap = []; - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - - return $this->getApi('chat/badges', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#get-global-chat-badges - */ - public function getGlobalChatBadges(string $bearer): ResponseInterface - { - return $this->getApi('chat/badges/global', $bearer); - } -} diff --git a/src/NewTwitchApi/Resources/ClipsApi.php b/src/NewTwitchApi/Resources/ClipsApi.php deleted file mode 100644 index 5e32f8d..0000000 --- a/src/NewTwitchApi/Resources/ClipsApi.php +++ /dev/null @@ -1,87 +0,0 @@ -getClips($bearer, $broadcasterId, null, null, $first, $before, $after, $startedAt, $endedAt); - } - - /** - * @throws GuzzleException - */ - public function getClipsByGameId(string $bearer, string $gameId, int $first = null, string $before = null, string $after = null, string $startedAt = null, string $endedAt = null): ResponseInterface - { - return $this->getClips($bearer, null, $gameId, null, $first, $before, $after, $startedAt, $endedAt); - } - - /** - * @throws GuzzleException - */ - public function getClipsByIds(string $bearer, string $clipIds, string $startedAt = null, string $endedAt = null): ResponseInterface - { - return $this->getClips($bearer, null, null, $clipIds, null, null, null, $startedAt, $endedAt); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#get-clips - */ - public function getClips(string $bearer, string $broadcasterId = null, string $gameId = null, string $clipIds = null, int $first = null, string $before = null, string $after = null, string $startedAt = null, string $endedAt = null): ResponseInterface - { - $queryParamsMap = []; - if ($broadcasterId) { - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - } - if ($gameId) { - $queryParamsMap[] = ['key' => 'game_id', 'value' => $gameId]; - } - if ($clipIds) { - $queryParamsMap[] = ['key' => 'id', 'value' => $clipIds]; - } - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - if ($before) { - $queryParamsMap[] = ['key' => 'before', 'value' => $before]; - } - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - if ($startedAt) { - $queryParamsMap[] = ['key' => 'started_at', 'value' => $startedAt]; - } - if ($endedAt) { - $queryParamsMap[] = ['key' => 'ended_at', 'value' => $endedAt]; - } - - return $this->getApi('clips', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#create-clip - */ - public function createClip(string $bearer, string $broadcasterId, bool $hasDelay = null): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - - if ($hasDelay) { - $queryParamsMap[] = ['key' => 'has_delay', 'value' => $hasDelay]; - } - - return $this->postApi('clips', $bearer, $queryParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/EntitlementsApi.php b/src/NewTwitchApi/Resources/EntitlementsApi.php deleted file mode 100644 index a4140ec..0000000 --- a/src/NewTwitchApi/Resources/EntitlementsApi.php +++ /dev/null @@ -1,89 +0,0 @@ - 'manifest_id', 'value' => $manifestId]; - $queryParamsMap[] = ['key' => 'type', 'value' => $type]; - - return $this->postApi('entitlements/upload', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#get-code-status - */ - public function getCodeStatus(string $bearer, int $userId, array $codes = []): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'user_id', 'value' => $userId]; - - foreach ($codes as $code) { - $queryParamsMap[] = ['key' => 'code', 'value' => $code]; - } - - return $this->getApi('entitlements/codes', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#get-drops-entitlements - */ - public function getDropsEntitlements(string $bearer, string $id = null, string $userId = null, string $gameId = null, string $after = null, int $first = null): ResponseInterface - { - $queryParamsMap = []; - - if ($id) { - $queryParamsMap[] = ['key' => 'id', 'value' => $id]; - } - - if ($userId) { - $queryParamsMap[] = ['key' => 'user_id', 'value' => $userId]; - } - - if ($gameId) { - $queryParamsMap[] = ['key' => 'game_id', 'value' => $gameId]; - } - - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - - return $this->getApi('entitlements/drops', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#redeem-code - */ - public function redeemCode(string $bearer, int $userId, array $codes = []): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'user_id', 'value' => $userId]; - - foreach ($codes as $code) { - $queryParamsMap[] = ['key' => 'code', 'value' => $code]; - } - - return $this->postApi('entitlements/code', $bearer, $queryParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/EventSubApi.php b/src/NewTwitchApi/Resources/EventSubApi.php deleted file mode 100644 index 65a21ac..0000000 --- a/src/NewTwitchApi/Resources/EventSubApi.php +++ /dev/null @@ -1,523 +0,0 @@ - 'status', 'value' => $status]; - } - - if ($type) { - $queryParamsMap[] = ['key' => 'type', 'value' => $type]; - } - - return $this->getApi('eventsub/subscriptions', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#create-eventsub-subscription - */ - public function createEventSubSubscription(string $bearer, string $secret, string $callback, string $type, string $version, array $condition): ResponseInterface - { - $bodyParams = []; - - $bodyParams[] = ['key' => 'type', 'value' => $type]; - $bodyParams[] = ['key' => 'version', 'value' => $version]; - $bodyParams[] = ['key' => 'condition', 'value' => $condition]; - $bodyParams[] = [ - 'key' => 'transport', - 'value' => [ - 'method' => 'webhook', - 'callback' => $callback, - 'secret' => $secret, - ], - ]; - - return $this->postApi('eventsub/subscriptions', $bearer, [], $bodyParams); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#delete-eventsub-subscription - */ - public function deleteEventSubSubscription(string $bearer, string $id): ResponseInterface - { - $queryParamsMap = []; - $queryParamsMap[] = ['key' => 'id', 'value' => $id]; - - return $this->deleteApi('eventsub/subscriptions', $bearer, $queryParamsMap); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelupdate - */ - public function subscribeToChannelUpdate(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - 'channel.update', - '1', - ['broadcaster_user_id' => $twitchId], - ); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelfollow - */ - public function subscribeToChannelFollow(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - 'channel.follow', - '1', - ['broadcaster_user_id' => $twitchId], - ); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelsubscribe - */ - public function subscribeToChannelSubscribe(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - 'channel.subscribe', - '1', - ['broadcaster_user_id' => $twitchId], - ); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/#channelsubscriptionend - */ - public function subscribeToChannelSubscriptionEnd(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - 'channel.subscription.end', - '1', - ['broadcaster_user_id' => $twitchId], - ); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types/#channelsubscriptiongift - */ - public function subscribeToChannelSubscriptionGift(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - 'channel.subscription.gift', - '1', - ['broadcaster_user_id' => $twitchId], - ); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelsubscriptionmessage-beta - */ - public function subscribeToChannelSubscriptionMessage(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - 'channel.subscription.message', - '1', - ['broadcaster_user_id' => $twitchId], - ); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelcheer - */ - public function subscribeToChannelCheer(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - 'channel.cheer', - '1', - ['broadcaster_user_id' => $twitchId], - ); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelraid - */ - public function subscribeToChannelRaid(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - 'channel.raid', - '1', - ['broadcaster_user_id' => $twitchId], - ); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelban - */ - public function subscribeToChannelBan(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - 'channel.ban', - '1', - ['broadcaster_user_id' => $twitchId], - ); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelunban - */ - public function subscribeToChannelUnban(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - 'channel.unban', - '1', - ['broadcaster_user_id' => $twitchId], - ); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelmoderatoradd - */ - public function subscribeToChannelModeratorAdd(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->subscribeToChannelModerator($bearer, $secret, $callback, $twitchId, 'add'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelmoderatorremove - */ - public function subscribeToChannelModeratorRemove(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->subscribeToChannelModerator($bearer, $secret, $callback, $twitchId, 'remove'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelchannel_points_custom_rewardadd - */ - public function subscribeToChannelPointsCustomRewardAdd(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->subscribeToChannelPointsCustomReward($bearer, $secret, $callback, $twitchId, null, 'add'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelchannel_points_custom_rewardupdate - */ - public function subscribeToChannelPointsCustomRewardUpdate(string $bearer, string $secret, string $callback, string $twitchId, string $rewardId = null): ResponseInterface - { - return $this->subscribeToChannelPointsCustomReward($bearer, $secret, $callback, $twitchId, $rewardId, 'update'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelchannel_points_custom_rewardremove - */ - public function subscribeToChannelPointsCustomRewardRemove(string $bearer, string $secret, string $callback, string $twitchId, string $rewardId = null): ResponseInterface - { - return $this->subscribeToChannelPointsCustomReward($bearer, $secret, $callback, $twitchId, $rewardId, 'remove'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelchannel_points_custom_reward_redemptionadd - */ - public function subscribeToChannelPointsCustomRewardRedemptionAdd(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->subscribeToChannelPointsCustomRewardRedemption($bearer, $secret, $callback, $twitchId, null, 'add'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelchannel_points_custom_reward_redemptionupdate - */ - public function subscribeToChannelPointsCustomRewardRedemptionUpdate(string $bearer, string $secret, string $callback, string $twitchId, string $rewardId = null): ResponseInterface - { - return $this->subscribeToChannelPointsCustomRewardRedemption($bearer, $secret, $callback, $twitchId, $rewardId, 'update'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelpollbegin - */ - public function subscribeToChannelPollBegin(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->subscribeToChannelPoll($bearer, $secret, $callback, $twitchId, 'begin'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelpollprogress - */ - public function subscribeToChannelPollProgress(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->subscribeToChannelPoll($bearer, $secret, $callback, $twitchId, 'progress'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelpollend - */ - public function subscribeToChannelPollEnd(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->subscribeToChannelPoll($bearer, $secret, $callback, $twitchId, 'end'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelpredictionbegin - */ - public function subscribeToChannelPredictionBegin(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->subscribeToChannelPrediction($bearer, $secret, $callback, $twitchId, 'begin'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelpredictionprogress - */ - public function subscribeToChannelPredictionProgress(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->subscribeToChannelPrediction($bearer, $secret, $callback, $twitchId, 'progress'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelpredictionprogress - */ - public function subscribeToChannelPredictionLock(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->subscribeToChannelPrediction($bearer, $secret, $callback, $twitchId, 'lock'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelpredictionend - */ - public function subscribeToChannelPredictionEnd(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->subscribeToChannelPrediction($bearer, $secret, $callback, $twitchId, 'end'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelhype_trainbegin - */ - public function subscribeToChannelHypeTrainBegin(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->subscribeToChannelHypeTrain($bearer, $secret, $callback, $twitchId, 'begin'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelhype_trainprogress - */ - public function subscribeToChannelHypeTrainProgress(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->subscribeToChannelHypeTrain($bearer, $secret, $callback, $twitchId, 'progress'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#channelhype_trainend - */ - public function subscribeToChannelHypeTrainEnd(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->subscribeToChannelHypeTrain($bearer, $secret, $callback, $twitchId, 'end'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#streamonline - */ - public function subscribeToStreamOnline(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->subscribeToStream($bearer, $secret, $callback, $twitchId, 'online'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#streamoffline - */ - public function subscribeToStreamOffline(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->subscribeToStream($bearer, $secret, $callback, $twitchId, 'offline'); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#userauthorizationrevoke - */ - public function subscribeToUserAuthorizationRevoke(string $bearer, string $secret, string $callback, string $clientId): ResponseInterface - { - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - 'user.authorization.revoke', - '1', - ['client_id' => $clientId], - ); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#userupdate - */ - public function subscribeToUserUpdate(string $bearer, string $secret, string $callback, string $twitchId): ResponseInterface - { - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - 'user.update', - '1', - ['user_id' => $twitchId], - ); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub/eventsub-subscription-types#extensionbits_transactioncreate-beta - */ - public function subscribeToExtensionBitsTransactionCreate(string $bearer, string $secret, string $callback, string $extensionClientId): ResponseInterface - { - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - 'extension.bits_transaction.create', - 'beta', - ['extension_client_id' => $extensionClientId], - ); - } - - /** - * @link https://dev.twitch.tv/docs/eventsub#verify-a-signature - */ - public function verifySignature(string $signature, string $secret, string $messageId, string $timestamp, string $body): bool - { - [$hashAlgorithm, $expectedHash] = explode('=', $signature); - $generatedHash = hash_hmac($hashAlgorithm, $messageId.$timestamp.$body, $secret); - - return $expectedHash === $generatedHash; - } - - private function subscribeToChannelModerator(string $bearer, string $secret, string $callback, string $twitchId, string $eventType): ResponseInterface - { - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - sprintf('channel.moderator.%s', $eventType), - '1', - ['broadcaster_user_id' => $twitchId], - ); - } - - private function subscribeToChannelPointsCustomReward(string $bearer, string $secret, string $callback, string $twitchId, string $rewardId = null, string $eventType): ResponseInterface - { - $condition = ['broadcaster_user_id' => $twitchId]; - - if ($rewardId) { - $condition['reward_id'] = $rewardId; - } - - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - sprintf('channel.channel_points_custom_reward.%s', $eventType), - '1', - $condition, - ); - } - - private function subscribeToChannelPointsCustomRewardRedemption(string $bearer, string $secret, string $callback, string $twitchId, string $rewardId = null, string $eventType): ResponseInterface - { - $condition = ['broadcaster_user_id' => $twitchId]; - - if ($rewardId) { - $condition['reward_id'] = $rewardId; - } - - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - sprintf('channel.channel_points_custom_reward_redemption.%s', $eventType), - '1', - $condition, - ); - } - - private function subscribeToChannelPoll(string $bearer, string $secret, string $callback, string $twitchId, string $eventType): ResponseInterface - { - $condition = ['broadcaster_user_id' => $twitchId]; - - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - sprintf('channel.poll.%s', $eventType), - '1', - $condition, - ); - } - - private function subscribeToChannelPrediction(string $bearer, string $secret, string $callback, string $twitchId, string $eventType): ResponseInterface - { - $condition = ['broadcaster_user_id' => $twitchId]; - - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - sprintf('channel.prediction.%s', $eventType), - '1', - $condition, - ); - } - - private function subscribeToChannelHypeTrain(string $bearer, string $secret, string $callback, string $twitchId, string $eventType): ResponseInterface - { - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - sprintf('channel.hype_train.%s', $eventType), - '1', - ['broadcaster_user_id' => $twitchId], - ); - } - - private function subscribeToStream(string $bearer, string $secret, string $callback, string $twitchId, string $eventType): ResponseInterface - { - return $this->createEventSubSubscription( - $bearer, - $secret, - $callback, - sprintf('stream.%s', $eventType), - '1', - ['broadcaster_user_id' => $twitchId], - ); - } -} diff --git a/src/NewTwitchApi/Resources/GamesApi.php b/src/NewTwitchApi/Resources/GamesApi.php deleted file mode 100644 index a80120a..0000000 --- a/src/NewTwitchApi/Resources/GamesApi.php +++ /dev/null @@ -1,51 +0,0 @@ - 'id', 'value' => $id]; - } - foreach ($names as $name) { - $queryParamsMap[] = ['key' => 'name', 'value' => $name]; - } - - return $this->getApi('games', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference/#get-top-games - */ - public function getTopGames(string $bearer, int $first = null, string $before = null, string $after = null): ResponseInterface - { - $queryParamsMap = []; - - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - - if ($before) { - $queryParamsMap[] = ['key' => 'before', 'value' => $before]; - } - - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - return $this->getApi('games/top', $bearer, $queryParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/HypeTrainApi.php b/src/NewTwitchApi/Resources/HypeTrainApi.php deleted file mode 100644 index f20443b..0000000 --- a/src/NewTwitchApi/Resources/HypeTrainApi.php +++ /dev/null @@ -1,36 +0,0 @@ - 'broadcaster_id', 'value' => $broadcasterId]; - - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - - if ($id) { - $queryParamsMap[] = ['key' => 'id', 'value' => $id]; - } - - if ($cursor) { - $queryParamsMap[] = ['key' => 'cursor', 'value' => $cursor]; - } - - return $this->getApi('bits/cheermotes', $bearer, $queryParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/ModerationApi.php b/src/NewTwitchApi/Resources/ModerationApi.php deleted file mode 100644 index 92ed3fd..0000000 --- a/src/NewTwitchApi/Resources/ModerationApi.php +++ /dev/null @@ -1,135 +0,0 @@ - 'broadcaster_id', 'value' => $broadcasterId]; - - foreach ($ids as $id) { - $queryParamsMap[] = ['key' => 'user_id', 'value' => $id]; - } - - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - return $this->getApi('moderation/banned/events', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference/#get-banned-users - */ - public function getBannedUsers(string $bearer, string $broadcasterId, array $ids = [], string $before = null, string $after = null): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - - foreach ($ids as $id) { - $queryParamsMap[] = ['key' => 'user_id', 'value' => $id]; - } - - if ($before) { - $queryParamsMap[] = ['key' => 'before', 'value' => $before]; - } - - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - return $this->getApi('moderation/banned', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference/#get-moderators - */ - public function getModerators(string $bearer, string $broadcasterId, array $ids = [], string $after = null): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - - foreach ($ids as $id) { - $queryParamsMap[] = ['key' => 'user_id', 'value' => $id]; - } - - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - return $this->getApi('moderation/moderators', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference/#get-moderator-events - */ - public function getModeratorEvents(string $bearer, string $broadcasterId, array $ids = [], string $after = null): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - - foreach ($ids as $id) { - $queryParamsMap[] = ['key' => 'user_id', 'value' => $id]; - } - - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - return $this->getApi('moderation/moderators/events', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#check-automod-status - */ - public function checkAutoModStatus(string $bearer, string $broadcasterId, string $msgId, string $msgText, string $userId): ResponseInterface - { - $queryParamsMap = $bodyParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - - $bodyParamsMap[] = ['key' => 'msg_id', 'value' => $msgId]; - $bodyParamsMap[] = ['key' => 'msg_text', 'value' => $msgText]; - $bodyParamsMap[] = ['key' => 'user_id', 'value' => $userId]; - - return $this->postApi('moderation/enforcements/status', $bearer, $queryParamsMap, $bodyParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#manage-held-automod-messages - */ - public function manageHeldAutoModMessage(string $bearer, string $userId, string $msgId, string $action): ResponseInterface - { - $bodyParamsMap = []; - - $bodyParamsMap[] = ['key' => 'user_id', 'value' => $userId]; - $bodyParamsMap[] = ['key' => 'msg_id', 'value' => $msgId]; - $bodyParamsMap[] = ['key' => 'action', 'value' => $action]; - - return $this->postApi('moderation/automod/message', $bearer, [], $bodyParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/PollsApi.php b/src/NewTwitchApi/Resources/PollsApi.php deleted file mode 100644 index 51ccb2a..0000000 --- a/src/NewTwitchApi/Resources/PollsApi.php +++ /dev/null @@ -1,71 +0,0 @@ - 'broadcaster_id', 'value' => $broadcasterId]; - - foreach ($ids as $id) { - $queryParamsMap[] = ['key' => 'id', 'value' => $id]; - } - - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - - return $this->getApi('polls', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#create-poll - */ - public function createPoll(string $bearer, string $broadcasterId, string $title, array $choices, int $duration, $optionalBodyParams = []): ResponseInterface - { - $bodyParamsMap = []; - - $bodyParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - $bodyParamsMap[] = ['key' => 'title', 'value' => $title]; - $bodyParamsMap[] = ['key' => 'choices', 'value' => $choices]; - $bodyParamsMap[] = ['key' => 'duration', 'value' => $duration]; - - foreach ($optionalBodyParams as $key => $value) { - $bodyParamsMap[] = ['key' => $key, 'value' => $value]; - } - - return $this->postApi('polls', $bearer, [], $bodyParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#end-poll - */ - public function endPoll(string $bearer, string $broadcasterId, string $pollId, string $status): ResponseInterface - { - $bodyParamsMap = []; - - $bodyParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - $bodyParamsMap[] = ['key' => 'id', 'value' => $pollId]; - $bodyParamsMap[] = ['key' => 'status', 'value' => $status]; - - return $this->patchApi('polls', $bearer, [], $bodyParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/PredictionsApi.php b/src/NewTwitchApi/Resources/PredictionsApi.php deleted file mode 100644 index d6554bd..0000000 --- a/src/NewTwitchApi/Resources/PredictionsApi.php +++ /dev/null @@ -1,71 +0,0 @@ - 'broadcaster_id', 'value' => $broadcasterId]; - - foreach ($ids as $id) { - $queryParamsMap[] = ['key' => 'id', 'value' => $id]; - } - - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - - return $this->getApi('predictions', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#create-prediction - */ - public function createPrediction(string $bearer, string $broadcasterId, string $title, array $outcomes, int $predictionWindow): ResponseInterface - { - $bodyParamsMap = []; - - $bodyParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - $bodyParamsMap[] = ['key' => 'title', 'value' => $title]; - $bodyParamsMap[] = ['key' => 'outcomes', 'value' => $outcomes]; - $bodyParamsMap[] = ['key' => 'prediction_window', 'value' => $predictionWindow]; - - return $this->postApi('predictions', $bearer, [], $bodyParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#end-prediction - */ - public function endPrediction(string $bearer, string $broadcasterId, string $pollId, string $status, string $winningOutcomeId = null): ResponseInterface - { - $bodyParamsMap = []; - - $bodyParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - $bodyParamsMap[] = ['key' => 'id', 'value' => $pollId]; - $bodyParamsMap[] = ['key' => 'status', 'value' => $status]; - - if ($winningOutcomeId) { - $bodyParamsMap[] = ['key' => 'winning_outcome_id', 'value' => $winningOutcomeId]; - } - - return $this->patchApi('predictions', $bearer, [], $bodyParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/ScheduleApi.php b/src/NewTwitchApi/Resources/ScheduleApi.php deleted file mode 100644 index 8c10d4c..0000000 --- a/src/NewTwitchApi/Resources/ScheduleApi.php +++ /dev/null @@ -1,145 +0,0 @@ - 'broadcaster_id', 'value' => $broadcasterId]; - - foreach ($ids as $id) { - $queryParamsMap[] = ['key' => 'id', 'value' => $id]; - } - - if ($startTime) { - $queryParamsMap[] = ['key' => 'start_time', 'value' => $startTime]; - } - - if ($utcOffset) { - $queryParamsMap[] = ['key' => 'utc_offset', 'value' => $utcOffset]; - } - - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - return $this->getApi('schedule', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference/#get-channel-icalendar - */ - public function getChanneliCalendar(string $bearer = null, string $broadcasterId): ResponseInterface - { - // This endpoint at the time of addition does not require any authorization, so the bearer is null. - // However, to prevent a breaking update in the future, it will remain the first function parameter. - // You may simple pass NULL to this to bypass authentication. - - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - - return $this->getApiWithOptionalAuth('schedule/icalendar', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference/#update-channel-stream-schedule - */ - public function updateChannelStreamSchedule(string $bearer, string $broadcasterId, bool $isVacationEnabled = null, $vacationStartTime = null, $vacationEndTime = null, $timezone = null): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - - if ($isVacationEnabled) { - $queryParamsMap[] = ['key' => 'is_vacation_enabled', 'value' => $isVacationEnabled]; - } - - if ($vacationStartTime) { - $queryParamsMap[] = ['key' => 'vacation_start_time', 'value' => $vacationStartTime]; - } - - if ($vacationEndTime) { - $queryParamsMap[] = ['key' => 'vacation_end_time', 'value' => $vacationEndTime]; - } - - if ($timezone) { - $queryParamsMap[] = ['key' => 'timezone', 'value' => $timezone]; - } - - return $this->patchApi('schedule/settings', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference/#create-channel-stream-schedule-segment - */ - public function createChannelStreamScheduleSegment(string $bearer, string $broadcasterId, string $startTime, string $timezone, bool $isRecurring, array $additionalBodyParams = []): ResponseInterface - { - // $additionalBodyParams should be a standard key => value format, eg. ['duration' => '240']; - $queryParamsMap = $bodyParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - - $bodyParamsMap[] = ['key' => 'start_time', 'value' => $startTime]; - $bodyParamsMap[] = ['key' => 'timezone', 'value' => $timezone]; - $bodyParamsMap[] = ['key' => 'is_recurring', 'value' => $isRecurring]; - - foreach ($additionalBodyParams as $key => $value) { - $bodyParamsMap[] = ['key' => $key, 'value' => $value]; - } - - return $this->postApi('schedule/segment', $bearer, $queryParamsMap, $bodyParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference/#update-channel-stream-schedule-segment - */ - public function updateChannelStreamScheduleSegment(string $bearer, string $broadcasterId, string $segmentId, array $updateValues = []): ResponseInterface - { - // $updateValues should be a standard key => value format based on the values available on the documentation, eg. ['duration' => '240']; - $queryParamsMap = $bodyParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - $queryParamsMap[] = ['key' => 'id', 'value' => $segmentId]; - - foreach ($updateValues as $key => $value) { - $bodyParamsMap[] = ['key' => $key, 'value' => $value]; - } - - return $this->patchApi('schedule/segment', $bearer, $queryParamsMap, $bodyParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference/#delete-channel-stream-schedule-segment - */ - public function deleteChannelStreamScheduleSegment(string $bearer, string $broadcasterId, string $segmentId): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - $queryParamsMap[] = ['key' => 'id', 'value' => $segmentId]; - - return $this->deleteApi('schedule/segment', $bearer, $queryParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/SearchApi.php b/src/NewTwitchApi/Resources/SearchApi.php deleted file mode 100644 index 3e0ae86..0000000 --- a/src/NewTwitchApi/Resources/SearchApi.php +++ /dev/null @@ -1,57 +0,0 @@ - 'query', 'value' => $query]; - - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - return $this->getApi('search/categories', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#search-channels - */ - public function searchChannels(string $bearer, string $query, $liveOnly = null, string $first = null, string $after = null): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'query', 'value' => $query]; - - if ($liveOnly) { - $queryParamsMap[] = ['key' => 'live_only', 'value' => $liveOnly]; - } - - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - return $this->getApi('search/channels', $bearer, $queryParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/StreamsApi.php b/src/NewTwitchApi/Resources/StreamsApi.php deleted file mode 100644 index 0435782..0000000 --- a/src/NewTwitchApi/Resources/StreamsApi.php +++ /dev/null @@ -1,156 +0,0 @@ -getStreams($bearer, [$userId]); - } - - /** - * @throws GuzzleException - */ - public function getStreamForUsername(string $bearer, string $username): ResponseInterface - { - return $this->getStreams($bearer, [], [$username]); - } - - /** - * @throws GuzzleException - */ - public function getStreamsByGameId(string $bearer, string $gameId, int $first = null, string $before = null, string $after = null): ResponseInterface - { - return $this->getStreams($bearer, [], [], [$gameId]); - } - - /** - * @throws GuzzleException - */ - public function getStreamsByLanguage(string $bearer, string $language, int $first = null, string $before = null, string $after = null): ResponseInterface - { - return $this->getStreams($bearer, [], [], [], [$language]); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#get-stream-key - */ - public function getStreamKey(string $bearer, string $broadcasterId): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - - return $this->getApi('streams/key', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference/#get-streams - */ - public function getStreams(string $bearer, array $userIds = [], array $usernames = [], array $gameIds = [], array $languages = [], int $first = null, string $before = null, string $after = null): ResponseInterface - { - $queryParamsMap = []; - foreach ($userIds as $id) { - $queryParamsMap[] = ['key' => 'user_id', 'value' => $id]; - } - foreach ($usernames as $username) { - $queryParamsMap[] = ['key' => 'user_login', 'value' => $username]; - } - foreach ($gameIds as $gameId) { - $queryParamsMap[] = ['key' => 'game_id', 'value' => $gameId]; - } - foreach ($languages as $language) { - $queryParamsMap[] = ['key' => 'language', 'value' => $language]; - } - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - if ($before) { - $queryParamsMap[] = ['key' => 'before', 'value' => $before]; - } - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - return $this->getApi('streams', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference/#get-stream-markers - */ - public function getStreamMarkers(string $bearer, string $userId = null, string $videoId = null, string $first = null, string $before = null, string $after = null): ResponseInterface - { - $queryParamsMap = []; - - if ($userId) { - $queryParamsMap[] = ['key' => 'user_id', 'value' => $userId]; - } - - if ($videoId) { - $queryParamsMap[] = ['key' => 'video_id', 'value' => $videoId]; - } - - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - - if ($before) { - $queryParamsMap[] = ['key' => 'before', 'value' => $before]; - } - - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - return $this->getApi('streams/markers', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference/#get-followed-streams - */ - public function getFollowedStreams(string $bearer, string $userId, int $first = null, string $after = null): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'user_id', 'value' => $userId]; - - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - return $this->getApi('streams/followed', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#create-stream-marker - */ - public function createStreamMarker(string $bearer, string $userId, string $description = null): ResponseInterface - { - $bodyParamsMap = []; - - $bodyParamsMap[] = ['key' => 'user_id', 'value' => $userId]; - if ($description) { - $bodyParamsMap[] = ['key' => 'description', 'value' => $description]; - } - - return $this->postApi('streams/markers', $bearer, [], $bodyParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/SubscriptionsApi.php b/src/NewTwitchApi/Resources/SubscriptionsApi.php deleted file mode 100644 index 42cde68..0000000 --- a/src/NewTwitchApi/Resources/SubscriptionsApi.php +++ /dev/null @@ -1,63 +0,0 @@ - 'broadcaster_id', 'value' => $broadcasterId]; - - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - return $this->getApi('subscriptions', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference/#get-broadcaster-subscriptions - */ - public function getBroadcasterSubscribers(string $bearer, string $broadcasterId, array $ids = []): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - - foreach ($ids as $id) { - $queryParamsMap[] = ['key' => 'user_id', 'value' => $id]; - } - - return $this->getApi('subscriptions', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#check-user-subscription - */ - public function checkUserSubscription(string $bearer, string $broadcasterId, string $userId): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - $queryParamsMap[] = ['key' => 'user_id', 'value' => $userId]; - - return $this->getApi('subscriptions/user', $bearer, $queryParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/TagsApi.php b/src/NewTwitchApi/Resources/TagsApi.php deleted file mode 100644 index 101117f..0000000 --- a/src/NewTwitchApi/Resources/TagsApi.php +++ /dev/null @@ -1,63 +0,0 @@ - 'tag_id', 'value' => $tagId]; - } - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - return $this->getApi('tags/streams', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#get-stream-tags - */ - public function getStreamTags(string $bearer, string $broadcasterId): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - - return $this->getApi('streams/tags', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#replace-stream-tags - */ - public function replaceStreamTags(string $bearer, string $broadcasterId, $tags = []): ResponseInterface - { - $queryParamsMap = $bodyParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - - if (count($tags) > 0) { - $bodyParamsMap[] = ['key' => 'tag_ids', 'value' => $tags]; - } - - return $this->putApi('streams/tags', $bearer, $queryParamsMap, $bodyParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/TeamsApi.php b/src/NewTwitchApi/Resources/TeamsApi.php deleted file mode 100644 index 4e46e3d..0000000 --- a/src/NewTwitchApi/Resources/TeamsApi.php +++ /dev/null @@ -1,59 +0,0 @@ - 'broadcaster_id', 'value' => $broadcasterId]; - - return $this->getApi('teams/channel', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#get-teams - */ - public function getTeams(string $bearer, string $name = null, string $id = null): ResponseInterface - { - $queryParamsMap = []; - - if ($name) { - $queryParamsMap[] = ['key' => 'name', 'value' => $name]; - } - - if ($id) { - $queryParamsMap[] = ['key' => 'id', 'value' => $id]; - } - - return $this->getApi('teams', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - */ - public function getTeamsByName(string $bearer, string $name): ResponseInterface - { - return $this->getTeams($bearer, $name, null); - } - - /** - * @throws GuzzleException - */ - public function getTeamsById(string $bearer, string $id): ResponseInterface - { - return $this->getTeams($bearer, null, $id); - } -} diff --git a/src/NewTwitchApi/Resources/UsersApi.php b/src/NewTwitchApi/Resources/UsersApi.php deleted file mode 100644 index 7e777ea..0000000 --- a/src/NewTwitchApi/Resources/UsersApi.php +++ /dev/null @@ -1,207 +0,0 @@ -getUsers($userAccessToken, [], [], $includeEmail); - } - - /** - * @throws GuzzleException - */ - public function getUserById(string $bearer, string $id, bool $includeEmail = false): ResponseInterface - { - return $this->getUsers($bearer, [$id], [], $includeEmail); - } - - /** - * @throws GuzzleException - */ - public function getUserByUsername(string $bearer, string $username, bool $includeEmail = false): ResponseInterface - { - return $this->getUsers($bearer, [], [$username], $includeEmail); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference/#get-users - */ - public function getUsers(string $bearer, array $ids = [], array $usernames = [], bool $includeEmail = false): ResponseInterface - { - $queryParamsMap = []; - foreach ($ids as $id) { - $queryParamsMap[] = ['key' => 'id', 'value' => $id]; - } - foreach ($usernames as $username) { - $queryParamsMap[] = ['key' => 'login', 'value' => $username]; - } - if ($includeEmail) { - $queryParamsMap[] = ['key' => 'scope', 'value' => 'user:read:email']; - } - - return $this->getApi('users', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference/#get-users-follows - */ - public function getUsersFollows(string $bearer, string $followerId = null, string $followedUserId = null, int $first = null, string $after = null): ResponseInterface - { - $queryParamsMap = []; - if ($followerId) { - $queryParamsMap[] = ['key' => 'from_id', 'value' => $followerId]; - } - if ($followedUserId) { - $queryParamsMap[] = ['key' => 'to_id', 'value' => $followedUserId]; - } - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - return $this->getApi('users/follows', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference/#get-user-extensions - */ - public function getUserExtensions(string $bearer): ResponseInterface - { - $queryParamsMap = []; - - return $this->getApi('users/extensions/list', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference/#get-user-active-extensions - */ - public function getActiveUserExtensions(string $bearer, string $userId = null): ResponseInterface - { - $queryParamsMap = []; - - if ($userId) { - $queryParamsMap[] = ['key' => 'user_id', 'value' => $userId]; - } - - return $this->getApi('users/extensions', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#create-user-follows - */ - public function createUserFollow(string $bearer, string $fromId, string $toId, bool $notifications = null): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'from_id', 'value' => $fromId]; - - $queryParamsMap[] = ['key' => 'to_id', 'value' => $toId]; - - if ($notifications !== null) { - $queryParamsMap[] = ['key' => 'allow_notifications', 'value' => $notifications]; - } - - return $this->postApi('users/follows', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#delete-user-follows - */ - public function deleteUserFollow(string $bearer, string $fromId, string $toId): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'from_id', 'value' => $fromId]; - - $queryParamsMap[] = ['key' => 'to_id', 'value' => $toId]; - - return $this->deleteApi('users/follows', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#update-user - */ - public function updateUser(string $bearer, string $description = null): ResponseInterface - { - $queryParamsMap = []; - - if ($description) { - $queryParamsMap[] = ['key' => 'description', 'value' => $description]; - } - - return $this->putApi('users', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#get-user-block-list - */ - public function getUserBlockList(string $bearer, string $broadcasterId, int $first = null, string $after = null): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'broadcaster_id', 'value' => $broadcasterId]; - - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - return $this->getApi('users/blocks', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#block-user - */ - public function blockUser(string $bearer, string $targetUserId, string $sourceContext = null, string $reason = null): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'target_user_id', 'value' => $targetUserId]; - - if ($sourceContext) { - $queryParamsMap[] = ['key' => 'source_context', 'value' => $sourceContext]; - } - - if ($reason) { - $queryParamsMap[] = ['key' => 'reason', 'value' => $reason]; - } - - return $this->putApi('users/blocks', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#unblock-user - */ - public function unblockUser(string $bearer, string $targetUserId): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'target_user_id', 'value' => $targetUserId]; - - return $this->deleteApi('users/blocks', $bearer, $queryParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/VideosApi.php b/src/NewTwitchApi/Resources/VideosApi.php deleted file mode 100644 index 684291e..0000000 --- a/src/NewTwitchApi/Resources/VideosApi.php +++ /dev/null @@ -1,77 +0,0 @@ - 'id', 'value' => $id]; - } - - if ($userId) { - $queryParamsMap[] = ['key' => 'user_id', 'value' => $userId]; - } - - if ($gameId) { - $queryParamsMap[] = ['key' => 'game_id', 'value' => $gameId]; - } - - if ($first) { - $queryParamsMap[] = ['key' => 'first', 'value' => $first]; - } - - if ($before) { - $queryParamsMap[] = ['key' => 'before', 'value' => $before]; - } - - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - if ($language) { - $queryParamsMap[] = ['key' => 'language', 'value' => $language]; - } - - if ($period) { - $queryParamsMap[] = ['key' => 'period', 'value' => $period]; - } - - if ($sort) { - $queryParamsMap[] = ['key' => 'sort', 'value' => $sort]; - } - - if ($type) { - $queryParamsMap[] = ['key' => 'type', 'value' => $type]; - } - - return $this->getApi('videos', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#delete-videos - */ - public function deleteVideos(string $bearer, array $ids = []): ResponseInterface - { - $queryParamsMap = []; - - foreach ($ids as $id) { - $queryParamsMap[] = ['key' => 'id', 'value' => $id]; - } - - return $this->deleteApi('videos', $bearer, $queryParamsMap); - } -} diff --git a/src/NewTwitchApi/Resources/WebhooksApi.php b/src/NewTwitchApi/Resources/WebhooksApi.php deleted file mode 100644 index 06e8325..0000000 --- a/src/NewTwitchApi/Resources/WebhooksApi.php +++ /dev/null @@ -1,28 +0,0 @@ - 'first', 'value' => $first]; - } - if ($after) { - $queryParamsMap[] = ['key' => 'after', 'value' => $after]; - } - - return $this->getApi('webhooks/subscriptions', $bearer, $queryParamsMap); - } -} diff --git a/src/NewTwitchApi/Webhooks/WebhooksSubscriptionApi.php b/src/NewTwitchApi/Webhooks/WebhooksSubscriptionApi.php deleted file mode 100644 index 2430f7c..0000000 --- a/src/NewTwitchApi/Webhooks/WebhooksSubscriptionApi.php +++ /dev/null @@ -1,161 +0,0 @@ -clientId = $clientId; - $this->secret = $secret; - $this->guzzleClient = $guzzleClient ?? HelixGuzzleClient::getClient($clientId); - } - - public function subscribeToStream(string $twitchId, string $callback, string $bearer, int $leaseSeconds = 0): void - { - $this->subscribe( - sprintf('https://api.twitch.tv/helix/streams?user_id=%s', $twitchId), - $callback, - $bearer, - $leaseSeconds - ); - } - - public function subscribeToSubscriptionEvents(string $twitchId, string $callback, string $bearer, int $leaseSeconds = 0): void - { - $this->subscribe( - sprintf('https://api.twitch.tv/helix/subscriptions/events?broadcaster_id=%s&first=1', $twitchId), - $callback, - $bearer, - $leaseSeconds - ); - } - - public function subscribeToUser(string $twitchId, string $callback, string $bearer, int $leaseSeconds = 0): void - { - $this->subscribe( - sprintf('https://api.twitch.tv/helix/users?id=%s', $twitchId), - $callback, - $bearer, - $leaseSeconds - ); - } - - public function subscribeToUserFollows(string $followerId, string $followedUserId, int $first, string $callback, string $bearer, int $leaseSeconds = 0): void - { - $queryParams = []; - if ($followerId) { - $queryParams['from_id'] = $followerId; - } - if ($followedUserId) { - $queryParams['to_id'] = $followedUserId; - } - if ($first) { - $queryParams['first'] = $first; - } - $this->subscribe( - sprintf('https://api.twitch.tv/helix/users/follows?%s', http_build_query($queryParams)), - $callback, - $bearer, - $leaseSeconds - ); - } - - public function unsubscribeFromStream(string $twitchId, string $callback, string $bearer): void - { - $this->unsubscribe( - sprintf('https://api.twitch.tv/helix/streams?user_id=%s', $twitchId), - $callback, - $bearer - ); - } - - public function unsubscribeFromUser(string $twitchId, string $callback, string $bearer) - { - $this->unsubscribe( - sprintf('https://api.twitch.tv/helix/users?id=%s', $twitchId), - $callback, - $bearer - ); - } - - public function unsubscribeFromUserFollows(string $followerId, string $followedUserId, int $first, string $callback, string $bearer) - { - $queryParams = []; - if ($followerId) { - $queryParams['from_id'] = $followerId; - } - if ($followedUserId) { - $queryParams['to_id'] = $followedUserId; - } - if ($first) { - $queryParams['first'] = $first; - } - $this->unsubscribe( - sprintf('https://api.twitch.tv/helix/users/follows?%s', http_build_query($queryParams)), - $callback, - $bearer - ); - } - - public function validateWebhookEventCallback(string $xHubSignature, string $content): bool - { - [$hashAlgorithm, $expectedHash] = explode('=', $xHubSignature); - $generatedHash = hash_hmac($hashAlgorithm, $content, $this->secret); - - return $expectedHash === $generatedHash; - } - - private function subscribe(string $topic, string $callback, string $bearer, int $leaseSeconds = 0): void - { - $headers = [ - 'Client-ID' => $this->clientId, - ]; - - $headers['Authorization'] = sprintf('Bearer %s', $bearer); - - $body = [ - 'hub.callback' => $callback, - 'hub.mode' => self::SUBSCRIBE, - 'hub.topic' => $topic, - 'hub.lease_seconds' => $leaseSeconds, - 'hub.secret' => $this->secret, - ]; - - $this->guzzleClient->post('webhooks/hub', [ - 'headers' => $headers, - 'body' => json_encode($body), - ]); - } - - private function unsubscribe(string $topic, string $callback, string $bearer): void - { - $headers = [ - 'Client-ID' => $this->clientId, - ]; - - $headers['Authorization'] = sprintf('Bearer %s', $bearer); - - $body = [ - 'hub.callback' => $callback, - 'hub.mode' => self::UNSUBSCRIBE, - 'hub.topic' => $topic, - ]; - - $this->guzzleClient->post('webhooks/hub', [ - 'headers' => $headers, - 'body' => json_encode($body), - ]); - } -} diff --git a/src/TwitchRequest.php b/src/TwitchRequest.php deleted file mode 100644 index 7bddaa3..0000000 --- a/src/TwitchRequest.php +++ /dev/null @@ -1,220 +0,0 @@ -getNewHttpClient($method, $params, $accessToken); - $response = $client->request($method, $endpoint); - $responseBody = $response->getBody()->getContents(); - - return $this->getReturnJson() ? $responseBody : json_decode($responseBody, true); - } - - /** - * Get a new HTTP Client - * - * @param strring $method - * @param array $params - * @param string $accessToken - * @return Client - */ - protected function getNewHttpClient($method, $params, $accessToken = null) - { - $config = [ - 'http_errors' => $this->getHttpErrors(), - 'base_uri' => $this->baseUri, - 'timeout' => $this->getTimeout(), - 'headers' => [ - 'Client-ID' => $this->getClientId(), - 'Accept' => sprintf('application/vnd.twitchtv.v%d+json', $this->getApiVersion()), - 'User-Agent' => ($this->getUserAgent() !== null) ? $this->getUserAgent() : GuzzleHttp\default_user_agent(), - ], - ]; - - if ($accessToken) { - $config['headers']['Authorization'] = sprintf('OAuth %s', $accessToken); - } - - if (!empty($params)) { - $config[($method == self::GET_METHOD) ? 'query' : 'json'] = $params; - } - - return new GuzzleHttp\Client($config); - } - - /** - * Send a GET request - * - * @param string $endpoint - * @param array $params - * @param bool $accessToken - * @return array|string - */ - protected function get($endpoint, $params = [], $accessToken = null) - { - return $this->sendRequest(self::GET_METHOD, $endpoint, $params, $accessToken); - } - - /** - * Send a POST request - * - * @param string $endpoint - * @param array $params - * @param bool $accessToken - * @return array|string - */ - protected function post($endpoint, $params = [], $accessToken = null) - { - return $this->sendRequest(self::POST_METHOD, $endpoint, $params, $accessToken); - } - - /** - * Send a PUT request - * - * @param string $endpoint - * @param array $params - * @param bool $accessToken - * @return array|string - */ - protected function put($endpoint, $params = [], $accessToken = null) - { - return $this->sendRequest(self::PUT_METHOD, $endpoint, $params, $accessToken); - } - - /** - * Send a DELETE request - * - * @param string $endpoint - * @param array $params - * @param bool $accessToken - * @return null|array|string - */ - protected function delete($endpoint, $params = [], $accessToken = null) - { - return $this->sendRequest(self::DELETE_METHOD, $endpoint, $params, $accessToken); - } - - /** - * Set timeout - * - * @param float $timeout - */ - public function setTimeout($timeout) - { - $this->timeout = (float) $timeout; - } - - /** - * Get timeout - * - * @return float - */ - public function getTimeout() - { - return $this->timeout; - } - - /** - * Set user agent - * - * @param string $userAgent - */ - public function setUserAgent($userAgent) - { - $this->userAgent = (string) $userAgent; - } - - /** - * Get user agent - * - * @return string - */ - public function getUserAgent() - { - return $this->userAgent; - } - - /** - * Set HTTP errors - * - * @param bool $httpErrors - */ - public function setHttpErrors($httpErrors) - { - $this->httpErrors = boolval($httpErrors); - } - - /** - * Get HTTP errors - * - * @return bool - */ - public function getHttpErrors() - { - return $this->httpErrors; - } - - /** - * Set return as JSON - * - * @param bool $returnJson - */ - public function setReturnJson($returnJson) - { - $this->returnJson = boolval($returnJson); - } - - /** - * Get return as JSON - * - * @return bool - */ - public function getReturnJson() - { - return $this->returnJson; - } -} diff --git a/test/NewTwitchApi/Resources/UsersTest.php b/test/NewTwitchApi/Resources/UsersTest.php deleted file mode 100644 index 4ac338d..0000000 --- a/test/NewTwitchApi/Resources/UsersTest.php +++ /dev/null @@ -1,68 +0,0 @@ -getHelixGuzzleClientWithMockUserResponse(), $this->getRequestGenerator()); - $response = $users->getUserById('TEST_APP_ACCESS_TOKEN', '44322889'); - - $this->assertEquals(200, $response->getStatusCode()); - $contents = json_decode($response->getBody()->getContents()); - $this->assertEquals('dallas', $contents->data[0]->login); - } - - public function testGetUserByUsernameShouldReturnSuccessfulResponseWithUserData(): void - { - $users = new UsersApi($this->getHelixGuzzleClientWithMockUserResponse(), $this->getRequestGenerator()); - $response = $users->getUserByUsername('TEST_APP_ACCESS_TOKEN', 'dallas'); - - $this->assertEquals(200, $response->getStatusCode()); - $contents = json_decode($response->getBody()->getContents()); - $this->assertEquals(44322889, $contents->data[0]->id); - } - - private function getHelixGuzzleClientWithMockUserResponse(): HelixGuzzleClient - { - // Example response from https://dev.twitch.tv/docs/api/reference/#get-users - $getUserReponseJson = << $handler]); - } - - private function getRequestGenerator(): RequestGenerator - { - return new RequestGenerator(); - } -} diff --git a/test/TwitchApiTest.php b/test/TwitchApiTest.php deleted file mode 100644 index 40caa75..0000000 --- a/test/TwitchApiTest.php +++ /dev/null @@ -1,81 +0,0 @@ - 'CLIENT-ID']); - $this->assertInstanceOf(TwitchApi::class, $twitchApi); - - return $twitchApi; - } - - /** - * @depends testCanCreateClassWithMinimumOptions - */ - public function testCanSetClientId(TwitchApi $twitchApi) - { - $options = [ - 'client_id' => 'TEST_CLIENT_ID', - ]; - $twitchApi->setClientId($options['client_id']); - $this->assertEquals($twitchApi->getClientId(), $options['client_id']); - } - - public function testCreateClassWithoutClientIdThrowsException() - { - $this->expectException(ClientIdRequiredException::class); - $twitchApi = new TwitchApi([]); - } - - public function testDefaultClassProperties() - { - $twitchApi = new TwitchApi(['client_id' => 'CLIENT-ID']); - $this->assertEmpty($twitchApi->getScope()); - $this->assertNotEmpty($twitchApi->getClientId()); - $this->assertEmpty($twitchApi->getRedirectUri()); - $this->assertEmpty($twitchApi->getClientSecret()); - $this->assertEquals($twitchApi->getApiVersion(), $twitchApi->getDefaultApiVersion()); - } - - public function testCanCreateClassWithValidOptions() - { - $options = [ - 'client_id' => 'CLIENT_ID', - 'client_secret' => 'CLIENT_SECRET', - 'redirect_uri' => 'REDIRECT_URI', - 'api_version' => 3, - 'scope' => ['user_read'], - ]; - $twitchApi = new TwitchApi($options); - $this->assertEquals($twitchApi->getClientId(), $options['client_id']); - $this->assertEquals($twitchApi->getClientSecret(), $options['client_secret']); - $this->assertEquals($twitchApi->getRedirectUri(), $options['redirect_uri']); - $this->assertEquals($twitchApi->getApiVersion(), $options['api_version']); - $this->assertEquals($twitchApi->getScope(), $options['scope']); - } - - /** - * @depends testCanCreateClassWithMinimumOptions - */ - public function testApiVersionDefaultsTo5IfNotSpecificallySet(TwitchApi $twitchApi) - { - $this->assertEquals($twitchApi->getApiVersion(), 5); - } - - public function testExceptionIsThrownIfApiVersionISNotSupported() - { - $this->expectException(UnsupportedApiVersionException::class); - $options = [ - 'client_id' => 'CLIENT_ID', - 'api_version' => 99, - ]; - $twitchApi = new TwitchApi($options); - $this->assertEquals($twitchApi->getApiVersion(), 5); - } -} From f7fd00fcaaa5e353171ba43ab6b6ad9d50f67743 Mon Sep 17 00:00:00 2001 From: Brandin Arsenault Date: Wed, 28 Jul 2021 15:06:14 -0300 Subject: [PATCH 3/6] Drop Create and Delete User Follow --- spec/TwitchApi/Resources/UsersApiSpec.php | 24 ---------------- src/Resources/UsersApi.php | 34 ----------------------- 2 files changed, 58 deletions(-) diff --git a/spec/TwitchApi/Resources/UsersApiSpec.php b/spec/TwitchApi/Resources/UsersApiSpec.php index c988648..1e2e910 100644 --- a/spec/TwitchApi/Resources/UsersApiSpec.php +++ b/spec/TwitchApi/Resources/UsersApiSpec.php @@ -94,30 +94,6 @@ function it_should_get_users_follows_by_everything(RequestGenerator $requestGene $this->getUsersFollows('TEST_TOKEN', '12345', '98765', 42, '99')->shouldBe($response); } - function it_should_create_a_follow(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'users/follows', 'TEST_TOKEN', [['key' => 'from_id', 'value' => '123'], ['key' => 'to_id', 'value' => '321']], [])->willReturn($request); - $this->createUserFollow('TEST_TOKEN', '123', '321')->shouldBe($response); - } - - function it_should_create_a_follow_with_notifications(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'users/follows', 'TEST_TOKEN', [['key' => 'from_id', 'value' => '123'], ['key' => 'to_id', 'value' => '321'], ['key' => 'allow_notifications', 'value' => 1]], [])->willReturn($request); - $this->createUserFollow('TEST_TOKEN', '123', '321', true)->shouldBe($response); - } - - function it_should_create_a_follow_without_notifications(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('POST', 'users/follows', 'TEST_TOKEN', [['key' => 'from_id', 'value' => '123'], ['key' => 'to_id', 'value' => '321'], ['key' => 'allow_notifications', 'value' => 0]], [])->willReturn($request); - $this->createUserFollow('TEST_TOKEN', '123', '321', false)->shouldBe($response); - } - - function it_should_delete_a_follow(RequestGenerator $requestGenerator, Request $request, Response $response) - { - $requestGenerator->generate('DELETE', 'users/follows', 'TEST_TOKEN', [['key' => 'from_id', 'value' => '123'], ['key' => 'to_id', 'value' => '321']], [])->willReturn($request); - $this->deleteUserFollow('TEST_TOKEN', '123', '321')->shouldBe($response); - } - function it_should_update_user(RequestGenerator $requestGenerator, Request $request, Response $response) { $requestGenerator->generate('PUT', 'users', 'TEST_TOKEN', [], [])->willReturn($request); diff --git a/src/Resources/UsersApi.php b/src/Resources/UsersApi.php index ca8d407..715b7cc 100644 --- a/src/Resources/UsersApi.php +++ b/src/Resources/UsersApi.php @@ -102,40 +102,6 @@ public function getActiveUserExtensions(string $bearer, string $userId = null): return $this->getApi('users/extensions', $bearer, $queryParamsMap); } - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#create-user-follows - */ - public function createUserFollow(string $bearer, string $fromId, string $toId, bool $notifications = null): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'from_id', 'value' => $fromId]; - - $queryParamsMap[] = ['key' => 'to_id', 'value' => $toId]; - - if ($notifications !== null) { - $queryParamsMap[] = ['key' => 'allow_notifications', 'value' => $notifications]; - } - - return $this->postApi('users/follows', $bearer, $queryParamsMap); - } - - /** - * @throws GuzzleException - * @link https://dev.twitch.tv/docs/api/reference#delete-user-follows - */ - public function deleteUserFollow(string $bearer, string $fromId, string $toId): ResponseInterface - { - $queryParamsMap = []; - - $queryParamsMap[] = ['key' => 'from_id', 'value' => $fromId]; - - $queryParamsMap[] = ['key' => 'to_id', 'value' => $toId]; - - return $this->deleteApi('users/follows', $bearer, $queryParamsMap); - } - /** * @throws GuzzleException * @link https://dev.twitch.tv/docs/api/reference#update-user From cd7340c3d8876a6cb0838abd5793e9b9d966bdd6 Mon Sep 17 00:00:00 2001 From: Brandin Arsenault Date: Wed, 28 Jul 2021 15:35:13 -0300 Subject: [PATCH 4/6] Update php_cs.dist --- .php_cs.dist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.php_cs.dist b/.php_cs.dist index 8d13765..684aaa2 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -1,8 +1,8 @@ in('src/NewTwitchApi/') - ->in('test/NewTwitchApi/') + ->in('src/') + ->in('test/') ; return PhpCsFixer\Config::create() From 3ed7683a357fe29416ef03ff1e720001341b6b9c Mon Sep 17 00:00:00 2001 From: Brandin Arsenault Date: Wed, 28 Jul 2021 15:39:56 -0300 Subject: [PATCH 5/6] Updated Tests to Resolve CS Issue --- test/TwitchApi/Resources/UsersTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/TwitchApi/Resources/UsersTest.php b/test/TwitchApi/Resources/UsersTest.php index fab45e6..61f8256 100644 --- a/test/TwitchApi/Resources/UsersTest.php +++ b/test/TwitchApi/Resources/UsersTest.php @@ -7,10 +7,10 @@ use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Response; +use PHPUnit\Framework\TestCase; use TwitchApi\HelixGuzzleClient; use TwitchApi\RequestGenerator; use TwitchApi\Resources\UsersApi; -use PHPUnit\Framework\TestCase; class UsersTest extends TestCase { From 5bcf412c8c4dc20579216f29d1f9ace730a18a9f Mon Sep 17 00:00:00 2001 From: Brandin Arsenault Date: Fri, 30 Jul 2021 11:36:17 -0300 Subject: [PATCH 6/6] Fix Var Names --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index bf65f87..653bdda 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,8 @@ $twitch_client_secret = 'TWITCH_CLIENT_SECRET'; $twitch_scopes = ''; $helixGuzzleClient = new \TwitchApi\HelixGuzzleClient($twitch_client_id); -$TwitchApi = new \TwitchApi\TwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); -$oauth = $TwitchApi->getOauthApi(); +$twitchApi = new \TwitchApi\TwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); +$oauth = $twitchApi->getOauthApi(); try { $token = $oauth->getAppAccessToken($twitch_scopes ?? ''); @@ -63,8 +63,8 @@ $twitch_client_secret = 'TWITCH_CLIENT_SECRET'; $twitch_scopes = ''; $helixGuzzleClient = new \TwitchApi\HelixGuzzleClient($twitch_client_id); -$TwitchApi = new \TwitchApi\TwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); -$oauth = $TwitchApi->getOauthApi(); +$twitchApi = new \TwitchApi\TwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); +$oauth = $twitchApi->getOauthApi(); // Get the code from URI $code = $_GET['code']; @@ -105,8 +105,8 @@ $twitch_scopes = ''; $user_refresh_token = 'REFRESH_TOKEN'; $helixGuzzleClient = new \TwitchApi\HelixGuzzleClient($twitch_client_id); -$TwitchApi = new \TwitchApi\TwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); -$oauth = $TwitchApi->getOauthApi(); +$twitchApi = new \TwitchApi\TwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); +$oauth = $twitchApi->getOauthApi(); try { $token = $oauth->getAppAccessToken($twitch_scopes ?? ''); @@ -143,11 +143,11 @@ $twitch_access_token = 'the token'; $helixGuzzleClient = new \TwitchApi\HelixGuzzleClient($twitch_client_id); // Instantiate TwitchApi. Can be done in a service layer and injected as well. -$TwitchApi = new TwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); +$twitchApi = new TwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret); try { // Make the API call. A ResponseInterface object is returned. - $response = $TwitchApi->getUsersApi()->getUserByAccessToken($twitch_access_token); + $response = $twitchApi->getUsersApi()->getUserByAccessToken($twitch_access_token); // Get and decode the actual content sent by Twitch. $responseContent = json_decode($response->getBody()->getContents());