Skip to content
This repository has been archived by the owner on Mar 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #186 from smrnv/GH-102-extended-tweet-mode-support
Browse files Browse the repository at this point in the history
Added tweet_mode to searchTweet (#102)
  • Loading branch information
DanielaSfregola authored Jan 28, 2018
2 parents 8d0166a + d66aee9 commit 71460d3
Show file tree
Hide file tree
Showing 28 changed files with 1,072 additions and 750 deletions.
71 changes: 36 additions & 35 deletions src/main/scala/com/danielasfregola/twitter4s/entities/Tweet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,42 @@ import java.util.Date
import com.danielasfregola.twitter4s.entities.streaming.CommonStreamingMessage

final case class Tweet(contributors: Seq[Contributor] = Seq.empty,
coordinates: Option[Coordinates] = None,
created_at: Date,
current_user_retweet: Option[TweetId] = None,
entities: Option[Entities] = None,
extended_entities: Option[Entities] = None,
favorite_count: Int = 0,
favorited: Boolean = false,
filter_level: Option[String] = None,
geo: Option[Geo] = None,
id: Long,
id_str: String,
in_reply_to_screen_name: Option[String] = None,
in_reply_to_status_id: Option[Long] = None,
in_reply_to_status_id_str: Option[String] = None,
in_reply_to_user_id: Option[Long] = None,
in_reply_to_user_id_str: Option[String] = None,
is_quote_status: Boolean = false,
lang: Option[String] = None,
place: Option[GeoPlace] = None,
possibly_sensitive: Boolean = false,
quoted_status_id: Option[Long] = None,
quoted_status_id_str: Option[String] = None,
quoted_status: Option[Tweet] = None,
scopes: Map[String, Boolean] = Map.empty,
retweet_count: Long = 0,
retweeted: Boolean = false,
retweeted_status: Option[Tweet] = None,
source: String,
text: String,
truncated: Boolean = false,
user: Option[User] = None,
withheld_copyright: Boolean = false,
withheld_in_countries: Seq[String] = Seq.empty,
withheld_scope: Option[String] = None,
metadata: Option[StatusMetadata] = None) extends CommonStreamingMessage
coordinates: Option[Coordinates] = None,
created_at: Date,
current_user_retweet: Option[TweetId] = None,
entities: Option[Entities] = None,
extended_entities: Option[Entities] = None,
favorite_count: Int = 0,
favorited: Boolean = false,
filter_level: Option[String] = None,
geo: Option[Geo] = None,
id: Long,
id_str: String,
in_reply_to_screen_name: Option[String] = None,
in_reply_to_status_id: Option[Long] = None,
in_reply_to_status_id_str: Option[String] = None,
in_reply_to_user_id: Option[Long] = None,
in_reply_to_user_id_str: Option[String] = None,
is_quote_status: Boolean = false,
lang: Option[String] = None,
place: Option[GeoPlace] = None,
possibly_sensitive: Boolean = false,
quoted_status_id: Option[Long] = None,
quoted_status_id_str: Option[String] = None,
quoted_status: Option[Tweet] = None,
scopes: Map[String, Boolean] = Map.empty,
retweet_count: Long = 0,
retweeted: Boolean = false,
retweeted_status: Option[Tweet] = None,
source: String,
text: String,
truncated: Boolean = false,
display_text_range: Option[Seq[Int]] = None,
user: Option[User] = None,
withheld_copyright: Boolean = false,
withheld_in_countries: Seq[String] = Seq.empty,
withheld_scope: Option[String] = None,
metadata: Option[StatusMetadata] = None) extends CommonStreamingMessage



Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.danielasfregola.twitter4s.entities.enums

object TweetMode extends Enumeration {
type TweetMode = Value

val Extended = Value("extended")
val Classic = Value("")
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.danielasfregola.twitter4s.http.clients.rest.lists.parameters

import com.danielasfregola.twitter4s.entities.enums.TweetMode.TweetMode
import com.danielasfregola.twitter4s.http.marshalling.Parameters

private[twitter4s] final case class ListTimelineParameters(list_id: Option[Long] = None,
slug: Option[String] = None,
owner_screen_name: Option[String] = None,
owner_id: Option[Long] = None,
count: Int,
since_id: Option[Long] = None,
max_id: Option[Long] = None,
include_entities: Boolean,
include_rts: Boolean) extends Parameters
slug: Option[String] = None,
owner_screen_name: Option[String] = None,
owner_id: Option[Long] = None,
count: Int,
since_id: Option[Long] = None,
max_id: Option[Long] = None,
include_entities: Boolean,
include_rts: Boolean,
tweet_mode: TweetMode) extends Parameters
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package clients.rest.search

import java.time.LocalDate

import com.danielasfregola.twitter4s.entities._
import com.danielasfregola.twitter4s.entities.enums.Language._
import com.danielasfregola.twitter4s.entities.enums.ResultType
import com.danielasfregola.twitter4s.entities.enums.{ResultType, TweetMode}
import com.danielasfregola.twitter4s.entities.enums.ResultType._
import com.danielasfregola.twitter4s.entities.{GeoCode, RatedData, StatusSearch}
import com.danielasfregola.twitter4s.entities.enums.TweetMode.TweetMode
import com.danielasfregola.twitter4s.http.clients.rest.RestClient
import com.danielasfregola.twitter4s.http.clients.rest.search.parameters.TweetSearchParameters
import com.danielasfregola.twitter4s.util.Configurations._
Expand All @@ -24,44 +25,46 @@ trait TwitterSearchClient {
/** Returns a collection of relevant Tweets matching a specified query.
* For more information see
* <a href="https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets" target="_blank">
* https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets</a>.
* https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets</a>.
*
* @param query : The search query of 500 characters maximum, including operators.
* Queries may additionally be limited by complexity.
* @param count : By default it is `15`.
* The number of tweets to return per page, up to a maximum of 100.
* @param query : The search query of 500 characters maximum, including operators.
* Queries may additionally be limited by complexity.
* @param count : By default it is `15`.
* The number of tweets to return per page, up to a maximum of 100.
* @param include_entities : By default it is `true`.
* The parameters node will be disincluded when set to `false`.
* @param result_type : By default it is `Mixed`.
* Specifies what type of search results you would prefer to receive.
* Valid values include:
* @param result_type : By default it is `Mixed`.
* Specifies what type of search results you would prefer to receive.
* Valid values include:
* - `Mixed`: Include both popular and real time results in the response.
* - `Recent`: return only the most recent results in the response
* - `Popular`: return only the most popular results in the response.
* @param geocode : Optional, by default it is `None`.
* Returns tweets by users located within a given radius of the given latitude/longitude.
* The location is preferentially taking from the Geotagging API, but will fall back to their Twitter profile.
* Note that you cannot use the near operator via the API to geocode arbitrary locations;
* however you can use this geocode parameter to search near geocodes directly.
* A maximum of 1,000 distinct “sub-regions” will be considered when using the radius modifier.
* @param language : Optional, by default it is `None`.
* Restricts tweets to the given language. Language detection is best-effort.
* @param locale : Optional, by default it is `None`.
* Specify the language of the query you are sending (only `ja` is currently effective).
* This is intended for language-specific consumers and the default should work in the majority of cases.
* @param until : Optional, by default it is `None`.
* Returns tweets created before the given date.
* Keep in mind that the search index has a 7-day limit.
* In other words, no tweets will be found for a date older than one week.
* @param since_id : Optional, by default it is `None`.
* Returns results with an ID greater than (that is, more recent than) the specified ID.
* There are limits to the number of Tweets which can be accessed through the API.
* If the limit of Tweets has occured since the since_id, the since_id will be forced to the oldest ID available.
* @param max_id : Optional, by default it is `None`.
* Returns results with an ID less than (that is, older than) or equal to the specified ID.
* @param callback : Optional, by default it is `None`.
* If supplied, the response will use the JSONP format with a callback of the given name.
* The usefulness of this parameter is somewhat diminished by the requirement of authentication for requests to this endpoint.
* @param geocode : Optional, by default it is `None`.
* Returns tweets by users located within a given radius of the given latitude/longitude.
* The location is preferentially taking from the Geotagging API, but will fall back to their Twitter profile.
* Note that you cannot use the near operator via the API to geocode arbitrary locations;
* however you can use this geocode parameter to search near geocodes directly.
* A maximum of 1,000 distinct “sub-regions” will be considered when using the radius modifier.
* @param language : Optional, by default it is `None`.
* Restricts tweets to the given language. Language detection is best-effort.
* @param locale : Optional, by default it is `None`.
* Specify the language of the query you are sending (only `ja` is currently effective).
* This is intended for language-specific consumers and the default should work in the majority of cases.
* @param until : Optional, by default it is `None`.
* Returns tweets created before the given date.
* Keep in mind that the search index has a 7-day limit.
* In other words, no tweets will be found for a date older than one week.
* @param since_id : Optional, by default it is `None`.
* Returns results with an ID greater than (that is, more recent than) the specified ID.
* There are limits to the number of Tweets which can be accessed through the API.
* If the limit of Tweets has occured since the since_id, the since_id will be forced to the oldest ID available.
* @param max_id : Optional, by default it is `None`.
* Returns results with an ID less than (that is, older than) or equal to the specified ID.
* @param callback : Optional, by default it is `None`.
* If supplied, the response will use the JSONP format with a callback of the given name.
* The usefulness of this parameter is somewhat diminished by the requirement of authentication for requests to this endpoint.
* @param tweet_mode : Optional, by default it is `Classic`.
* When set to `Extended` prevents tweet text truncating, see https://developer.twitter.com/en/docs/tweets/tweet-updates
* @return : The representation of the search results.
*/
def searchTweet(query: String,
Expand All @@ -74,9 +77,13 @@ trait TwitterSearchClient {
until: Option[LocalDate] = None,
since_id: Option[Long] = None,
max_id: Option[Long] = None,
callback: Option[String] = None): Future[RatedData[StatusSearch]] = {
callback: Option[String] = None,
tweet_mode: TweetMode = TweetMode.Classic): Future[RatedData[StatusSearch]] = {
import restClient._
val parameters = TweetSearchParameters(query.escapeSpecialChars, count, include_entities, result_type, geocode, language, locale, until, since_id, max_id, callback)
val parameters = TweetSearchParameters(
query.escapeSpecialChars, count, include_entities, result_type, geocode,
language, locale, until, since_id, max_id, callback, tweet_mode
)
Get(s"$searchUrl/tweets.json", parameters).respondAsRated[StatusSearch]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import java.time.LocalDate
import com.danielasfregola.twitter4s.entities.GeoCode
import com.danielasfregola.twitter4s.entities.enums.Language.Language
import com.danielasfregola.twitter4s.entities.enums.ResultType.ResultType
import com.danielasfregola.twitter4s.entities.enums.TweetMode.TweetMode
import com.danielasfregola.twitter4s.http.marshalling.Parameters

private[twitter4s] final case class TweetSearchParameters(q: String,
count: Int,
include_entities: Boolean,
result_type: ResultType,
geocode: Option[GeoCode],
lang: Option[Language],
locale: Option[String],
until: Option[LocalDate],
since_id: Option[Long],
max_id: Option[Long],
callback: Option[String]) extends Parameters
count: Int,
include_entities: Boolean,
result_type: ResultType,
geocode: Option[GeoCode],
lang: Option[Language],
locale: Option[String],
until: Option[LocalDate],
since_id: Option[Long],
max_id: Option[Long],
callback: Option[String],
tweet_mode: TweetMode) extends Parameters
Loading

0 comments on commit 71460d3

Please sign in to comment.