00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_GoogleBase_Model_Service extends Varien_Object
00035 {
00036
00037
00038
00039
00040
00041 public function getClient($storeId = null, $loginToken = null, $loginCaptcha = null)
00042 {
00043 $user = $this->getConfig()->getAccountLogin($storeId);
00044 $pass = $this->getConfig()->getAccountPassword($storeId);
00045
00046
00047 $errorMsg = Mage::helper('googlebase')->__('Unable to connect to Google Base. Please, check Account settings in configuration.');
00048 try {
00049 $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, Zend_Gdata_Gbase::AUTH_SERVICE_NAME, null, '', $loginToken, $loginCaptcha);
00050 } catch (Zend_Gdata_App_CaptchaRequiredException $e) {
00051 throw $e;
00052 } catch (Zend_Gdata_App_HttpException $e) {
00053 Mage::throwException($errorMsg . Mage::helper('googlebase')->__('Error: %s', $e->getMessage()));
00054 } catch (Zend_Gdata_App_AuthException $e) {
00055 Mage::throwException($errorMsg . Mage::helper('googlebase')->__('Error: %s', $e->getMessage()));
00056 }
00057
00058 return $client;
00059 }
00060
00061
00062
00063
00064
00065
00066 public function getService($storeId = null)
00067 {
00068 if (!$this->_service) {
00069 $service = $this->_connect($storeId);
00070 $this->_service = $service;
00071 }
00072 return $this->_service;
00073 }
00074
00075
00076
00077
00078
00079
00080 public function getGuestService()
00081 {
00082 return new Zend_Gdata_Gbase(new Zend_Http_Client());
00083 }
00084
00085
00086
00087
00088
00089
00090 public function getConfig()
00091 {
00092 return Mage::getSingleton('googlebase/config');
00093 }
00094
00095
00096
00097
00098
00099
00100 protected function _connect($storeId = null)
00101 {
00102 $client = $this->getClient($storeId);
00103 $service = new Zend_Gdata_Gbase($client);
00104 return $service;
00105 }
00106
00107
00108
00109
00110
00111
00112 public function getDryRun()
00113 {
00114 return $this->getDataSetDefault('dry_run', false);
00115 }
00116 }