From 876f4258ca3d09598dcf49eb6e6283227904f05f Mon Sep 17 00:00:00 2001 From: Vincent Privat Date: Sat, 6 Apr 2024 22:55:00 +0200 Subject: [PATCH] Deprecate lookupUser. New method to return a User instead of username --- .../flickr/urls/UrlsInterface.java | 31 ++++++++++++++++++- .../flickr/test/UrlsInterfaceTest.java | 4 +-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/flickr4java/flickr/urls/UrlsInterface.java b/src/main/java/com/flickr4java/flickr/urls/UrlsInterface.java index 80948eb5..2f0c1693 100644 --- a/src/main/java/com/flickr4java/flickr/urls/UrlsInterface.java +++ b/src/main/java/com/flickr4java/flickr/urls/UrlsInterface.java @@ -150,6 +150,18 @@ 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. * @@ -157,8 +169,22 @@ public Group lookupGroup(String url) throws FlickrException { * 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 parameters = new HashMap(); parameters.put("method", METHOD_LOOKUP_USER); @@ -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; } /** diff --git a/src/test/java/com/flickr4java/flickr/test/UrlsInterfaceTest.java b/src/test/java/com/flickr4java/flickr/test/UrlsInterfaceTest.java index a1ca91f7..256cf633 100644 --- a/src/test/java/com/flickr4java/flickr/test/UrlsInterfaceTest.java +++ b/src/test/java/com/flickr4java/flickr/test/UrlsInterfaceTest.java @@ -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); }