Skip to content

Commit

Permalink
Read 'description' from 'flickr.people.getInfo' response. Fix #139
Browse files Browse the repository at this point in the history
  • Loading branch information
boncey committed Aug 2, 2015
1 parent 7534591 commit 7cf3a6a
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
package com.flickr4java.flickr.people;

import com.flickr4java.flickr.Flickr;
import com.flickr4java.flickr.FlickrException;
import com.flickr4java.flickr.Response;
import com.flickr4java.flickr.Transport;
Expand All @@ -30,7 +29,7 @@

/**
* Interface for finding Flickr users.
*
*
* @author Anthony Eden
* @version $Id: PeopleInterface.java,v 1.28 2010/09/12 20:13:57 x-mago Exp $
*/
Expand All @@ -55,7 +54,7 @@ public class PeopleInterface {
public static final String METHOD_GET_PHOTOS_OF = "flickr.people.getPhotosOf";

public static final String METHOD_GET_GROUPS = "flickr.people.getGroups";

public static final String METHOD_GET_LIMITS = "flickr.people.getLimits";

private final String apiKey;
Expand All @@ -72,9 +71,9 @@ public PeopleInterface(String apiKey, String sharedSecret, Transport transportAP

/**
* Find the user by their email address.
*
*
* This method does not require authentication.
*
*
* @param email
* The email address
* @return The User
Expand All @@ -99,9 +98,9 @@ public User findByEmail(String email) throws FlickrException {

/**
* Find a User by the username.
*
*
* This method does not require authentication.
*
*
* @param username
* The username
* @return The User object
Expand All @@ -110,7 +109,7 @@ public User findByEmail(String email) throws FlickrException {
public User findByUsername(String username) throws FlickrException {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("method", METHOD_FIND_BY_USERNAME);

parameters.put("username", username);

Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
Expand All @@ -126,9 +125,9 @@ public User findByUsername(String username) throws FlickrException {

/**
* Get info about the specified user.
*
*
* This method does not require authentication.
*
*
* @param userId
* The user ID
* @return The User object
Expand All @@ -137,10 +136,10 @@ public User findByUsername(String username) throws FlickrException {
public User getInfo(String userId) throws FlickrException {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("method", METHOD_GET_INFO);

parameters.put("user_id", userId);

Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
if (response.isError()) {
throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
}
Expand All @@ -157,6 +156,7 @@ public User getInfo(String userId) throws FlickrException {
String lPathAlias = userElement.getAttribute("path_alias");
user.setPathAlias(lPathAlias == null || "".equals(lPathAlias) ? null : lPathAlias);
user.setUsername(XMLUtilities.getChildValue(userElement, "username"));
user.setDescription(XMLUtilities.getChildValue(userElement, "description"));
user.setRealName(XMLUtilities.getChildValue(userElement, "realname"));
user.setLocation(XMLUtilities.getChildValue(userElement, "location"));
user.setMbox_sha1sum(XMLUtilities.getChildValue(userElement, "mbox_sha1sum"));
Expand All @@ -168,7 +168,7 @@ public User getInfo(String userId) throws FlickrException {
user.setPhotosFirstDate(XMLUtilities.getChildValue(photosElement, "firstdate"));
user.setPhotosFirstDateTaken(XMLUtilities.getChildValue(photosElement, "firstdatetaken"));
user.setPhotosCount(XMLUtilities.getChildValue(photosElement, "count"));

NodeList tzNodes = userElement.getElementsByTagName("timezone");
for (int i = 0; i < tzNodes.getLength(); i++) {
Element tzElement = (Element) tzNodes.item(i);
Expand All @@ -183,12 +183,12 @@ public User getInfo(String userId) throws FlickrException {

/**
* Get a collection of public groups for the user.
*
*
* The groups will contain only the members nsid, name, admin and eighteenplus. If you want the whole group-information, you have to call
* {@link com.flickr4java.flickr.groups.GroupsInterface#getInfo(String)}.
*
*
* This method does not require authentication.
*
*
* @param userId
* The user ID
* @return The public groups
Expand All @@ -202,7 +202,7 @@ public Collection<Group> getPublicGroups(String userId) throws FlickrException {

parameters.put("user_id", userId);

Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
if (response.isError()) {
throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
}
Expand All @@ -226,9 +226,9 @@ public PhotoList<Photo> getPublicPhotos(String userId, int perPage, int page) th

/**
* Get a collection of public photos for the specified user ID.
*
*
* This method does not require authentication.
*
*
* @see com.flickr4java.flickr.photos.Extras
* @param userId
* The User ID
Expand Down Expand Up @@ -260,7 +260,7 @@ public PhotoList<Photo> getPublicPhotos(String userId, Set<String> extras, int p
parameters.put(Extras.KEY_EXTRAS, StringUtilities.join(extras, ","));
}

Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
if (response.isError()) {
throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
}
Expand All @@ -280,17 +280,17 @@ public PhotoList<Photo> getPublicPhotos(String userId, Set<String> extras, int p

/**
* Get upload status for the currently authenticated user.
*
*
* Requires authentication with 'read' permission using the new authentication API.
*
*
* @return A User object with upload status data fields filled
* @throws FlickrException
*/
public User getUploadStatus() throws FlickrException {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("method", METHOD_GET_UPLOAD_STATUS);

Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
if (response.isError()) {
throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
}
Expand All @@ -307,19 +307,18 @@ public User getUploadStatus() throws FlickrException {

Element filesizeElement = XMLUtilities.getChild(userElement, "filesize");
user.setFilesizeMax(filesizeElement.getAttribute("max"));

Element setsElement = XMLUtilities.getChild(userElement, "sets");
user.setSetsCreated(setsElement.getAttribute("created"));
user.setSetsRemaining(setsElement.getAttribute("remaining"));

Element videosElement = XMLUtilities.getChild(userElement, "videos");
user.setVideosUploaded(videosElement.getAttribute("uploaded"));
user.setVideosRemaining(videosElement.getAttribute("remaining"));

Element videoSizeElement = XMLUtilities.getChild(userElement, "videosize");
user.setVideoSizeMax(videoSizeElement.getAttribute("maxbytes"));


return user;
}

Expand Down Expand Up @@ -361,7 +360,7 @@ public PhotoList<Photo> getPhotos(String userId, String safeSearch, Date minUplo
parameters.put(Extras.KEY_EXTRAS, StringUtilities.join(extras, ","));
}

Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
if (response.isError()) {
throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
}
Expand Down Expand Up @@ -400,7 +399,7 @@ public PhotoList<Photo> getPhotosOf(String userId, String ownerId, Set<String> e
parameters.put("page", "" + page);
}

Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
if (response.isError()) {
throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
}
Expand Down Expand Up @@ -433,7 +432,7 @@ public PhotoList<Photo> getPhotosOf(String userId, String ownerId, Set<String> e

/**
* Add the given person to the photo. Optionally, send in co-ordinates
*
*
* @param photoId
* @param userId
* @param bounds
Expand All @@ -448,7 +447,7 @@ public void add(String photoId, String userId, Rectangle bounds) throws FlickrEx

/**
* Delete the person from the photo
*
*
* @param photoId
* @param userId
* @throws FlickrException
Expand All @@ -462,7 +461,7 @@ public void delete(String photoId, String userId) throws FlickrException {

/**
* Delete the co-ordinates that the user is shown in
*
*
* @param photoId
* @param userId
* @throws FlickrException
Expand All @@ -476,7 +475,7 @@ public void deleteCoords(String photoId, String userId) throws FlickrException {

/**
* Edit the co-ordinates that the user shows in
*
*
* @param photoId
* @param userId
* @param bounds
Expand All @@ -491,7 +490,7 @@ public void editCoords(String photoId, String userId, Rectangle bounds) throws F

/**
* Get a list of people in a given photo.
*
*
* @param photoId
* @throws FlickrException
*/
Expand All @@ -503,7 +502,7 @@ public PersonTagList<PersonTag> getList(String photoId) throws FlickrException {
}

/**
*
*
* @param userId
* @throws FlickrException
*/
Expand All @@ -514,7 +513,7 @@ public GroupList<Group> getGroups(String userId) throws FlickrException {
parameters.put("method", METHOD_GET_GROUPS);
parameters.put("user_id", userId);

Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
if (response.isError()) {
throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
}
Expand All @@ -537,18 +536,18 @@ public GroupList<Group> getGroups(String userId) throws FlickrException {
return groupList;

}

/**
* Get's the user's current upload limits, User object only contains user_id
*
* @return Media Limits
*/

public User getLimits() throws FlickrException {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("method", METHOD_GET_LIMITS);

Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
Response response = transportAPI.get(transportAPI.getPath(), parameters, apiKey, sharedSecret);
if (response.isError()) {
throw new FlickrException(response.getErrorCode(), response.getErrorMessage());
}
Expand Down
Loading

0 comments on commit 7cf3a6a

Please sign in to comment.