Example #1
0
 /**
  *	Parses the given response depending on its format.
  *
  *	@param string $response Response.
  *	@param string $format Format.
  *	@return array Data.
  */
 protected function _parse($response, $format)
 {
     switch ($format) {
         case Format::json:
             return Json::parse($response);
         case Format::xml:
             return Xml::parse($response);
         default:
             throw new Exception('Unsupported response format.');
     }
 }
Example #2
0
 /**
  *	Fetches embed information from the given endpoint.
  *
  *	@param string $endpoint Endpoint to fetch informations from.
  *	@param string $format Response format.
  *	@return Media Embed informations.
  */
 protected function _embedEndpoint($endpoint, $format)
 {
     $response = $this->_Http->get($endpoint);
     switch ($format) {
         case self::json:
             $data = Json::parse($response);
             break;
         case self::xml:
             $data = Xml::parse($response);
             break;
         default:
             throw new Exception('Unsupported response format.');
     }
     return new Media(Hash::reindex($data, ['author_name' => 'authorName', 'author_url' => 'authorUrl', 'provider_name' => 'providerName', 'provider_url' => 'providerUrl', 'cache_age' => 'cacheAge', 'thumbnail_url' => 'thumbnailUrl', 'thumbnail_width' => 'thumbnailWidth', 'thumbnail_height' => 'thumbnailHeight']));
 }
 /**
  *
  */
 public function testParseInvalid()
 {
     $this->setExpectedException('Exception');
     Xml::parse($this->invalid);
 }