protected function _query($type)
 {
     //perform request
     $response = $this->_client->request();
     // check if authentified
     Sh404sefHelperAnalytics::verifyAuthResponse($response);
     // analyze response
     $parser = new DOMDocument();
     $parser->loadXML($response->getBody());
     $this->_rawData[$type] = $parser->getElementsByTagName('entry');
     $this->_decodeXml($type);
 }
 protected function _fetchAccountsList()
 {
     $hClient =& Sh404sefHelperAnalytics::getHttpClient();
     $hClient->resetParameters($clearAll = true);
     // set target API url
     $hClient->setUri($this->_endPoint . 'accounts/default');
     // make sure we use GET
     $hClient->setMethod(Sh_Zend_Http_Client::GET);
     // set headers required by Google Analytics
     $headers = array('GData-Version' => 2, 'Authorization' => 'GoogleLogin auth="' . $this->_Auth . '"');
     $hClient->setHeaders($headers);
     //perform request
     // establish connection with available methods
     $adapters = array('Sh_Zend_Http_Client_Adapter_Curl', 'Sh_Zend_Http_Client_Adapter_Socket');
     $rawResponse = null;
     // perform connect request
     foreach ($adapters as $adapter) {
         try {
             $hClient->setAdapter($adapter);
             $response = $hClient->request();
             break;
         } catch (Exception $e) {
             // need that to be Exception, so as to catch Sh_Zend_Exceptions.. as well
             // we failed, let's try another method
         }
     }
     // return if error
     if (empty($response)) {
         $msg = 'unknown code';
         throw new Sh404sefExceptionDefault(JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', $msg));
     }
     if (empty($response) || !is_object($response) || $response->isError()) {
         $msg = method_exists($response, 'getStatus') ? $response->getStatus() : 'unknown code';
         throw new Sh404sefExceptionDefault(JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', $msg));
     }
     // analyze response
     // check if authentified
     Sh404sefHelperAnalytics::verifyAuthResponse($response);
     $xml = simplexml_load_string($response->getBody());
     if (!empty($xml->entry)) {
         foreach ($xml->entry as $entry) {
             $account = new StdClass();
             $accId = explode(':', (string) $entry->id);
             $account->id = array_pop($accId);
             $account->title = (string) $entry->title;
             $this->_accounts[] = clone $account;
         }
     }
 }
Пример #3
0
 protected function _fetchAccountsList()
 {
     $hClient = Sh404sefHelperAnalytics::getHttpClient();
     $hClient->resetParameters($clearAll = true);
     // build the request
     $sefConfig = Sh404sefFactory::getConfig();
     $accountIdBits = explode('-', trim($sefConfig->analyticsId));
     if (empty($accountIdBits) || count($accountIdBits) < 3) {
         throw new Sh404sefExceptionDefault(JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', 'Invalid account Id'));
     }
     $accoundId = $accountIdBits[1];
     // set target API url
     $hClient->setUri($this->_endPoint . 'management/accounts/' . $accoundId . '/webproperties/' . trim($sefConfig->analyticsId) . '/profiles?key=' . $this->_getAppKey());
     // make sure we use GET
     $hClient->setMethod(Zendshl_Http_Client::GET);
     // set headers required by Google Analytics
     $headers = array('GData-Version' => 2, 'Authorization' => 'GoogleLogin auth=' . $this->_Auth);
     $hClient->setHeaders($headers);
     //perform request
     // establish connection with available methods
     $adapters = array('Zendshl_Http_Client_Adapter_Curl', 'Zendshl_Http_Client_Adapter_Socket');
     $rawResponse = null;
     // perform connect request
     foreach ($adapters as $adapter) {
         try {
             $hClient->setAdapter($adapter);
             $response = $hClient->request();
             break;
         } catch (Exception $e) {
             // we failed, let's try another method
         }
     }
     // return if error
     if (empty($response)) {
         $msg = 'unknown code';
         throw new Sh404sefExceptionDefault(JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', $msg));
     }
     if (empty($response) || !is_object($response) || $response->isError()) {
         $msg = method_exists($response, 'getStatus') ? $response->getStatus() : 'unknown code';
         throw new Sh404sefExceptionDefault(JText::sprintf('COM_SH404SEF_ERROR_CHECKING_ANALYTICS', $msg));
     }
     // analyze response
     // check if authentified
     Sh404sefHelperAnalytics::verifyAuthResponse($response);
     $xml = simplexml_load_string($response->getBody());
     if (!empty($xml->entry)) {
         foreach ($xml->entry as $entry) {
             $account = new StdClass();
             $bits = explode('/', (string) $entry->id);
             $account->id = array_pop($bits);
             $account->title = str_replace('Google Analytics Profile ', '', (string) $entry->title);
             $this->_accounts[] = clone $account;
         }
     }
 }