Пример #1
0
 /**
  * Send a GET request to the Hail API for a specific URI and returns
  * the results. Extra paremeters can be specified via $request.
  *
  * @param string $uri ressource to get
  * @param StdClass $request Body of the request to send to the Hail API.
  * @return StdClass Reply from Hail
  * @throws HailApiException
  */
 protected static function get($uri, $request = false)
 {
     // Initialise request
     $response = Request::get(static::config()->Url . $uri)->addHeader('Authorization', 'Bearer ' . HailProvider::getHailAccessToken())->timeoutIn(static::config()->Timeout);
     // If we have a request body
     if ($request) {
         $response->sendsJson()->body(json_encode($request));
     }
     // Send the request and catch any Comms Exception
     try {
         $reply = $response->send();
     } catch (ConnectionErrorException $ex) {
         throw new HailApiException($ex->getMessage(), 0, $ex);
     }
     // Validate the response we get from Hail
     if (!empty($reply->body->error->message)) {
         throw new HailApiException($reply->body->error->message, $reply->code);
     }
     return $reply->body;
 }