You are here

private function gapiRequest::curlRequest in Google Analytics Statistics 7.2

HTTP request using PHP CURL functions Requires curl library installed and configured for PHP

Parameters

Array $get_variables:

Array $post_variables:

Array $headers:

1 call to gapiRequest::curlRequest()
gapiRequest::request in includes/gapi.class.php
Perform http request

File

includes/gapi.class.php, line 749

Class

gapiRequest
Google Analytics API request

Code

private function curlRequest($get_variables = null, $post_variables = null, $headers = null) {
  $ch = curl_init();
  if (is_array($get_variables)) {
    $get_variables = '?' . str_replace('&', '&', urldecode(http_build_query($get_variables, '', '&')));
  }
  else {
    $get_variables = null;
  }
  curl_setopt($ch, CURLOPT_URL, $this->url . $get_variables);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

  //CURL doesn't like google's cert
  if (is_array($post_variables)) {
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_variables, '', '&'));
  }
  if (is_array($headers)) {
    $string_headers = array();
    foreach ($headers as $key => $value) {
      $string_headers[] = "{$key}: {$value}";
    }
    curl_setopt($ch, CURLOPT_HTTPHEADER, $string_headers);
  }
  $response = curl_exec($ch);
  $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  curl_close($ch);
  return array(
    'body' => $response,
    'code' => $code,
  );
}