Skip to content

Commit

Permalink
Merge pull request #724 from don-vip/lookup-user
Browse files Browse the repository at this point in the history
Deprecate lookupUser. New method to return a User instead of username
  • Loading branch information
boncey authored Apr 7, 2024
2 parents 62506e3 + 876f425 commit 7a87dee
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
31 changes: 30 additions & 1 deletion src/main/java/com/flickr4java/flickr/urls/UrlsInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,41 @@ public Group lookupGroup(String url) throws FlickrException {
return group;
}

/**
* Lookup the username for the specified User URL.
*
* @param url
* The user profile URL
* @return The username
* @throws FlickrException if there was a problem connecting to Flickr
*/
public String lookupUsernameByURL(String url) throws FlickrException {
return lookupUserByURL(url).getUsername();
}

/**
* Lookup the username for the specified User URL.
*
* @param url
* The user profile URL
* @return The username
* @throws FlickrException if there was a problem connecting to Flickr
* @deprecated use {@link #lookupUsernameByURL(String) }
*/
@Deprecated
public String lookupUser(String url) throws FlickrException {
return lookupUsernameByURL(url);
}

/**
* Lookup the user for the specified User URL.
*
* @param url
* The user profile URL
* @return The user
* @throws FlickrException if there was a problem connecting to Flickr
*/
public User lookupUserByURL(String url) throws FlickrException {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("method", METHOD_LOOKUP_USER);

Expand All @@ -171,7 +197,10 @@ public String lookupUser(String url) throws FlickrException {

Element payload = response.getPayload();
Element groupnameElement = (Element) payload.getElementsByTagName("username").item(0);
return ((Text) groupnameElement.getFirstChild()).getData();
User user = new User();
user.setId(payload.getAttribute("id"));
user.setUsername(((Text) groupnameElement.getFirstChild()).getData());
return user;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public void testLookupGroup() throws FlickrException {
}

@Test
public void testLookupUser() throws FlickrException {
public void testLookupUsernameByURL() throws FlickrException {
UrlsInterface iface = flickr.getUrlsInterface();
String username = testProperties.getUsername();
String usernameOnFlickr = iface.lookupUser(String.format("https://www.flickr.com/people/%s/", username));
String usernameOnFlickr = iface.lookupUsernameByURL(String.format("https://www.flickr.com/people/%s/", username));
assertEquals(username, usernameOnFlickr);
}

Expand Down

0 comments on commit 7a87dee

Please sign in to comment.