Ejemplo n.º 1
0
 /**
  * Send a request to the server, receive a response
  *
  * @param  string $url Request url
  * @param string $method HTTP method to use
  * @param array $parameters Parameters
  *
  * @return array HTTP response
  */
 public function makeRequest($url, $method = 'GET', array $parameters = array())
 {
     //Set cURL options
     $this->curl_opts[CURLOPT_URL] = $url;
     $this->curl_opts[CURLOPT_HTTPHEADER] = $this->headers->getHeaders();
     // Prepare Data
     if (!empty($parameters)) {
         switch ($method) {
             case 'POST':
                 $this->curl_opts[CURLOPT_POST] = true;
                 $this->curl_opts[CURLOPT_POSTFIELDS] = Utilities::encodeUrlParam($parameters);
                 break;
             case 'PUT':
                 $file_handle = fopen($parameters, 'r');
                 $this->curl_opts[CURLOPT_PUT] = true;
                 $this->curl_opts[CURLOPT_INFILE] = $file_handle;
                 break;
             case 'DELETE':
                 $this->curl_opts[CURLOPT_CUSTOMREQUEST] = 'delete';
                 break;
         }
     }
     $response = $this->doCurlCall();
     if ($response['response'] === false) {
         throw new RequestException($response['errorMessage'], $response['errorNumber']);
     }
     return $response;
 }
Ejemplo n.º 2
0
 protected function getUrl($path, $queryParams = array())
 {
     $replacements = array();
     $replacements[':protocol'] = $this->client->options->get('protocol');
     $replacements[':region'] = $this->client->options->get('region');
     $replacements[':fullPath'] = $path;
     $url = strtr($this->client->options->get('url'), $replacements);
     //Add locale to query parameters
     $queryParams['locale'] = $this->client->options->get('locale');
     if (!empty($queryParams)) {
         $url .= Utilities::build_http_query($queryParams);
     }
     return $url;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function generatePath($path, $parameters = array())
 {
     $replacements = array();
     foreach ($parameters as $key => $parameter) {
         $replacements[':' . $key] = Utilities::urlencode($parameter);
     }
     return strtr($path, $replacements);
 }