Skip to content

Commit e939425

Browse files
author
boncey
committed
Add support for 'primary_photo_extras' in 'flickr.photosets.getList'
1 parent 83665c7 commit e939425

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

Flickr4Java/src/main/java/com/flickr4java/flickr/photosets/PhotosetsInterface.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,23 @@ public Photoset getInfo(String photosetId) throws FlickrException {
313313
* @throws FlickrException
314314
*/
315315
public Photosets getList(String userId) throws FlickrException {
316-
return getList(userId, 0, 0);
316+
return getList(userId, 0, 0, null);
317+
}
318+
319+
/**
320+
* Get a list of all photosets for the specified user.
321+
*
322+
* This method does not require authentication. But to get a Photoset into the list, that contains just private photos, the call needs to be authenticated.
323+
*
324+
* @param userId
325+
* The User id
326+
* @param primaryPhotoExtras
327+
* A comma-delimited list of extra information to fetch for the primary photo
328+
* @return The Photosets collection
329+
* @throws FlickrException
330+
*/
331+
public Photosets getList(String userId, String primaryPhotoExtras) throws FlickrException {
332+
return getList(userId, 0, 0, primaryPhotoExtras);
317333
}
318334

319335
/**
@@ -327,10 +343,12 @@ public Photosets getList(String userId) throws FlickrException {
327343
* The number of photosets per page
328344
* @param page
329345
* The page offset
346+
* @param primaryPhotoExtras
347+
* A comma-delimited list of extra information to fetch for the primary photo
330348
* @return The Photosets collection
331349
* @throws FlickrException
332350
*/
333-
public Photosets getList(String userId, int perPage, int page) throws FlickrException {
351+
public Photosets getList(String userId, int perPage, int page, String primaryPhotoExtras) throws FlickrException {
334352
Map<String, Object> parameters = new HashMap<String, Object>();
335353
parameters.put("method", METHOD_GET_LIST);
336354

@@ -346,6 +364,10 @@ public Photosets getList(String userId, int perPage, int page) throws FlickrExce
346364
parameters.put("page", String.valueOf(page));
347365
}
348366

367+
if (primaryPhotoExtras != null) {
368+
parameters.put("primary_photo_extras", primaryPhotoExtras);
369+
}
370+
349371
Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
350372
if (response.isError()) {
351373
throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
@@ -368,7 +390,13 @@ public Photosets getList(String userId, int perPage, int page) throws FlickrExce
368390
owner.setId(photosetElement.getAttribute("owner"));
369391
photoset.setOwner(owner);
370392

371-
Photo primaryPhoto = new Photo();
393+
Element primaryPhotoExtrasEl = XMLUtilities.getChild(photosetElement, "primary_photo_extras");
394+
Photo primaryPhoto;
395+
if (primaryPhotoExtrasEl != null) {
396+
primaryPhoto = PhotoUtils.createPhoto(primaryPhotoExtrasEl);
397+
} else {
398+
primaryPhoto = new Photo();
399+
}
372400
primaryPhoto.setId(photosetElement.getAttribute("primary"));
373401
primaryPhoto.setSecret(photosetElement.getAttribute("secret")); // TODO verify that this is the secret for the photo
374402
primaryPhoto.setServer(photosetElement.getAttribute("server")); // TODO verify that this is the server for the photo

Flickr4Java/src/test/java/com/flickr4java/flickr/test/PhotosetsInterfaceTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.junit.Before;
2121
import org.junit.Test;
2222

23+
import java.util.Collection;
2324
import java.util.Collections;
2425
import java.util.List;
2526

@@ -118,10 +119,17 @@ public void testGetList() throws FlickrException {
118119
}
119120

120121
@Test
121-
public void testGetList2() throws FlickrException {
122+
public void testGetListWithExtras() throws FlickrException {
122123
PhotosetsInterface iface = flickr.getPhotosetsInterface();
123-
Photosets photosets = iface.getList("26095690@N00");
124+
Photosets photosets = iface.getList(testProperties.getNsid(), "last_update, owner_name");
124125
assertNotNull(photosets);
126+
Collection<Photoset> photosetsList = photosets.getPhotosets();
127+
assertFalse(photosetsList.isEmpty());
128+
Photoset photoset = photosetsList.iterator().next();
129+
assertNotNull(photoset.getPrimaryPhoto().getLastUpdate());
130+
assertNotNull(photoset.getPrimaryPhoto().getOwner());
131+
assertNotNull(photoset.getPrimaryPhoto().getOwner().getUsername());
132+
assertTrue(photoset.getPrimaryPhoto().getOwner().getUsername().length() > 0);
125133
}
126134

127135
@Test

0 commit comments

Comments
 (0)