Skip to content

Commit 1846cb2

Browse files
authored
Merge pull request #134 from nicklaw5/v6
2 parents d4cab23 + 5bcf412 commit 1846cb2

File tree

92 files changed

+396
-3982
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+396
-3982
lines changed

.php_cs.dist

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

33
$finder = PhpCsFixer\Finder::create()
4-
->in('src/NewTwitchApi/')
5-
->in('test/NewTwitchApi/')
4+
->in('src/')
5+
->in('test/')
66
;
77

88
return PhpCsFixer\Config::create()

README.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ $twitch_client_id = 'TWITCH_CLIENT_ID';
4040
$twitch_client_secret = 'TWITCH_CLIENT_SECRET';
4141
$twitch_scopes = '';
4242

43-
$helixGuzzleClient = new \NewTwitchApi\HelixGuzzleClient($twitch_client_id);
44-
$newTwitchApi = new \NewTwitchApi\NewTwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret);
45-
$oauth = $newTwitchApi->getOauthApi();
43+
$helixGuzzleClient = new \TwitchApi\HelixGuzzleClient($twitch_client_id);
44+
$twitchApi = new \TwitchApi\TwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret);
45+
$oauth = $twitchApi->getOauthApi();
4646

4747
try {
4848
$token = $oauth->getAppAccessToken($twitch_scopes ?? '');
@@ -62,9 +62,9 @@ $twitch_client_id = 'TWITCH_CLIENT_ID';
6262
$twitch_client_secret = 'TWITCH_CLIENT_SECRET';
6363
$twitch_scopes = '';
6464

65-
$helixGuzzleClient = new \NewTwitchApi\HelixGuzzleClient($twitch_client_id);
66-
$newTwitchApi = new \NewTwitchApi\NewTwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret);
67-
$oauth = $newTwitchApi->getOauthApi();
65+
$helixGuzzleClient = new \TwitchApi\HelixGuzzleClient($twitch_client_id);
66+
$twitchApi = new \TwitchApi\TwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret);
67+
$oauth = $twitchApi->getOauthApi();
6868

6969
// Get the code from URI
7070
$code = $_GET['code'];
@@ -104,9 +104,9 @@ $twitch_client_secret = 'TWITCH_CLIENT_SECRET';
104104
$twitch_scopes = '';
105105
$user_refresh_token = 'REFRESH_TOKEN';
106106

107-
$helixGuzzleClient = new \NewTwitchApi\HelixGuzzleClient($twitch_client_id);
108-
$newTwitchApi = new \NewTwitchApi\NewTwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret);
109-
$oauth = $newTwitchApi->getOauthApi();
107+
$helixGuzzleClient = new \TwitchApi\HelixGuzzleClient($twitch_client_id);
108+
$twitchApi = new \TwitchApi\TwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret);
109+
$oauth = $twitchApi->getOauthApi();
110110

111111
try {
112112
$token = $oauth->getAppAccessToken($twitch_scopes ?? '');
@@ -124,11 +124,11 @@ try {
124124

125125
### Usage of the API Classes
126126

127-
Everything stems from the `NewTwitchApi` class. However, if you want to individually instantiate `UsersApi`, `OauthApi`, etc. you are free to do so.
127+
Everything stems from the `TwitchApi` class. However, if you want to individually instantiate `UsersApi`, `OauthApi`, etc. you are free to do so.
128128

129129
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.
130130

131-
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.
131+
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.
132132

133133
Here is a sample of retrieving a users table from their access token:
134134

@@ -140,14 +140,14 @@ $twitch_access_token = 'the token';
140140

141141
// The Guzzle client used can be the included `HelixGuzzleClient` class, for convenience.
142142
// You can also use a mock, fake, or other double for testing, of course.
143-
$helixGuzzleClient = new \NewTwitchApi\HelixGuzzleClient($twitch_client_id);
143+
$helixGuzzleClient = new \TwitchApi\HelixGuzzleClient($twitch_client_id);
144144

145-
// Instantiate NewTwitchApi. Can be done in a service layer and injected as well.
146-
$newTwitchApi = new NewTwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret);
145+
// Instantiate TwitchApi. Can be done in a service layer and injected as well.
146+
$twitchApi = new TwitchApi($helixGuzzleClient, $twitch_client_id, $twitch_client_secret);
147147

148148
try {
149149
// Make the API call. A ResponseInterface object is returned.
150-
$response = $newTwitchApi->getUsersApi()->getUserByAccessToken($twitch_access_token);
150+
$response = $twitchApi->getUsersApi()->getUserByAccessToken($twitch_access_token);
151151

152152
// Get and decode the actual content sent by Twitch.
153153
$responseContent = json_decode($response->getBody()->getContents());

composer.json

+45-39
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,50 @@
11
{
2-
"name": "nicklaw5/twitch-api-php",
3-
"type": "library",
4-
"description": "A Twitch API client for PHP.",
5-
"keywords": ["twitch", "twitch.tv", "twitch-tv", "twitch-api", "api"],
6-
"homepage": "http://github.com/nicklaw5/twitch-api-php",
7-
"license": "MIT",
8-
"authors": [
9-
{
10-
"name": "Nicholas Law",
11-
"homepage": "https://github.com/nicklaw5"
12-
},
13-
{
14-
"name": "Brian Zwahr",
15-
"homepage": "https://github.com/echosa"
16-
},
17-
{
18-
"name": "Brandin Arsenault",
19-
"homepage": "https://github.com/brandinarsenault"
20-
}
21-
],
22-
"require": {
23-
"php": ">=7.4.0",
24-
"ext-json": "*",
25-
"guzzlehttp/guzzle": "~6.0|~7.0"
2+
"name": "nicklaw5/twitch-api-php",
3+
"type": "library",
4+
"description": "A Twitch API client for PHP.",
5+
"keywords": [
6+
"twitch",
7+
"twitch.tv",
8+
"twitch-tv",
9+
"twitch-api",
10+
"api"
11+
],
12+
"homepage": "http://github.com/nicklaw5/twitch-api-php",
13+
"license": "MIT",
14+
"authors": [
15+
{
16+
"name": "Nicholas Law",
17+
"homepage": "https://github.com/nicklaw5"
2618
},
27-
"require-dev": {
28-
"friendsofphp/php-cs-fixer": "^2.13",
29-
"phpspec/phpspec": "^6.1",
30-
"phpunit/phpunit": "^8.5"
19+
{
20+
"name": "Brian Zwahr",
21+
"homepage": "https://github.com/echosa"
3122
},
32-
"autoload": {
33-
"psr-4": {
34-
"TwitchApi\\": "src/",
35-
"NewTwitchApi\\": "src/NewTwitchApi",
36-
"NewTwitchApi\\Tests\\": "test/NewTwitchApi"
37-
}
38-
},
39-
"autoload-dev": {
40-
"psr-4": {
41-
"Tests\\": "test/"
42-
}
23+
{
24+
"name": "Brandin Arsenault",
25+
"homepage": "https://github.com/brandinarsenault"
26+
}
27+
],
28+
"require": {
29+
"php": ">=7.4.0",
30+
"ext-json": "*",
31+
"guzzlehttp/guzzle": "~6.0|~7.0"
32+
},
33+
"require-dev": {
34+
"friendsofphp/php-cs-fixer": "^2.13",
35+
"phpspec/phpspec": "^6.1",
36+
"phpunit/phpunit": "^8.5"
37+
},
38+
"autoload": {
39+
"psr-4": {
40+
"TwitchApi\\": "src/",
41+
"TwitchApi\\Tests\\": "test/TwitchApi",
42+
"NewTwitchApi\\": "src/NewTwitchApi"
43+
}
44+
},
45+
"autoload-dev": {
46+
"psr-4": {
47+
"Tests\\": "test/"
4348
}
49+
}
4450
}

spec/NewTwitchApi/Auth/AuthGuzzleClientSpec.php spec/TwitchApi/Auth/AuthGuzzleClientSpec.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace spec\NewTwitchApi\Auth;
3+
namespace spec\TwitchApi\Auth;
44

55
use GuzzleHttp\Psr7\Uri;
66
use PhpSpec\ObjectBehavior;

spec/NewTwitchApi/Auth/OauthApiSpec.php spec/TwitchApi/Auth/OauthApiSpec.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace spec\NewTwitchApi\Auth;
3+
namespace spec\TwitchApi\Auth;
44

55
use GuzzleHttp\Client;
66
use GuzzleHttp\Psr7\Request;

spec/NewTwitchApi/HelixGuzzleClientSpec.php spec/TwitchApi/HelixGuzzleClientSpec.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
namespace spec\NewTwitchApi;
3+
namespace spec\TwitchApi;
44

5-
use NewTwitchApi\HelixGuzzleClient;
5+
use TwitchApi\HelixGuzzleClient;
66
use PhpSpec\ObjectBehavior;
77

88
class HelixGuzzleClientSpec extends ObjectBehavior
@@ -14,7 +14,7 @@ function let(HelixGuzzleClient $guzzleClient)
1414

1515
function it_should_have_correct_base_uri()
1616
{
17-
$this->shouldHaveType('\NewTwitchApi\HelixGuzzleClient');
17+
$this->shouldHaveType('\TwitchApi\HelixGuzzleClient');
1818

1919
/** @var Uri $uri */
2020
$uri = $this->getConfig('base_uri');
@@ -25,21 +25,21 @@ function it_should_have_correct_base_uri()
2525

2626
function it_should_have_client_id_header()
2727
{
28-
$this->shouldHaveType('\NewTwitchApi\HelixGuzzleClient');
28+
$this->shouldHaveType('\TwitchApi\HelixGuzzleClient');
2929
$this->getConfig('headers')->shouldHaveKeyWithValue('Client-ID', 'TEST_CLIENT_ID');
3030
}
3131

3232
function it_should_have_json_content_type_header()
3333
{
3434

35-
$this->shouldHaveType('\NewTwitchApi\HelixGuzzleClient');
35+
$this->shouldHaveType('\TwitchApi\HelixGuzzleClient');
3636
$this->getConfig('headers')->shouldHaveKeyWithValue('Content-Type', 'application/json');
3737
}
3838

3939
function it_should_have_passed_in_config_params_instead_of_defaults()
4040
{
4141
$this->beConstructedWith('TEST_CLIENT_ID', ['base_uri' => 'https://different.url']);
42-
$this->shouldHaveType('\NewTwitchApi\HelixGuzzleClient');
42+
$this->shouldHaveType('\TwitchApi\HelixGuzzleClient');
4343
$this->getConfig('base_uri')->getHost()->shouldBe('different.url');
4444
}
4545
}

spec/NewTwitchApi/Resources/AdsApiSpec.php spec/TwitchApi/Resources/AdsApiSpec.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace spec\NewTwitchApi\Resources;
3+
namespace spec\TwitchApi\Resources;
44

55
use GuzzleHttp\Psr7\Request;
66
use GuzzleHttp\Psr7\Response;
7-
use NewTwitchApi\RequestGenerator;
8-
use NewTwitchApi\HelixGuzzleClient;
7+
use TwitchApi\RequestGenerator;
8+
use TwitchApi\HelixGuzzleClient;
99
use PhpSpec\ObjectBehavior;
1010

1111
class AdsApiSpec extends ObjectBehavior

spec/NewTwitchApi/Resources/AnalyticsApiSpec.php spec/TwitchApi/Resources/AnalyticsApiSpec.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace spec\NewTwitchApi\Resources;
3+
namespace spec\TwitchApi\Resources;
44

55
use GuzzleHttp\Psr7\Request;
66
use GuzzleHttp\Psr7\Response;
7-
use NewTwitchApi\RequestGenerator;
8-
use NewTwitchApi\HelixGuzzleClient;
7+
use TwitchApi\RequestGenerator;
8+
use TwitchApi\HelixGuzzleClient;
99
use PhpSpec\ObjectBehavior;
1010

1111
class AnalyticsApiSpec extends ObjectBehavior

spec/NewTwitchApi/Resources/BitsApiSpec.php spec/TwitchApi/Resources/BitsApiSpec.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace spec\NewTwitchApi\Resources;
3+
namespace spec\TwitchApi\Resources;
44

55
use GuzzleHttp\Psr7\Request;
66
use GuzzleHttp\Psr7\Response;
7-
use NewTwitchApi\RequestGenerator;
8-
use NewTwitchApi\HelixGuzzleClient;
7+
use TwitchApi\RequestGenerator;
8+
use TwitchApi\HelixGuzzleClient;
99
use PhpSpec\ObjectBehavior;
1010

1111
class BitsApiSpec extends ObjectBehavior

spec/NewTwitchApi/Resources/ChannelPointsApiSpec.php spec/TwitchApi/Resources/ChannelPointsApiSpec.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace spec\NewTwitchApi\Resources;
3+
namespace spec\TwitchApi\Resources;
44

55
use GuzzleHttp\Psr7\Request;
66
use GuzzleHttp\Psr7\Response;
7-
use NewTwitchApi\RequestGenerator;
8-
use NewTwitchApi\HelixGuzzleClient;
7+
use TwitchApi\RequestGenerator;
8+
use TwitchApi\HelixGuzzleClient;
99
use PhpSpec\ObjectBehavior;
1010

1111
class ChannelPointsApiSpec extends ObjectBehavior

spec/NewTwitchApi/Resources/ChannelsApiSpec.php spec/TwitchApi/Resources/ChannelsApiSpec.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace spec\NewTwitchApi\Resources;
3+
namespace spec\TwitchApi\Resources;
44

55
use GuzzleHttp\Psr7\Request;
66
use GuzzleHttp\Psr7\Response;
7-
use NewTwitchApi\RequestGenerator;
8-
use NewTwitchApi\HelixGuzzleClient;
7+
use TwitchApi\RequestGenerator;
8+
use TwitchApi\HelixGuzzleClient;
99
use PhpSpec\ObjectBehavior;
1010

1111
class ChannelsApiSpec extends ObjectBehavior

spec/NewTwitchApi/Resources/ChatApiSpec.php spec/TwitchApi/Resources/ChatApiSpec.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace spec\NewTwitchApi\Resources;
3+
namespace spec\TwitchApi\Resources;
44

55
use GuzzleHttp\Psr7\Request;
66
use GuzzleHttp\Psr7\Response;
7-
use NewTwitchApi\RequestGenerator;
8-
use NewTwitchApi\HelixGuzzleClient;
7+
use TwitchApi\RequestGenerator;
8+
use TwitchApi\HelixGuzzleClient;
99
use PhpSpec\ObjectBehavior;
1010

1111
class ChatApiSpec extends ObjectBehavior

spec/NewTwitchApi/Resources/EntitlementsApiSpec.php spec/TwitchApi/Resources/EntitlementsApiSpec.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace spec\NewTwitchApi\Resources;
3+
namespace spec\TwitchApi\Resources;
44

55
use GuzzleHttp\Psr7\Request;
66
use GuzzleHttp\Psr7\Response;
7-
use NewTwitchApi\RequestGenerator;
8-
use NewTwitchApi\HelixGuzzleClient;
7+
use TwitchApi\RequestGenerator;
8+
use TwitchApi\HelixGuzzleClient;
99
use PhpSpec\ObjectBehavior;
1010

1111
class EntitlementsApiSpec extends ObjectBehavior

spec/NewTwitchApi/Resources/EventSubApiSpec.php spec/TwitchApi/Resources/EventSubApiSpec.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace spec\NewTwitchApi\Resources;
3+
namespace spec\TwitchApi\Resources;
44

55
use GuzzleHttp\Psr7\Request;
66
use GuzzleHttp\Psr7\Response;
7-
use NewTwitchApi\RequestGenerator;
8-
use NewTwitchApi\HelixGuzzleClient;
7+
use TwitchApi\RequestGenerator;
8+
use TwitchApi\HelixGuzzleClient;
99
use PhpSpec\ObjectBehavior;
1010

1111
class EventSubApiSpec extends ObjectBehavior

spec/NewTwitchApi/Resources/GamesApiSpec.php spec/TwitchApi/Resources/GamesApiSpec.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace spec\NewTwitchApi\Resources;
3+
namespace spec\TwitchApi\Resources;
44

55
use GuzzleHttp\Psr7\Request;
66
use GuzzleHttp\Psr7\Response;
7-
use NewTwitchApi\RequestGenerator;
8-
use NewTwitchApi\HelixGuzzleClient;
7+
use TwitchApi\RequestGenerator;
8+
use TwitchApi\HelixGuzzleClient;
99
use PhpSpec\ObjectBehavior;
1010

1111
class GamesApiSpec extends ObjectBehavior

spec/NewTwitchApi/Resources/ModerationApiSpec.php spec/TwitchApi/Resources/ModerationApiSpec.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace spec\NewTwitchApi\Resources;
3+
namespace spec\TwitchApi\Resources;
44

55
use GuzzleHttp\Psr7\Request;
66
use GuzzleHttp\Psr7\Response;
7-
use NewTwitchApi\RequestGenerator;
8-
use NewTwitchApi\HelixGuzzleClient;
7+
use TwitchApi\RequestGenerator;
8+
use TwitchApi\HelixGuzzleClient;
99
use PhpSpec\ObjectBehavior;
1010

1111
class ModerationApiSpec extends ObjectBehavior

spec/NewTwitchApi/Resources/PollsApiSpec.php spec/TwitchApi/Resources/PollsApiSpec.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace spec\NewTwitchApi\Resources;
3+
namespace spec\TwitchApi\Resources;
44

55
use GuzzleHttp\Psr7\Request;
66
use GuzzleHttp\Psr7\Response;
7-
use NewTwitchApi\RequestGenerator;
8-
use NewTwitchApi\HelixGuzzleClient;
7+
use TwitchApi\RequestGenerator;
8+
use TwitchApi\HelixGuzzleClient;
99
use PhpSpec\ObjectBehavior;
1010

1111
class PollsApiSpec extends ObjectBehavior

0 commit comments

Comments
 (0)