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.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +1 -1
  3. data/README.md +173 -11
  4. data/lib/twitter/arguments.rb +14 -1
  5. data/lib/twitter/base.rb +72 -11
  6. data/lib/twitter/basic_user.rb +7 -1
  7. data/lib/twitter/client.rb +94 -3
  8. data/lib/twitter/creatable.rb +11 -2
  9. data/lib/twitter/cursor.rb +58 -11
  10. data/lib/twitter/direct_message.rb +32 -4
  11. data/lib/twitter/direct_message_event.rb +34 -10
  12. data/lib/twitter/direct_messages/welcome_message.rb +22 -1
  13. data/lib/twitter/direct_messages/welcome_message_rule.rb +7 -0
  14. data/lib/twitter/direct_messages/welcome_message_rule_wrapper.rb +26 -3
  15. data/lib/twitter/direct_messages/welcome_message_wrapper.rb +36 -11
  16. data/lib/twitter/entities.rb +84 -8
  17. data/lib/twitter/entity/hashtag.rb +7 -1
  18. data/lib/twitter/entity/symbol.rb +7 -1
  19. data/lib/twitter/entity/uri.rb +2 -1
  20. data/lib/twitter/entity/user_mention.rb +20 -1
  21. data/lib/twitter/entity.rb +7 -1
  22. data/lib/twitter/enumerable.rb +20 -3
  23. data/lib/twitter/error.rb +137 -61
  24. data/lib/twitter/factory.rb +9 -5
  25. data/lib/twitter/geo/point.rb +37 -5
  26. data/lib/twitter/geo/polygon.rb +1 -0
  27. data/lib/twitter/geo.rb +16 -2
  28. data/lib/twitter/geo_factory.rb +7 -3
  29. data/lib/twitter/geo_results.rb +39 -8
  30. data/lib/twitter/headers.rb +44 -7
  31. data/lib/twitter/identity.rb +13 -3
  32. data/lib/twitter/language.rb +21 -1
  33. data/lib/twitter/list.rb +101 -11
  34. data/lib/twitter/media/animated_gif.rb +1 -0
  35. data/lib/twitter/media/photo.rb +19 -3
  36. data/lib/twitter/media/video.rb +21 -3
  37. data/lib/twitter/media/video_info.rb +15 -1
  38. data/lib/twitter/media_factory.rb +7 -3
  39. data/lib/twitter/metadata.rb +14 -1
  40. data/lib/twitter/null_object.rb +16 -14
  41. data/lib/twitter/oembed.rb +56 -2
  42. data/lib/twitter/place.rb +74 -6
  43. data/lib/twitter/premium_search_results.rb +87 -18
  44. data/lib/twitter/profile.rb +100 -44
  45. data/lib/twitter/profile_banner.rb +9 -4
  46. data/lib/twitter/rate_limit.rb +32 -3
  47. data/lib/twitter/relationship.rb +8 -5
  48. data/lib/twitter/rest/account_activity.rb +55 -26
  49. data/lib/twitter/rest/api.rb +2 -0
  50. data/lib/twitter/rest/client.rb +18 -0
  51. data/lib/twitter/rest/direct_messages/welcome_messages.rb +89 -18
  52. data/lib/twitter/rest/direct_messages.rb +158 -94
  53. data/lib/twitter/rest/favorites.rb +57 -21
  54. data/lib/twitter/rest/form_encoder.rb +57 -17
  55. data/lib/twitter/rest/friends_and_followers.rb +101 -35
  56. data/lib/twitter/rest/help.rb +13 -3
  57. data/lib/twitter/rest/lists.rb +133 -45
  58. data/lib/twitter/rest/oauth.rb +23 -17
  59. data/lib/twitter/rest/places_and_geo.rb +44 -28
  60. data/lib/twitter/rest/premium_search.rb +18 -13
  61. data/lib/twitter/rest/request.rb +171 -53
  62. data/lib/twitter/rest/saved_searches.rb +22 -7
  63. data/lib/twitter/rest/search.rb +20 -16
  64. data/lib/twitter/rest/spam_reporting.rb +5 -1
  65. data/lib/twitter/rest/suggested_users.rb +14 -5
  66. data/lib/twitter/rest/timelines.rb +92 -52
  67. data/lib/twitter/rest/trends.rb +31 -12
  68. data/lib/twitter/rest/tweets.rb +145 -88
  69. data/lib/twitter/rest/undocumented.rb +11 -2
  70. data/lib/twitter/rest/upload_utils.rb +42 -26
  71. data/lib/twitter/rest/users.rb +150 -71
  72. data/lib/twitter/rest/utils.rb +135 -39
  73. data/lib/twitter/saved_search.rb +23 -2
  74. data/lib/twitter/search_results.rb +62 -17
  75. data/lib/twitter/settings.rb +37 -11
  76. data/lib/twitter/size.rb +37 -3
  77. data/lib/twitter/source_user.rb +4 -3
  78. data/lib/twitter/streaming/client.rb +60 -8
  79. data/lib/twitter/streaming/connection.rb +55 -8
  80. data/lib/twitter/streaming/deleted_tweet.rb +8 -0
  81. data/lib/twitter/streaming/event.rb +43 -1
  82. data/lib/twitter/streaming/friend_list.rb +1 -0
  83. data/lib/twitter/streaming/message_parser.rb +20 -10
  84. data/lib/twitter/streaming/response.rb +31 -5
  85. data/lib/twitter/streaming/stall_warning.rb +23 -0
  86. data/lib/twitter/suggestion.rb +25 -1
  87. data/lib/twitter/target_user.rb +2 -1
  88. data/lib/twitter/trend.rb +29 -1
  89. data/lib/twitter/trend_results.rb +50 -7
  90. data/lib/twitter/tweet.rb +180 -21
  91. data/lib/twitter/user.rb +289 -53
  92. data/lib/twitter/utils.rb +12 -13
  93. data/lib/twitter/variant.rb +12 -1
  94. data/lib/twitter/version.rb +66 -29
  95. data/lib/twitter.rb +6 -1
  96. metadata +29 -73
  97. data/.yardopts +0 -16
  98. data/CHANGELOG.md +0 -1035
  99. data/CONTRIBUTING.md +0 -49
  100. data/twitter.gemspec +0 -57
@@ -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
- # @see https://dev.twitter.com/rest/public/search
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 of the given latitude/longitude. The location is preferentially taking from the Geotagging API, but will fall back to their Twitter profile. The parameter value is specified by "latitude,longitude,radius", where radius units must be specified as either "mi" (miles) or "km" (kilometers). 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.
20
- # @option options [String] :lang Restricts tweets to the given language, given by an ISO 639-1 code.
21
- # @option options [String] :locale Specify the language of the query you are sending (only ja is currently effective). This is intended for language-specific clients and the default should work in the majority of cases.
22
- # @option options [String] :result_type Specifies what type of search results you would prefer to receive. Options are "mixed", "recent", and "popular". The current default is "mixed."
23
- # @option options [Integer] :count The number of tweets to return per page, up to a maximum of 100.
24
- # @option options [String] :until Optional. Returns tweets generated before the given date. Date should be formatted as YYYY-MM-DD.
25
- # @option options [Integer] :since_id 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.
26
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
27
- # @option options [Boolean] :include_entities The entities node will be disincluded when set to false.
28
- # @option options [String] :tweet_mode The entities node will truncate or not tweet text. Options are "compat" and "extended". The current default is "compat" (truncate).
29
- # @return [Twitter::SearchResults] Return tweets that match a specified query with search metadata
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 = Twitter::REST::Request.new(self, :get, "/1.1/search/tweets.json", options.merge(q: query))
34
- Twitter::SearchResults.new(request)
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
- # The users specified are blocked by the authenticated user and reported as spammers
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 = Twitter::Arguments.new(args)
33
+ arguments = Arguments.new(args)
28
34
  if arguments.last
29
- perform_get_with_object("/1.1/users/suggestions/#{arguments.pop}.json", arguments.options, Twitter::Suggestion)
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, Twitter::Suggestion)
37
+ perform_get_with_objects("/1.1/users/suggestions.json", arguments.options, Suggestion)
32
38
  end
33
39
  end
34
40
 
35
- # Access the users in a given category of the Twitter suggested user list and return their most recent Tweet if they are not a protected user
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, Twitter::User)
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 (statuses containing @username) for the authenticating user
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 (that is, more recent than) the specified ID.
22
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
23
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
24
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
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, Twitter::Tweet)
33
+ perform_get_with_objects("/1.1/statuses/mentions_timeline.json", options, Tweet)
27
34
  end
28
- alias mentions mentions_timeline
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(Twitter::Tweet, :get, "/1.1/statuses/user_timeline.json", args)
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 (that is, more recent than) the specified ID.
63
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
64
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
65
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
66
- # @option options [Boolean, String, Integer] :exclude_replies This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets - this is because the count parameter retrieves that many tweets before filtering out retweets and replies.
67
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
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
- alias retweeted_by retweeted_by_user
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 (that is, more recent than) the specified ID.
85
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
86
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
87
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
88
- # @option options [Boolean, String, Integer] :exclude_replies This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets - this is because the count parameter retrieves that many tweets before filtering out retweets and replies.
89
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
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, including retweets if they exist, posted by the authenticating user and the users they follow
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 (that is, more recent than) the specified ID.
106
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
107
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
108
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
109
- # @option options [Boolean, String, Integer] :exclude_replies This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets - this is because the count parameter retrieves that many tweets before filtering out retweets and replies.
110
- # @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.
111
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
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, Twitter::Tweet)
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 the authenticating user follow.
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 (that is, more recent than) the specified ID.
126
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
127
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
128
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
129
- # @option options [Boolean, String, Integer] :exclude_replies This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets - this is because the count parameter retrieves that many tweets before filtering out retweets and replies.
130
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
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 of the authenticated user that have been retweeted by others
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. Must be less than or equal to 200.
146
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
147
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
148
- # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
149
- # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false.
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, Twitter::Tweet)
182
+ perform_get_with_objects("/1.1/statuses/retweets_of_me.json", options, Tweet)
152
183
  end
153
184
 
154
- private
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
- # @param tweets [Array]
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
- # @param count [Integer]
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.flatten.compact[0...count]
221
+ end[nil...count]
183
222
  end
184
223
 
185
- # @param collection [Array]
186
- # @param max_id [Integer, NilClass]
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.flatten : collect_with_max_id(collection, tweets.last.id - 1, &)
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
@@ -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
- # @param id [Integer] The {https://developer.yahoo.com/geo/geoplanet Yahoo! Where On Earth ID} of the location to return trending information for. WOEIDs can be retrieved by calling {Twitter::REST::Trends#trends_available}. Global information is available by using 1 as the WOEID.
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' will remove all hashtags from the trends list.
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
- Twitter::TrendResults.new(response)
29
+ TrendResults.new(response)
26
30
  end
27
- alias local_trends trends
28
- alias trends_place trends
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 the locations that Twitter has trending topic information for
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, Twitter::Place)
52
+ perform_get_with_objects("/1.1/trends/available.json", options, Place)
40
53
  end
41
- alias trend_locations trends_available
54
+ # @!method trend_locations
55
+ # @api public
56
+ # @see #trends_available
57
+ alias_method :trend_locations, :trends_available
42
58
 
43
- # Returns the locations that Twitter has trending topic information for, closest to a specified location.
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 If provided with a :long option the available trend locations will be sorted by distance, nearest to furthest, to the co-ordinate pair. The valid ranges for latitude are -90.0 to +90.0 (North is positive) inclusive.
51
- # @option options [Float] :long If provided with a :lat option the available trend locations will be sorted by distance, nearest to furthest, to the co-ordinate pair. The valid ranges for longitude are -180.0 to +180.0 (East is positive) inclusive.
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, Twitter::Place)
73
+ perform_get_with_objects("/1.1/trends/closest.json", options, Place)
55
74
  end
56
75
  end
57
76
  end