Skip to content

Commit

Permalink
Merge pull request #15 from samwilson/photosets-getphotos
Browse files Browse the repository at this point in the history
Fix up photosets.getPhotos
  • Loading branch information
samwilson committed Jan 20, 2019
2 parents 2e7ca25 + 8f42723 commit 6dcc438
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -5,11 +5,11 @@ php:
- '7.2'

install:
- echo "<?php \$apiKey = '$FLICKR_API_KEY'; \$apiSecret = '$FLICKR_API_SECRET';" > tests/config.php;
- echo "<?php \$apiKey = '$FLICKR_API_KEY'; \$apiSecret = '$FLICKR_API_SECRET'; \$accessToken = '$FLICKR_ACCESS_KEY'; \$accessTokenSecret = '$FLICKR_ACCESS_SECRET';" > tests/config.php;
- composer install

script:
- composer validate
- ./vendor/bin/minus-x check . -q
- ./vendor/bin/phpunit --exclude-group auth
- ./vendor/bin/phpunit
- git status | grep "nothing to commit, working tree clean"
4 changes: 2 additions & 2 deletions examples/get_auth_token.php
Expand Up @@ -28,7 +28,7 @@

if (!isset($_GET['oauth_token'])) {
$callbackHere = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$url = $flickr->getAuthUrl('write', $callbackHere);
$url = $flickr->getAuthUrl('delete', $callbackHere);
echo "<a href='$url'>$url</a>";
}

Expand All @@ -42,7 +42,7 @@
$storage = new \OAuth\Common\Storage\Memory();
$flickr->setOauthStorage($storage);

$url = $flickr->getAuthUrl('write');
$url = $flickr->getAuthUrl('delete');
echo "Go to $url\nEnter access code: ";
$code = fgets(STDIN);
$verifier = preg_replace('/[^0-9]/', '', $code);
Expand Down
28 changes: 28 additions & 0 deletions src/PhotosApi.php
Expand Up @@ -71,6 +71,15 @@ public function addTags($photoId, $tags)
], true);
}

//flickr.photos.delete
//flickr.photos.getAllContexts
//flickr.photos.getContactsPhotos
//flickr.photos.getContactsPublicPhotos
//flickr.photos.getContext
//flickr.photos.getCounts
//flickr.photos.getExif
//flickr.photos.getFavorites

/**
* Get information about a photo. The calling user must have permission to view the photo.
* @link https://www.flickr.com/services/api/flickr.photos.getInfo.html
Expand All @@ -87,6 +96,11 @@ public function getInfo($photoId, $secret = null)
return isset($response['photo']) ? $response['photo'] : false;
}

//flickr.photos.getInfo
//flickr.photos.getNotInSet
//flickr.photos.getPerms
//flickr.photos.getPopular

/**
* Get information about the sets to which the given photos belong.
* @param int[] $photoIds The photo IDs to look for.
Expand Down Expand Up @@ -191,4 +205,18 @@ public function getRecent($extras = [], $perPage = null, $page = null)
$result = $this->flickr->request('flickr.photos.getRecent', $args);
return isset($result['photos']['photo']) ? $result['photos']['photo'] : false;
}

//flickr.photos.getUntagged
//flickr.photos.getWithGeoData
//flickr.photos.getWithoutGeoData
//flickr.photos.recentlyUpdated
//flickr.photos.removeTag
//flickr.photos.search
//flickr.photos.setContentType
//flickr.photos.setDates
//flickr.photos.setMeta
//flickr.photos.setPerms
//flickr.photos.setSafetyLevel
//flickr.photos.setTags

}
45 changes: 44 additions & 1 deletion src/PhotosetsApi.php
Expand Up @@ -171,7 +171,50 @@ public function getList(
return isset($response['photosets']) ? $response['photosets'] : false;
}

//flickr.photosets.getPhotos
/**
* Get the list of photos in a set.
*
* @param int $photosetId The photoset ID.
* @param string $userId The owner of the photo set.
* @param string|string[] $extras Extra information to fetch for each photo. Comma-delimited string or array of
* strings. Possible values: license, date_upload, date_taken, owner_name, icon_server, original_format,
* last_update, geo, tags, machine_tags, o_dims, views, media, path_alias, url_sq, url_t, url_s, url_m, and url_o.
* @param int $perPage The number of results per page. Default and maximum are 500.
* @param int $page Which page of results to return.
* @param int $privacyFilter Return photos matching one of the following privacy levels:
* 1 public photos;
* 2 private photos visible to friends;
* 3 private photos visible to family;
* 4 private photos visible to friends & family;
* 5 completely private photos.
* @param string $media Filter results by media type. One of 'all', 'photos', or 'videos'.
* @return array[]|bool
*/
public function getPhotos(
$photosetId,
$userId = null,
$extras = null,
$perPage = null,
$page = null,
$privacyFilter = null,
$media = null
) {
if (is_array($extras)) {
$extras = join(',', $extras);
}
$args= [
'photoset_id' => $photosetId,
'user_id' => $userId,
'extras' => $extras,
'per_page' => $perPage,
'page' => $page,
'privacy_filter' => $privacyFilter,
'media' => $media,
];
$response = $this->flickr->request('flickr.photosets.getPhotos', $args);
return isset($response['photoset']) ? $response['photoset'] : false;
}

//flickr.photosets.orderSets
//flickr.photosets.removePhoto
//flickr.photosets.removePhotos
Expand Down
6 changes: 4 additions & 2 deletions src/PhpFlickr.php
Expand Up @@ -1550,10 +1550,12 @@ public function photosets_getList($user_id = null, $page = null, $per_page = nul
return $this->photosets()->getList($user_id, $page, $per_page, $primary_photo_extras);
}

/**
* @deprecated
*/
public function photosets_getPhotos($photoset_id, $extras = null, $privacy_filter = null, $per_page = null, $page = null, $media = null)
{
/* https://www.flickr.com/services/api/flickr.photosets.getPhotos.html */
return $this->call('flickr.photosets.getPhotos', array('photoset_id' => $photoset_id, 'extras' => $extras, 'privacy_filter' => $privacy_filter, 'per_page' => $per_page, 'page' => $page, 'media' => $media));
return $this->photosets()->getPhotos($photoset_id, null, $extras, $per_page, $page, $privacy_filter, $media);
}

public function photosets_orderSets($photoset_ids)
Expand Down
2 changes: 1 addition & 1 deletion tests/ApiMethodGroup/PhotosApiTest.php
Expand Up @@ -13,7 +13,7 @@ class PhotosApiTest extends TestCase
public function testAddTags()
{
$flickr = $this->getFlickr(true);
$testFilename = dirname(__DIR__, 2).'/examples/Agateware_Example.JPG';
$testFilename = dirname(__DIR__).'/../examples/Agateware_Example.JPG';
$photo = $flickr->uploader()->upload($testFilename);

// Add a string of tags.
Expand Down
41 changes: 41 additions & 0 deletions tests/ApiMethodGroup/PhotosetsApiTest.php
@@ -0,0 +1,41 @@
<?php

namespace Samwilson\PhpFlickr\Tests\ApiMethodGroup;

use Samwilson\PhpFlickr\Tests\TestCase;

class PhotosetsApiTest extends TestCase
{

protected $testPhotoId;

public function setUp()
{
parent::setUp();
$flickr = $this->getFlickr(true);
$testFilename = dirname(__DIR__).'/../examples/Agateware_Example.JPG';
$uploaded = $flickr->uploader()->upload($testFilename);
$this->testPhotoId = $uploaded['photoid'];
}

public function tearDown()
{
$this->getFlickr(true)->photos_delete($this->testPhotoId);
}

public function testCreate()
{
$flickr = $this->getFlickr(true);
$photoset = $flickr->photosets()->create('Test album', 'The description.', $this->testPhotoId);
static::assertEquals(['id', 'url'], array_keys($photoset));
$photos = $flickr->photosets()->getPhotos($photoset['id']);
static::assertCount(1, $photos['photo']);
static::assertEquals($this->testPhotoId, $photos['photo'][0]['id']);
}

public function testAddPhotoToNoneExistantPhotoset()
{
static::expectExceptionMessage('Photoset not found');
$this->getFlickr(true)->photosets()->addPhoto('xxx', $this->testPhotoId);
}
}
13 changes: 10 additions & 3 deletions tests/TestCase.php
Expand Up @@ -9,6 +9,9 @@
abstract class TestCase extends PhpUnitTestCase
{

/** @var PhpFlickr */
private $flickr;

/**
* Get an instance of PhpFlickr, configured by the config.php file in the tests directory.
* @param bool $authenticate Whether to authenticate the user with the access token, if it's
Expand All @@ -17,17 +20,21 @@ abstract class TestCase extends PhpUnitTestCase
*/
public function getFlickr($authenticate = false)
{
if ($this->flickr instanceof PhpFlickr) {
return $this->flickr;
}

require __DIR__.'/config.php';
$flickr = new PhpFlickr($apiKey, $apiSecret);
$this->flickr = new PhpFlickr($apiKey, $apiSecret);

// Authenticate?
if ($authenticate && isset($accessToken) && isset($accessTokenSecret)) {
$token = new StdOAuth1Token();
$token->setAccessToken($accessToken);
$token->setAccessTokenSecret($accessTokenSecret);
$flickr->getOauthTokenStorage()->storeAccessToken('Flickr', $token);
$this->flickr->getOauthTokenStorage()->storeAccessToken('Flickr', $token);
}

return $flickr;
return $this->flickr;
}
}

0 comments on commit 6dcc438

Please sign in to comment.