Changeset View
Changeset View
Standalone View
Standalone View
src/future/twitch/PhutilTwitchFuture.php
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | if (!$this->future) { | ||||
throw new Exception(pht('You must %s!', 'setRawTwitchQuery()')); | throw new Exception(pht('You must %s!', 'setRawTwitchQuery()')); | ||||
} | } | ||||
if (!$this->accessToken) { | if (!$this->accessToken) { | ||||
throw new Exception(pht('You must %s!', 'setAccessToken()')); | throw new Exception(pht('You must %s!', 'setAccessToken()')); | ||||
} | } | ||||
$uri = new PhutilURI('https://api.twitch.tv/'); | $uri = new PhutilURI('https://api.twitch.tv/'); | ||||
$uri->setPath('/kraken/'.ltrim($this->action, '/')); | $uri->setPath('/helix/'.ltrim($this->action, '/')); | ||||
$uri->replaceQueryParam('oauth_token', $this->accessToken); | |||||
$future = new HTTPSFuture($uri); | $future = new HTTPSFuture($uri); | ||||
$future->setData($this->params); | $future->setData($this->params); | ||||
$future->setMethod($this->method); | $future->setMethod($this->method); | ||||
$future->addHeader('Authorization', 'Bearer '.$this->accessToken); | |||||
// NOTE: This is how the Twitch API is versioned. | // NOTE: This is how the Twitch API is versioned. | ||||
$future->addHeader('Accept', 'application/vnd.twitchtv.2+json'); | $future->addHeader('Accept', 'application/vnd.twitchtv.2+json'); | ||||
// NOTE: This is required to avoid rate limiting. | // NOTE: This is required to avoid rate limiting. | ||||
$future->addHeader('Client-ID', $this->clientID); | $future->addHeader('Client-ID', $this->clientID); | ||||
$this->future = $future; | $this->future = $future; | ||||
Show All 18 Lines | try { | ||||
$ex); | $ex); | ||||
} | } | ||||
if (idx($data, 'error')) { | if (idx($data, 'error')) { | ||||
$error = $data['error']; | $error = $data['error']; | ||||
throw new Exception(pht('Received error from Twitch: %s', $error)); | throw new Exception(pht('Received error from Twitch: %s', $error)); | ||||
} | } | ||||
return $data; | return $data['data'][0]; | ||||
} | } | ||||
} | } |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0