You are here

function piwik_stats_api_request in Piwik Statistic Integration 7.2

Same name and namespace in other branches
  1. 7 piwik_stats.module \piwik_stats_api_request()

Sends a Piwik API request.

Parameters

string $piwik_url: URL to piwik.

string $token_auth: Authentication token needed to authenticate with piwik.

string $method: Piwik API request method.

int $site_id: Unique site ID of piwik.

string $period: Statistical period. Default is 'year' but also 'day', 'week' or 'month' is possible.

int $date: Statistic base date.

string $format: API return format. Default is XML but also CSV, TSV and JSON is possible.

Return value

object The returned object of drupal_http_request().

1 call to piwik_stats_api_request()
piwik_stats_get_xml_data in ./piwik_stats.module
Get statistical XML data (either by fresh request or cached).

File

./piwik_stats.module, line 689
Integrates piwik statistics as entity fields.

Code

function piwik_stats_api_request($piwik_url, $token_auth, $method, $site_id, $period = 'year', $date = 'now', $format = 'xml') {

  // Send off the API request.
  return drupal_http_request(url($piwik_url, array(
    'query' => array(
      'module' => 'API',
      'method' => $method,
      'idSite' => $site_id,
      'period' => $period,
      'date' => $date,
      'format' => $format,
      'token_auth' => $token_auth,
      'expanded' => TRUE,
      'filter_limit' => -1,
    ),
  )), array(
    'timeout' => variable_get('piwik_stats_request_timeout', 30),
  ));
}