Source for file adsense.php
Documentation is available at adsense.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
* @license GNU General Public License version 2 or later; see LICENSE
* Google Adsense data class for the Joomla Platform.
* @package Joomla.Platform
* @param JRegistry $options Google options object
* @param JGoogleAuth $auth Google data http client object
public function __construct(JRegistry $options =
null, JGoogleAuth $auth =
null)
if (isset
($this->auth) &&
!$this->auth->getOption('scope'))
$this->auth->setOption('scope', 'https://www.googleapis.com/auth/adsense');
* Method to get an Adsense account's settings from Google
* @param string $accountID ID of account to get
* @param boolean $subaccounts Include list of subaccounts
* @return mixed Data from Google
public function getAccount($accountID, $subaccounts =
true)
$url =
'https://www.googleapis.com/adsense/v1.1/accounts/' .
urlencode($accountID) .
($subaccounts ?
'?tree=true' :
'');
$jdata =
$this->query($url);
throw
new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.
");
* Method to retrieve a list of AdSense accounts from Google
* @param array $options Search settings
* @param int $maxpages Maximum number of pages of accounts to return
* @return mixed Data from Google
* @throws UnexpectedValueException
public function listAccounts($options =
array(), $maxpages =
1)
$next =
array_key_exists('nextPageToken', $options) ?
$options['nextPage'] :
null;
unset
($options['nextPageToken']);
$url =
'https://www.googleapis.com/adsense/v1.1/accounts?' .
http_build_query($options);
* Method to retrieve a list of AdSense clients from Google
* @param string $accountID ID of account to list the clients from
* @param array $options Search settings
* @param int $maxpages Maximum number of pages of accounts to return
* @return mixed Data from Google
* @throws UnexpectedValueException
public function listClients($accountID, $options =
array(), $maxpages =
1)
$next =
array_key_exists('nextPageToken', $options) ?
$options['nextPage'] :
null;
unset
($options['nextPageToken']);
$url =
'https://www.googleapis.com/adsense/v1.1/accounts/' .
urlencode($accountID) .
'/adclients?' .
http_build_query($options);
* Method to get an AdSense AdUnit
* @param string $accountID ID of account to get
* @param string $adclientID ID of client to get
* @param string $adunitID ID of adunit to get
* @return mixed Data from Google
public function getUnit($accountID, $adclientID, $adunitID)
$url =
'https://www.googleapis.com/adsense/v1.1/accounts/' .
urlencode($accountID);
$jdata =
$this->query($url);
throw
new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.
");
* Method to retrieve a list of AdSense Custom Channels for a specific Adunit
* @param string $accountID ID of account
* @param string $adclientID ID of client
* @param string $adunitID ID of adunit to list channels from
* @param array $options Search settings
* @param int $maxpages Maximum number of pages of accounts to return
* @return mixed Data from Google
* @throws UnexpectedValueException
public function listUnitChannels($accountID, $adclientID, $adunitID, $options =
array(), $maxpages =
1)
$next =
array_key_exists('nextPageToken', $options) ?
$options['nextPage'] :
null;
unset
($options['nextPageToken']);
$url =
'https://www.googleapis.com/adsense/v1.1/accounts/' .
urlencode($accountID);
* Method to get an Adsense Channel
* @param string $accountID ID of account to get
* @param string $adclientID ID of client to get
* @param string $channelID ID of channel to get
* @return mixed Data from Google
public function getChannel($accountID, $adclientID, $channelID)
$url =
'https://www.googleapis.com/adsense/v1.1/accounts/' .
urlencode($accountID) .
'/adclients/';
$jdata =
$this->query($url);
throw
new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.
");
* Method to retrieve a list of AdSense Custom Channels
* @param string $accountID ID of account
* @param string $adclientID ID of client to list channels from
* @param array $options Search settings
* @param int $maxpages Maximum number of pages of accounts to return
* @return mixed Data from Google
* @throws UnexpectedValueException
public function listChannels($accountID, $adclientID, $options =
array(), $maxpages =
1)
$next =
array_key_exists('nextPageToken', $options) ?
$options['nextPage'] :
null;
unset
($options['nextPageToken']);
$url =
'https://www.googleapis.com/adsense/v1.1/accounts/' .
urlencode($accountID) .
'/adclients/' .
urlencode($adclientID);
* Method to retrieve a list of AdSense Adunits for a specific Custom Channel
* @param string $accountID ID of account
* @param string $adclientID ID of client
* @param string $channelID ID of channel to list units from
* @param array $options Search settings
* @param int $maxpages Maximum number of pages of accounts to return
* @return mixed Data from Google
* @throws UnexpectedValueException
public function listChannelUnits($accountID, $adclientID, $channelID, $options =
array(), $maxpages =
1)
$next =
array_key_exists('nextPageToken', $options) ?
$options['nextPage'] :
null;
unset
($options['nextPageToken']);
$url =
'https://www.googleapis.com/adsense/v1.1/accounts/' .
urlencode($accountID) .
'/adclients/' .
urlencode($adclientID);
* Method to generate a report from Google AdSense
* @param string $accountID ID of account
* @param string $adclientID ID of client
* @param array $options Search settings
* @param int $maxpages Maximum number of pages of accounts to return
* @return mixed Data from Google
* @throws UnexpectedValueException
public function listUrlChannels($accountID, $adclientID, $options =
array(), $maxpages =
1)
$next =
array_key_exists('nextPageToken', $options) ?
$options['nextPage'] :
null;
unset
($options['nextPageToken']);
$url =
'https://www.googleapis.com/adsense/v1.1/accounts/' .
urlencode($accountID);
* Method to retrieve a list of AdSense Channel URLs
* @param string $accountID ID of account
* @param mixed $start Start day
* @param mixed $end End day
* @param array $options Search settings
* @param int $maxpages Maximum number of pages of accounts to return
* @return mixed Data from Google
* @throws UnexpectedValueException
public function generateReport($accountID, $start, $end =
false, $options =
array(), $maxpages =
1)
$startobj =
new DateTime;
$startobj->setTimestamp($start);
$startobj =
new DateTime($start);
elseif (is_a($start, 'DateTime'))
throw
new InvalidArgumentException('Invalid start time.');
$endobj->setTimestamp($end);
$endobj =
new DateTime($end);
elseif (is_a($end, 'DateTime'))
throw
new InvalidArgumentException('Invalid end time.');
$options['startDate'] =
$startobj->format('Y-m-d');
$options['endDate'] =
$endobj->format('Y-m-d');
unset
($options['startIndex']);
$url =
'https://www.googleapis.com/adsense/v1.1/accounts/' .
urlencode($accountID) .
'/reports?' .
http_build_query($options);
$jdata =
$this->query($url .
'startIndex=' .
count($data['rows']));
$newdata['rows'] =
array_merge($data['rows'], $newdata['rows']);
throw
new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.
");
while (count($data['rows']) <
$data['totalMatchedRows'] &&
$i <
$maxpages);
Documentation generated on Tue, 19 Nov 2013 14:53:37 +0100 by phpDocumentor 1.4.3