/**
  * @param string $service
  * @param array $params
  * @return array
  */
 public function call($service, array $params = array())
 {
     $params['format'] = 'json';
     $params['nojsoncallback'] = 1;
     try {
         $response = $this->httpClient->call($service, $params);
         $this->dieOnErrorResponse($response);
         return $response;
     } catch (\LogicException $e) {
         $msg = $e->getMessage() . "\nTry to run:\nflickr_downloadr authorize";
         throw new \Nette\Security\AuthenticationException($msg);
     }
 }
 /**
  * @param  string $photosetId
  * @param  string $photoId
  *
  * @return void
  */
 public function addPhotoToPhotoset($photosetId, $photoId)
 {
     $addPhotoReturn = $this->flickerApiFactory->call('flickr.photosets.addPhoto', array('photoset_id' => $photosetId, 'photo_id' => $photoId));
     if ($addPhotoReturn['stat']->__toString() === 'ok') {
         return;
     } else {
         if ($addPhotoReturn['stat']->__toString() === 'fail') {
             throw new FlickrException($addPhotoReturn->err['msg']->__toString(), $addPhotoReturn->err['code']->__toString());
         } else {
             throw new FlickrException('Unknown exception');
         }
     }
 }
Example #3
0
 public function testMultiCall()
 {
     $recents_xml = $this->api->call('flickr.photos.getRecent');
     $calls = array();
     foreach ($recents_xml->photos->photo as $photo_metadata_xml) {
         $photo_id = (string) $photo_metadata_xml['id'];
         $calls[] = array('service' => 'flickr.photos.getSizes', 'parameters' => array('photo_id' => $photo_id), 'endpoint' => null);
     }
     $photos_xml = $this->api->multiCall($calls);
     foreach ($photos_xml as $photo_xml) {
         $this->assertInstanceOf('\\SimpleXMLElement', $photo_xml);
         $this->assertObjectNotHasAttribute('err', $photo_xml);
     }
 }
Example #4
0
 /**
  * 写真をFlickrにアップロード
  * @param $picture
  * @param null $title
  * @param null $description
  * @param null $tags
  * @return Flickr
  * @throws FlickrFailedException
  */
 public function uploadFlickr($picture, $title = null, $description = null, $tags = null)
 {
     $metadata = new Metadata(config('const.flickr.apikey'), config('const.flickr.secret'));
     $metadata->setOauthAccess(config('const.flickr.oauth_token'), config('const.flickr.oauth_token_secret'));
     $factory = new ApiFactory($metadata, new GuzzleAdapter());
     $upload = $factory->upload($picture, $title, $description, $tags, true);
     if ((string) $upload->attributes()->stat === 'fail') {
         $errAttr = $upload->err->attributes();
         throw new FlickrFailedException((string) $errAttr->msg, (int) $errAttr->code);
     }
     $getInfo = $factory->call('flickr.photos.getInfo', array('photo_id' => (string) $upload->photoid));
     $photoAttr = $getInfo->photo->attributes();
     $flickr = new Flickr();
     foreach (['id', 'server', 'farm', 'secret'] as $name) {
         $flickr->{'flickr_' . $name} = (string) $photoAttr->{$name};
     }
     $flickr->save();
     return $flickr;
 }
Example #5
0
 /**
  * Get photo info and sizes
  * @since Version 3.5
  * @param int $photo_id
  * @return array
  */
 public function getPhotoLegacy($photo_id = false)
 {
     if (!$photo_id) {
         throw new Exception("Cannot fetch photo info and sizes - no photo ID given");
         return false;
     }
     $mckey = "railpage:railcam.photo.id=" . $photo_id;
     #deleteMemcacheObject($mckey);
     if ($return = getMemcacheObject($mckey)) {
         $return['photo']['time_relative'] = relative_date($return['photo']['dateuploaded']);
         return $return;
     } else {
         $use_rezzza = false;
         if ($use_rezzza) {
             $metadata = new Metadata(RP_FLICKR_API_KEY, RP_FLICKR_API_SECRET);
             $metadata->setOauthAccess($this->flickr_oauth_token, $this->flickr_oauth_secret);
             $factory = new ApiFactory($metadata, new GuzzleAdapter());
             $photo_info = $factory->call('flickr.photos.getInfo', array('photo_id' => $photo_id));
             if ($photo_info) {
                 $photo_sizes = $factory->call('flickr.photos.getSizes', array('photo_id' => $photo_id));
             }
             /**
              * do stuff!
              */
             if ($photo_info && $photo_sizes) {
                 $return = array();
                 /**
                  * Photo info
                  */
                 foreach ($photo_info->photo->attributes() as $a => $b) {
                     $return['photo'][$a] = $b->__toString();
                 }
                 foreach ($photo_info->photo->children() as $element) {
                     foreach ($element->attributes() as $a => $b) {
                         $return['photo'][$element->getName()][$a] = $b->__toString();
                     }
                     foreach ($element->children() as $child) {
                         foreach ($child->attributes() as $a => $b) {
                             $return['photo'][$element->getName()][$child->getName()][$a] = $b->__toString();
                         }
                         foreach ($child->children() as $blah) {
                             $return['photo'][$element->getName()][$child->getName()][$blah->getName()][$a] = $b->__toString();
                             foreach ($blah->attributes() as $a => $b) {
                                 $return['photo'][$element->getName()][$child->getName()][$blah->getName()][$a] = $b->__toString();
                             }
                         }
                     }
                 }
                 /**
                  * Photo sizes
                  */
                 $i = 0;
                 foreach ($photo_sizes->sizes->size as $key => $element) {
                     foreach ($element->attributes() as $a => $b) {
                         $return['photo']['sizes'][$i][$a] = $b->__toString();
                     }
                     $i++;
                 }
             }
             return $return;
         }
         $f = new flickr_railpage(RP_FLICKR_API_KEY);
         $f->oauth_token = $this->flickr_oauth_token;
         $f->oauth_secret = $this->flickr_oauth_secret;
         $f->cache = false;
         $return = array();
         if ($return = $f->photos_getInfo($photo_id)) {
             $return['photo']['sizes'] = $f->photos_getSizes($photo_id);
             $return['photo']['time_relative'] = relative_date($return['photo']['dateuploaded']);
             setMemcacheObject($mckey, $return, strtotime("+2 hours"));
         }
         return $return;
     }
 }