/**
  * @covers Bronto_Api::getTokenInfo
  */
 public function testGetTokenInfo()
 {
     $api = new Bronto_Api(TEST_API_TOKEN_1);
     $apiToken = $api->getTokenInfo();
     $this->assertInstanceOf('Bronto_Api_ApiToken_Row', $apiToken);
     $this->assertSame(TEST_API_TOKEN_1, $apiToken->id);
 }
Beispiel #2
0
 /**
  * @see parent
  *
  * @param int $identifier
  * @return bool
  */
 public function attempt($identifier)
 {
     $request = unserialize($this->getObject());
     $api = new Bronto_Api($request->getToken());
     try {
         $this->delete();
         $deliveryOps = $api->transferDelivery();
         foreach ($deliveryOps->createWritePager($request) as $result) {
             $delivery = $result->getOriginal();
             $item = $result->getItem();
             if ($item->getIsError()) {
                 Mage::throwException("Failed to send failed delivery {$item->getErrorString()}");
             }
             if ($delivery->hasEmailClass()) {
                 $delivery->withId($item->getId());
                 $email = Mage::getModel($delivery->getEmailClass());
                 $email->triggerBeforeAfterSend($deliveryOps, $delivery);
             }
         }
     } catch (Exception $e) {
         $this->store($delivery, $request->getToken(), $this->getAttempts() + 1);
         return false;
     }
     return true;
 }
Beispiel #3
0
 /**
  * @see parent
  *
  * @param Bronto_Api $api
  * @param string $sessionId
  */
 public function onAfterLogin($api, $sessionId)
 {
     try {
         $this->setToken($api->getToken())->setSessionId($sessionId)->setCreatedAt(Mage::getSingleton('core/date')->gmtDate())->save();
         Mage::helper('bronto_common')->writeDebug("Initiating API for token: {$this->getToken()}");
     } catch (Exception $e) {
         Mage::helper('bronto_common')->writeError("Failed to update API {$this->getToken()} Session: " . $e->getMessage());
     }
 }
 public function testApiTokenReadPerformance()
 {
     $time = microtime(true);
     for ($i = 0, $iterations = 10; $i < $iterations; $i++) {
         $api = new Bronto_Api(TEST_API_TOKEN_1);
         $apiToken = $api->getApiTokenObject()->createRow();
         $apiToken->id = TEST_API_TOKEN_1;
         $apiToken->read();
     }
     $time = microtime(true) - $time;
     $this->printResults('Bronto_Api_ApiToken_Row::read', $time, $iterations);
 }
Beispiel #5
0
 /**
  * @see parent
  * @param Bronto_Api_Exception $exception
  * @param Bronto_Api $api
  * @param Bronto_Object $request
  * @return boolean
  */
 public function recover(Bronto_Api_Exception $exception, Bronto_Api $api, Bronto_Object $request)
 {
     $canRetry = $exception->getAttempts() < $api->getOptions()->getRetries();
     if ($exception->isRecoverable() && $canRetry) {
         if ($exception->isInvalidSession()) {
             $api->login();
             return true;
         } else {
             if ($exception->isNetworkRelated() && !$request->hasUpdates()) {
                 // Incrementally backoff the read request
                 $backOff = $api->getOptions()->getBackOff() * $exception->getAttempts();
                 sleep($backOff);
                 return true;
             }
         }
     }
     return false;
 }
Beispiel #6
0
 /**
  * @see parent
  *
  * @param Bronto_Api $api
  * @param Bronto_Api_Exception $exception
  */
 public function onError(Bronto_Api $api, Bronto_Api_Exception $exception)
 {
     if ($exception instanceof Bronto_Api_Exception) {
         if ($request = $api->getLastRequest()) {
             Mage::helper('bronto_common')->writeDebug(var_export($request, true));
         }
         if ($response = $api->getLastResponse()) {
             Mage::helper('bronto_common')->writeDebug(var_export($response, true));
         }
     }
 }
Beispiel #7
0
 /**
  * Write the API delivery flush
  *
  * @param Bronto_Api $api
  */
 protected function _flushLogs(Bronto_Api $api)
 {
     $helper = Mage::helper($this->_helper);
     $apiLog = "{$this->_helper}_api.log";
     $helper->writeVerboseDebug("===== {$helper->getName()} Delivery =====", $apiLog);
     $helper->writeVerboseDebug(var_export($api->getLastRequest(), true), $apiLog);
     $helper->writeVerboseDebug(var_export($api->getLastResponse(), true), $apiLog);
 }
Beispiel #8
0
 /**
  * Writes the contact save logs
  *
  * @param Bronto_Api $api
  * @return void
  */
 protected function _flushApiLogs($api)
 {
     $this->writeVerboseDebug('===== CONTACT SAVE =====', 'bronto_common_api.log');
     $this->writeVerboseDebug(var_export($api->getLastRequest(), true), 'bronto_common_api.log');
     $this->writeVerboseDebug(var_export($api->getLastResponse(), true), 'bronto_common_api.log');
 }
 /**
  * @param string $email
  * @param string $list
  */
 public function removeEmailFromList($email, $list)
 {
     $soapClient = $this->brontoAPI->getSoapClient();
     $soapClient->removeFromList(array('contacts' => array('email' => $email), 'list' => array('id' => $list)));
 }