Skip to content

Commit 876f425

Browse files
committed
Deprecate lookupUser. New method to return a User instead of username
1 parent 62506e3 commit 876f425

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/main/java/com/flickr4java/flickr/urls/UrlsInterface.java

+30-1
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,41 @@ public Group lookupGroup(String url) throws FlickrException {
150150
return group;
151151
}
152152

153+
/**
154+
* Lookup the username for the specified User URL.
155+
*
156+
* @param url
157+
* The user profile URL
158+
* @return The username
159+
* @throws FlickrException if there was a problem connecting to Flickr
160+
*/
161+
public String lookupUsernameByURL(String url) throws FlickrException {
162+
return lookupUserByURL(url).getUsername();
163+
}
164+
153165
/**
154166
* Lookup the username for the specified User URL.
155167
*
156168
* @param url
157169
* The user profile URL
158170
* @return The username
159171
* @throws FlickrException if there was a problem connecting to Flickr
172+
* @deprecated use {@link #lookupUsernameByURL(String) }
160173
*/
174+
@Deprecated
161175
public String lookupUser(String url) throws FlickrException {
176+
return lookupUsernameByURL(url);
177+
}
178+
179+
/**
180+
* Lookup the user for the specified User URL.
181+
*
182+
* @param url
183+
* The user profile URL
184+
* @return The user
185+
* @throws FlickrException if there was a problem connecting to Flickr
186+
*/
187+
public User lookupUserByURL(String url) throws FlickrException {
162188
Map<String, Object> parameters = new HashMap<String, Object>();
163189
parameters.put("method", METHOD_LOOKUP_USER);
164190

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

172198
Element payload = response.getPayload();
173199
Element groupnameElement = (Element) payload.getElementsByTagName("username").item(0);
174-
return ((Text) groupnameElement.getFirstChild()).getData();
200+
User user = new User();
201+
user.setId(payload.getAttribute("id"));
202+
user.setUsername(((Text) groupnameElement.getFirstChild()).getData());
203+
return user;
175204
}
176205

177206
/**

src/test/java/com/flickr4java/flickr/test/UrlsInterfaceTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public void testLookupGroup() throws FlickrException {
5656
}
5757

5858
@Test
59-
public void testLookupUser() throws FlickrException {
59+
public void testLookupUsernameByURL() throws FlickrException {
6060
UrlsInterface iface = flickr.getUrlsInterface();
6161
String username = testProperties.getUsername();
62-
String usernameOnFlickr = iface.lookupUser(String.format("https://www.flickr.com/people/%s/", username));
62+
String usernameOnFlickr = iface.lookupUsernameByURL(String.format("https://www.flickr.com/people/%s/", username));
6363
assertEquals(username, usernameOnFlickr);
6464
}
6565

0 commit comments

Comments
 (0)