public function AddThis::fetch in Drupal Most Popular 6
Makes a generic call to the AddThis.com server.
See http://www.addthis.com/help/analytics-api
Parameters
string $dimension: The dimension we're interested in. It must be null or one of:
- content
- continent
- country
- domain
- service
string $format: The format to return results, either 'csv' or 'json'.
string $params: Additional parameters to send. The following are allowed:
- pubid: The publisher profile for which you're requesting data.
Can be omitted if you have only one profile.
- Modified in Settings form
- period: 'day', 'week' or 'month'
- domain: any URL domain
- service: 'email'
- url: Collect response data only for the specified url.
1 call to AddThis::fetch()
- AddThis::fetchCSV in modules/
mostpopular_addthis/ mostpopular_addthis.classes.inc - Makes a call to the AddThis.com server and parses the CSV response.
File
- modules/
mostpopular_addthis/ mostpopular_addthis.classes.inc, line 63 - Provides a connector to the AddThis.com API.
Class
- AddThis
- @file Provides a connector to the AddThis.com API.
Code
public function fetch($dimension = '', $format = 'csv', $params = array()) {
if (empty($this->username) || empty($this->password)) {
drupal_set_message(t('You must configure the AddThis.com username and password'), 'error');
return NULL;
}
if (isset($this->pubid)) {
// add pubid to params
$params['pubid'] = $this->pubid;
}
// Create the URL
$auth = $this->username . ':' . $this->password . '@';
$url = self::data_url;
if (!empty($dimension)) {
$url .= '/' . $dimension;
}
$url .= '.' . $format;
// Clean up the URL and add query parameters
$request_url = url(self::data_scheme . $auth . $url, array(
'query' => $params,
));
$this->result = drupal_http_request($request_url);
if (isset($this->result->error)) {
drupal_set_message(t("Error connecting to AddThis.com service.<br/>!url<br/>@code @error", array(
'!url' => url(self::data_scheme . $url, array(
'query' => $params,
)),
'@code' => $this->result->code,
'@error' => $this->result->error,
)), 'error');
return NULL;
}
return $this->result->data;
}