1 | <?php |
||
14 | class TwitchRequest |
||
15 | { |
||
16 | /** @var string Set the useragnet */ |
||
17 | private $userAgent = 'jofner TwitchSDK 2.*'; |
||
18 | |||
19 | /** @var integer Set connect timeout */ |
||
20 | public $connectTimeout = 30; |
||
21 | |||
22 | /** @var integer Set timeout default. */ |
||
23 | public $timeout = 30; |
||
24 | |||
25 | /** @var boolean Verify SSL Cert */ |
||
26 | public $sslVerifypeer = false; |
||
27 | |||
28 | /** @var integer Contains the last HTTP status code returned */ |
||
29 | public $httpCode = 0; |
||
30 | |||
31 | /** @var array Contains the last HTTP headers returned */ |
||
32 | public $httpInfo = array(); |
||
33 | |||
34 | /** @var array Contains the last Server headers returned */ |
||
35 | public $httpHeader = array(); |
||
36 | |||
37 | /** @var boolean Throw cURL errors */ |
||
38 | public $throwCurlErrors = true; |
||
39 | |||
40 | /** @var int API version to use */ |
||
41 | private $apiVersion = 3; |
||
42 | |||
43 | /** @var string */ |
||
44 | private $clientId; |
||
45 | |||
46 | const URL_TWITCH = 'https://api.twitch.tv/kraken/'; |
||
47 | const URL_TWITCH_TEAM = 'http://api.twitch.tv/api/team/'; |
||
48 | const URI_AUTH = 'oauth2/authorize'; |
||
49 | const URI_AUTH_TOKEN = 'oauth2/token'; |
||
50 | const MIME_TYPE = 'application/vnd.twitchtv.v%d+json'; |
||
51 | |||
52 | /** |
||
53 | * Set the API version to use |
||
54 | * @param integer $version |
||
55 | * @deprecated will be removed, force to use v3 API, which is current stable Twitch API version |
||
56 | */ |
||
57 | public function setApiVersion($version) |
||
63 | |||
64 | /** |
||
65 | * Get the API version |
||
66 | * @return int |
||
67 | */ |
||
68 | public function getApiVersion() |
||
72 | |||
73 | /** |
||
74 | * Get Client ID |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getClientId() |
||
81 | |||
82 | /** |
||
83 | * Set CLient ID |
||
84 | * @param string $clientId |
||
85 | */ |
||
86 | public function setClientId($clientId) |
||
90 | |||
91 | /** |
||
92 | * TwitchAPI request |
||
93 | * @param string $uri |
||
94 | * @param string $method |
||
95 | * @param string $postfields |
||
96 | * @return \stdClass |
||
97 | * @throws \jofner\SDK\TwitchTV\TwitchSDKException |
||
98 | */ |
||
99 | public function request($uri, $method = 'GET', $postfields = null) |
||
103 | |||
104 | /** |
||
105 | * Twitch Team API request |
||
106 | * @param string $uri |
||
107 | * @param string $method |
||
108 | * @param string $postfields |
||
109 | * @return \stdClass |
||
110 | * @throws \jofner\SDK\TwitchTV\TwitchSDKException |
||
111 | */ |
||
112 | public function teamRequest($uri, $method = 'GET', $postfields = null) |
||
116 | |||
117 | /** |
||
118 | * TwitchAPI request |
||
119 | * method used by teamRequest && request methods |
||
120 | * because there are two different Twitch APIs |
||
121 | * don't call it directly |
||
122 | * @param string $uri |
||
123 | * @param string $method |
||
124 | * @param string $postfields |
||
125 | * @return \stdClass |
||
126 | * @throws \jofner\SDK\TwitchTV\TwitchSDKException |
||
127 | */ |
||
128 | private function generalRequest($uri, $method = 'GET', $postfields = null) |
||
146 | |||
147 | /** |
||
148 | * Initialize a cURL session |
||
149 | * @param string $uri |
||
150 | * @param string $method |
||
151 | * @param string|null $postfields |
||
152 | * @return resource |
||
153 | */ |
||
154 | private function initCrl($uri, $method, $postfields) |
||
191 | |||
192 | /** |
||
193 | * Get the header info to store |
||
194 | * @param $ch |
||
195 | * @param $header |
||
196 | * @return int |
||
197 | */ |
||
198 | private function getHeader($ch, $header) |
||
209 | } |
||
210 |