public function createAuthUrl($scopes = '', $state = null) { $addy = ''; if ($this->client->isForceRelogin() === true) { $addy .= '&force_verify=true'; } if ($state) { $addy .= '&state=' . $state; } $url = sprintf('%s/oauth2/authorize/?response_type=code&client_id=%s&redirect_uri=%s&scope=%s%s', $this->client->getApiUrl(), $this->client->getClientId(), $this->client->getRedirectUri(), urlencode($scopes), $addy); return $url; }
public function sendRequest(HttpRequest $request) { if (!$this->client) { throw new Exception\TwitchException('Client was not set'); } $apiurl = rtrim($this->client->getApiUrl(), '/'); $url = sprintf('%s/%s', $apiurl, $request->getUrl()); $url = rtrim($url, '/'); $this->getAdapter()->open(); $data = $this->getAdapter()->send($url, $request->getRequestMethod(), $request->getRequestHeaders(), $request->getPostBody()); $status_code = $this->getAdapter()->getHttpStatusCode(); $data = json_decode($data); $this->getAdapter()->close(); // TODO we need to return more info if ($status_code !== 200) { throw new Exception\TwitchException($data->error, $data->status); } return $data; }