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]]);
 }
Example #2
0
 /**
  * Inactive module
  *
  * @return XException
  */
 public function deactivate()
 {
     $module = Module::model()->find('name=:name', array(':name' => $this->getName()));
     if (is_object($module)) {
         //Deactive module in db
         $module->enabled = false;
         if (!$module->save()) {
             return errorHandler()->getException();
         }
         //Call clear cache service
         Application::api('Xpress.Cache.clearCache');
         //Update module file for current workflow
         Application::api('Xpress.Settings.generateModuleConfig');
     }
 }
 /**
  * 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()]));
 }
Example #4
0
 /**
  * Shortcut to run an Api
  * @param string $apiId in format of module/controller/action
  */
 public function api($apiId, $params = array())
 {
     return Application::api($apiId, $params);
 }