Example #1
0
 /**
  *
  * @param string $shortUrl
  *
  * @throws Exception
  * @return string
  */
 public function expand($shortUrl)
 {
     $this->init();
     $url = Zend_Uri::factory(self::ENDPOINT_URL . '/v3/expand');
     $client = $this->getHttpClient();
     $response = $client->setUri($url)->setParameterPost('format', 'json')->setParameterPost('access_token', $this->getToken())->setParameterPost('shortUrl', $shortUrl)->request('POST');
     if ($response->isError()) {
         throw new Exception('HTTP Error: ' . $response->getStatus() . ' ' . $response->getMessage());
     }
     Mage::log($response->getBody(), Zend_Log::DEBUG);
     $jsonResponse = new Varien_Object(Zend_Json::decode($response->getBody()));
     if ($jsonResponse->getStatusCode() != '200') {
         throw new Exception('Bitly Error: ' . $jsonResponse->getStatusCode() . ' ' . $jsonResponse->getStatusTxt());
     }
     $this->_lastResponse = new Varien_Object($jsonResponse->getData('data'));
     // attention: Bitly return a key 'data'
     return $this->_lastResponse->getLongUrl();
 }