twitter 4.8.1 → 5.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG.md +30 -0
  3. data/LICENSE.md +1 -1
  4. data/README.md +386 -266
  5. data/lib/twitter.rb +4 -39
  6. data/lib/twitter/arguments.rb +11 -0
  7. data/lib/twitter/base.rb +89 -68
  8. data/lib/twitter/client.rb +69 -110
  9. data/lib/twitter/configuration.rb +7 -3
  10. data/lib/twitter/creatable.rb +2 -4
  11. data/lib/twitter/cursor.rb +50 -42
  12. data/lib/twitter/direct_message.rb +2 -11
  13. data/lib/twitter/entity/uri.rb +13 -0
  14. data/lib/twitter/enumerable.rb +15 -0
  15. data/lib/twitter/error.rb +55 -7
  16. data/lib/twitter/error/already_favorited.rb +1 -1
  17. data/lib/twitter/error/already_posted.rb +10 -0
  18. data/lib/twitter/error/already_retweeted.rb +1 -1
  19. data/lib/twitter/error/bad_gateway.rb +2 -3
  20. data/lib/twitter/error/bad_request.rb +2 -2
  21. data/lib/twitter/error/forbidden.rb +2 -2
  22. data/lib/twitter/error/gateway_timeout.rb +2 -3
  23. data/lib/twitter/error/internal_server_error.rb +2 -3
  24. data/lib/twitter/error/not_acceptable.rb +2 -2
  25. data/lib/twitter/error/not_found.rb +2 -2
  26. data/lib/twitter/error/service_unavailable.rb +2 -3
  27. data/lib/twitter/error/too_many_requests.rb +2 -2
  28. data/lib/twitter/error/unauthorized.rb +2 -2
  29. data/lib/twitter/error/unprocessable_entity.rb +2 -2
  30. data/lib/twitter/factory.rb +2 -8
  31. data/lib/twitter/geo_factory.rb +2 -2
  32. data/lib/twitter/geo_results.rb +36 -0
  33. data/lib/twitter/identity.rb +0 -22
  34. data/lib/twitter/list.rb +18 -4
  35. data/lib/twitter/media/photo.rb +3 -3
  36. data/lib/twitter/media_factory.rb +2 -2
  37. data/lib/twitter/null_object.rb +24 -0
  38. data/lib/twitter/oembed.rb +3 -2
  39. data/lib/twitter/place.rb +15 -9
  40. data/lib/twitter/profile_banner.rb +5 -3
  41. data/lib/twitter/rate_limit.rb +1 -17
  42. data/lib/twitter/relationship.rb +2 -10
  43. data/lib/twitter/rest/api/direct_messages.rb +135 -0
  44. data/lib/twitter/rest/api/favorites.rb +120 -0
  45. data/lib/twitter/rest/api/friends_and_followers.rb +290 -0
  46. data/lib/twitter/rest/api/help.rb +58 -0
  47. data/lib/twitter/rest/api/lists.rb +491 -0
  48. data/lib/twitter/rest/api/oauth.rb +45 -0
  49. data/lib/twitter/rest/api/places_and_geo.rb +104 -0
  50. data/lib/twitter/rest/api/saved_searches.rb +91 -0
  51. data/lib/twitter/rest/api/search.rb +37 -0
  52. data/lib/twitter/rest/api/spam_reporting.rb +29 -0
  53. data/lib/twitter/rest/api/suggested_users.rb +51 -0
  54. data/lib/twitter/rest/api/timelines.rb +202 -0
  55. data/lib/twitter/rest/api/trends.rb +58 -0
  56. data/lib/twitter/rest/api/tweets.rb +293 -0
  57. data/lib/twitter/rest/api/undocumented.rb +52 -0
  58. data/lib/twitter/rest/api/users.rb +383 -0
  59. data/lib/twitter/rest/api/utils.rb +219 -0
  60. data/lib/twitter/rest/client.rb +193 -0
  61. data/lib/twitter/rest/request/multipart_with_file.rb +36 -0
  62. data/lib/twitter/rest/response/parse_json.rb +27 -0
  63. data/lib/twitter/{response → rest/response}/raise_error.rb +8 -11
  64. data/lib/twitter/search_results.rb +33 -21
  65. data/lib/twitter/settings.rb +1 -6
  66. data/lib/twitter/size.rb +1 -1
  67. data/lib/twitter/streaming/client.rb +77 -0
  68. data/lib/twitter/streaming/connection.rb +22 -0
  69. data/lib/twitter/streaming/response.rb +30 -0
  70. data/lib/twitter/suggestion.rb +4 -2
  71. data/lib/twitter/token.rb +8 -0
  72. data/lib/twitter/trend.rb +2 -1
  73. data/lib/twitter/trend_results.rb +59 -0
  74. data/lib/twitter/tweet.rb +41 -85
  75. data/lib/twitter/user.rb +51 -41
  76. data/lib/twitter/version.rb +4 -4
  77. data/spec/fixtures/already_posted.json +1 -0
  78. data/spec/fixtures/ids_list.json +1 -1
  79. data/spec/fixtures/ids_list2.json +1 -1
  80. data/spec/fixtures/search.json +1 -1
  81. data/spec/fixtures/search_malformed.json +1 -1
  82. data/spec/fixtures/track_streaming.json +3 -0
  83. data/spec/helper.rb +8 -13
  84. data/spec/twitter/base_spec.rb +25 -99
  85. data/spec/twitter/configuration_spec.rb +1 -1
  86. data/spec/twitter/cursor_spec.rb +13 -31
  87. data/spec/twitter/direct_message_spec.rb +41 -8
  88. data/spec/twitter/entity/uri_spec.rb +74 -0
  89. data/spec/twitter/error_spec.rb +59 -11
  90. data/spec/twitter/geo/point_spec.rb +1 -1
  91. data/spec/twitter/geo_factory_spec.rb +3 -3
  92. data/spec/twitter/geo_results_spec.rb +35 -0
  93. data/spec/twitter/identifiable_spec.rb +0 -21
  94. data/spec/twitter/list_spec.rb +51 -8
  95. data/spec/twitter/media/photo_spec.rb +118 -3
  96. data/spec/twitter/media_factory_spec.rb +2 -2
  97. data/spec/twitter/null_object_spec.rb +26 -0
  98. data/spec/twitter/oembed_spec.rb +69 -45
  99. data/spec/twitter/place_spec.rb +68 -12
  100. data/spec/twitter/profile_banner_spec.rb +1 -1
  101. data/spec/twitter/rate_limit_spec.rb +12 -12
  102. data/spec/twitter/relationship_spec.rb +31 -9
  103. data/spec/twitter/{api → rest/api}/direct_messages_spec.rb +22 -9
  104. data/spec/twitter/{api → rest/api}/favorites_spec.rb +80 -7
  105. data/spec/twitter/{api → rest/api}/friends_and_followers_spec.rb +104 -65
  106. data/spec/twitter/{api → rest/api}/geo_spec.rb +10 -10
  107. data/spec/twitter/{api → rest/api}/help_spec.rb +6 -6
  108. data/spec/twitter/{api → rest/api}/lists_spec.rb +77 -56
  109. data/spec/twitter/{api → rest/api}/oauth_spec.rb +6 -6
  110. data/spec/twitter/{api → rest/api}/saved_searches_spec.rb +7 -7
  111. data/spec/twitter/{api → rest/api}/search_spec.rb +8 -9
  112. data/spec/twitter/{api → rest/api}/spam_reporting_spec.rb +3 -3
  113. data/spec/twitter/{api → rest/api}/suggested_users_spec.rb +5 -5
  114. data/spec/twitter/{api → rest/api}/timelines_spec.rb +9 -9
  115. data/spec/twitter/{api → rest/api}/trends_spec.rb +6 -6
  116. data/spec/twitter/rest/api/tweets_spec.rb +503 -0
  117. data/spec/twitter/{api → rest/api}/undocumented_spec.rb +19 -45
  118. data/spec/twitter/{api → rest/api}/users_spec.rb +60 -35
  119. data/spec/twitter/rest/client_spec.rb +193 -0
  120. data/spec/twitter/saved_search_spec.rb +11 -0
  121. data/spec/twitter/search_results_spec.rb +29 -42
  122. data/spec/twitter/settings_spec.rb +17 -6
  123. data/spec/twitter/streaming/client_spec.rb +75 -0
  124. data/spec/twitter/token_spec.rb +16 -0
  125. data/spec/twitter/trend_results_spec.rb +89 -0
  126. data/spec/twitter/trend_spec.rb +23 -0
  127. data/spec/twitter/tweet_spec.rb +122 -115
  128. data/spec/twitter/user_spec.rb +136 -77
  129. data/spec/twitter_spec.rb +0 -119
  130. data/twitter.gemspec +8 -5
  131. metadata +148 -141
  132. metadata.gz.sig +0 -0
  133. data/lib/twitter/action/favorite.rb +0 -19
  134. data/lib/twitter/action/follow.rb +0 -30
  135. data/lib/twitter/action/list_member_added.rb +0 -39
  136. data/lib/twitter/action/mention.rb +0 -46
  137. data/lib/twitter/action/reply.rb +0 -27
  138. data/lib/twitter/action/retweet.rb +0 -27
  139. data/lib/twitter/action/tweet.rb +0 -20
  140. data/lib/twitter/action_factory.rb +0 -22
  141. data/lib/twitter/api/arguments.rb +0 -13
  142. data/lib/twitter/api/direct_messages.rb +0 -148
  143. data/lib/twitter/api/favorites.rb +0 -126
  144. data/lib/twitter/api/friends_and_followers.rb +0 -334
  145. data/lib/twitter/api/help.rb +0 -64
  146. data/lib/twitter/api/lists.rb +0 -618
  147. data/lib/twitter/api/oauth.rb +0 -44
  148. data/lib/twitter/api/places_and_geo.rb +0 -121
  149. data/lib/twitter/api/saved_searches.rb +0 -99
  150. data/lib/twitter/api/search.rb +0 -37
  151. data/lib/twitter/api/spam_reporting.rb +0 -30
  152. data/lib/twitter/api/suggested_users.rb +0 -55
  153. data/lib/twitter/api/timelines.rb +0 -214
  154. data/lib/twitter/api/trends.rb +0 -63
  155. data/lib/twitter/api/tweets.rb +0 -304
  156. data/lib/twitter/api/undocumented.rb +0 -97
  157. data/lib/twitter/api/users.rb +0 -439
  158. data/lib/twitter/api/utils.rb +0 -187
  159. data/lib/twitter/configurable.rb +0 -96
  160. data/lib/twitter/default.rb +0 -102
  161. data/lib/twitter/entity/url.rb +0 -9
  162. data/lib/twitter/error/client_error.rb +0 -35
  163. data/lib/twitter/error/decode_error.rb +0 -9
  164. data/lib/twitter/error/identity_map_key_error.rb +0 -9
  165. data/lib/twitter/error/server_error.rb +0 -28
  166. data/lib/twitter/exceptable.rb +0 -36
  167. data/lib/twitter/identity_map.rb +0 -22
  168. data/lib/twitter/request/multipart_with_file.rb +0 -34
  169. data/lib/twitter/response/parse_json.rb +0 -25
  170. data/spec/fixtures/about_me.json +0 -1
  171. data/spec/fixtures/activity_summary.json +0 -1
  172. data/spec/fixtures/bad_gateway.json +0 -1
  173. data/spec/fixtures/bad_request.json +0 -1
  174. data/spec/fixtures/by_friends.json +0 -1
  175. data/spec/fixtures/end_session.json +0 -1
  176. data/spec/fixtures/forbidden.json +0 -1
  177. data/spec/fixtures/internal_server_error.json +0 -1
  178. data/spec/fixtures/not_acceptable.json +0 -1
  179. data/spec/fixtures/phoenix_search.phoenix +0 -1
  180. data/spec/fixtures/resolve.json +0 -1
  181. data/spec/fixtures/service_unavailable.json +0 -1
  182. data/spec/fixtures/totals.json +0 -1
  183. data/spec/fixtures/trends.json +0 -1
  184. data/spec/fixtures/unauthorized.json +0 -1
  185. data/spec/fixtures/video_facets.json +0 -1
  186. data/spec/twitter/action/favorite_spec.rb +0 -29
  187. data/spec/twitter/action/follow_spec.rb +0 -29
  188. data/spec/twitter/action/list_member_added_spec.rb +0 -41
  189. data/spec/twitter/action/mention_spec.rb +0 -52
  190. data/spec/twitter/action/reply_spec.rb +0 -41
  191. data/spec/twitter/action/retweet_spec.rb +0 -41
  192. data/spec/twitter/action_factory_spec.rb +0 -35
  193. data/spec/twitter/action_spec.rb +0 -16
  194. data/spec/twitter/api/tweets_spec.rb +0 -285
  195. data/spec/twitter/client_spec.rb +0 -223
  196. data/spec/twitter/error/client_error_spec.rb +0 -23
  197. data/spec/twitter/error/server_error_spec.rb +0 -20
@@ -0,0 +1,45 @@
1
+ require 'twitter/rest/api/utils'
2
+ require 'twitter/token'
3
+
4
+ module Twitter
5
+ module REST
6
+ module API
7
+ module OAuth
8
+ include Twitter::REST::API::Utils
9
+
10
+ # Allows a registered application to obtain an OAuth 2 Bearer Token, which can be used to make API requests
11
+ # on an application's own behalf, without a user context.
12
+ #
13
+ # Only one bearer token may exist outstanding for an application, and repeated requests to this method
14
+ # will yield the same already-existent token until it has been invalidated.
15
+ #
16
+ # @see https://dev.twitter.com/docs/api/1.1/post/oauth2/token
17
+ # @rate_limited No
18
+ # @authentication Required
19
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
20
+ # @return [Twitter::Token] The Bearer Token. token_type should be 'bearer'.
21
+ # @example Generate a Bearer Token
22
+ # client = Twitter::REST::Client.new(:consumer_key => "abc", :consumer_secret => 'def')
23
+ # bearer_token = client.token
24
+ def token
25
+ object_from_response(Twitter::Token, :post, "/oauth2/token", :grant_type => "client_credentials", :bearer_token_request => true)
26
+ end
27
+ alias bearer_token token
28
+
29
+ # Allows a registered application to revoke an issued OAuth 2 Bearer Token by presenting its client credentials.
30
+ #
31
+ # @see https://dev.twitter.com/docs/api/1.1/post/oauth2/invalidate_token
32
+ # @rate_limited No
33
+ # @authentication Required
34
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
35
+ # @param access_token [String, Twitter::Token] The bearer token to revoke.
36
+ # @return [Twitter::Token] The invalidated token. token_type should be nil.
37
+ def invalidate_token(access_token)
38
+ access_token = access_token.access_token if access_token.is_a?(Twitter::Token)
39
+ object_from_response(Twitter::Token, :post, "/oauth2/invalidate_token", :access_token => access_token)
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,104 @@
1
+ require 'twitter/rest/api/utils'
2
+ require 'twitter/geo_results'
3
+ require 'twitter/place'
4
+
5
+ module Twitter
6
+ module REST
7
+ module API
8
+ module PlacesAndGeo
9
+ include Twitter::REST::API::Utils
10
+
11
+ # Returns all the information about a known place
12
+ #
13
+ # @see https://dev.twitter.com/docs/api/1.1/get/geo/id/:place_id
14
+ # @rate_limited Yes
15
+ # @authentication Requires user context
16
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
17
+ # @param place_id [String] A place in the world. These IDs can be retrieved from {Twitter::REST::API::PlacesAndGeo#reverse_geocode}.
18
+ # @param options [Hash] A customizable set of options.
19
+ # @return [Twitter::Place] The requested place.
20
+ def place(place_id, options={})
21
+ object_from_response(Twitter::Place, :get, "/1.1/geo/id/#{place_id}.json", options)
22
+ end
23
+
24
+ # Searches for up to 20 places that can be used as a place_id
25
+ #
26
+ # @see https://dev.twitter.com/docs/api/1.1/get/geo/reverse_geocode
27
+ # @note This request is an informative call and will deliver generalized results about geography.
28
+ # @rate_limited Yes
29
+ # @authentication Requires user context
30
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
31
+ # @param options [Hash] A customizable set of options.
32
+ # @option options [Float] :lat The latitude to search around. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
33
+ # @option options [Float] :long The longitude to search around. The valid range for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
34
+ # @option options [String] :accuracy ('0m') A hint on the "region" in which to search. If a number, then this is a radius in meters, but it can also take a string that is suffixed with ft to specify feet. If coming from a device, in practice, this value is whatever accuracy the device has measuring its location (whether it be coming from a GPS, WiFi triangulation, etc.).
35
+ # @option options [String] :granularity ('neighborhood') This is the minimal granularity of place types to return and must be one of: 'poi', 'neighborhood', 'city', 'admin' or 'country'.
36
+ # @option options [Integer] :max_results A hint as to the number of results to return. This does not guarantee that the number of results returned will equal max_results, but instead informs how many "nearby" results to return. Ideally, only pass in the number of places you intend to display to the user here.
37
+ # @return [Array<Twitter::Place>]
38
+ def reverse_geocode(options={})
39
+ object_from_response(Twitter::GeoResults, :get, "/1.1/geo/reverse_geocode.json", options)
40
+ end
41
+
42
+ # Search for places that can be attached to a {Twitter::REST::API::Tweets#update}
43
+ #
44
+ # @see https://dev.twitter.com/docs/api/1.1/get/geo/search
45
+ # @rate_limited Yes
46
+ # @authentication Requires user context
47
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
48
+ # @param options [Hash] A customizable set of options.
49
+ # @option options [Float] :lat The latitude to search around. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
50
+ # @option options [Float] :long The longitude to search around. The valid range for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
51
+ # @option options [String] :query Free-form text to match against while executing a geo-based query, best suited for finding nearby locations by name.
52
+ # @option options [String] :ip An IP address. Used when attempting to fix geolocation based off of the user's IP address.
53
+ # @option options [String] :granularity ('neighborhood') This is the minimal granularity of place types to return and must be one of: 'poi', 'neighborhood', 'city', 'admin' or 'country'.
54
+ # @option options [String] :accuracy ('0m') A hint on the "region" in which to search. If a number, then this is a radius in meters, but it can also take a string that is suffixed with ft to specify feet. If coming from a device, in practice, this value is whatever accuracy the device has measuring its location (whether it be coming from a GPS, WiFi triangulation, etc.).
55
+ # @option options [Integer] :max_results A hint as to the number of results to return. This does not guarantee that the number of results returned will equal max_results, but instead informs how many "nearby" results to return. Ideally, only pass in the number of places you intend to display to the user here.
56
+ # @option options [String] :contained_within This is the place_id which you would like to restrict the search results to. Setting this value means only places within the given place_id will be found.
57
+ # @option options [String] :"attribute:street_address" This option searches for places which have this given street address. There are other well-known and application-specific attributes available. Custom attributes are also permitted.
58
+ # @return [Array<Twitter::Place>]
59
+ def geo_search(options={})
60
+ object_from_response(Twitter::GeoResults, :get, "/1.1/geo/search.json", options)
61
+ end
62
+ alias places_nearby geo_search
63
+
64
+ # Locates places near the given coordinates which are similar in name
65
+ #
66
+ # @see https://dev.twitter.com/docs/api/1.1/get/geo/similar_places
67
+ # @note Conceptually, you would use this method to get a list of known places to choose from first. Then, if the desired place doesn't exist, make a request to {Twitter::REST::API::PlacesAndGeo#place} to create a new one. The token contained in the response is the token necessary to create a new place.
68
+ # @rate_limited Yes
69
+ # @authentication Requires user context
70
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
71
+ # @param options [Hash] A customizable set of options.
72
+ # @option options [Float] :lat The latitude to search around. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
73
+ # @option options [Float] :long The longitude to search around. The valid range for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
74
+ # @option options [String] :name The name a place is known as.
75
+ # @option options [String] :contained_within This is the place_id which you would like to restrict the search results to. Setting this value means only places within the given place_id will be found.
76
+ # @option options [String] :"attribute:street_address" This option searches for places which have this given street address. There are other well-known and application-specific attributes available. Custom attributes are also permitted.
77
+ # @return [Array<Twitter::Place>]
78
+ def similar_places(options={})
79
+ object_from_response(Twitter::GeoResults, :get, "/1.1/geo/similar_places.json", options)
80
+ end
81
+ alias places_similar similar_places
82
+
83
+ # Creates a new place at the given latitude and longitude
84
+ #
85
+ # @see https://dev.twitter.com/docs/api/1.1/post/geo/place
86
+ # @rate_limited Yes
87
+ # @authentication Requires user context
88
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
89
+ # @param options [Hash] A customizable set of options.
90
+ # @option options [String] :name The name a place is known as.
91
+ # @option options [String] :contained_within This is the place_id which you would like to restrict the search results to. Setting this value means only places within the given place_id will be found.
92
+ # @option options [String] :token The token found in the response from {Twitter::REST::API::PlacesAndGeo#places_similar}.
93
+ # @option options [Float] :lat The latitude to search around. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
94
+ # @option options [Float] :long The longitude to search around. The valid range for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
95
+ # @option options [String] :"attribute:street_address" This option searches for places which have this given street address. There are other well-known and application-specific attributes available. Custom attributes are also permitted.
96
+ # @return [Twitter::Place] The created place.
97
+ def place_create(options={})
98
+ object_from_response(Twitter::Place, :post, "/1.1/geo/place.json", options)
99
+ end
100
+
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,91 @@
1
+ require 'twitter/arguments'
2
+ require 'twitter/rest/api/utils'
3
+ require 'twitter/saved_search'
4
+
5
+ module Twitter
6
+ module REST
7
+ module API
8
+ module SavedSearches
9
+ include Twitter::REST::API::Utils
10
+
11
+ # @rate_limited Yes
12
+ # @authentication Requires user context
13
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
14
+ # @return [Array<Twitter::SavedSearch>] The saved searches.
15
+ # @overload saved_search(options={})
16
+ # Returns the authenticated user's saved search queries
17
+ #
18
+ # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/list
19
+ # @param options [Hash] A customizable set of options.
20
+ # @overload saved_search(*ids)
21
+ # Retrieve the data for saved searches owned by the authenticating user
22
+ #
23
+ # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/:id
24
+ # @param ids [Enumerable<Integer>] A collection of saved search IDs.
25
+ # @overload saved_search(*ids, options)
26
+ # Retrieve the data for saved searches owned by the authenticating user
27
+ #
28
+ # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/:id
29
+ # @param ids [Enumerable<Integer>] A collection of saved search IDs.
30
+ # @param options [Hash] A customizable set of options.
31
+ def saved_searches(*args)
32
+ arguments = Twitter::Arguments.new(args)
33
+ if arguments.empty?
34
+ objects_from_response(Twitter::SavedSearch, :get, "/1.1/saved_searches/list.json", arguments.options)
35
+ else
36
+ arguments.flatten.threaded_map do |id|
37
+ saved_search(id, arguments.options)
38
+ end
39
+ end
40
+ end
41
+
42
+ # Retrieve the data for saved searches owned by the authenticating user
43
+ #
44
+ # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/:id
45
+ # @rate_limited Yes
46
+ # @authentication Requires user context
47
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
48
+ # @return [Twitter::SavedSearch] The saved searches.
49
+ # @param id [Integer] The ID of the saved search.
50
+ # @param options [Hash] A customizable set of options.
51
+ def saved_search(id, options={})
52
+ object_from_response(Twitter::SavedSearch, :get, "/1.1/saved_searches/show/#{id}.json", options)
53
+ end
54
+
55
+ # Creates a saved search for the authenticated user
56
+ #
57
+ # @see https://dev.twitter.com/docs/api/1.1/post/saved_searches/create
58
+ # @rate_limited No
59
+ # @authentication Requires user context
60
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
61
+ # @return [Twitter::SavedSearch] The created saved search.
62
+ # @param query [String] The query of the search the user would like to save.
63
+ # @param options [Hash] A customizable set of options.
64
+ def saved_search_create(query, options={})
65
+ object_from_response(Twitter::SavedSearch, :post, "/1.1/saved_searches/create.json", options.merge(:query => query))
66
+ end
67
+
68
+ # Destroys saved searches for the authenticated user
69
+ #
70
+ # @see https://dev.twitter.com/docs/api/1.1/post/saved_searches/destroy/:id
71
+ # @note The search specified by ID must be owned by the authenticating user.
72
+ # @rate_limited No
73
+ # @authentication Requires user context
74
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
75
+ # @return [Array<Twitter::SavedSearch>] The deleted saved searches.
76
+ # @overload saved_search_destroy(*ids)
77
+ # @param ids [Enumerable<Integer>] A collection of saved search IDs.
78
+ # @overload saved_search_destroy(*ids, options)
79
+ # @param ids [Enumerable<Integer>] A collection of saved search IDs.
80
+ # @param options [Hash] A customizable set of options.
81
+ def saved_search_destroy(*args)
82
+ arguments = Twitter::Arguments.new(args)
83
+ arguments.flatten.threaded_map do |id|
84
+ object_from_response(Twitter::SavedSearch, :post, "/1.1/saved_searches/destroy/#{id}.json", arguments.options)
85
+ end
86
+ end
87
+
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,37 @@
1
+ require 'twitter/rest/api/utils'
2
+ require 'twitter/search_results'
3
+
4
+ module Twitter
5
+ module REST
6
+ module API
7
+ module Search
8
+ include Twitter::REST::API::Utils
9
+
10
+ # Returns tweets that match a specified query.
11
+ #
12
+ # @see https://dev.twitter.com/docs/api/1.1/get/search/tweets
13
+ # @see https://dev.twitter.com/docs/using-search
14
+ # @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
+ # @rate_limited Yes
16
+ # @authentication Requires user context
17
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
18
+ # @param q [String] A search term.
19
+ # @param options [Hash] A customizable set of options.
20
+ # @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.
21
+ # @option options [String] :lang Restricts tweets to the given language, given by an ISO 639-1 code.
22
+ # @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.
23
+ # @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."
24
+ # @option options [Integer] :count The number of tweets to return per page, up to a maximum of 100.
25
+ # @option options [String] :until Optional. Returns tweets generated before the given date. Date should be formatted as YYYY-MM-DD.
26
+ # @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.
27
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
28
+ # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
29
+ # @return [Twitter::SearchResults] Return tweets that match a specified query with search metadata
30
+ def search(q, options={})
31
+ object_from_response(Twitter::SearchResults, :get, "/1.1/search/tweets.json", options.merge(:q => q))
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ require 'twitter/rest/api/utils'
2
+ require 'twitter/user'
3
+
4
+ module Twitter
5
+ module REST
6
+ module API
7
+ module SpamReporting
8
+ include Twitter::REST::API::Utils
9
+
10
+ # The users specified are blocked by the authenticated user and reported as spammers
11
+ #
12
+ # @see https://dev.twitter.com/docs/api/1.1/post/users/report_spam
13
+ # @rate_limited Yes
14
+ # @authentication Requires user context
15
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
16
+ # @return [Array<Twitter::User>] The reported users.
17
+ # @overload report_spam(*users)
18
+ # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
19
+ # @overload report_spam(*users, options)
20
+ # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
21
+ # @param options [Hash] A customizable set of options.
22
+ def report_spam(*args)
23
+ threaded_user_objects_from_response(:post, "/1.1/users/report_spam.json", args)
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,51 @@
1
+ require 'twitter/arguments'
2
+ require 'twitter/rest/api/utils'
3
+ require 'twitter/suggestion'
4
+ require 'twitter/user'
5
+
6
+ module Twitter
7
+ module REST
8
+ module API
9
+ module SuggestedUsers
10
+ include Twitter::REST::API::Utils
11
+
12
+ # @return [Array<Twitter::Suggestion>]
13
+ # @rate_limited Yes
14
+ # @authentication Requires user context
15
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
16
+ # @overload suggestions(options={})
17
+ # Returns the list of suggested user categories
18
+ #
19
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions
20
+ # @param options [Hash] A customizable set of options.
21
+ # @overload suggestions(slug, options={})
22
+ # Returns the users in a given category
23
+ #
24
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions/:slug
25
+ # @param slug [String] The short name of list or a category.
26
+ # @param options [Hash] A customizable set of options.
27
+ def suggestions(*args)
28
+ arguments = Twitter::Arguments.new(args)
29
+ if slug = arguments.pop
30
+ object_from_response(Twitter::Suggestion, :get, "/1.1/users/suggestions/#{slug}.json", arguments.options)
31
+ else
32
+ objects_from_response(Twitter::Suggestion, :get, "/1.1/users/suggestions.json", arguments.options)
33
+ end
34
+ end
35
+
36
+ # 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
37
+ #
38
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions/:slug/members
39
+ # @rate_limited Yes
40
+ # @authentication Requires user context
41
+ # @param slug [String] The short name of list or a category.
42
+ # @param options [Hash] A customizable set of options.
43
+ # @return [Array<Twitter::User>]
44
+ def suggest_users(slug, options={})
45
+ objects_from_response(Twitter::User, :get, "/1.1/users/suggestions/#{slug}/members.json", options)
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,202 @@
1
+ require 'twitter/rest/api/utils'
2
+ require 'twitter/tweet'
3
+ require 'twitter/user'
4
+
5
+ module Twitter
6
+ module REST
7
+ module API
8
+ module Timelines
9
+ include Twitter::REST::API::Utils
10
+ DEFAULT_TWEETS_PER_REQUEST = 20
11
+ MAX_TWEETS_PER_REQUEST = 200
12
+
13
+ # Returns the 20 most recent mentions (statuses containing @username) for the authenticating user
14
+ #
15
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/mentions_timeline
16
+ # @note This method can only return up to 800 Tweets.
17
+ # @rate_limited Yes
18
+ # @authentication Requires user context
19
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
20
+ # @return [Array<Twitter::Tweet>]
21
+ # @param options [Hash] A customizable set of options.
22
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
23
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
24
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
25
+ # @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.
26
+ def mentions_timeline(options={})
27
+ objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/mentions_timeline.json", options)
28
+ end
29
+ alias mentions mentions_timeline
30
+
31
+ # Returns the 20 most recent Tweets posted by the specified user
32
+ #
33
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
34
+ # @note This method can only return up to 3,200 Tweets.
35
+ # @rate_limited Yes
36
+ # @authentication Requires user context
37
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
38
+ # @return [Array<Twitter::Tweet>]
39
+ # @overload user_timeline(user, options={})
40
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
41
+ # @param options [Hash] A customizable set of options.
42
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
43
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
44
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
45
+ # @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.
46
+ # @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.
47
+ # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
48
+ # @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.
49
+ def user_timeline(*args)
50
+ objects_from_response_with_user(Twitter::Tweet, :get, "/1.1/statuses/user_timeline.json", args)
51
+ end
52
+
53
+ # Returns the 20 most recent retweets posted by the specified user
54
+ #
55
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
56
+ # @note This method can only return up to 3,200 Tweets.
57
+ # @rate_limited Yes
58
+ # @authentication Requires user context
59
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
60
+ # @return [Array<Twitter::Tweet>]
61
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
62
+ # @param options [Hash] A customizable set of options.
63
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
64
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
65
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
66
+ # @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.
67
+ # @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.
68
+ # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
69
+ def retweeted_by_user(user, options={})
70
+ retweets_from_timeline(options) do |opts|
71
+ user_timeline(user, opts)
72
+ end
73
+ end
74
+ alias retweeted_by retweeted_by_user
75
+
76
+ # Returns the 20 most recent retweets posted by the authenticating user
77
+ #
78
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
79
+ # @note This method can only return up to 3,200 Tweets.
80
+ # @rate_limited Yes
81
+ # @authentication Requires user context
82
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
83
+ # @return [Array<Twitter::Tweet>]
84
+ # @param options [Hash] A customizable set of options.
85
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
86
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
87
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
88
+ # @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.
89
+ # @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.
90
+ # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
91
+ def retweeted_by_me(options={})
92
+ retweets_from_timeline(options) do |opts|
93
+ user_timeline(opts)
94
+ end
95
+ end
96
+
97
+ # Returns the 20 most recent Tweets, including retweets if they exist, posted by the authenticating user and the users they follow
98
+ #
99
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline
100
+ # @note This method can only return up to 800 Tweets, including retweets.
101
+ # @rate_limited Yes
102
+ # @authentication Requires user context
103
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
104
+ # @return [Array<Twitter::Tweet>]
105
+ # @param options [Hash] A customizable set of options.
106
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
107
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
108
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
109
+ # @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.
110
+ # @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.
111
+ # @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.
112
+ # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
113
+ # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
114
+ def home_timeline(options={})
115
+ objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/home_timeline.json", options)
116
+ end
117
+
118
+ # Returns the 20 most recent retweets posted by users the authenticating user follow.
119
+ #
120
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline
121
+ # @note This method can only return up to 800 Tweets, including retweets.
122
+ # @rate_limited Yes
123
+ # @authentication Requires user context
124
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
125
+ # @return [Array<Twitter::Tweet>]
126
+ # @param options [Hash] A customizable set of options.
127
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
128
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
129
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
130
+ # @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.
131
+ # @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.
132
+ # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
133
+ # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
134
+ def retweeted_to_me(options={})
135
+ retweets_from_timeline(options) do |opts|
136
+ home_timeline(opts)
137
+ end
138
+ end
139
+
140
+ # Returns the 20 most recent tweets of the authenticated user that have been retweeted by others
141
+ #
142
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets_of_me
143
+ # @rate_limited Yes
144
+ # @authentication Requires user context
145
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
146
+ # @return [Array<Twitter::Tweet>]
147
+ # @param options [Hash] A customizable set of options.
148
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
149
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
150
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
151
+ # @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.
152
+ # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
153
+ # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false.
154
+ def retweets_of_me(options={})
155
+ objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/retweets_of_me.json", options)
156
+ end
157
+
158
+ private
159
+
160
+ def retweets_from_timeline(options)
161
+ options[:include_rts] = true
162
+ count = options[:count] || DEFAULT_TWEETS_PER_REQUEST
163
+ collect_with_count(count) do |count_options|
164
+ select_retweets(yield(options.merge(count_options)))
165
+ end
166
+ end
167
+
168
+ # @param tweets [Array]
169
+ # @return [Array]
170
+ def select_retweets(tweets)
171
+ tweets.select(&:retweet?)
172
+ end
173
+
174
+ # @param count [Integer]
175
+ # @return [Array]
176
+ def collect_with_count(count, &block)
177
+ options = {}
178
+ options[:count] = MAX_TWEETS_PER_REQUEST
179
+ collect_with_max_id do |max_id|
180
+ options[:max_id] = max_id unless max_id.nil?
181
+ if count > 0
182
+ tweets = yield(options)
183
+ count -= tweets.length
184
+ tweets
185
+ end
186
+ end.flatten.compact[0...count]
187
+ end
188
+
189
+ # @param collection [Array]
190
+ # @param max_id [Integer, NilClass]
191
+ # @return [Array]
192
+ def collect_with_max_id(collection=[], max_id=nil, &block)
193
+ tweets = yield(max_id)
194
+ return collection if tweets.nil?
195
+ collection += tweets
196
+ tweets.empty? ? collection.flatten : collect_with_max_id(collection, tweets.last.id - 1, &block)
197
+ end
198
+
199
+ end
200
+ end
201
+ end
202
+ end