Пример #1
0
 /**
  * @param array $options
  * @return Robo47_Service_Bitly
  */
 protected function _setupService($options)
 {
     if (!isset($options['login'])) {
         $message = 'No login provided';
         throw new Robo47_Application_Resource_Exception($message);
     }
     if (!isset($options['apiKey'])) {
         $message = 'No apiKey provided';
         throw new Robo47_Application_Resource_Exception($message);
     }
     $bitly = new Robo47_Service_Bitly($options['login'], $options['apiKey']);
     if (isset($options['format'])) {
         $bitly->setFormat($options['format']);
     }
     if (isset($options['resultFormat'])) {
         $bitly->setResultFormat($options['resultFormat']);
     }
     if (isset($options['callback'])) {
         $bitly->setCallback($options['callback']);
     }
     if (isset($options['version'])) {
         $bitly->setVersion($options['version']);
     }
     if (isset($options['registryKey'])) {
         Zend_Registry::set($options['registryKey'], $bitly);
     }
     return $bitly;
 }
Пример #2
0
 /**
  * @covers Robo47_Service_Bitly::_callApi
  * @covers Robo47_Service_Bitly::_getData
  * @covers Robo47_Service_Bitly::shorten
  * @covers Robo47_Service_Bitly::expandByHash
  * @covers Robo47_Service_Bitly::expandByShortUrl
  * @covers Robo47_Service_Bitly::infoByHash
  * @covers Robo47_Service_Bitly::infoByHashWithKeys
  * @covers Robo47_Service_Bitly::infoByShortUrl
  * @covers Robo47_Service_Bitly::infoByShortUrlWithKeys
  * @covers Robo47_Service_Bitly::statsByHash
  * @covers Robo47_Service_Bitly::statsByShortUrl
  * @covers Robo47_Service_Bitly::errors
  * @dataProvider apiMethodsProvider
  */
 public function testApiMethods($method, $params, $format, $resultFormat)
 {
     $service = new Robo47_Service_Bitly('login', 'apiKey', $format, $resultFormat);
     $this->_adapter->setResponse($this->getResponse($format, $method));
     $result = call_user_func_array(array($service, $method), $params);
     $response = $service->getHttpClient()->request()->getBody();
     if ($format == Robo47_Service_Bitly::FORMAT_JSON) {
         if ($resultFormat == Robo47_Service_Bitly::FORMAT_RESULT_NATIVE) {
             $this->assertEquals($result, $response, 'Mismatch of result and response');
         } else {
             if ($resultFormat == Robo47_Service_Bitly::FORMAT_RESULT_ARRAY) {
                 $this->assertEquals($result, json_decode($response, true), 'Mismatch of result and response');
             } else {
                 if ($resultFormat == Robo47_Service_Bitly::FORMAT_RESULT_OBJECT) {
                     $this->assertEquals($result, json_decode($response, false), 'Mismatch of result and response');
                 } else {
                     $this->fail('invalid resultformat: ' . $resultFormat);
                 }
             }
         }
     } else {
         if ($format == Robo47_Service_Bitly::FORMAT_XML) {
             if ($resultFormat == Robo47_Service_Bitly::FORMAT_RESULT_NATIVE) {
                 $this->assertEquals($result, $response, 'Mismatch of result and response');
             } else {
                 if ($resultFormat == Robo47_Service_Bitly::FORMAT_RESULT_ARRAY) {
                     $this->assertEquals($result, $service->xmlToArray($response), 'Mismatch of result and response');
                 } else {
                     if ($resultFormat == Robo47_Service_Bitly::FORMAT_RESULT_OBJECT) {
                         $this->assertEquals($result, $service->xmlToObject($response), 'Mismatch of result and response');
                     } else {
                         $this->fail('invalid resultformat: ' . $resultFormat);
                     }
                 }
             }
         } else {
             $this->fail('invalid format: ' . $format);
         }
     }
 }