Skip to content

Commit

Permalink
v2.22 (#429)
Browse files Browse the repository at this point in the history
* Added @Jacksonized to all @builder classes. (#428)

* Updated README.md (#431)

Updated README.md with the correct print statements for the user example.

* Empty predicate (#434)

* Fix formatting

* Handle empty predicates

This commit improves FilteredStreamRulePredicate so that an empty
predicate is handled properly when associated with an operator.

* Bump jackson-databind from 2.13.4.1 to 2.13.4.2 (#441)

Bumps [jackson-databind](https://github.com/FasterXML/jackson) from 2.13.4.1 to 2.13.4.2.
- [Release notes](https://github.com/FasterXML/jackson/releases)
- [Commits](https://github.com/FasterXML/jackson/commits)

---
updated-dependencies:
- dependency-name: com.fasterxml.jackson.core:jackson-databind
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix for issue #440 and improved rate limit handling (#442)

* update version

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: takeshitakenji <[email protected]>
Co-authored-by: suomi35 <[email protected]>
Co-authored-by: Stéphane Nicoll <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Swiss Dev <[email protected]>
  • Loading branch information
6 people authored Apr 3, 2023
1 parent b8bf00f commit ff71389
Show file tree
Hide file tree
Showing 24 changed files with 241 additions and 264 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,18 @@ System.out.println(tweet.getUser().getName());

```java
User user = twitterClient.getUserFromUserName("RedouaneBali");
System.out.println(tweet.getUser().getName());
System.out.println(tweet.getUser().getDisplayedName());
System.out.println(tweet.getUser().getDateOfCreation());
System.out.println(tweet.getUser().getDescription());
System.out.println(tweet.getUser().getTweetCount());
System.out.println(tweet.getUser().getFollowersCount());
System.out.println(tweet.getUser().getFollowingCount());
System.out.println(tweet.getUser().getPinnedTweet());
System.out.println(tweet.getUser().getPinnedTweet());
System.out.println(tweet.getUser().getLocation());
System.out.println(tweet.getUser().getId());
System.out.println(tweet.getUser().getUrl());
System.out.println(user.getName());
System.out.println(user.getDisplayedName());
System.out.println(user.getDateOfCreation());
System.out.println(user.getDescription());
System.out.println(user.getTweetCount());
System.out.println(user.getFollowersCount());
System.out.println(user.getFollowingCount());
System.out.println(user.getPinnedTweet());
System.out.println(user.getPinnedTweet());
System.out.println(user.getLocation());
System.out.println(user.getId());
System.out.println(user.getUrl());
```

### Contribution
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<dependency>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<version>2.13.4.1</version>
<version>2.13.4.2</version>
</dependency>
<dependency>
<artifactId>jackson-datatype-jsr310</artifactId>
Expand Down Expand Up @@ -195,5 +195,5 @@

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

<version>2.21</version>
<version>2.22</version>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import java.util.List;
import lombok.Builder;
import lombok.Getter;
import lombok.extern.jackson.Jacksonized;

@Builder
@Jacksonized
public class DmParameters {

@JsonProperty("conversation_type")
Expand All @@ -18,6 +20,7 @@ public class DmParameters {

@Builder
@Getter
@Jacksonized
public static class DmMessage {

private String text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.jackson.Jacksonized;

@Builder
@Getter
@Setter
@Jacksonized
public class AdditionalParameters {

public static final String SINCE_ID = "since_id";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.jackson.Jacksonized;

@NoArgsConstructor
@AllArgsConstructor
@Builder
@Getter
@Jacksonized
public class TwitterListMember {

private TwitterListMemberData data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public class FilteredStreamRulePredicate {
FilteredStreamRulePredicate() {
}

private FilteredStreamRulePredicate(String predicate) {
this.predicate = predicate;
}

private static FilteredStreamRulePredicate build(String one, String two, String operator) {
FilteredStreamRulePredicate p = new FilteredStreamRulePredicate();
if (one == null || one.isEmpty()) {
Expand All @@ -27,194 +31,196 @@ public static FilteredStreamRulePredicate withKeyword(String keyword) {
}

public static FilteredStreamRulePredicate withEmoji(String emoji) {
return build("", emoji, "");
return new FilteredStreamRulePredicate(emoji);
}

public static FilteredStreamRulePredicate withExactPhrase(String phrase) {
return build("", "\"" + phrase + "\"", "");
return new FilteredStreamRulePredicate(quote(phrase));
}

public static FilteredStreamRulePredicate withHashtag(String hashtag) {
return build("", hashtag.startsWith("#") ? hashtag : "#" + hashtag, "");
String predicate = hashtag.startsWith("#") ? hashtag : "#" + hashtag;
return new FilteredStreamRulePredicate(predicate);
}

public static FilteredStreamRulePredicate withMention(String mention) {
return build("", mention.startsWith("@") ? mention : "@" + mention, "");
String predicate = mention.startsWith("@") ? mention : "@" + mention;
return new FilteredStreamRulePredicate(predicate);
}

public static FilteredStreamRulePredicate withCashtag(String cashtag) {
return build("", cashtag.startsWith("$") ? cashtag : "$" + cashtag, "");
String predicate = cashtag.startsWith("$") ? cashtag : "$" + cashtag;
return new FilteredStreamRulePredicate(predicate);
}

public static FilteredStreamRulePredicate withUser(String user) {
return build("", user, "from:");
return new FilteredStreamRulePredicate("from:" + user);
}

public static FilteredStreamRulePredicate withReplyTo(String user) {
return build("", user, "to:");
return new FilteredStreamRulePredicate("to:" + user);
}

public static FilteredStreamRulePredicate withUrl(String url) {
return build("", withExactPhrase(url).toString(), "url:");
return new FilteredStreamRulePredicate("url:" + quote(url));
}

public static FilteredStreamRulePredicate withRetweetsOf(String user) {
return build("", user, "retweets_of:");
return new FilteredStreamRulePredicate("retweets_of:" + user);
}

public static FilteredStreamRulePredicate withContext(String context) {
return build("", context, "context:");
return new FilteredStreamRulePredicate("context:" + context);
}

public static FilteredStreamRulePredicate withEntity(String entity) {
return build("", withExactPhrase(entity).toString(), "entity:");
return new FilteredStreamRulePredicate("entity:" + quote(entity));
}

public static FilteredStreamRulePredicate withConversationId(String conversationId) {
return build("", conversationId, "conversation_id:");
return new FilteredStreamRulePredicate("conversation_id:" + conversationId);
}

public static FilteredStreamRulePredicate withBio(String bio) {
return build("", bio, "bio:");
return new FilteredStreamRulePredicate("bio:" + bio);
}

public static FilteredStreamRulePredicate withBioName(String bioName) {
return build("", bioName, "bio_name:");
return new FilteredStreamRulePredicate("bio_name:" + bioName);
}

public static FilteredStreamRulePredicate withBioLocation(String bioLocation) {
return build("", bioLocation, "bio_location:");
return new FilteredStreamRulePredicate("bio_location:" + bioLocation);
}

public static FilteredStreamRulePredicate withPlace(String place) {
return build("", place, "place:");
return new FilteredStreamRulePredicate("place:" + place);
}

public static FilteredStreamRulePredicate withPlaceCountry(String alpha2IsoCode) {
return build("", alpha2IsoCode, "place_country:");
return new FilteredStreamRulePredicate("place_country:" + alpha2IsoCode);
}

public static FilteredStreamRulePredicate withPointRadius(double longitude, double latitude, String radius) {
//mi or km
return build("", "[" + longitude + " " + latitude + " " + radius + "]", "point_radius:");
String pointRadius = "[" + longitude + " " + latitude + " " + radius + "]";
return new FilteredStreamRulePredicate("point_radius:" + pointRadius);
}

public static FilteredStreamRulePredicate withBoundingBox(double westLongitude, double southLatitude, double eastLongitude, double northLatitude) {
//mi or km
return build("", "[" + westLongitude + " " + southLatitude + " " + eastLongitude + " " + northLatitude + "]", "bounding_box:");
String boundingBox = "[" + westLongitude + " " + southLatitude + " " + eastLongitude + " " + northLatitude + "]";
return new FilteredStreamRulePredicate("bounding_box:" + boundingBox);
}

public static FilteredStreamRulePredicate withLanguage(String language) {
return build("", language, "lang:");
}

public static FilteredStreamRulePredicate isRetweet(FilteredStreamRulePredicate predicate) {
checkConjunction(predicate);
return build(predicate.toString(), "", "is:retweet");
return new FilteredStreamRulePredicate("lang:" + language);
}

public static FilteredStreamRulePredicate isReply(FilteredStreamRulePredicate predicate) {
checkConjunction(predicate);
return build(predicate.toString(), "", "is:reply");
public static FilteredStreamRulePredicate isRetweet() {
return new FilteredStreamRulePredicate("is:retweet");
}

public static FilteredStreamRulePredicate isQuote(FilteredStreamRulePredicate predicate) {
checkConjunction(predicate);
return build(predicate.toString(), "", "is:quote");
public static FilteredStreamRulePredicate isReply() {
return new FilteredStreamRulePredicate("is:reply");
}

public static FilteredStreamRulePredicate isVerified(FilteredStreamRulePredicate predicate) {
checkConjunction(predicate);
return build(predicate.toString(), "", "is:verified");
public static FilteredStreamRulePredicate isQuote() {
return new FilteredStreamRulePredicate("is:quote");
}

public static FilteredStreamRulePredicate isNullcast(FilteredStreamRulePredicate predicate) {
checkConjunction(predicate);
return build(predicate.toString(), "", "-is:nullcast");
public static FilteredStreamRulePredicate isVerified() {
return new FilteredStreamRulePredicate("is:verified");
}

public static FilteredStreamRulePredicate hasHashtags(FilteredStreamRulePredicate predicate) {
checkConjunction(predicate);
return build(predicate.toString(), "", "has:hashtags");
public static FilteredStreamRulePredicate isNullcast() {
return new FilteredStreamRulePredicate("-is:nullcast");
}

public static FilteredStreamRulePredicate hasCashtags(FilteredStreamRulePredicate predicate) {
checkConjunction(predicate);
return build(predicate.toString(), "", "has:cashtags");
public static FilteredStreamRulePredicate hasHashtags() {
return new FilteredStreamRulePredicate("has:hashtags");
}

public static FilteredStreamRulePredicate hasLinks(FilteredStreamRulePredicate predicate) {
checkConjunction(predicate);
return build(predicate.toString(), "", "has:links");
public static FilteredStreamRulePredicate hasCashtags() {
return new FilteredStreamRulePredicate("has:cashtags");
}

public static FilteredStreamRulePredicate hasMentions(FilteredStreamRulePredicate predicate) {
checkConjunction(predicate);
return build(predicate.toString(), "", "has:mentions");
public static FilteredStreamRulePredicate hasLinks() {
return new FilteredStreamRulePredicate("has:links");
}

public static FilteredStreamRulePredicate hasMedia(FilteredStreamRulePredicate predicate) {
checkConjunction(predicate);
return build(predicate.toString(), "", "has:media");
public static FilteredStreamRulePredicate hasMentions() {
return new FilteredStreamRulePredicate("has:mentions");
}

public static FilteredStreamRulePredicate hasImages(FilteredStreamRulePredicate predicate) {
checkConjunction(predicate);
return build(predicate.toString(), "", "has:images");
public static FilteredStreamRulePredicate hasMedia() {
return new FilteredStreamRulePredicate("has:media");
}

public static FilteredStreamRulePredicate hasVideos(FilteredStreamRulePredicate predicate) {
checkConjunction(predicate);
return build(predicate.toString(), "", "has:videos");
public static FilteredStreamRulePredicate hasImages() {
return new FilteredStreamRulePredicate("has:images");
}

public static FilteredStreamRulePredicate hasGeo(FilteredStreamRulePredicate predicate, String geo) {
checkConjunction(predicate);
return build(predicate.toString(), " " + geo, "has:geo");
public static FilteredStreamRulePredicate hasVideos() {
return new FilteredStreamRulePredicate("has:videos");
}

public static FilteredStreamRulePredicate doSampling(FilteredStreamRulePredicate predicate, int sampleSize) {
checkConjunction(predicate);
return build(predicate.toString(), Integer.toString(sampleSize), "sample:");
public static FilteredStreamRulePredicate hasGeo(String geo) {
return new FilteredStreamRulePredicate("has:geo " + geo);
}

private static void checkConjunction(FilteredStreamRulePredicate predicate) {
if (predicate == null || predicate.isEmpty()) {
throw new RuleBuilderException("Given operator can only be used in an conjunction");
}
public static FilteredStreamRulePredicate doSampling(int sampleSize) {
return new FilteredStreamRulePredicate("sample:" + sampleSize);
}

public FilteredStreamRulePredicate negate() {
if (predicate == null) {
throw new RuleBuilderException("Cannot negate empty predicate");
}
predicate = "-" + capsule();
return this;
}

public FilteredStreamRulePredicate capsule() {
predicate = "(" + predicate + ")";
if (predicate != null) {
predicate = "(" + predicate + ")";
}
return this;
}

public FilteredStreamRulePredicate or(FilteredStreamRulePredicate other) {
predicate += " OR " + other.predicate;
applyOperator(" OR ", other);
return this;
}

public FilteredStreamRulePredicate and(FilteredStreamRulePredicate other) {
predicate += " " + other.predicate;
applyOperator(" ", other);
return this;
}

public static FilteredStreamRulePredicate empty() {
return build("","","");
return new FilteredStreamRulePredicate(null);
}

public boolean isEmpty() {
return predicate == null;
}

private void applyOperator(String operator, FilteredStreamRulePredicate right) {
if (this.predicate == null) {
this.predicate = right.predicate;
} else if (right != null && !right.isEmpty()) {
this.predicate = this.predicate + operator + right.predicate;
}
}

private static String quote(String phrase) {
return "\"" + phrase + "\"";
}

@Override
public String toString() {
return predicate;
return (predicate != null ? predicate : "");
}

public static class RuleBuilderException extends RuntimeException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.jackson.Jacksonized;

@NoArgsConstructor
@AllArgsConstructor
@Builder
@Getter
@Jacksonized
public class Space {

private SpaceData data;
Expand All @@ -22,6 +24,7 @@ public class Space {
@AllArgsConstructor
@Builder
@Getter
@Jacksonized
public static class SpaceData {

private String id;
Expand Down
Loading

0 comments on commit ff71389

Please sign in to comment.