Example #1
0
 public static function getInstance($storeId)
 {
     $createNewInstance = true;
     if (self::$_instance) {
         if (self::$_instance->_client && self::$_instance->_clientStoreId == $storeId) {
             $createNewInstance = false;
         }
     }
     if ($createNewInstance) {
         $instance = new self();
         $instance->setKeys($storeId);
         try {
             $instance->_client = new Zend_XmlRpc_Client($instance->_connect());
         } catch (Exception $e) {
             throw new AW_Core_Exception(Mage::helper('advancednewsletter')->__('Couldn\'t connect to MailChimp'));
         }
         $instance->_clientStoreId = $storeId;
         self::$_instance = $instance;
     }
     return self::$_instance;
 }
 public static function testConnection($params)
 {
     $helper = Mage::helper('advancednewsletter');
     if (!isset($params['apikey'])) {
         throw new AW_Advancednewsletter_Exception($helper->__('Invalid Request. Api key info not found'));
     }
     if (!isset($params['xmlrpc'])) {
         throw new AW_Advancednewsletter_Exception($helper->__('Invalid Request. Xmlrpc info not found'));
     }
     $instance = new self();
     $instance->_keysValues[self::MAILCHIMP_APIKEY] = trim($params['apikey']);
     $instance->_keysValues[self::MAILCHIMP_XMLRPC] = trim($params['xmlrpc']);
     try {
         $client = new Zend_XmlRpc_Client($instance->_connect());
         $client->getHttpClient()->setConfig(array('timeout' => self::REQUEST_TIMEOUT));
         $client->call('chimpChatter', array($instance->_keysValues[self::MAILCHIMP_APIKEY]));
     } catch (Exception $e) {
         throw new AW_Advancednewsletter_Exception($helper->__('Cannot connect to MailChimp'));
     }
 }