Skip to content

Commit

Permalink
Merge pull request Twitter4J#205 from takke/add-quoted-status
Browse files Browse the repository at this point in the history
TFJ-878 add "quoted_status" and "quoted_status_id" to Status object
  • Loading branch information
yusuke committed Jun 22, 2015
2 parents 642e522 + 75a27e6 commit ee1580e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
10 changes: 10 additions & 0 deletions twitter4j-appengine/src/main/java/twitter4j/LazyStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ public String[] getWithheldInCountries() {
return getTarget().getWithheldInCountries();
}

@Override
public long getQuotedStatusId() {
return getTarget().getQuotedStatusId();
}

@Override
public Status getQuotedStatus() {
return getTarget().getQuotedStatus();
}

public RateLimitStatus getRateLimitStatus() {
return getTarget().getRateLimitStatus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
private Scopes scopes;
private User user = null;
private String[] withheldInCountries = null;
private Status quotedStatus;
private long quotedStatusId = -1L;

/*package*/StatusJSONImpl(HttpResponse res, Configuration conf) throws TwitterException {
super(res);
Expand Down Expand Up @@ -185,6 +187,12 @@ private void init(JSONObject json) throws TwitterException {
}
}
}
if (!json.isNull("quoted_status")) {
quotedStatus = new StatusJSONImpl(json.getJSONObject("quoted_status"));
}
if (!json.isNull("quoted_status_id")) {
quotedStatusId = ParseUtil.getLong("quoted_status_id", json);
}

userMentionEntities = userMentionEntities == null ? new UserMentionEntity[0] : userMentionEntities;
urlEntities = urlEntities == null ? new URLEntity[0] : urlEntities;
Expand Down Expand Up @@ -383,6 +391,16 @@ public String[] getWithheldInCountries() {
return withheldInCountries;
}

@Override
public long getQuotedStatusId() {
return quotedStatusId;
}

@Override
public Status getQuotedStatus() {
return quotedStatus;
}

@Override
public String getLang() {
return lang;
Expand Down Expand Up @@ -459,6 +477,8 @@ public String toString() {
", currentUserRetweetId=" + currentUserRetweetId +
", user=" + user +
", withHeldInCountries=" + Arrays.toString(withheldInCountries)+
", quotedStatusId=" + quotedStatusId +
", quotedStatus=" + quotedStatus +
'}';
}
}
16 changes: 16 additions & 0 deletions twitter4j-core/src/main/java/twitter4j/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,20 @@ public interface Status extends Comparable<Status>, TwitterResponse,
* @since Twitter4j 4.0.3
*/
String[] getWithheldInCountries();

/**
* Returns the Tweet ID of the quoted Tweet
*
* @return the Tweet ID of the quoted Tweet
* @since Twitter4J 4.0.x
*/
long getQuotedStatusId();

/**
* Returns the Tweet object of the original Tweet that was quoted.
*
* @return the quoted Tweet object
* @since Twitter4J 4.0.x
*/
Status getQuotedStatus();
}
15 changes: 15 additions & 0 deletions twitter4j-core/src/test/java/twitter4j/StatusJSONImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ public void testExtendedMediaEntities() throws Exception {
assertEquals(4, status.getExtendedMediaEntities().length);
}

public void testQuotedStatus() throws Exception {

//given from https://twittercommunity.com/t/api-payloads-to-include-original-quoted-tweet-objects/38184
String rawJson = "{\"created_at\":\"Thu May 21 20:03:48 +0000 2015\",\"id\":601478517394636801,\"id_str\":\"601478517394636801\",\"text\":\"Awesome news! https://t.co/plSZZhcvkP\",\"source\":\"<a href=\\\"http://twitter.com\\\" rel=\\\"nofollow\\\">Twitter Web Client</a>\",\"truncated\":false,\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":null,\"in_reply_to_user_id_str\":null,\"in_reply_to_screen_name\":null,\"user\":{\"id\":3001969357,\"id_str\":\"3001969357\",\"name\":\"Jordan Brinks\",\"screen_name\":\"ilyanshe\",\"location\":\"Madagascar\",\"url\":\"http://spacejam.com\",\"description\":\"Alter Ego\",\"protected\":false,\"verified\":false,\"followers_count\":8,\"friends_count\":37,\"listed_count\":0,\"favourites_count\":1,\"statuses_count\":118,\"created_at\":\"Thu Jan 29 18:27:49 +0000 2015\",\"utc_offset\":3600,\"time_zone\":\"West Central Africa\",\"geo_enabled\":true,\"lang\":\"en\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"C0DEED\",\"profile_background_image_url\":\"http://abs.twimg.com/images/themes/theme1/bg.png\",\"profile_background_image_url_https\":\"https://abs.twimg.com/images/themes/theme1/bg.png\",\"profile_background_tile\":false,\"profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"profile_image_url\":\"http://pbs.twimg.com/profile_images/601155672395227136/qakfE9EU_normal.jpg\",\"profile_image_url_https\":\"https://pbs.twimg.com/profile_images/601155672395227136/qakfE9EU_normal.jpg\",\"profile_banner_url\":\"https://pbs.twimg.com/profile_banners/3001969357/1432161817\",\"default_profile\":true,\"default_profile_image\":false,\"following\":null,\"follow_request_sent\":null,\"notifications\":null},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"quoted_status_id\":560101531794821120,\"quoted_status_id_str\":\"560101531794821120\",\"quoted_status\":{\"created_at\":\"Tue Jan 27 15:46:26 +0000 2015\",\"id\":560101531794821120,\"id_str\":\"560101531794821120\",\"text\":\"Native video support in REST and Streaming API https://t.co/VrFm1qGZnF\",\"source\":\"<a href=\\\"http://itunes.apple.com/us/app/twitter/id409789998?mt=12\\\" rel=\\\"nofollow\\\">Twitter for Mac</a>\",\"truncated\":false,\"in_reply_to_status_id\":null,\"in_reply_to_status_id_str\":null,\"in_reply_to_user_id\":null,\"in_reply_to_user_id_str\":null,\"in_reply_to_screen_name\":null,\"user\":{\"id\":6253282,\"id_str\":\"6253282\",\"name\":\"Twitter API\",\"screen_name\":\"twitterapi\",\"location\":\"San Francisco, CA\",\"url\":\"http://dev.twitter.com\",\"description\":\"The Real Twitter API. I tweet about API changes, service issues and happily answer questions about Twitter and our API. Don't get an answer? It's on my website.\",\"protected\":false,\"verified\":true,\"followers_count\":3331390,\"friends_count\":48,\"listed_count\":12956,\"favourites_count\":27,\"statuses_count\":3534,\"created_at\":\"Wed May 23 06:01:13 +0000 2007\",\"utc_offset\":-25200,\"time_zone\":\"Pacific Time (US & Canada)\",\"geo_enabled\":true,\"lang\":\"en\",\"contributors_enabled\":false,\"is_translator\":false,\"profile_background_color\":\"C0DEED\",\"profile_background_image_url\":\"http://pbs.twimg.com/profile_background_images/656927849/miyt9dpjz77sc0w3d4vj.png\",\"profile_background_image_url_https\":\"https://pbs.twimg.com/profile_background_images/656927849/miyt9dpjz77sc0w3d4vj.png\",\"profile_background_tile\":true,\"profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"profile_image_url\":\"http://pbs.twimg.com/profile_images/2284174872/7df3h38zabcvjylnyfe3_normal.png\",\"profile_image_url_https\":\"https://pbs.twimg.com/profile_images/2284174872/7df3h38zabcvjylnyfe3_normal.png\",\"profile_banner_url\":\"https://pbs.twimg.com/profile_banners/6253282/1431474710\",\"default_profile\":false,\"default_profile_image\":false,\"following\":null,\"follow_request_sent\":null,\"notifications\":null,\"place\":{\"id\":\"96683cc9126741d1\"}},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"retweet_count\":0,\"favorite_count\":0,\"entities\":{\"hashtags\":[],\"trends\":[],\"urls\":[{\"url\":\"https://t.co/VrFm1qGZnF\",\"expanded_url\":\"https://twittercommunity.com/t/twitter-video-now-supported-in-rest-and-streaming-api/31258\",\"display_url\":\"twittercommunity.com/t/twitter-vide…\",\"indices\":[47,70]}],\"user_mentions\":[],\"symbols\":[]},\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"filter_level\":\"low\",\"lang\":\"en\"},\"retweet_count\":0,\"favorite_count\":0,\"entities\":{\"hashtags\":[],\"trends\":[],\"urls\":[{\"url\":\"https://t.co/plSZZhcvkP\",\"expanded_url\":\"https://twitter.com/twitterapi/status/560101531794821120\",\"display_url\":\"twitter.com/twitterapi/sta…\",\"indices\":[14,37]}],\"user_mentions\":[],\"symbols\":[]},\"favorited\":false,\"retweeted\":false,\"possibly_sensitive\":false,\"filter_level\":\"low\",\"lang\":\"en\",\"timestamp_ms\":\"1432238628134\"}";

JSONObject json = new JSONObject(rawJson);
Status status = new StatusJSONImpl(json);

assertEquals(560101531794821120L, status.getQuotedStatusId());

Status quotedStatus = status.getQuotedStatus();
assertNotNull(quotedStatus);
assertEquals(560101531794821120L, quotedStatus.getId());
}

public void testAcitivityWithheldInCountries() throws Exception {
String rawJson = "{\"created_at\":\"Tue Nov 12 14:15:41 +0000 2013\",\"id\":400265648674467840,\"id_str\":\"400265648674467840\",\"text\":\"@ADecherf On t\\u2019a siffl\\u00e9 ?? Non, alors va te faire enculer au lieu de casser les couilles aux gens ! Adieu gros #PayDay !!\\n@fallenangels667\",\"source\":\"\\u003ca href=\\\"http:\\/\\/tapbots.com\\/tweetbot\\\" rel=\\\"nofollow\\\"\\u003eTweetbot for iOS\\u003c\\/a\\u003e\",\"truncated\":false,\"in_reply_to_status_id\":400250694789103616,\"in_reply_to_status_id_str\":\"400250694789103616\",\"in_reply_to_user_id\":1339289664,\"in_reply_to_user_id_str\":\"1339289664\",\"in_reply_to_screen_name\":\"ADecherf\",\"user\":{\"id\":587870719,\"id_str\":\"587870719\",\"name\":\"il Padrino\",\"screen_name\":\"DulezC\",\"location\":\"France (34) - Sicilia (CT)\",\"description\":\"Contre la bien-pensance. En guerre contre les collabos et les socialauds qui ruinent notre pays et le d\\u00e9g\\u00e9n\\u00e8rent ! Honneur et Patrie. \\u270bMEMENTO AUDERE SEMPER\\u270b\",\"url\":null,\"entities\":{\"description\":{\"urls\":[]}},\"protected\":false,\"followers_count\":2909,\"friends_count\":2525,\"listed_count\":16,\"created_at\":\"Wed May 23 00:25:40 +0000 2012\",\"favourites_count\":244,\"utc_offset\":7200,\"time_zone\":\"Paris\",\"geo_enabled\":false,\"verified\":false,\"statuses_count\":22124,\"lang\":\"fr\",\"contributors_enabled\":false,\"is_translator\":false,\"is_translation_enabled\":false,\"profile_background_color\":\"C0DEED\",\"profile_background_image_url\":\"http:\\/\\/abs.twimg.com\\/images\\/themes\\/theme1\\/bg.png\",\"profile_background_image_url_https\":\"https:\\/\\/abs.twimg.com\\/images\\/themes\\/theme1\\/bg.png\",\"profile_background_tile\":false,\"profile_image_url\":\"http:\\/\\/pbs.twimg.com\\/profile_images\\/3069773085\\/f483e45f226bea36fff5b67f300a52f9_normal.jpeg\",\"profile_image_url_https\":\"https:\\/\\/pbs.twimg.com\\/profile_images\\/3069773085\\/f483e45f226bea36fff5b67f300a52f9_normal.jpeg\",\"profile_banner_url\":\"https:\\/\\/pbs.twimg.com\\/profile_banners\\/587870719\\/1406034390\",\"profile_link_color\":\"0084B4\",\"profile_sidebar_border_color\":\"C0DEED\",\"profile_sidebar_fill_color\":\"DDEEF6\",\"profile_text_color\":\"333333\",\"profile_use_background_image\":true,\"default_profile\":true,\"default_profile_image\":false,\"following\":false,\"follow_request_sent\":false,\"notifications\":false},\"geo\":null,\"coordinates\":null,\"place\":null,\"contributors\":null,\"withheld_in_countries\":[\"FR\"],\"retweet_count\":0,\"favorite_count\":0,\"entities\":{\"hashtags\":[{\"text\":\"PayDay\",\"indices\":[111,118]}],\"symbols\":[],\"urls\":[],\"user_mentions\":[{\"screen_name\":\"ADecherf\",\"name\":\"(*\\u00a5*)\",\"id\":1339289664,\"id_str\":\"1339289664\",\"indices\":[0,9]},{\"screen_name\":\"FaLLenAngeLs667\",\"name\":\"Fallen Angel\",\"id\":1219663764,\"id_str\":\"1219663764\",\"indices\":[122,138]}]},\"favorited\":false,\"retweeted\":false,\"lang\":\"fr\"}";

Expand Down

0 comments on commit ee1580e

Please sign in to comment.