Skip to content

Commit

Permalink
TFJ-697 add getters for profile banner urls
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuke committed Nov 7, 2012
1 parent 639cb11 commit 589bee4
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 14 deletions.
Expand Up @@ -246,6 +246,34 @@ public String getProfileBackgroundImageUrlHttps() {
return getTarget().getProfileBackgroundImageUrlHttps();
}

public String getProfileBannerUrl() {
return getTarget().getProfileBannerUrl();
}

@Override
public String getProfileBannerRetinaUrl() {
return getTarget().getProfileBannerRetinaUrl();
}

@Override
public String getProfileBannerIPadUrl() {
return getTarget().getProfileBannerIPadUrl();
}

@Override
public String getProfileBannerIPadRetinaUrl() {
return getTarget().getProfileBannerIPadRetinaUrl();
}

@Override
public String getProfileBannerMobileUrl() {
return getTarget().getProfileBannerMobileUrl();
}

@Override
public String getProfileBannerMobileRetinaUrl() {
return getTarget().getProfileBannerMobileRetinaUrl();
}

public boolean isProfileBackgroundTiled() {
return getTarget().isProfileBackgroundTiled();
Expand Down
25 changes: 25 additions & 0 deletions twitter4j-core/src/main/java/twitter4j/User.java
Expand Up @@ -141,6 +141,31 @@ public interface User extends Comparable<User>, TwitterResponse, java.io.Seriali

String getProfileBackgroundImageUrlHttps();

/**
* @since Twitter4J 3.0.0
*/
String getProfileBannerUrl();
/**
* @since Twitter4J 3.0.0
*/
String getProfileBannerRetinaUrl();
/**
* @since Twitter4J 3.0.0
*/
String getProfileBannerIPadUrl();
/**
* @since Twitter4J 3.0.0
*/
String getProfileBannerIPadRetinaUrl();
/**
* @since Twitter4J 3.0.0
*/
String getProfileBannerMobileUrl();
/**
* @since Twitter4J 3.0.0
*/
String getProfileBannerMobileRetinaUrl();

boolean isProfileBackgroundTiled();

/**
Expand Down
Expand Up @@ -64,6 +64,7 @@
private String timeZone;
private String profileBackgroundImageUrl;
private String profileBackgroundImageUrlHttps;
private String profileBannerImageUrl;
private boolean profileBackgroundTiled;
private String lang;
private int statusesCount;
Expand Down Expand Up @@ -127,6 +128,7 @@ private void init(JSONObject json) throws TwitterException {
timeZone = getRawString("time_zone", json);
profileBackgroundImageUrl = getRawString("profile_background_image_url", json);
profileBackgroundImageUrlHttps = getRawString("profile_background_image_url_https", json);
profileBannerImageUrl = getRawString("profile_banner_url", json);
profileBackgroundTiled = getBoolean("profile_background_tile", json);
lang = getRawString("lang", json);
statusesCount = getInt("statuses_count", json);
Expand Down Expand Up @@ -366,6 +368,39 @@ public String getProfileBackgroundImageUrlHttps() {
return profileBackgroundImageUrlHttps;
}

/**
* {@inheritDoc}
*/
@Override
public String getProfileBannerUrl() {
return profileBannerImageUrl != null ? profileBannerImageUrl+"/web" : null;
}

@Override
public String getProfileBannerRetinaUrl() {
return profileBannerImageUrl != null ? profileBannerImageUrl + "/web_retina" : null;
}

@Override
public String getProfileBannerIPadUrl() {
return profileBannerImageUrl != null ? profileBannerImageUrl + "/ipad" : null;
}

@Override
public String getProfileBannerIPadRetinaUrl() {
return profileBannerImageUrl != null ? profileBannerImageUrl + "/ipad_retina" : null;
}

@Override
public String getProfileBannerMobileUrl() {
return profileBannerImageUrl != null ? profileBannerImageUrl + "/mobile" : null;
}

@Override
public String getProfileBannerMobileRetinaUrl() {
return profileBannerImageUrl != null ? profileBannerImageUrl + "/ipad_retina" : null;
}

/**
* {@inheritDoc}
*/
Expand Down
17 changes: 14 additions & 3 deletions twitter4j-core/src/test/java/twitter4j/UsersResourcesTest.java
Expand Up @@ -15,6 +15,7 @@
*/
package twitter4j;

import twitter4j.internal.http.HttpClientWrapper;
import twitter4j.json.DataObjectFactory;

import java.io.File;
Expand All @@ -39,11 +40,19 @@ protected void tearDown() throws Exception {
}

public void testShowUser() throws Exception {
User user = twitter1.showUser(id1.screenName);
assertEquals(id1.screenName, user.getScreenName());
User user = twitter1.showUser("yusuke");
assertEquals("yusuke", user.getScreenName());
assertNotNull(user.getLocation());
assertNotNull(user.getDescription());
assertNotNull(user.getProfileImageURL());
assertNotNull(user.getProfileBannerUrl());
HttpClientWrapper wrapper = new HttpClientWrapper();
wrapper.head(user.getProfileBannerUrl());
wrapper.head(user.getProfileBannerRetinaUrl());
wrapper.head(user.getProfileBannerIPadUrl());
wrapper.head(user.getProfileBannerIPadRetinaUrl());
wrapper.head(user.getProfileBannerMobileUrl());
wrapper.head(user.getProfileBannerMobileRetinaUrl());
assertNotNull(user.getURL());
assertFalse(user.isProtected());

Expand Down Expand Up @@ -79,7 +88,9 @@ public void testShowUser() throws Exception {

//test case for TFJ-91 null pointer exception getting user detail on users with no statuses
//http://yusuke.homeip.net/jira/browse/TFJ-91
twitter1.showUser("twit4jnoupdate");
user = twitter1.showUser("twit4jnoupdate");
System.out.println("----"+user.getProfileBannerUrl());
assertNull(user.getProfileBannerUrl());
user = twitter1.showUser("tigertest");
User previousUser = user;
assertNotNull(DataObjectFactory.getRawJSON(user));
Expand Down
22 changes: 11 additions & 11 deletions twitter4j-stream/src/test/java/twitter4j/internal/json/DAOTest.java
Expand Up @@ -107,7 +107,7 @@ public void testUnparsable() throws Exception {
} catch (Error notExpected) {
fail("failed" + notExpected.getMessage());
}
str = "{\"in_reply_to_status_id_str\":null,\"place\":null,\"in_reply_to_user_id\":null,\"text\":\"working\",\"contributors\":null,\"retweet_count\":0,\"in_reply_to_user_id_str\":null,\"retweeted\":false,\"id_str\":\"794626207\",\"source\":\"\\u003Ca href=\\\"http:\\/\\/twitterhelp.blogspot.com\\/2008\\/05\\/twitter-via-mobile-web-mtwittercom.html\\\" rel=\\\"nofollow\\\"\\u003Emobile web\\u003C\\/a\\u003E\",\"truncated\":false,\"geo\":null,\"in_reply_to_status_id\":null,\"favorited\":false,\"user\":{\"show_all_inline_media\":false,\"geo_enabled\":false,\"profile_background_tile\":false,\"time_zone\":null,\"favourites_count\":0,\"description\":null,\"friends_count\":0,\"profile_link_color\":\"0084B4\",\"location\":null,\"profile_sidebar_border_color\":\"C0DEED\",\"id_str\":\"14481043\",\"url\":null,\"follow_request_sent\":false,\"statuses_count\":1,\"profile_use_background_image\":true,\"lang\":\"en\",\"profile_background_color\":\"C0DEED\",\"profile_image_url\":\"http:\\/\\/a3.twimg.com\\/a\\/1292975674\\/images\\/default_profile_3_normal.png\",\"profile_background_image_url\":\"http:\\/\\/a3.twimg.com\\/a\\/1292975674\\/images\\/themes\\/theme1\\/bg.png\",\"followers_count\":44,\"protected\":false,\"contributors_enabled\":false,\"notifications\":false,\"screen_name\":\"Yusuke\",\"name\":\"Yusuke\",\"is_translator\":false,\"listed_count\":1,\"following\":false,\"verified\":false,\"profile_text_color\":\"333333\",\"id\":14481043,\"utc_offset\":null,\"created_at\":\"Tue Apr 22 21:49:13 +0000 2008\",\"profile_sidebar_fill_color\":\"DDEEF6\"},\"id\":794626207,\"coordinates\":null,\"in_reply_to_screen_name\":null,\"created_at\":\"Tue Apr 2200 21:49:34 +0000 2008\"}";
str = "{\"in_reply_to_status_id_str\":null,\"place\":null,\"in_reply_to_user_id\":null,\"text\":\"working\",\"contributors\":null,\"retweet_count\":0,\"in_reply_to_user_id_str\":null,\"retweeted\":false,\"id_str\":\"794626207\",\"source\":\"\\u003Ca href=\\\"http:\\/\\/twitterhelp.blogspot.com\\/2008\\/05\\/twitter-via-mobile-web-mtwittercom.html\\\" rel=\\\"nofollow\\\"\\u003Emobile web\\u003C\\/a\\u003E\",\"truncated\":false,\"geo\":null,\"in_reply_to_status_id\":null,\"favorited\":false,\"user\":{\"show_all_inline_media\":false,\"geo_enabled\":false,\"profile_background_tile\":false,\"time_zone\":null,\"favourites_count\":0,\"description\":null,\"friends_count\":0,\"profile_link_color\":\"0084B4\",\"location\":null,\"profile_sidebar_border_color\":\"C0DEED\",\"id_str\":\"14481043\",\"url\":null,\"follow_request_sent\":false,\"statuses_count\":1,\"profile_use_background_image\":true,\"lang\":\"en\",\"profile_background_color\":\"C0DEED\",\"profile_image_url\":\"http:\\/\\/a3.twimg.com\\/a\\/1292975674\\/images\\/default_profile_3_normal.png\",\"profile_background_image_url\":\"http:\\/\\/a3.twimg.com\\/a\\/1292975674\\/images\\/themes\\/theme1\\/bg.png\",\"followers_count\":44,\"protected\":false,\"contributors_enabled\":false,\"notifications\":false,\"screen_name\":\"Yusuke\",\"name\":\"Yusuke\",\"is_translator\":false,\"listed_count\":1,\"following\":false,\"verified\":false,\"profile_text_color\":\"333333\",\"id\":14481043,\"utc_offset\":null,\"created_at\":\"Tue Apr 22 21:49:13 +0000 2008\",\"profile_sidebar_fill_color\":\"DDEEF6\"},\"id\":794626207,\"coordinates\":null,\"in_reply_to_screen_name\":null,\"created_at\":\"Tue Apr 2200 21:49:34 +0000 2008\"";

try {
DataObjectFactory.createCategory(str);
Expand Down Expand Up @@ -165,7 +165,7 @@ public void testSchema() throws Exception {
// Location

// schema = new String[]{"url","country","woeid","placeType/name","placeType/code","name","countryCode"};
// url = "http://api.twitter.com/1/trends/available.json";
// url = "http://api.twitter.com/1.1/trends/available.json";
// validateJSONArraySchema(url, schema);
// Place
if (!Boolean.valueOf(System.getProperties().getProperty("twitter4j.test.schema"))) {
Expand All @@ -178,7 +178,7 @@ public void testSchema() throws Exception {
"name",
"size",
};
url = "http://api.twitter.com/1/users/suggestions.json";
url = "http://api.twitter.com/1.1/users/suggestions.json";
List categories = CategoryJSONImpl.createCategoriesList(validateJSONArraySchema(url, schema), null, conf);
Assert.assertEquals(20, categories.size());

Expand All @@ -189,7 +189,7 @@ public void testSchema() throws Exception {
"categories/*",
"users/*"
};
url = "http://api.twitter.com/1/users/suggestions/art-design.json";
url = "http://api.twitter.com/1.1/users/suggestions/art-design.json";
validateJSONObjectSchema(url, schema);


Expand Down Expand Up @@ -226,7 +226,7 @@ public void testSchema() throws Exception {
"query/params/coordinates/coordinates/*",
"query/params/accuracy",
};
url = "http://api.twitter.com/1/geo/reverse_geocode.json?lat=37.78215&long=-122.40060";
url = "http://api.twitter.com/1.1/geo/reverse_geocode.json?lat=37.78215&long=-122.40060";
validateJSONObjectSchema(url, schema);


Expand All @@ -249,7 +249,7 @@ public void testSchema() throws Exception {
"lists/following",

};
url = "http://api.twitter.com/1/twit4j2/lists.json";
url = "http://api.twitter.com/1.1/twit4j2/lists.json";
validateJSONObjectSchema(url, schema);

schema = new String[]{
Expand All @@ -267,7 +267,7 @@ public void testSchema() throws Exception {
"following",

};
url = "http://api.twitter.com/1/twit4j2/lists/9499823.json";
url = "http://api.twitter.com/1.1/twit4j2/lists/9499823.json";
UserList userList = new UserListJSONImpl(validateJSONObjectSchema(url, schema));
Assert.assertEquals("", userList.getDescription());
Assert.assertEquals("@twit4j2/test", userList.getFullName());
Expand Down Expand Up @@ -304,7 +304,7 @@ public void testSchema() throws Exception {
"retweet_count"

};
url = "http://api.twitter.com/1/statuses/show/2245071380.json";
url = "http://api.twitter.com/1.1/statuses/show/2245071380.json";
Status status = new StatusJSONImpl(validateJSONObjectSchema(url, schema));

schema = new String[]{
Expand Down Expand Up @@ -344,7 +344,7 @@ public void testSchema() throws Exception {
"is_translator",
"show_all_inline_media"};

url = "http://api.twitter.com/1/users/show/yusukey.json";
url = "http://api.twitter.com/1.1/users/show/yusukey.json";
User user = new UserJSONImpl(validateJSONObjectSchema(url, schema));
}

Expand Down Expand Up @@ -630,7 +630,7 @@ public void testPlaceAsJSON() throws Exception {
Assert.assertEquals("2b6ff8c22edd9576", place.getId());
Assert.assertEquals("", place.getCountry());
Assert.assertEquals("neighborhood", place.getPlaceType());
Assert.assertEquals("http://api.twitter.com/1/geo/id/2b6ff8c22edd9576.json", place.getURL());
Assert.assertEquals("http://api.twitter.com/1.1/geo/id/2b6ff8c22edd9576.json", place.getURL());
Assert.assertEquals("SoMa, San Francisco", place.getFullName());
Assert.assertEquals("Polygon", place.getBoundingBoxType());
GeoLocation[][] boundingBox = place.getBoundingBoxCoordinates();
Expand All @@ -656,7 +656,7 @@ public void testPlaceAsJSON() throws Exception {
Assert.assertEquals("5a110d312052166f", containedWithin.getId());
Assert.assertEquals("", containedWithin.getCountry());
Assert.assertEquals("city", containedWithin.getPlaceType());
Assert.assertEquals("http://api.twitter.com/1/geo/id/5a110d312052166f.json", containedWithin.getURL());
Assert.assertEquals("http://api.twitter.com/1.1/geo/id/5a110d312052166f.json", containedWithin.getURL());
Assert.assertEquals("San Francisco", containedWithin.getFullName());
boundingBox = containedWithin.getBoundingBoxCoordinates();
Assert.assertEquals("Polygon", place.getBoundingBoxType());
Expand Down

0 comments on commit 589bee4

Please sign in to comment.