Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: user timeline v1 #66

Merged
merged 1 commit into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/main/java/com/github/redouane59/twitter/ITwitterClientV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,24 @@ public interface ITwitterClientV1 {
*/
List<Tweet> getMentionsTimeline(int count, String maxId);

/**
* Get the 200 most recent Tweets posted by the user calling https://api.twitter.com/1.1/statuses/user_timeline.json
*
* @param userId the id of the user
* @return a list of the 200 most recent Tweets posted by the user
*/
List<Tweet> getUserTimeline(String userId);

/**
* Get the most recent Tweets posted by the user calling https://api.twitter.com/1.1/statuses/user_timeline.json
*
* @param userId the id of the user
* @param count Specifies the number of Tweets to try and retrieve, up to a maximum of 200 per distinct request
* @param maxId Returns results with an ID less than (that is, older than) or equal to the specified ID.
* @return a list of the most recent Tweets posted by the user
*/
List<Tweet> getUserTimeline(String userId, int count, String maxId);


}

17 changes: 15 additions & 2 deletions src/main/java/com/github/redouane59/twitter/TwitterClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,26 @@ public void startSampledStream(Consumer<Tweet> consumer) {
@Override
public List<Tweet> getMentionsTimeline() {
int maxCount = 200;
String url = this.urlHelper.getMentionsTimelinerl(maxCount);
String url = this.urlHelper.getMentionsTimelineUrl(maxCount);
return List.of(this.requestHelper.getRequest(url, TweetV1[].class).orElseThrow(NoSuchElementException::new));
}

@Override
public List<Tweet> getMentionsTimeline(int count, String maxId) {
String url = this.urlHelper.getMentionsTimelinerl(count, maxId);
String url = this.urlHelper.getMentionsTimelineUrl(count, maxId);
return List.of(this.requestHelper.getRequest(url, TweetV1[].class).orElseThrow(NoSuchElementException::new));
}

@Override
public List<Tweet> getUserTimeline(final String userId) {
int maxCount = 200;
String url = this.urlHelper.getUserTimelineUrl(userId, maxCount);
return List.of(this.requestHelper.getRequest(url, TweetV1[].class).orElseThrow(NoSuchElementException::new));
}

@Override
public List<Tweet> getUserTimeline(final String userId, final int count, final String maxId) {
String url = this.urlHelper.getUserTimelineUrl(userId, count, maxId);
return List.of(this.requestHelper.getRequest(url, TweetV1[].class).orElseThrow(NoSuchElementException::new));
}

Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/github/redouane59/twitter/helpers/URLHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,21 @@ public String getSampledStreamUrl() {
return ROOT_URL_V2 + TWEETS + SAMPLE + STREAM;
}

public String getMentionsTimelinerl(int count) {
public String getMentionsTimelineUrl(int count) {
return ROOT_URL_V1 + STATUSES + "/mentions_timeline.json?include_entities=true&" + COUNT + "=" + count;
}

public String getMentionsTimelinerl(int count, String maxId) {
public String getMentionsTimelineUrl(int count, String maxId) {
return ROOT_URL_V1 + STATUSES + "/mentions_timeline.json?include_entities=true&"
+ COUNT + "=" + count
+ "&max_id=" + maxId;
}

public String getUserTimelineUrl(final String userId, final int count) {
return ROOT_URL_V1 + STATUSES + "/user_timeline.json?user_id=" + userId + "&" + COUNT + "=" + count;
}

public String getUserTimelineUrl(final String userId, final int count, final String maxId) {
return ROOT_URL_V1 + STATUSES + "/user_timeline.json?user_id=" + userId + "&" + COUNT + "=" + count + "&max_id=" + maxId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,21 @@ public void testGetMentionsTimelineWithMaxId() {
List<Tweet> result = twitterClient.getMentionsTimeline(10, "1302072684629590016");
assertTrue(result.size() > 0);
}
/*

@Test
public void testGetUserTimeline() {
List<Tweet> result = twitterClient.getUserTimeline("1120050519182016513");
assertTrue(result.size() > 0);
}

@Test
public void testGetUserTimelineWithMaxId() {
List<Tweet> result = twitterClient.getUserTimeline("1120050519182016513", 10, "1300007914674040832");
assertTrue(result.size() > 0);
}


/*

@Test
public void testSearchTweetsArchive(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,25 @@ public void testLiveEventUrl() {
@Test
public void testGetMentionsTimelineUrl() {
assertEquals("https://api.twitter.com/1.1/statuses/mentions_timeline.json?include_entities=true&count=200",
urlHelper.getMentionsTimelinerl(200));
urlHelper.getMentionsTimelineUrl(200));
}

@Test
public void testGetMentionsTimelineUrlWithMaxId() {
assertEquals("https://api.twitter.com/1.1/statuses/mentions_timeline.json?include_entities=true&count=10&max_id=12345",
urlHelper.getMentionsTimelinerl(10, "12345"));
urlHelper.getMentionsTimelineUrl(10, "12345"));
}

@Test
public void testGetUserTimelineUrl() {
assertEquals("https://api.twitter.com/1.1/statuses/user_timeline.json?user_id=99999&count=200",
urlHelper.getUserTimelineUrl("99999", 200));
}

@Test
public void testGetUserTimelineUrlWithMaxId() {
assertEquals("https://api.twitter.com/1.1/statuses/user_timeline.json?user_id=99999&count=10&max_id=12345",
urlHelper.getUserTimelineUrl("99999", 10, "12345"));
}

}