Example #1
0
 /**
  * Send a HTTP GET request to a specific endpoint.
  *
  * @param  string  $endpoint
  * @param  array  $parameters  []
  * @param  array  $headers  []
  * @return \TwitchApi\Contracts\Response
  */
 private function request($method, $endpoint, array $parameters = [], array $headers = [])
 {
     $request = curl_init($endpoint = Application::api() . $endpoint);
     curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($request, CURLOPT_SSL_VERIFYPEER, (bool) $this->app->verifypeer);
     if (strtoupper($method) === 'POST') {
         curl_setopt($request, CURLOPT_POST, true);
     }
     if (!empty($parameters)) {
         curl_setopt($request, CURLOPT_POSTFIELDS, $parameters);
     }
     $headers = array_merge($headers, array_filter([$this->app->v3 ? 'Accept: application/vnd.twitchtv.v3+json' : null, 'Client-ID: ' . Application::client()]));
     curl_setopt($request, CURLOPT_HTTPHEADER, $headers);
     $response = curl_exec($request);
     curl_close($request);
     return $this->app->make('TwitchApi\\Contracts\\Response', [$response, ['method' => $method, 'endpoint' => $endpoint, 'parameters' => $parameters, 'headers' => $headers]]);
 }
 /**
  * Return a Twitch authentication URL.
  *
  * @param  string  $client
  * @param  string  $redirect
  * @param  string  $scopes
  * @return string
  */
 public static function url($client = null, $redirect = null, $scopes = null)
 {
     return sprintf("%s/oauth2/authorize?%s", Application::api(), http_build_query(['response_type' => 'code', 'client_id' => $client ?: Application::client(), 'redirect_uri' => $redirect ?: Application::redirect(), 'scope' => $scopes ?: Application::scopes()]));
 }