Exemplo n.º 1
0
 /**
  * @param string $url
  * @param string $method
  * @param array $queryData
  * @param array $postData
  * @param null $contentType
  * @param array $arrHeaders
  * @return string
  * @throws \LogicException
  * @throws HttpException
  */
 protected function makeRequest($url, $method = null, array $queryData = array(), array $postData = array(), $contentType = null, array $arrHeaders = array())
 {
     if (null == $method) {
         if ($this->authType == self::AUTH_TYPE_REQUEST) {
             $method = 'post';
         } else {
             $method = 'get';
         }
     }
     $this->prepareRequest($arrHeaders, $postData);
     switch ($method) {
         case 'post':
             $json = $this->httpClient->post($url, $queryData, $postData, $contentType, $arrHeaders);
             break;
         case 'get':
             $json = $this->httpClient->get($url, $queryData, $arrHeaders);
             break;
         case 'delete':
             $json = $this->httpClient->delete($url, $queryData, $arrHeaders);
             break;
         default:
             throw new \LogicException(sprintf("Unsupported HTTP method '%s'", $method));
     }
     if ($this->httpClient->getStatusCode() != HttpStatusCode::OK) {
         throw new HttpException($this->httpClient->getStatusCode(), $json);
     }
     return $json;
 }