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: add place includes #357

Merged
merged 1 commit into from
Feb 5, 2022
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
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -152,6 +153,11 @@ public interface Tweet {
*/
List<? extends MediaEntity> getMedia();

/**
* Get the {@link Place place} of the tweet
*/
List<Place> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -120,6 +121,12 @@ public List<MediaEntityV1> getMedia() {
return Collections.emptyList();
}

@Override
public List<Place> getPlaces() {
LOGGER.error(NOT_IMPLEMENTED_EXCEPTION);
return Collections.emptyList();
}

@Override
public List<StreamRule> getMatchingRules() {
LOGGER.error(NOT_IMPLEMENTED_EXCEPTION);
Expand Down
45 changes: 43 additions & 2 deletions src/main/java/io/github/redouane59/twitter/dto/tweet/TweetV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -147,6 +148,14 @@ public List<MediaEntityV2> getMedia() {
return includes.getMedia();
}

@Override
public List<Place> getPlaces() {
if (includes == null) {
return Collections.emptyList();
}
return includes.getPlaces();
}

@Override
public int getRetweetCount() {
if (data == null) {
Expand Down Expand Up @@ -327,13 +336,19 @@ public TweetType getTweetType() {

@Override
public List<MediaEntityV2> getMedia() {
LOGGER.error(NOT_IMPLEMENTED_EXCEPTION);
LOGGER.info(NOT_IMPLEMENTED_EXCEPTION);
return Collections.emptyList();
}

@Override
public List<Place> getPlaces() {
LOGGER.info(NOT_IMPLEMENTED_EXCEPTION);
return Collections.emptyList();
}

@Override
public List<StreamRule> getMatchingRules() {
LOGGER.error(NOT_IMPLEMENTED_EXCEPTION);
LOGGER.info(NOT_IMPLEMENTED_EXCEPTION);
return Collections.emptyList();
}

Expand Down Expand Up @@ -367,6 +382,7 @@ public static class Includes {
private List<UserV2.UserData> users;
private List<TweetV2.TweetData> tweets;
private List<TweetV2.MediaEntityV2> media;
private List<TweetV2.Place> places;
}


Expand Down Expand Up @@ -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<Double> bbox;
private JsonNode properties;
}
}

@Getter
@Setter
public static class MediaPublicMetricsDTO {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -230,4 +231,18 @@ public void testEntitiesMedia() {
assertEquals(1280, ev2.getWidth());
assertEquals("test", ev2.getAltText());
}

@Test
public void testIncludesPlace() {
List<Place> 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);
}
}
20 changes: 20 additions & 0 deletions src/test/resources/tests/tweet_example_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
}