Beispiel #1
0
 function testExecute_ThrowsWithBadUrl()
 {
     $this->api->setEndpointUrl('http://example.com/BAD/');
     $req = new Phlickr_Request($this->api, 'flickr.test.echo');
     try {
         $result = $req->execute();
     } catch (Phlickr_ConnectionException $ex) {
         $this->assertEquals(array(), $this->reqInvalid->getParams());
         return;
     } catch (Exception $ex) {
         $this->fail('threw the wrong type (' . get_class($ex) . ') of exception.');
     }
     $this->Fail('An exception should have been thrown.');
 }
 function __construct(Phlickr_Api $api, $totalPhotos, $perPage)
 {
     parent::__construct($api, 'MOCK PHOTOLIST REQUEST');
     $this->perPage = (int) $perPage;
     $this->totalPhotos = (int) $totalPhotos;
     $this->totalPages = (int) ($totalPhotos / $perPage) + 1;
 }
Beispiel #3
0
 /**
  * Upload a photo to Flickr.
  *
  * If tags are specified, they'll be appended to those listed in getTags().
  * If permissions are specified, they'll override those set by setPerms().
  *
  * The permissions assigned will based on those set using setPerms().
  *
  * @param   string $fullFilePath Full path and file name of the photo.
  * @param   string $title Photo title.
  * @param   string $desc Photo description.
  * @param   string|array $tags A space separated list of tags to add to the photo.
  *          These will be added to those listed in getTags().
  * @return  string id of the new photo
  * @throws  Phlickr_ConnectionException
  * @see     isForPublic(), isForFriends(), isForFamily(), getTags()
  */
 public function upload($fullFilePath, $title = '', $desc = '', $tags = '')
 {
     if (!file_exists($fullFilePath) || !is_readable($fullFilePath)) {
         throw new Phlickr_Exception("The file '{$fullFilePath}' does not exist or can not be accessed.");
     }
     // concat the class's tags with this photos.
     if (is_array($tags)) {
         $tags = '"' . implode('" "', $this->_tags + $tags) . '"';
     } elseif ($tags) {
         $tags = '"' . implode('" "', $this->_tags) . '" ' . (string) $tags;
     } else {
         $tags = '';
     }
     // get the parameters ready for signing ...
     $params = array_merge($this->_api->getParamsForRequest(), array('title' => $title, 'description' => $desc, 'tags' => $tags, 'is_public' => (int) $this->_forPublic, 'is_friend' => (int) $this->_forFriends, 'is_family' => (int) $this->_forFamily));
     // ... compute a signature ...
     ksort($params);
     $signing = '';
     foreach ($params as $key => $value) {
         $signing .= $key . $value;
     }
     $params['api_sig'] = md5($this->_api->getSecret() . $signing);
     // ... then put in the photo. the @ tells CURL to upload the file's
     // contents
     $params['photo'] = '@' . $fullFilePath;
     // use the requst to submit
     $result = Phlickr_Request::SubmitHttpPost(self::UPLOAD_URL, $params, self::TIMEOUT);
     // use the reponse object to parse the results
     $resp = new Phlickr_Response($result, true);
     // return a photo id
     return (string) $resp->getXml()->photoid;
 }
Beispiel #4
0
 function testExecute_FromCache()
 {
     $xml = TESTING_RESP_OK_PREFIX . TESTING_XML_ECHO . TESTING_RESP_SUFIX;
     $request = new Phlickr_Request($this->api, 'NOT_A_REAL_METHOD', array('foo' => 'bar'));
     $this->api->getCache()->set($request->buildUrl(), $xml);
     $expected = new Phlickr_Response($xml);
     $actual = $request->execute(true);
     $this->assertEquals($expected->xml, $actual->xml, "Returned response didn't match the exepect cache value");
 }
Beispiel #5
0
 /**
  * @param $group_id
  * @param $photo_id
  * @return string
  * @throws Phlickr_ConnectionException
  */
 public function addToGroup($group_id, $photo_id)
 {
     $url = $this->buildPhotoAddUrl($group_id);
     $params = array_merge($this->_api->getParamsForRequest(), ['photo_id' => $photo_id, 'group_id' => $group_id, 'method' => 'flickr.groups.pools.add']);
     $signing = '';
     ksort($params);
     foreach ($params as $key => $value) {
         $signing .= $key . $value;
     }
     $params['api_sig'] = md5($this->_api->getSecret() . $signing);
     // use the requst to submit
     $result = Phlickr_Request::SubmitHttpPost($url, $params, self::TIMEOUT);
     return $result;
 }
Beispiel #6
0
 /**
  * Create a mock Request that returns the provided xml
  *
  * @param object Phlickr_Api.
  * @param string the name of the method.
  * @param string the xml to return.
  */
 function __construct(Phlickr_Api $api, $method, $xmlToReturn)
 {
     parent::__construct($api, $method);
     $this->xmlToReturn = (string) $xmlToReturn;
 }
Beispiel #7
0
 /**
  * Build a URL to request a token.
  *
  * If a frob is omitted it is assumed that you've registered a callback URL
  * as per the Flickr documentation.
  *
  * @param   string $perms The desired permissions 'read', 'write', or
  *          'delete'.
  * @param   string $frob optional Frob
  * @return  void
  * @see     requestFrob()
  * @since   0.2.3
  * @uses    Phlickr_Request::signParams() to create a signed URL.
  */
 function buildAuthUrl($perms, $frob = '')
 {
     $params = array('api_key' => $this->getKey(), 'perms' => $perms);
     if ($frob != '') {
         $params['frob'] = (string) $frob;
     }
     return 'http://flickr.com/services/auth/?' . Phlickr_Request::signParams($this->getSecret(), $params);
 }