You are here

protected function GoogleAnalyticsCounterFeed::request in Google Analytics Counter 7.3

Execute a query.

1 call to GoogleAnalyticsCounterFeed::request()
GoogleAnalyticsCounterFeed::query in ./google_analytics_counter_oauth2.lib.inc
Public query method for all Core Reporting API features.

File

./google_analytics_counter_oauth2.lib.inc, line 296
Provides the Google Analytics Counter Feed object type and associated methods. Most of the Google Analytics authentication process is taken over from http://drupal.org/project/google_analytics_reports because all we need here is its Google Analytics…

Class

GoogleAnalyticsCounterFeed
GoogleAnalyticsCounterFeed class to authorize access to and request data from the Google Analytics Core Reporting API.

Code

protected function request($url, $params = array(), $headers = array(), $method = 'GET') {
  $options = array(
    'method' => $method,
    'headers' => $headers,
  );
  if (count($params) > 0) {
    if ($method == 'GET') {
      $url .= '?' . drupal_http_build_query($params);
    }
    else {
      $options['data'] = drupal_http_build_query($params);
    }
  }
  $this->response = drupal_http_request($url, $options);
  if ($this->response->code == '200') {
    $this->results = json_decode($this->response->data);
  }
  else {

    // Data is undefined if the connection failed.
    if (!isset($this->response->data)) {
      $this->response->data = '';
    }
    $error_vars = array(
      '@code' => $this->response->code,
      '@message' => $this->response->error,
      '@details' => strip_tags($this->response->data),
    );
    $this->error = t('Code: @code, Error: @message, Message: @details', $error_vars);
    watchdog('Google Analytics Counter', 'Code: @code, Error: @message, Message: @details', $error_vars, WATCHDOG_ERROR);
  }
}