Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
xberger committed Nov 8, 2022
2 parents 82eed8c + b8bf00f commit 5d49d4a
Show file tree
Hide file tree
Showing 48 changed files with 1,001 additions and 336 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
test-twitter-credentials.json
/test-twitter-credentials.json
./test-twitter-credentials.json
/.idea/libraries
/.idea/*.xml
/.target
Expand Down
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This project is a JAVA library which allows you to consume the Twitter API.

In your pom.xml, add the following dependency and replace `VERSION` with the version you wish:

```
```xml
<dependency>
<groupId>io.github.redouane59.twitter</groupId>
<artifactId>twittered</artifactId>
Expand All @@ -21,21 +21,21 @@ In your pom.xml, add the following dependency and replace `VERSION` with the ver
```

If you are using Gradle Kotlin DSL, make sure you have MavenCentral among the available repositories:
```
```kotlin
repositories {
mavenCentral()
[...]
// [...]
}
```
Then add the following line to your `dependencies` block:

```
```kotlin
implementation("io.github.redouane59.twitter:twittered:VERSION")
```

To be able to see library logs, also add sl4j references :

```
```xml
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand All @@ -54,7 +54,7 @@ In order to use your own developer credentials, you have several options :

File example :

```
```json
{
"apiKey": "xxx",
"apiSecretKey": "xxx",
Expand All @@ -68,22 +68,22 @@ File example :
Pass through java argument your file path like `-Dtwitter.credentials.file.path=/your/path/to/json`
. Then instantiate the client like

```
```java
TwitterClient client = new TwitterClient();
```

or

##### Using deserialization in your code

```
```java
TwitterClient twitterClient = new TwitterClient(TwitterClient.OBJECT_MAPPER
.readValue(new File("/your/path/to/json"), TwitterCredentials.class));
```

#### With hard-coded values

```
```java
TwitterClient twitterClient = new TwitterClient(TwitterCredentials.builder()
.accessToken("<access_token>")
.accessTokenSecret("<secret_token>")
Expand Down Expand Up @@ -117,14 +117,14 @@ See :

#### 1. Init TwitterClient

```
```java
TwitterClient twitterClient = new TwitterClient(TwitterClient.OBJECT_MAPPER
.readValue(new File("/your/path/to/json"), TwitterCredentials.class));
```

#### 2. Get Tweet object from tweet id and display some information

```
```java
Tweet tweet = twitterClient.getTweet("1224041905333379073");
System.out.println(tweet.getText());
System.out.println(tweet.getCreatedAt());
Expand All @@ -137,7 +137,7 @@ System.out.println(tweet.getUser().getName());

#### 3. Get User object from username and display some information

```
```java
User user = twitterClient.getUserFromUserName("RedouaneBali");
System.out.println(tweet.getUser().getName());
System.out.println(tweet.getUser().getDisplayedName());
Expand Down
29 changes: 15 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,34 +71,35 @@
<groupId>org.apache.maven.plugins</groupId>
<version>3.2.0</version>
</plugin>
<plugin>
<artifactId>sonar-maven-plugin</artifactId>
<groupId>org.codehaus.sonar</groupId>
<version>3.8.0.2131</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<groupId>org.codehaus.sonar</groupId>
<type>maven-plugin</type>
<version>1.13</version>
</dependency>
<dependency>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<version>2.12.5</version>
<version>2.13.4.1</version>
</dependency>
<dependency>
<artifactId>jackson-datatype-jsr310</artifactId>
<groupId>com.fasterxml.jackson.datatype</groupId>
<version>2.12.5</version>
<version>2.13.2</version>
</dependency>
<dependency>
<artifactId>jackson-dataformat-yaml</artifactId>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<version>2.12.5</version>
<version>2.13.2</version>
</dependency>
<dependency>
<artifactId>lombok</artifactId>
<groupId>org.projectlombok</groupId>
<scope>provided</scope>
<version>1.18.20</version>
<version>1.18.22</version>
</dependency>
<dependency>
<artifactId>scribejava-apis</artifactId>
Expand All @@ -115,7 +116,7 @@
<dependency>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
<version>1.7.32</version>
<version>1.7.36</version>
</dependency>
<dependency>
<artifactId>httpclient</artifactId>
Expand All @@ -126,19 +127,19 @@
<artifactId>junit-jupiter-api</artifactId>
<groupId>org.junit.jupiter</groupId>
<scope>test</scope>
<version>5.7.2</version>
<version>5.8.2</version>
</dependency>
<dependency>
<artifactId>junit-jupiter-params</artifactId>
<groupId>org.junit.jupiter</groupId>
<scope>test</scope>
<version>5.7.2</version>
<version>5.8.2</version>
</dependency>
<dependency>
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
<scope>test</scope>
<version>1.2.3</version>
<version>1.2.11</version>
</dependency>
</dependencies>
<description>Java Client for the Twitter API</description>
Expand Down Expand Up @@ -194,5 +195,5 @@

<url>https://github.com/Redouane59/twittered</url>

<version>2.16</version>
<version>2.21</version>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import io.github.redouane59.twitter.dto.collections.CollectionsResponse;
import io.github.redouane59.twitter.dto.collections.CollectionsResponse.Response.Position;
import io.github.redouane59.twitter.dto.collections.TimeLineOrder;
import io.github.redouane59.twitter.dto.dm.DirectMessage;
import io.github.redouane59.twitter.dto.dm.DmEvent;
import io.github.redouane59.twitter.dto.dm.deprecatedV1.DirectMessage;
import io.github.redouane59.twitter.dto.dm.deprecatedV1.DmEvent;
import io.github.redouane59.twitter.dto.others.RateLimitStatus;
import io.github.redouane59.twitter.dto.others.RequestToken;
import io.github.redouane59.twitter.dto.tweet.MediaCategory;
Expand Down Expand Up @@ -161,6 +161,7 @@ public interface ITwitterClientV1 {
* Returns all Direct Message events (both sent and received) within the last 30 days. Sorted in reverse-chronological order. Calling
* https://api.twitter.com/1.1/direct_messages/events/list.json
*/
@Deprecated
List<DirectMessage> getDmList();

/**
Expand All @@ -169,13 +170,15 @@ public interface ITwitterClientV1 {
*
* @param count Number of direct messages to be returned
*/
@Deprecated
List<DirectMessage> getDmList(int count);

/**
* Returns a single Direct Message event by the given id.
*
* @param dmId The id of the Direct Message event that should be returned.
*/
@Deprecated
DirectMessage getDm(String dmId);

/**
Expand All @@ -184,6 +187,7 @@ public interface ITwitterClientV1 {
* @param text defining the content to deliver to the reciepient
* @param userId The ID of the user who should receive the direct message.
*/
@Deprecated
DmEvent postDm(String text, String userId);

}
96 changes: 95 additions & 1 deletion src/main/java/io/github/redouane59/twitter/ITwitterClientV2.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package io.github.redouane59.twitter;

import com.github.scribejava.core.model.Response;
import io.github.redouane59.twitter.dto.dm.DirectMessage;
import io.github.redouane59.twitter.dto.dm.DmParameters;
import io.github.redouane59.twitter.dto.dm.DmParameters.DmMessage;
import io.github.redouane59.twitter.dto.dm.PostDmResponse;
import io.github.redouane59.twitter.dto.endpoints.AdditionalParameters;
import io.github.redouane59.twitter.dto.list.TwitterList;
import io.github.redouane59.twitter.dto.list.TwitterListList;
Expand All @@ -23,6 +27,7 @@
import io.github.redouane59.twitter.dto.user.UserList;
import java.util.List;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

public interface ITwitterClientV2 {
Expand Down Expand Up @@ -201,6 +206,16 @@ public static enum REQUEST_TWEET_FIELDS_SCOPE {
*/
Future<Response> startFilteredStream(IAPIEventListener listener, int backfillMinutes);

/**
* Stops the filtered stream with the result of the startFilteredStream. It'll wait a maximum of timeout before giving up and returning false. If
* timeout isn't hit, it'll close the socket opened.
*
* @param response Future<Response> given by startFilteredStream
* @param timeout long How long to wait
* @param unit TimeUnit Units for timeout
*/
boolean stopFilteredStream(Future<Response> response, long timeout, TimeUnit unit);

/**
* Stops the filtered stream with the result of the startFilteredStream. It'll close the socket opened.
*
Expand Down Expand Up @@ -642,6 +657,14 @@ public static enum REQUEST_TWEET_FIELDS_SCOPE {
*/
TwitterList getList(String listId);

/**
* Get a tweet list by list id calling https://api.twitter.com/2/lists/:id/tweets
*
* @param listId The ID of the List to lookup.
* @param additionalParameters accepted parameters are recursiveCall, sinceId, maxResults*
*/
TweetList getListTweets(String listId, AdditionalParameters additionalParameters);

/**
* Returns a list of users who are members of the specified List
*
Expand Down Expand Up @@ -680,5 +703,76 @@ public static enum REQUEST_TWEET_FIELDS_SCOPE {
*/
boolean deleteTweet(String tweetId);

/**
* Returns a list of Direct Messages for the authenticated user, both sent and received calling https://api.twitter.com/2/dm_events. Direct Message
* events are returned in reverse chronological order. Supports retrieving events from the previous 30 days.
*/
DirectMessage getDirectMessageEvents();

/**
* Returns a list of Direct Messages for the authenticated user, both sent and received calling https://api.twitter.com/2/dm_events. Direct Message
* events are returned in reverse chronological order. Supports retrieving events from the previous 30 days.
*/
DirectMessage getDirectMessageEvents(AdditionalParameters additionalParameters);

/**
* Returns a list of Direct Messages within a conversation specified in the dm_conversation_id path parameter calling
* https://api.twitter.com/2/dm_conversations/:dm_conversation_id/dm_events. Messages are returned in reverse chronological order.
*/
DirectMessage getDirectMessagesByConversation(String conversationId);

/**
* Returns a list of Direct Messages within a conversation specified in the dm_conversation_id path parameter calling
* https://api.twitter.com/2/dm_conversations/:dm_conversation_id/dm_events. Messages are returned in reverse chronological order.
*/
DirectMessage getDirectMessagesByConversation(String conversationId, AdditionalParameters additionalParameters);

/**
* Returns a list of Direct Messages (DM) events within a 1-1 conversation with the user specified in the participant_id path parameter calling
* https://api.twitter.com/2/dm_conversations/with/:participant_id/dm_events. Messages are returned in reverse chronological order.
*/
DirectMessage getDirectMessagesByUser(String participantId);

/**
* Returns a list of Direct Messages (DM) events within a 1-1 conversation with the user specified in the participant_id path parameter calling
* https://api.twitter.com/2/dm_conversations/with/:participant_id/dm_events. Messages are returned in reverse chronological order.
*/
DirectMessage getDirectMessagesByUser(String participantId, AdditionalParameters additionalParameters);

/**
* Creates a Direct Message on behalf of an authenticated user, and adds it to the specified conversation calling
* https://api.twitter.com/2/dm_conversations/:dm_conversation_id/messages.
*/
PostDmResponse createDirectMessage(String conversationId, String text);

/**
* Creates a Direct Message on behalf of an authenticated user, and adds it to the specified conversation calling
* https://api.twitter.com/2/dm_conversations/:dm_conversation_id/messages.
*/
PostDmResponse createDirectMessage(String conversationId, DmMessage message);

/**
* Creates a new group conversation and adds a Direct Message to it on behalf of an authenticated user calling
* https://api.twitter.com/2/dm_conversations
*/
PostDmResponse createGroupDmConversation(DmParameters parameters);

/**
* Creates a new group conversation and adds a Direct Message to it on behalf of an authenticated user calling
* https://api.twitter.com/2/dm_conversations
*/
PostDmResponse createGroupDmConversation(List<String> participantIds, String text);

/**
* Creates a one-to-one Direct Message and adds it to the one-to-one conversation. This method either creates a new one-to-one conversation or
* retrieves the current conversation and adds the Direct Message to it calling https://api.twitter.com/2/dm_conversations/with/:participant_id/messages.
*/
PostDmResponse createUserDmConversation(String participantId, String text);

/**
* Creates a one-to-one Direct Message and adds it to the one-to-one conversation. This method either creates a new one-to-one conversation or
* retrieves the current conversation and adds the Direct Message to it calling https://api.twitter.com/2/dm_conversations/with/:participant_id/messages.
*/
PostDmResponse createUserDmConversation(String participantId, DmMessage message);

}
}
Loading

0 comments on commit 5d49d4a

Please sign in to comment.