twitter 8.1.0 → 8.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.md +1 -1
- data/README.md +173 -11
- data/lib/twitter/arguments.rb +14 -1
- data/lib/twitter/base.rb +72 -11
- data/lib/twitter/basic_user.rb +7 -1
- data/lib/twitter/client.rb +94 -3
- data/lib/twitter/creatable.rb +11 -2
- data/lib/twitter/cursor.rb +58 -11
- data/lib/twitter/direct_message.rb +32 -4
- data/lib/twitter/direct_message_event.rb +34 -10
- data/lib/twitter/direct_messages/welcome_message.rb +22 -1
- data/lib/twitter/direct_messages/welcome_message_rule.rb +7 -0
- data/lib/twitter/direct_messages/welcome_message_rule_wrapper.rb +26 -3
- data/lib/twitter/direct_messages/welcome_message_wrapper.rb +36 -11
- data/lib/twitter/entities.rb +84 -8
- data/lib/twitter/entity/hashtag.rb +7 -1
- data/lib/twitter/entity/symbol.rb +7 -1
- data/lib/twitter/entity/uri.rb +2 -1
- data/lib/twitter/entity/user_mention.rb +20 -1
- data/lib/twitter/entity.rb +7 -1
- data/lib/twitter/enumerable.rb +20 -3
- data/lib/twitter/error.rb +137 -61
- data/lib/twitter/factory.rb +9 -5
- data/lib/twitter/geo/point.rb +37 -5
- data/lib/twitter/geo/polygon.rb +1 -0
- data/lib/twitter/geo.rb +16 -2
- data/lib/twitter/geo_factory.rb +7 -3
- data/lib/twitter/geo_results.rb +39 -8
- data/lib/twitter/headers.rb +44 -7
- data/lib/twitter/identity.rb +13 -3
- data/lib/twitter/language.rb +21 -1
- data/lib/twitter/list.rb +101 -11
- data/lib/twitter/media/animated_gif.rb +1 -0
- data/lib/twitter/media/photo.rb +19 -3
- data/lib/twitter/media/video.rb +21 -3
- data/lib/twitter/media/video_info.rb +15 -1
- data/lib/twitter/media_factory.rb +7 -3
- data/lib/twitter/metadata.rb +14 -1
- data/lib/twitter/null_object.rb +16 -14
- data/lib/twitter/oembed.rb +56 -2
- data/lib/twitter/place.rb +74 -6
- data/lib/twitter/premium_search_results.rb +87 -18
- data/lib/twitter/profile.rb +100 -44
- data/lib/twitter/profile_banner.rb +9 -4
- data/lib/twitter/rate_limit.rb +32 -3
- data/lib/twitter/relationship.rb +8 -5
- data/lib/twitter/rest/account_activity.rb +55 -26
- data/lib/twitter/rest/api.rb +2 -0
- data/lib/twitter/rest/client.rb +18 -0
- data/lib/twitter/rest/direct_messages/welcome_messages.rb +89 -18
- data/lib/twitter/rest/direct_messages.rb +158 -94
- data/lib/twitter/rest/favorites.rb +57 -21
- data/lib/twitter/rest/form_encoder.rb +57 -17
- data/lib/twitter/rest/friends_and_followers.rb +101 -35
- data/lib/twitter/rest/help.rb +13 -3
- data/lib/twitter/rest/lists.rb +133 -45
- data/lib/twitter/rest/oauth.rb +23 -17
- data/lib/twitter/rest/places_and_geo.rb +44 -28
- data/lib/twitter/rest/premium_search.rb +18 -13
- data/lib/twitter/rest/request.rb +171 -53
- data/lib/twitter/rest/saved_searches.rb +22 -7
- data/lib/twitter/rest/search.rb +20 -16
- data/lib/twitter/rest/spam_reporting.rb +5 -1
- data/lib/twitter/rest/suggested_users.rb +14 -5
- data/lib/twitter/rest/timelines.rb +92 -52
- data/lib/twitter/rest/trends.rb +31 -12
- data/lib/twitter/rest/tweets.rb +145 -88
- data/lib/twitter/rest/undocumented.rb +11 -2
- data/lib/twitter/rest/upload_utils.rb +42 -26
- data/lib/twitter/rest/users.rb +150 -71
- data/lib/twitter/rest/utils.rb +135 -39
- data/lib/twitter/saved_search.rb +23 -2
- data/lib/twitter/search_results.rb +62 -17
- data/lib/twitter/settings.rb +37 -11
- data/lib/twitter/size.rb +37 -3
- data/lib/twitter/source_user.rb +4 -3
- data/lib/twitter/streaming/client.rb +60 -8
- data/lib/twitter/streaming/connection.rb +55 -8
- data/lib/twitter/streaming/deleted_tweet.rb +8 -0
- data/lib/twitter/streaming/event.rb +43 -1
- data/lib/twitter/streaming/friend_list.rb +1 -0
- data/lib/twitter/streaming/message_parser.rb +20 -10
- data/lib/twitter/streaming/response.rb +31 -5
- data/lib/twitter/streaming/stall_warning.rb +23 -0
- data/lib/twitter/suggestion.rb +25 -1
- data/lib/twitter/target_user.rb +2 -1
- data/lib/twitter/trend.rb +29 -1
- data/lib/twitter/trend_results.rb +50 -7
- data/lib/twitter/tweet.rb +180 -21
- data/lib/twitter/user.rb +289 -53
- data/lib/twitter/utils.rb +12 -13
- data/lib/twitter/variant.rb +12 -1
- data/lib/twitter/version.rb +66 -29
- data/lib/twitter.rb +6 -1
- metadata +29 -73
- data/.yardopts +0 -16
- data/CHANGELOG.md +0 -1035
- data/CONTRIBUTING.md +0 -49
- data/twitter.gemspec +0 -57
data/lib/twitter/rest/search.rb
CHANGED
|
@@ -3,35 +3,39 @@ require "twitter/search_results"
|
|
|
3
3
|
|
|
4
4
|
module Twitter
|
|
5
5
|
module REST
|
|
6
|
+
# Methods for searching tweets
|
|
6
7
|
module Search
|
|
8
|
+
# Maximum tweets per request
|
|
7
9
|
MAX_TWEETS_PER_REQUEST = 100
|
|
8
10
|
|
|
9
|
-
# Returns tweets that match a specified query
|
|
11
|
+
# Returns tweets that match a specified query
|
|
10
12
|
#
|
|
13
|
+
# @api public
|
|
11
14
|
# @see https://dev.twitter.com/rest/reference/get/search/tweets
|
|
12
|
-
# @
|
|
13
|
-
# @note Please note that Twitter's search service and, by extension, the Search API is not meant to be an exhaustive source of Tweets. Not all Tweets will be indexed or made available via the search interface.
|
|
15
|
+
# @note Not all Tweets will be indexed or made available via the search interface.
|
|
14
16
|
# @rate_limited Yes
|
|
15
17
|
# @authentication Requires user context
|
|
16
18
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
19
|
+
# @example
|
|
20
|
+
# client.search('twitter')
|
|
17
21
|
# @param query [String] A search term.
|
|
18
22
|
# @param options [Hash] A customizable set of options.
|
|
19
|
-
# @option options [String] :geocode Returns tweets by users located within a given radius
|
|
20
|
-
# @option options [String] :lang Restricts tweets to the given language
|
|
21
|
-
# @option options [String] :locale Specify the language of the query you are sending
|
|
22
|
-
# @option options [String] :result_type Specifies
|
|
23
|
-
# @option options [Integer] :count The number of tweets to return per page
|
|
24
|
-
# @option options [String] :until
|
|
25
|
-
# @option options [Integer] :since_id Returns results with an ID greater than
|
|
26
|
-
# @option options [Integer] :max_id Returns results with an ID less than
|
|
27
|
-
# @option options [Boolean] :include_entities
|
|
28
|
-
# @option options [String] :tweet_mode
|
|
29
|
-
# @return [Twitter::SearchResults]
|
|
23
|
+
# @option options [String] :geocode Returns tweets by users located within a given radius.
|
|
24
|
+
# @option options [String] :lang Restricts tweets to the given language.
|
|
25
|
+
# @option options [String] :locale Specify the language of the query you are sending.
|
|
26
|
+
# @option options [String] :result_type Specifies result type: mixed, recent, or popular.
|
|
27
|
+
# @option options [Integer] :count The number of tweets to return per page.
|
|
28
|
+
# @option options [String] :until Returns tweets generated before the given date.
|
|
29
|
+
# @option options [Integer] :since_id Returns results with an ID greater than the specified ID.
|
|
30
|
+
# @option options [Integer] :max_id Returns results with an ID less than the specified ID.
|
|
31
|
+
# @option options [Boolean] :include_entities Include entities node.
|
|
32
|
+
# @option options [String] :tweet_mode Tweet text mode: compat or extended.
|
|
33
|
+
# @return [Twitter::SearchResults] Tweets matching the query with search metadata.
|
|
30
34
|
def search(query, options = {})
|
|
31
35
|
options = options.dup
|
|
32
36
|
options[:count] ||= MAX_TWEETS_PER_REQUEST
|
|
33
|
-
request =
|
|
34
|
-
|
|
37
|
+
request = Request.new(self, :get, "/1.1/search/tweets.json", options.merge(q: query))
|
|
38
|
+
SearchResults.new(request)
|
|
35
39
|
end
|
|
36
40
|
end
|
|
37
41
|
end
|
|
@@ -3,15 +3,19 @@ require "twitter/user"
|
|
|
3
3
|
|
|
4
4
|
module Twitter
|
|
5
5
|
module REST
|
|
6
|
+
# Methods for reporting spam accounts
|
|
6
7
|
module SpamReporting
|
|
7
8
|
include Twitter::REST::Utils
|
|
8
9
|
|
|
9
|
-
#
|
|
10
|
+
# Blocks users and reports them as spammers
|
|
10
11
|
#
|
|
12
|
+
# @api public
|
|
11
13
|
# @see https://dev.twitter.com/rest/reference/post/users/report_spam
|
|
12
14
|
# @rate_limited Yes
|
|
13
15
|
# @authentication Requires user context
|
|
14
16
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
17
|
+
# @example
|
|
18
|
+
# client.report_spam('spammer')
|
|
15
19
|
# @return [Array<Twitter::User>] The reported users.
|
|
16
20
|
# @overload report_spam(*users)
|
|
17
21
|
# @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
|
|
@@ -5,13 +5,19 @@ require "twitter/user"
|
|
|
5
5
|
|
|
6
6
|
module Twitter
|
|
7
7
|
module REST
|
|
8
|
+
# Methods for accessing suggested users
|
|
8
9
|
module SuggestedUsers
|
|
9
10
|
include Twitter::REST::Utils
|
|
10
11
|
|
|
12
|
+
# Returns suggested user categories or users in a category
|
|
13
|
+
#
|
|
14
|
+
# @api public
|
|
11
15
|
# @return [Array<Twitter::Suggestion>]
|
|
12
16
|
# @rate_limited Yes
|
|
13
17
|
# @authentication Requires user context
|
|
14
18
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
19
|
+
# @example
|
|
20
|
+
# client.suggestions
|
|
15
21
|
# @overload suggestions(options = {})
|
|
16
22
|
# Returns the list of suggested user categories
|
|
17
23
|
#
|
|
@@ -24,24 +30,27 @@ module Twitter
|
|
|
24
30
|
# @param slug [String] The short name of list or a category.
|
|
25
31
|
# @param options [Hash] A customizable set of options.
|
|
26
32
|
def suggestions(*args)
|
|
27
|
-
arguments =
|
|
33
|
+
arguments = Arguments.new(args)
|
|
28
34
|
if arguments.last
|
|
29
|
-
perform_get_with_object("/1.1/users/suggestions/#{arguments.pop}.json", arguments.options,
|
|
35
|
+
perform_get_with_object("/1.1/users/suggestions/#{arguments.pop}.json", arguments.options, Suggestion)
|
|
30
36
|
else
|
|
31
|
-
perform_get_with_objects("/1.1/users/suggestions.json", arguments.options,
|
|
37
|
+
perform_get_with_objects("/1.1/users/suggestions.json", arguments.options, Suggestion)
|
|
32
38
|
end
|
|
33
39
|
end
|
|
34
40
|
|
|
35
|
-
#
|
|
41
|
+
# Returns users in a given category with their most recent Tweet
|
|
36
42
|
#
|
|
43
|
+
# @api public
|
|
37
44
|
# @see https://dev.twitter.com/rest/reference/get/users/suggestions/:slug/members
|
|
38
45
|
# @rate_limited Yes
|
|
39
46
|
# @authentication Requires user context
|
|
47
|
+
# @example
|
|
48
|
+
# client.suggest_users('technology')
|
|
40
49
|
# @param slug [String] The short name of list or a category.
|
|
41
50
|
# @param options [Hash] A customizable set of options.
|
|
42
51
|
# @return [Array<Twitter::User>]
|
|
43
52
|
def suggest_users(slug, options = {})
|
|
44
|
-
perform_get_with_objects("/1.1/users/suggestions/#{slug}/members.json", options,
|
|
53
|
+
perform_get_with_objects("/1.1/users/suggestions/#{slug}/members.json", options, User)
|
|
45
54
|
end
|
|
46
55
|
end
|
|
47
56
|
end
|
|
@@ -4,36 +4,49 @@ require "twitter/user"
|
|
|
4
4
|
|
|
5
5
|
module Twitter
|
|
6
6
|
module REST
|
|
7
|
+
# Methods for accessing timelines
|
|
7
8
|
module Timelines
|
|
8
9
|
include Twitter::REST::Utils
|
|
10
|
+
|
|
11
|
+
# Default number of tweets per request
|
|
9
12
|
DEFAULT_TWEETS_PER_REQUEST = 20
|
|
13
|
+
# Maximum tweets per request
|
|
10
14
|
MAX_TWEETS_PER_REQUEST = 200
|
|
11
15
|
|
|
12
|
-
# Returns the 20 most recent mentions
|
|
16
|
+
# Returns the 20 most recent mentions for the authenticating user
|
|
13
17
|
#
|
|
18
|
+
# @api public
|
|
14
19
|
# @see https://dev.twitter.com/rest/reference/get/statuses/mentions_timeline
|
|
15
20
|
# @note This method can only return up to 800 Tweets.
|
|
16
21
|
# @rate_limited Yes
|
|
17
22
|
# @authentication Requires user context
|
|
18
23
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
24
|
+
# @example
|
|
25
|
+
# client.mentions_timeline
|
|
19
26
|
# @return [Array<Twitter::Tweet>]
|
|
20
27
|
# @param options [Hash] A customizable set of options.
|
|
21
|
-
# @option options [Integer] :since_id Returns results with an ID greater than
|
|
22
|
-
# @option options [Integer] :max_id Returns results with an ID less than
|
|
23
|
-
# @option options [Integer] :count Specifies the number of records to retrieve.
|
|
24
|
-
# @option options [Boolean, String, Integer] :trim_user
|
|
28
|
+
# @option options [Integer] :since_id Returns results with an ID greater than the specified ID.
|
|
29
|
+
# @option options [Integer] :max_id Returns results with an ID less than the specified ID.
|
|
30
|
+
# @option options [Integer] :count Specifies the number of records to retrieve.
|
|
31
|
+
# @option options [Boolean, String, Integer] :trim_user Include only the author's ID.
|
|
25
32
|
def mentions_timeline(options = {})
|
|
26
|
-
perform_get_with_objects("/1.1/statuses/mentions_timeline.json", options,
|
|
33
|
+
perform_get_with_objects("/1.1/statuses/mentions_timeline.json", options, Tweet)
|
|
27
34
|
end
|
|
28
|
-
|
|
35
|
+
# @!method mentions
|
|
36
|
+
# @api public
|
|
37
|
+
# @see #mentions_timeline
|
|
38
|
+
alias_method :mentions, :mentions_timeline
|
|
29
39
|
|
|
30
40
|
# Returns the 20 most recent Tweets posted by the specified user
|
|
31
41
|
#
|
|
42
|
+
# @api public
|
|
32
43
|
# @see https://dev.twitter.com/rest/reference/get/statuses/user_timeline
|
|
33
44
|
# @note This method can only return up to 3,200 Tweets.
|
|
34
45
|
# @rate_limited Yes
|
|
35
46
|
# @authentication Requires user context
|
|
36
47
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
48
|
+
# @example
|
|
49
|
+
# client.user_timeline('sferik')
|
|
37
50
|
# @return [Array<Twitter::Tweet>]
|
|
38
51
|
# @overload user_timeline(user, options = {})
|
|
39
52
|
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
|
@@ -46,113 +59,135 @@ module Twitter
|
|
|
46
59
|
# @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
|
|
47
60
|
# @option options [Boolean, String, Integer] :include_rts Specifies that the timeline should include native retweets in addition to regular tweets. Note: If you're using the trim_user parameter in conjunction with include_rts, the retweets will no longer contain a full user object.
|
|
48
61
|
def user_timeline(*args)
|
|
49
|
-
objects_from_response_with_user(
|
|
62
|
+
objects_from_response_with_user(Tweet, :get, "/1.1/statuses/user_timeline.json", args)
|
|
50
63
|
end
|
|
51
64
|
|
|
52
65
|
# Returns the 20 most recent retweets posted by the specified user
|
|
53
66
|
#
|
|
67
|
+
# @api public
|
|
54
68
|
# @see https://dev.twitter.com/rest/reference/get/statuses/user_timeline
|
|
55
69
|
# @note This method can only return up to 3,200 Tweets.
|
|
56
70
|
# @rate_limited Yes
|
|
57
71
|
# @authentication Requires user context
|
|
58
72
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
73
|
+
# @example
|
|
74
|
+
# client.retweeted_by_user('sferik')
|
|
59
75
|
# @return [Array<Twitter::Tweet>]
|
|
60
76
|
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
|
|
61
77
|
# @param options [Hash] A customizable set of options.
|
|
62
|
-
# @option options [Integer] :since_id Returns results with an ID greater than
|
|
63
|
-
# @option options [Integer] :max_id Returns results with an ID less than
|
|
64
|
-
# @option options [Integer] :count Specifies the number of records to retrieve.
|
|
65
|
-
# @option options [Boolean, String, Integer] :trim_user
|
|
66
|
-
# @option options [Boolean, String, Integer] :exclude_replies
|
|
67
|
-
# @option options [Boolean, String, Integer] :contributor_details
|
|
78
|
+
# @option options [Integer] :since_id Returns results with an ID greater than the specified ID.
|
|
79
|
+
# @option options [Integer] :max_id Returns results with an ID less than the specified ID.
|
|
80
|
+
# @option options [Integer] :count Specifies the number of records to retrieve.
|
|
81
|
+
# @option options [Boolean, String, Integer] :trim_user Include only the author's ID.
|
|
82
|
+
# @option options [Boolean, String, Integer] :exclude_replies Exclude replies from results.
|
|
83
|
+
# @option options [Boolean, String, Integer] :contributor_details Include contributor screen names.
|
|
68
84
|
def retweeted_by_user(user, options = {})
|
|
69
85
|
retweets_from_timeline(options) do |opts|
|
|
70
86
|
user_timeline(user, opts)
|
|
71
87
|
end
|
|
72
88
|
end
|
|
73
|
-
|
|
89
|
+
# @!method retweeted_by
|
|
90
|
+
# @api public
|
|
91
|
+
# @see #retweeted_by_user
|
|
92
|
+
alias_method :retweeted_by, :retweeted_by_user
|
|
74
93
|
|
|
75
94
|
# Returns the 20 most recent retweets posted by the authenticating user
|
|
76
95
|
#
|
|
96
|
+
# @api public
|
|
77
97
|
# @see https://dev.twitter.com/rest/reference/get/statuses/user_timeline
|
|
78
98
|
# @note This method can only return up to 3,200 Tweets.
|
|
79
99
|
# @rate_limited Yes
|
|
80
100
|
# @authentication Requires user context
|
|
81
101
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
102
|
+
# @example
|
|
103
|
+
# client.retweeted_by_me
|
|
82
104
|
# @return [Array<Twitter::Tweet>]
|
|
83
105
|
# @param options [Hash] A customizable set of options.
|
|
84
|
-
# @option options [Integer] :since_id Returns results with an ID greater than
|
|
85
|
-
# @option options [Integer] :max_id Returns results with an ID less than
|
|
86
|
-
# @option options [Integer] :count Specifies the number of records to retrieve.
|
|
87
|
-
# @option options [Boolean, String, Integer] :trim_user
|
|
88
|
-
# @option options [Boolean, String, Integer] :exclude_replies
|
|
89
|
-
# @option options [Boolean, String, Integer] :contributor_details
|
|
106
|
+
# @option options [Integer] :since_id Returns results with an ID greater than the specified ID.
|
|
107
|
+
# @option options [Integer] :max_id Returns results with an ID less than the specified ID.
|
|
108
|
+
# @option options [Integer] :count Specifies the number of records to retrieve.
|
|
109
|
+
# @option options [Boolean, String, Integer] :trim_user Include only the author's ID.
|
|
110
|
+
# @option options [Boolean, String, Integer] :exclude_replies Exclude replies from results.
|
|
111
|
+
# @option options [Boolean, String, Integer] :contributor_details Include contributor screen names.
|
|
90
112
|
def retweeted_by_me(options = {})
|
|
91
113
|
retweets_from_timeline(options) do |opts|
|
|
92
114
|
user_timeline(opts)
|
|
93
115
|
end
|
|
94
116
|
end
|
|
95
117
|
|
|
96
|
-
# Returns the 20 most recent Tweets
|
|
118
|
+
# Returns the 20 most recent Tweets from the authenticating user's timeline
|
|
97
119
|
#
|
|
120
|
+
# @api public
|
|
98
121
|
# @see https://dev.twitter.com/rest/reference/get/statuses/home_timeline
|
|
99
122
|
# @note This method can only return up to 800 Tweets, including retweets.
|
|
100
123
|
# @rate_limited Yes
|
|
101
124
|
# @authentication Requires user context
|
|
102
125
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
126
|
+
# @example
|
|
127
|
+
# client.home_timeline
|
|
103
128
|
# @return [Array<Twitter::Tweet>]
|
|
104
129
|
# @param options [Hash] A customizable set of options.
|
|
105
|
-
# @option options [Integer] :since_id Returns results with an ID greater than
|
|
106
|
-
# @option options [Integer] :max_id Returns results with an ID less than
|
|
107
|
-
# @option options [Integer] :count Specifies the number of records to retrieve.
|
|
108
|
-
# @option options [Boolean, String, Integer] :trim_user
|
|
109
|
-
# @option options [Boolean, String, Integer] :exclude_replies
|
|
110
|
-
# @option options [Boolean, String, Integer] :include_rts
|
|
111
|
-
# @option options [Boolean, String, Integer] :contributor_details
|
|
130
|
+
# @option options [Integer] :since_id Returns results with an ID greater than the specified ID.
|
|
131
|
+
# @option options [Integer] :max_id Returns results with an ID less than the specified ID.
|
|
132
|
+
# @option options [Integer] :count Specifies the number of records to retrieve.
|
|
133
|
+
# @option options [Boolean, String, Integer] :trim_user Include only the author's ID.
|
|
134
|
+
# @option options [Boolean, String, Integer] :exclude_replies Exclude replies from results.
|
|
135
|
+
# @option options [Boolean, String, Integer] :include_rts Include native retweets.
|
|
136
|
+
# @option options [Boolean, String, Integer] :contributor_details Include contributor screen names.
|
|
112
137
|
def home_timeline(options = {})
|
|
113
|
-
perform_get_with_objects("/1.1/statuses/home_timeline.json", options,
|
|
138
|
+
perform_get_with_objects("/1.1/statuses/home_timeline.json", options, Tweet)
|
|
114
139
|
end
|
|
115
140
|
|
|
116
|
-
# Returns the 20 most recent retweets posted by users
|
|
141
|
+
# Returns the 20 most recent retweets posted by followed users
|
|
117
142
|
#
|
|
143
|
+
# @api public
|
|
118
144
|
# @see https://dev.twitter.com/rest/reference/get/statuses/home_timeline
|
|
119
145
|
# @note This method can only return up to 800 Tweets, including retweets.
|
|
120
146
|
# @rate_limited Yes
|
|
121
147
|
# @authentication Requires user context
|
|
122
148
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
149
|
+
# @example
|
|
150
|
+
# client.retweeted_to_me
|
|
123
151
|
# @return [Array<Twitter::Tweet>]
|
|
124
152
|
# @param options [Hash] A customizable set of options.
|
|
125
|
-
# @option options [Integer] :since_id Returns results with an ID greater than
|
|
126
|
-
# @option options [Integer] :max_id Returns results with an ID less than
|
|
127
|
-
# @option options [Integer] :count Specifies the number of records to retrieve.
|
|
128
|
-
# @option options [Boolean, String, Integer] :trim_user
|
|
129
|
-
# @option options [Boolean, String, Integer] :exclude_replies
|
|
130
|
-
# @option options [Boolean, String, Integer] :contributor_details
|
|
153
|
+
# @option options [Integer] :since_id Returns results with an ID greater than the specified ID.
|
|
154
|
+
# @option options [Integer] :max_id Returns results with an ID less than the specified ID.
|
|
155
|
+
# @option options [Integer] :count Specifies the number of records to retrieve.
|
|
156
|
+
# @option options [Boolean, String, Integer] :trim_user Include only the author's ID.
|
|
157
|
+
# @option options [Boolean, String, Integer] :exclude_replies Exclude replies from results.
|
|
158
|
+
# @option options [Boolean, String, Integer] :contributor_details Include contributor screen names.
|
|
131
159
|
def retweeted_to_me(options = {})
|
|
132
160
|
retweets_from_timeline(options) do |opts|
|
|
133
161
|
home_timeline(opts)
|
|
134
162
|
end
|
|
135
163
|
end
|
|
136
164
|
|
|
137
|
-
# Returns the 20 most recent tweets
|
|
165
|
+
# Returns the 20 most recent tweets that have been retweeted by others
|
|
138
166
|
#
|
|
167
|
+
# @api public
|
|
139
168
|
# @see https://dev.twitter.com/rest/reference/get/statuses/retweets_of_me
|
|
140
169
|
# @rate_limited Yes
|
|
141
170
|
# @authentication Requires user context
|
|
142
171
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
172
|
+
# @example
|
|
173
|
+
# client.retweets_of_me
|
|
143
174
|
# @return [Array<Twitter::Tweet>]
|
|
144
175
|
# @param options [Hash] A customizable set of options.
|
|
145
|
-
# @option options [Integer] :count Specifies the number of records to retrieve.
|
|
146
|
-
# @option options [Integer] :since_id Returns results with an ID greater than
|
|
147
|
-
# @option options [Integer] :max_id Returns results with an ID less than
|
|
148
|
-
# @option options [Boolean, String, Integer] :trim_user
|
|
149
|
-
# @option options [Boolean, String, Integer] :include_user_entities
|
|
176
|
+
# @option options [Integer] :count Specifies the number of records to retrieve.
|
|
177
|
+
# @option options [Integer] :since_id Returns results with an ID greater than the specified ID.
|
|
178
|
+
# @option options [Integer] :max_id Returns results with an ID less than the specified ID.
|
|
179
|
+
# @option options [Boolean, String, Integer] :trim_user Include only the author's ID.
|
|
180
|
+
# @option options [Boolean, String, Integer] :include_user_entities Include user entities.
|
|
150
181
|
def retweets_of_me(options = {})
|
|
151
|
-
perform_get_with_objects("/1.1/statuses/retweets_of_me.json", options,
|
|
182
|
+
perform_get_with_objects("/1.1/statuses/retweets_of_me.json", options, Tweet)
|
|
152
183
|
end
|
|
153
184
|
|
|
154
|
-
|
|
185
|
+
private
|
|
155
186
|
|
|
187
|
+
# Retrieves retweets from a timeline
|
|
188
|
+
#
|
|
189
|
+
# @api private
|
|
190
|
+
# @return [Array<Twitter::Tweet>]
|
|
156
191
|
def retweets_from_timeline(options)
|
|
157
192
|
options[:include_rts] = true
|
|
158
193
|
count = options[:count] || DEFAULT_TWEETS_PER_REQUEST
|
|
@@ -161,16 +196,20 @@ module Twitter
|
|
|
161
196
|
end
|
|
162
197
|
end
|
|
163
198
|
|
|
164
|
-
#
|
|
199
|
+
# Selects retweets from a collection of tweets
|
|
200
|
+
#
|
|
201
|
+
# @api private
|
|
165
202
|
# @return [Array<Twitter::Tweet>]
|
|
166
203
|
def select_retweets(tweets)
|
|
167
204
|
tweets.select(&:retweet?)
|
|
168
205
|
end
|
|
169
206
|
|
|
170
|
-
#
|
|
207
|
+
# Collects tweets up to a specified count
|
|
208
|
+
#
|
|
209
|
+
# @api private
|
|
171
210
|
# @return [Array<Twitter::Tweet>]
|
|
172
211
|
def collect_with_count(count)
|
|
173
|
-
options = {}
|
|
212
|
+
options = {} # : Hash[Symbol, untyped]
|
|
174
213
|
options[:count] = MAX_TWEETS_PER_REQUEST
|
|
175
214
|
collect_with_max_id do |max_id|
|
|
176
215
|
options[:max_id] = max_id unless max_id.nil?
|
|
@@ -179,18 +218,19 @@ module Twitter
|
|
|
179
218
|
count -= tweets.length
|
|
180
219
|
tweets
|
|
181
220
|
end
|
|
182
|
-
end
|
|
221
|
+
end[nil...count]
|
|
183
222
|
end
|
|
184
223
|
|
|
185
|
-
#
|
|
186
|
-
#
|
|
224
|
+
# Collects tweets using max_id pagination
|
|
225
|
+
#
|
|
226
|
+
# @api private
|
|
187
227
|
# @return [Array<Twitter::Tweet>]
|
|
188
228
|
def collect_with_max_id(collection = [], max_id = nil, &)
|
|
189
229
|
tweets = yield(max_id)
|
|
190
230
|
return collection if tweets.nil?
|
|
191
231
|
|
|
192
232
|
collection += tweets
|
|
193
|
-
tweets.empty? ? collection
|
|
233
|
+
tweets.empty? ? collection : collect_with_max_id(collection, tweets.last.id - 1, &) # steep:ignore NoMethod
|
|
194
234
|
end
|
|
195
235
|
end
|
|
196
236
|
end
|
data/lib/twitter/rest/trends.rb
CHANGED
|
@@ -5,53 +5,72 @@ require "twitter/trend_results"
|
|
|
5
5
|
|
|
6
6
|
module Twitter
|
|
7
7
|
module REST
|
|
8
|
+
# Methods for accessing trending topics
|
|
8
9
|
module Trends
|
|
9
10
|
include Twitter::REST::Utils
|
|
10
11
|
|
|
11
12
|
# Returns the top 50 trending topics for a specific WOEID
|
|
12
13
|
#
|
|
14
|
+
# @api public
|
|
13
15
|
# @see https://dev.twitter.com/rest/reference/get/trends/place
|
|
14
16
|
# @rate_limited Yes
|
|
15
17
|
# @authentication Requires user context
|
|
16
18
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
17
|
-
# @
|
|
19
|
+
# @example
|
|
20
|
+
# client.trends
|
|
21
|
+
# @param id [Integer] The Yahoo! Where On Earth ID of the location.
|
|
18
22
|
# @param options [Hash] A customizable set of options.
|
|
19
|
-
# @option options [String] :exclude Setting this equal to 'hashtags'
|
|
23
|
+
# @option options [String] :exclude Setting this equal to 'hashtags' excludes hashtags.
|
|
20
24
|
# @return [Array<Twitter::Trend>]
|
|
21
25
|
def trends(id = 1, options = {})
|
|
22
26
|
options = options.dup
|
|
23
27
|
options[:id] = id
|
|
24
28
|
response = perform_get("/1.1/trends/place.json", options).first
|
|
25
|
-
|
|
29
|
+
TrendResults.new(response)
|
|
26
30
|
end
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
# @!method local_trends
|
|
32
|
+
# @api public
|
|
33
|
+
# @see #trends
|
|
34
|
+
alias_method :local_trends, :trends
|
|
35
|
+
# @!method trends_place
|
|
36
|
+
# @api public
|
|
37
|
+
# @see #trends
|
|
38
|
+
alias_method :trends_place, :trends
|
|
29
39
|
|
|
30
|
-
# Returns
|
|
40
|
+
# Returns locations with trending topic information
|
|
31
41
|
#
|
|
42
|
+
# @api public
|
|
32
43
|
# @see https://dev.twitter.com/rest/reference/get/trends/available
|
|
33
44
|
# @rate_limited Yes
|
|
34
45
|
# @authentication Requires user context
|
|
35
46
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
47
|
+
# @example
|
|
48
|
+
# client.trends_available
|
|
36
49
|
# @param options [Hash] A customizable set of options.
|
|
37
50
|
# @return [Array<Twitter::Place>]
|
|
38
51
|
def trends_available(options = {})
|
|
39
|
-
perform_get_with_objects("/1.1/trends/available.json", options,
|
|
52
|
+
perform_get_with_objects("/1.1/trends/available.json", options, Place)
|
|
40
53
|
end
|
|
41
|
-
|
|
54
|
+
# @!method trend_locations
|
|
55
|
+
# @api public
|
|
56
|
+
# @see #trends_available
|
|
57
|
+
alias_method :trend_locations, :trends_available
|
|
42
58
|
|
|
43
|
-
# Returns
|
|
59
|
+
# Returns trend locations closest to a specified location
|
|
44
60
|
#
|
|
61
|
+
# @api public
|
|
45
62
|
# @see https://dev.twitter.com/rest/reference/get/trends/closest
|
|
46
63
|
# @rate_limited Yes
|
|
47
64
|
# @authentication Requires user context
|
|
48
65
|
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
|
|
66
|
+
# @example
|
|
67
|
+
# client.trends_closest(lat: 37.7821, long: -122.4093)
|
|
49
68
|
# @param options [Hash] A customizable set of options.
|
|
50
|
-
# @option options [Float] :lat
|
|
51
|
-
# @option options [Float] :long
|
|
69
|
+
# @option options [Float] :lat The latitude to search around.
|
|
70
|
+
# @option options [Float] :long The longitude to search around.
|
|
52
71
|
# @return [Array<Twitter::Place>]
|
|
53
72
|
def trends_closest(options = {})
|
|
54
|
-
perform_get_with_objects("/1.1/trends/closest.json", options,
|
|
73
|
+
perform_get_with_objects("/1.1/trends/closest.json", options, Place)
|
|
55
74
|
end
|
|
56
75
|
end
|
|
57
76
|
end
|