diff --git a/src/main/java/io/github/redouane59/twitter/dto/tweet/Tweet.java b/src/main/java/io/github/redouane59/twitter/dto/tweet/Tweet.java index 9e7a35fe..2f11f621 100644 --- a/src/main/java/io/github/redouane59/twitter/dto/tweet/Tweet.java +++ b/src/main/java/io/github/redouane59/twitter/dto/tweet/Tweet.java @@ -1,6 +1,7 @@ package io.github.redouane59.twitter.dto.tweet; import io.github.redouane59.twitter.dto.stream.StreamRules; +import io.github.redouane59.twitter.dto.tweet.TweetV2.Place; import io.github.redouane59.twitter.dto.tweet.entities.Entities; import io.github.redouane59.twitter.dto.tweet.entities.MediaEntity; import io.github.redouane59.twitter.dto.user.User; @@ -152,6 +153,11 @@ public interface Tweet { */ List getMedia(); + /** + * Get the {@link Place place} of the tweet + */ + List getPlaces(); + /** * When an activity is delivered through a filtered stream connection, the matching_rules list contains which list of filters matched against the * Tweet delivered. diff --git a/src/main/java/io/github/redouane59/twitter/dto/tweet/TweetV1.java b/src/main/java/io/github/redouane59/twitter/dto/tweet/TweetV1.java index 1f40041d..3b438d18 100644 --- a/src/main/java/io/github/redouane59/twitter/dto/tweet/TweetV1.java +++ b/src/main/java/io/github/redouane59/twitter/dto/tweet/TweetV1.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import io.github.redouane59.twitter.dto.stream.StreamRules.StreamRule; +import io.github.redouane59.twitter.dto.tweet.TweetV2.Place; import io.github.redouane59.twitter.dto.tweet.entities.BaseEntity; import io.github.redouane59.twitter.dto.tweet.entities.Entities; import io.github.redouane59.twitter.dto.tweet.entities.HashtagEntity; @@ -120,6 +121,12 @@ public List getMedia() { return Collections.emptyList(); } + @Override + public List getPlaces() { + LOGGER.error(NOT_IMPLEMENTED_EXCEPTION); + return Collections.emptyList(); + } + @Override public List getMatchingRules() { LOGGER.error(NOT_IMPLEMENTED_EXCEPTION); diff --git a/src/main/java/io/github/redouane59/twitter/dto/tweet/TweetV2.java b/src/main/java/io/github/redouane59/twitter/dto/tweet/TweetV2.java index 061dbe93..2c093330 100644 --- a/src/main/java/io/github/redouane59/twitter/dto/tweet/TweetV2.java +++ b/src/main/java/io/github/redouane59/twitter/dto/tweet/TweetV2.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; import io.github.redouane59.twitter.dto.stream.StreamRules; import io.github.redouane59.twitter.dto.stream.StreamRules.StreamRule; import io.github.redouane59.twitter.dto.tweet.entities.BaseEntity; @@ -147,6 +148,14 @@ public List getMedia() { return includes.getMedia(); } + @Override + public List getPlaces() { + if (includes == null) { + return Collections.emptyList(); + } + return includes.getPlaces(); + } + @Override public int getRetweetCount() { if (data == null) { @@ -327,13 +336,19 @@ public TweetType getTweetType() { @Override public List getMedia() { - LOGGER.error(NOT_IMPLEMENTED_EXCEPTION); + LOGGER.info(NOT_IMPLEMENTED_EXCEPTION); + return Collections.emptyList(); + } + + @Override + public List getPlaces() { + LOGGER.info(NOT_IMPLEMENTED_EXCEPTION); return Collections.emptyList(); } @Override public List getMatchingRules() { - LOGGER.error(NOT_IMPLEMENTED_EXCEPTION); + LOGGER.info(NOT_IMPLEMENTED_EXCEPTION); return Collections.emptyList(); } @@ -367,6 +382,7 @@ public static class Includes { private List users; private List tweets; private List media; + private List places; } @@ -515,6 +531,31 @@ public long getId() { } } + @Getter + @Setter + public static class Place { + + private Geo geo; + @JsonProperty("country_code") + private String countryCode; + private String name; + private String id; + @JsonProperty("place_type") + private String placeType; + private String country; + @JsonProperty("full_name") + private String fullName; + + @Getter + @Setter + public static class Geo { + + private String type; + private List bbox; + private JsonNode properties; + } + } + @Getter @Setter public static class MediaPublicMetricsDTO { diff --git a/src/test/java/io/github/redouane59/twitter/unit/TweetDeserializerV2Test.java b/src/test/java/io/github/redouane59/twitter/unit/TweetDeserializerV2Test.java index 193515eb..a0755bd7 100644 --- a/src/test/java/io/github/redouane59/twitter/unit/TweetDeserializerV2Test.java +++ b/src/test/java/io/github/redouane59/twitter/unit/TweetDeserializerV2Test.java @@ -10,6 +10,7 @@ import io.github.redouane59.twitter.dto.tweet.ReplySettings; import io.github.redouane59.twitter.dto.tweet.Tweet; import io.github.redouane59.twitter.dto.tweet.TweetV2; +import io.github.redouane59.twitter.dto.tweet.TweetV2.Place; import io.github.redouane59.twitter.dto.tweet.entities.HashtagEntity; import io.github.redouane59.twitter.dto.tweet.entities.MediaEntity; import io.github.redouane59.twitter.dto.tweet.entities.SymbolEntity; @@ -230,4 +231,18 @@ public void testEntitiesMedia() { assertEquals(1280, ev2.getWidth()); assertEquals("test", ev2.getAltText()); } + + @Test + public void testIncludesPlace() { + List places = tweetv2.getPlaces(); + Place place = places.get(0); + assertEquals("US", place.getCountryCode()); + assertEquals("Manhattan", place.getName()); + assertEquals("01a9a39529b27f36", place.getId()); + assertEquals("city", place.getPlaceType()); + assertEquals("United States", place.getCountry()); + assertEquals("Manhattan, NY", place.getFullName()); + assertEquals("Feature", place.getGeo().getType()); + assertTrue(place.getGeo().getBbox().size() > 0); + } } diff --git a/src/test/resources/tests/tweet_example_v2.json b/src/test/resources/tests/tweet_example_v2.json index ee26e6ed..07eaa1ce 100644 --- a/src/test/resources/tests/tweet_example_v2.json +++ b/src/test/resources/tests/tweet_example_v2.json @@ -139,6 +139,26 @@ "created_at": "2007-11-03T17:51:40.000Z", "url": "https://t.co/VDTjQvcKXp" } + ], + "places": [ + { + "geo": { + "type": "Feature", + "bbox": [ + -74.026675, + 40.683935, + -73.910408, + 40.877483 + ], + "properties": {} + }, + "country_code": "US", + "name": "Manhattan", + "id": "01a9a39529b27f36", + "place_type": "city", + "country": "United States", + "full_name": "Manhattan, NY" + } ] } } \ No newline at end of file