示例#1
0
 /**
  * @param $method
  * @param $uri
  * @param $queryParams
  * @return array
  */
 private function prepareRequest($method, $uri, $queryParams)
 {
     $headers = array();
     if ($this->getAccessToken() !== null and !empty($this->getAccessToken())) {
         $headers['Authorization'] = 'Bearer ' . $this->access_token;
     }
     switch ($method) {
         case 'GET':
             $request = $this->client->get($uri, $queryParams, $headers);
             break;
         case 'POST':
             $headers['Content-Type'] = 'application/json';
             $queryParams = json_encode($queryParams);
             $request = $this->client->post($uri, $queryParams, $headers);
             break;
         case 'PUT':
             $headers['Content-Type'] = 'application/json';
             $queryParams = json_encode($queryParams);
             $request = $this->client->put($uri, $queryParams, $headers);
             break;
         case 'DELETE':
             $headers['Content-Type'] = 'application/json';
             $request = $this->client->delete($uri, $queryParams, $headers);
             break;
     }
     return $request;
 }
示例#2
0
 /**
  * @param string $baseUrl
  * @param \GuzzleHttp\Client|null $client
  */
 public function __construct($baseUrl, $client = null)
 {
     if ($client !== null) {
         $this->client = $client;
         return;
     }
     $client = new Resty();
     $client->setBaseURL($baseUrl);
     $this->client = $client;
 }
 public function __construct($baseUrl, $client = null)
 {
     if (!is_null($client)) {
         $this->client = $client;
         return;
     }
     $client = new Resty();
     $client->setBaseURL($baseUrl . '/' . HipChat::API_VERSION . '/');
     $this->client = $client;
 }
示例#4
0
 /**
  * @return \Aikidesk\SDK\WWW\HttpClients\GuzzleV6|\Aikidesk\SDK\WWW\HttpClients\RestyClient|null
  * @throws \Aikidesk\SDK\WWW\Exceptions\ApiException
  */
 public static function createOAuthHttpClient()
 {
     if (self::$httpOAuthClient !== null) {
         return self::$httpOAuthClient;
     }
     if (class_exists('GuzzleHttp\\Client')) {
         $client = new Client(array('base_uri' => self::$baseUrl . '/'));
         self::$httpOAuthClient = new \Aikidesk\SDK\WWW\HttpClients\GuzzleV6(self::$baseUrl, $client);
     } elseif (class_exists('Resty\\Resty')) {
         $client = new Resty();
         $client->setBaseURL(self::$baseUrl . '/');
         self::$httpClient = new \Aikidesk\SDK\WWW\HttpClients\RestyClient(self::$baseUrl, $client);
     } elseif (extension_loaded('curl') and class_exists('Curl\\Curl')) {
         $client = new \Curl\Curl(self::$baseUrl . '/');
         self::$httpClient = new \Aikidesk\SDK\WWW\HttpClients\PhpCurlClient(self::$baseUrl, $client);
     } else {
         throw new ApiException('There is no supported HTTP Client!', 999);
     }
     return self::$httpOAuthClient;
 }
示例#5
0
 /**
  * {@inheritdoc}
  * Overridden method to decode JSON to array instead of stdClass.
  *
  * @param  string        $resp
  * @return object|string
  */
 protected function processResponseBody($resp)
 {
     if ($this->parse_body === true) {
         if (isset($resp['headers']['Content-Type'])) {
             $contentType = preg_split('/[;\\s]+/', $resp['headers']['Content-Type']);
             $contentType = $contentType[0];
         } else {
             $contentType = null;
         }
         if (null !== $contentType && !empty($contentType)) {
             if (in_array($contentType, self::$JSON_TYPES) || strpos($contentType, '+json') !== false) {
                 $this->log('Response body is JSON');
                 $resp['body_raw'] = $resp['body'];
                 $resp['body'] = json_decode($resp['body'], true);
                 return $resp;
             }
             parent::processResponseBody($resp);
         }
     }
     $this->log('Response body not parsed');
     return $resp;
 }