Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/redouane59/twittered int…
Browse files Browse the repository at this point in the history
…o develop
  • Loading branch information
redouane59 committed May 28, 2021
2 parents 03b51f0 + 8bcdf55 commit c275301
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.redouane59.twitter</groupId>
<artifactId>twittered</artifactId>
<version>1.24</version>
<version>1.25</version>

<name>twittered</name>
<description>java client for twitter API</description>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/github/redouane59/twitter/ITwitterClientV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ public interface ITwitterClientV1 {
*/
Tweet postTweet(String text, String inReplyToStatusId, String mediaIds);

/**
* Post a tweet calling https://api.twitter.com/1.1/statuses/update.json
*
* @param text the tweet text
* @param inReplyToStatusId the id of the tweet to answer.
* @param mediaIds the ids of the media obtained calling the uploadMedia() method, separated by commas
* @param attachmentUrl provide a URL as a Tweet attachment
* @return the created tweet
*/
Tweet postTweet(String text, String inReplyToStatusId, String mediaIds, String attachmentUrl);

/**
* Delete a tweet calling https://api.twitter.com/1.1/statuses/destroy/:id.json
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ public Tweet postTweet(String text, String inReplyToStatusId) {

@Override
public Tweet postTweet(String text, String inReplyToStatusId, String mediaIds) {
return this.postTweet(text, inReplyToStatusId, mediaIds, null);
}

@Override
public Tweet postTweet(final String text, final String inReplyToStatusId, final String mediaIds, final String attachmentUrl) {
String url = this.getUrlHelper().getPostTweetUrl();
Map<String, String> parameters = new HashMap<>();
parameters.put("status", text);
Expand All @@ -344,6 +349,9 @@ public Tweet postTweet(String text, String inReplyToStatusId, String mediaIds) {
if (mediaIds != null) {
parameters.put("media_ids", mediaIds);
}
if (attachmentUrl != null) {
parameters.put("attachment_url", attachmentUrl);
}
return this.requestHelperV1.postRequest(url, parameters, TweetV1.class).orElseThrow(NoSuchElementException::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public <T> Optional<T> makeRequest(OAuthRequest request, boolean signRequired, C
LOGGER.error("Using default retry after because header format is invalid: " + retryAfterStr, e);
}
}
LOGGER.debug("Rate limit exceeded, new retry in " + 1000L * retryAfter + "s");
Thread.sleep(1000L * retryAfter);
return makeRequest(request, false, classType); // We have already signed if it was requested
} else if (response.getCode() < 200 || response.getCode() > 299) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ public void testPostAndRTandDeleteTweet() {
assertEquals(resultPostAnswer.getId(), resultDelete2.getId());
}

@Test
public void postTweetWithUrl() {
Tweet resultPost = twitterClient.postTweet("test", null, null, "https://twitter.com/TwitterDev/status/1392465174708187137");
assertNotNull(resultPost);
assertNotNull(resultPost.getId());
Tweet resultDelete = twitterClient.deleteTweet(resultPost.getId());
assertNotNull(resultDelete);
}

@Test
public void testGetFavorites() {
int count = 1500;
Expand Down

0 comments on commit c275301

Please sign in to comment.