コード例 #1
0
 /**
  * Execute API call and return the response
  *
  * @param $path
  * @param string $method
  * @param array $params
  * @param array $data
  *
  * @return mixed
  */
 public function execute($path, $method = 'GET', array $params = [], $data = [])
 {
     $this->url = $this->httpConfig->getURL($path, $params);
     $client = new GuzzleHttpConnection();
     $response = $client->execute($this->url, $method, static::prepareHeaders($data));
     if ($method == 'GET') {
         self::$totalPageCount = $response->hasHeader('X-Pagination-Page-Count') ? (int) reset($response->getHeader('X-Pagination-Page-Count')) : 1;
     }
     return $this->parseResponse($response);
 }
コード例 #2
0
 /**
  * Execute guzzle method
  *
  * @param $url
  * @param $method
  *
  * @return bool
  * @throws \Exception
  */
 public function execute($url, $method, $headers)
 {
     if (!array_key_exists($method, $this->requestMethods)) {
         throw new \Exception('Undefined method');
     }
     try {
         $options = array_merge(['headers' => $headers['headers'], 'verify' => false], array_key_exists('data', $headers) ? $headers['data'] : []);
         $response = $this->client->request($this->requestMethods[$method], $url, $options);
         if ($response->getStatusCode() != 200 && $response->getStatusCode() != 201 && $response->getStatusCode() != 204) {
             throw new \Exception('Invalid respone code - ' . $response->getStatusCode());
         }
         return $response;
     } catch (RequestException $e) {
         throw new \Exception($e->getMessage());
     }
 }