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
@@ -1,44 +0,0 @@
1
- require 'twitter/api/utils'
2
- require 'twitter/token'
3
-
4
- module Twitter
5
- module API
6
- module OAuth
7
- include Twitter::API::Utils
8
-
9
- # Allows a registered application to obtain an OAuth 2 Bearer Token, which can be used to make API requests
10
- # on an application's own behalf, without a user context.
11
- #
12
- # Only one bearer token may exist outstanding for an application, and repeated requests to this method
13
- # will yield the same already-existent token until it has been invalidated.
14
- #
15
- # @see https://dev.twitter.com/docs/api/1.1/post/oauth2/token
16
- # @rate_limited No
17
- # @authentication Required
18
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
19
- # @return [Twitter::Token] The Bearer Token. token_type should be 'bearer'.
20
- # @example Generate a Bearer Token
21
- # client = Twitter::Client.new(:consumer_key => "abc", :consumer_secret => 'def')
22
- # bearer_token = client.token
23
- def token
24
- object_from_response(Twitter::Token, :post, "/oauth2/token", :grant_type => "client_credentials", :bearer_token_request => true)
25
- end
26
- alias bearer_token token
27
-
28
- # Allows a registered application to revoke an issued OAuth 2 Bearer Token by presenting its client credentials.
29
- #
30
- # @see https://dev.twitter.com/docs/api/1.1/post/oauth2/invalidate_token
31
- # @rate_limited No
32
- # @authentication Required
33
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
34
- # @param access_token [String, Twitter::Token] The bearer token to revoke.
35
- # @return [Twitter::Token] The invalidated token. token_type should be nil.
36
- # @example Revoke a token
37
- # Twitter.invalidate_token("AAAA%2FAAA%3DAAAAAAAA")
38
- def invalidate_token(access_token)
39
- access_token = access_token.access_token if access_token.is_a?(Twitter::Token)
40
- object_from_response(Twitter::Token, :post, "/oauth2/invalidate_token", :access_token => access_token)
41
- end
42
- end
43
- end
44
- end
@@ -1,121 +0,0 @@
1
- require 'twitter/api/utils'
2
- require 'twitter/place'
3
-
4
- module Twitter
5
- module API
6
- module PlacesAndGeo
7
- include Twitter::API::Utils
8
-
9
- # Returns all the information about a known place
10
- #
11
- # @see https://dev.twitter.com/docs/api/1.1/get/geo/id/:place_id
12
- # @rate_limited Yes
13
- # @authentication Requires user context
14
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
15
- # @param place_id [String] A place in the world. These IDs can be retrieved from {Twitter::API::PlacesAndGeo#reverse_geocode}.
16
- # @param options [Hash] A customizable set of options.
17
- # @return [Twitter::Place] The requested place.
18
- # @example Return all the information about Twitter HQ
19
- # Twitter.place("247f43d441defc03")
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
- # @example Return an array of places within the specified region
39
- # Twitter.reverse_geocode(:lat => "37.7821120598956", :long => "-122.400612831116")
40
- def reverse_geocode(options={})
41
- geo_objects_from_response(:get, "/1.1/geo/reverse_geocode.json", options)
42
- end
43
-
44
- # Search for places that can be attached to a {Twitter::API::Tweets#update}
45
- #
46
- # @see https://dev.twitter.com/docs/api/1.1/get/geo/search
47
- # @rate_limited Yes
48
- # @authentication Requires user context
49
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
50
- # @param options [Hash] A customizable set of options.
51
- # @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.
52
- # @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.
53
- # @option options [String] :query Free-form text to match against while executing a geo-based query, best suited for finding nearby locations by name.
54
- # @option options [String] :ip An IP address. Used when attempting to fix geolocation based off of the user's IP address.
55
- # @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'.
56
- # @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.).
57
- # @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.
58
- # @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.
59
- # @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.
60
- # @return [Array<Twitter::Place>]
61
- # @example Return an array of places near the IP address 74.125.19.104
62
- # Twitter.geo_search(:ip => "74.125.19.104")
63
- def geo_search(options={})
64
- geo_objects_from_response(:get, "/1.1/geo/search.json", options)
65
- end
66
- alias places_nearby geo_search
67
-
68
- # Locates places near the given coordinates which are similar in name
69
- #
70
- # @see https://dev.twitter.com/docs/api/1.1/get/geo/similar_places
71
- # @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::API::PlacesAndGeo#place} to create a new one. The token contained in the response is the token necessary to create a new place.
72
- # @rate_limited Yes
73
- # @authentication Requires user context
74
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
75
- # @param options [Hash] A customizable set of options.
76
- # @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.
77
- # @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.
78
- # @option options [String] :name The name a place is known as.
79
- # @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.
80
- # @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.
81
- # @return [Array<Twitter::Place>]
82
- # @example Return an array of places similar to Twitter HQ
83
- # Twitter.similar_places(:lat => "37.7821120598956", :long => "-122.400612831116", :name => "Twitter HQ")
84
- def similar_places(options={})
85
- geo_objects_from_response(:get, "/1.1/geo/similar_places.json", options)
86
- end
87
- alias places_similar similar_places
88
-
89
- # Creates a new place at the given latitude and longitude
90
- #
91
- # @see https://dev.twitter.com/docs/api/1.1/post/geo/place
92
- # @rate_limited Yes
93
- # @authentication Requires user context
94
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
95
- # @param options [Hash] A customizable set of options.
96
- # @option options [String] :name The name a place is known as.
97
- # @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.
98
- # @option options [String] :token The token found in the response from {Twitter::API::PlacesAndGeo#places_similar}.
99
- # @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.
100
- # @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.
101
- # @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.
102
- # @return [Twitter::Place] The created place.
103
- # @example Create a new place
104
- # Twitter.place_create(:name => "@sferik's Apartment", :token => "22ff5b1f7159032cf69218c4d8bb78bc", :contained_within => "41bcb736f84a799e", :lat => "37.783699", :long => "-122.393581")
105
- def place_create(options={})
106
- object_from_response(Twitter::Place, :post, "/1.1/geo/place.json", options)
107
- end
108
-
109
- private
110
-
111
- # @param request_method [Symbol]
112
- # @param path [String]
113
- # @param params [Hash]
114
- # @return [Array]
115
- def geo_objects_from_response(request_method, path, params={})
116
- objects_from_array(Twitter::Place, send(request_method.to_sym, path, params)[:body][:result][:places])
117
- end
118
-
119
- end
120
- end
121
- end
@@ -1,99 +0,0 @@
1
- require 'twitter/api/arguments'
2
- require 'twitter/api/utils'
3
- require 'twitter/saved_search'
4
-
5
- module Twitter
6
- module API
7
- module SavedSearches
8
- include Twitter::API::Utils
9
-
10
- # @rate_limited Yes
11
- # @authentication Requires user context
12
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
13
- # @return [Array<Twitter::SavedSearch>] The saved searches.
14
- # @overload saved_search(options={})
15
- # Returns the authenticated user's saved search queries
16
- #
17
- # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/list
18
- # @param options [Hash] A customizable set of options.
19
- # @example Return the authenticated user's saved search queries
20
- # Twitter.saved_searches
21
- # @overload saved_search(*ids)
22
- # Retrieve the data for saved searches owned by the authenticating user
23
- #
24
- # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/:id
25
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
26
- # @example Retrieve the data for a saved search owned by the authenticating user with the ID 16129012
27
- # Twitter.saved_search(16129012)
28
- # @overload saved_search(*ids, options)
29
- # Retrieve the data for saved searches owned by the authenticating user
30
- #
31
- # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/:id
32
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
33
- # @param options [Hash] A customizable set of options.
34
- def saved_searches(*args)
35
- arguments = Twitter::API::Arguments.new(args)
36
- if arguments.empty?
37
- objects_from_response(Twitter::SavedSearch, :get, "/1.1/saved_searches/list.json", arguments.options)
38
- else
39
- arguments.flatten.threaded_map do |id|
40
- saved_search(id, arguments.options)
41
- end
42
- end
43
- end
44
-
45
- # Retrieve the data for saved searches owned by the authenticating user
46
- #
47
- # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/:id
48
- # @rate_limited Yes
49
- # @authentication Requires user context
50
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
51
- # @return [Twitter::SavedSearch] The saved searches.
52
- # @param id [Integer] A Tweet IDs.
53
- # @param options [Hash] A customizable set of options.
54
- # @example Retrieve the data for a saved search owned by the authenticating user with the ID 16129012
55
- # Twitter.saved_search(16129012)
56
- def saved_search(id, options={})
57
- object_from_response(Twitter::SavedSearch, :get, "/1.1/saved_searches/show/#{id}.json", options)
58
- end
59
-
60
- # Creates a saved search for the authenticated user
61
- #
62
- # @see https://dev.twitter.com/docs/api/1.1/post/saved_searches/create
63
- # @rate_limited No
64
- # @authentication Requires user context
65
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
66
- # @return [Twitter::SavedSearch] The created saved search.
67
- # @param query [String] The query of the search the user would like to save.
68
- # @param options [Hash] A customizable set of options.
69
- # @example Create a saved search for the authenticated user with the query "twitter"
70
- # Twitter.saved_search_create("twitter")
71
- def saved_search_create(query, options={})
72
- object_from_response(Twitter::SavedSearch, :post, "/1.1/saved_searches/create.json", options.merge(:query => query))
73
- end
74
-
75
- # Destroys saved searches for the authenticated user
76
- #
77
- # @see https://dev.twitter.com/docs/api/1.1/post/saved_searches/destroy/:id
78
- # @note The search specified by ID must be owned by the authenticating user.
79
- # @rate_limited No
80
- # @authentication Requires user context
81
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
82
- # @return [Array<Twitter::SavedSearch>] The deleted saved searches.
83
- # @overload saved_search_destroy(*ids)
84
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
85
- # @example Destroys a saved search for the authenticated user with the ID 16129012
86
- # Twitter.saved_search_destroy(16129012)
87
- # @overload saved_search_destroy(*ids, options)
88
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
89
- # @param options [Hash] A customizable set of options.
90
- def saved_search_destroy(*args)
91
- arguments = Twitter::API::Arguments.new(args)
92
- arguments.flatten.threaded_map do |id|
93
- object_from_response(Twitter::SavedSearch, :post, "/1.1/saved_searches/destroy/#{id}.json", arguments.options)
94
- end
95
- end
96
-
97
- end
98
- end
99
- end
@@ -1,37 +0,0 @@
1
- require 'twitter/api/utils'
2
- require 'twitter/search_results'
3
-
4
- module Twitter
5
- module API
6
- module Search
7
- include Twitter::API::Utils
8
-
9
- # Returns tweets that match a specified query.
10
- #
11
- # @see https://dev.twitter.com/docs/api/1.1/get/search/tweets
12
- # @see https://dev.twitter.com/docs/using-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.
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 q [String] A search term.
18
- # @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, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
28
- # @return [Twitter::SearchResults] Return tweets that match a specified query with search metadata
29
- # @example Return tweets related to twitter
30
- # Twitter.search('twitter')
31
- def search(q, options={})
32
- object_from_response(Twitter::SearchResults, :get, "/1.1/search/tweets.json", options.merge(:q => q))
33
- end
34
-
35
- end
36
- end
37
- end
@@ -1,30 +0,0 @@
1
- require 'twitter/api/utils'
2
- require 'twitter/user'
3
-
4
- module Twitter
5
- module API
6
- module SpamReporting
7
- include Twitter::API::Utils
8
-
9
- # The users specified are blocked by the authenticated user and reported as spammers
10
- #
11
- # @see https://dev.twitter.com/docs/api/1.1/post/users/report_spam
12
- # @rate_limited Yes
13
- # @authentication Requires user context
14
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
15
- # @return [Array<Twitter::User>] The reported users.
16
- # @overload report_spam(*users)
17
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
18
- # @example Report @spam for spam
19
- # Twitter.report_spam("spam")
20
- # Twitter.report_spam(14589771) # Same as above
21
- # @overload report_spam(*users, options)
22
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
23
- # @param options [Hash] A customizable set of options.
24
- def report_spam(*args)
25
- threaded_user_objects_from_response(:post, "/1.1/users/report_spam.json", args)
26
- end
27
-
28
- end
29
- end
30
- end
@@ -1,55 +0,0 @@
1
- require 'twitter/api/arguments'
2
- require 'twitter/api/utils'
3
- require 'twitter/suggestion'
4
- require 'twitter/user'
5
-
6
- module Twitter
7
- module API
8
- module SuggestedUsers
9
- include Twitter::API::Utils
10
-
11
- # @return [Array<Twitter::Suggestion>]
12
- # @rate_limited Yes
13
- # @authentication Requires user context
14
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
15
- # @overload suggestions(options={})
16
- # Returns the list of suggested user categories
17
- #
18
- # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions
19
- # @param options [Hash] A customizable set of options.
20
- # @example Return the list of suggested user categories
21
- # Twitter.suggestions
22
- # @overload suggestions(slug, options={})
23
- # Returns the users in a given category
24
- #
25
- # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions/:slug
26
- # @param slug [String] The short name of list or a category.
27
- # @param options [Hash] A customizable set of options.
28
- # @example Return the users in the Art & Design category
29
- # Twitter.suggestions("art-design")
30
- def suggestions(*args)
31
- arguments = Twitter::API::Arguments.new(args)
32
- if slug = arguments.pop
33
- object_from_response(Twitter::Suggestion, :get, "/1.1/users/suggestions/#{slug}.json", arguments.options)
34
- else
35
- objects_from_response(Twitter::Suggestion, :get, "/1.1/users/suggestions.json", arguments.options)
36
- end
37
- end
38
-
39
- # 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
40
- #
41
- # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions/:slug/members
42
- # @rate_limited Yes
43
- # @authentication Requires user context
44
- # @param slug [String] The short name of list or a category.
45
- # @param options [Hash] A customizable set of options.
46
- # @return [Array<Twitter::User>]
47
- # @example Return the users in the Art & Design category and their most recent Tweet if they are not a protected user
48
- # Twitter.suggest_users("art-design")
49
- def suggest_users(slug, options={})
50
- objects_from_response(Twitter::User, :get, "/1.1/users/suggestions/#{slug}/members.json", options)
51
- end
52
-
53
- end
54
- end
55
- end
@@ -1,214 +0,0 @@
1
- require 'twitter/api/utils'
2
- require 'twitter/tweet'
3
- require 'twitter/user'
4
-
5
- module Twitter
6
- module API
7
- module Timelines
8
- include Twitter::API::Utils
9
- DEFAULT_TWEETS_PER_REQUEST = 20
10
- MAX_TWEETS_PER_REQUEST = 200
11
-
12
- # Returns the 20 most recent mentions (statuses containing @username) for the authenticating user
13
- #
14
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/mentions_timeline
15
- # @note This method can only return up to 800 Tweets.
16
- # @rate_limited Yes
17
- # @authentication Requires user context
18
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
19
- # @return [Array<Twitter::Tweet>]
20
- # @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.
25
- # @example Return the 20 most recent mentions (statuses containing @username) for the authenticating user
26
- # Twitter.mentions
27
- def mentions_timeline(options={})
28
- objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/mentions_timeline.json", options)
29
- end
30
- alias mentions mentions_timeline
31
-
32
- # Returns the 20 most recent Tweets posted by the specified user
33
- #
34
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
35
- # @note This method can only return up to 3,200 Tweets.
36
- # @rate_limited Yes
37
- # @authentication Requires user context
38
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
39
- # @return [Array<Twitter::Tweet>]
40
- # @overload user_timeline(user, options={})
41
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
42
- # @param options [Hash] A customizable set of options.
43
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
44
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
45
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
46
- # @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.
47
- # @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.
48
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
49
- # @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.
50
- # @example Return the 20 most recent Tweets posted by @sferik
51
- # Twitter.user_timeline('sferik')
52
- def user_timeline(*args)
53
- objects_from_response_with_user(Twitter::Tweet, :get, "/1.1/statuses/user_timeline.json", args)
54
- end
55
-
56
- # Returns the 20 most recent retweets posted by the specified user
57
- #
58
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
59
- # @note This method can only return up to 3,200 Tweets.
60
- # @rate_limited Yes
61
- # @authentication Requires user context
62
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
63
- # @return [Array<Twitter::Tweet>]
64
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
65
- # @param options [Hash] A customizable set of options.
66
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
67
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
68
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
69
- # @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.
70
- # @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.
71
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
72
- # @example Return the 20 most recent retweets posted by @sferik
73
- # Twitter.retweeted_by_user('sferik')
74
- def retweeted_by_user(user, options={})
75
- retweets_from_timeline(options) do |opts|
76
- user_timeline(user, opts)
77
- end
78
- end
79
- alias retweeted_by retweeted_by_user
80
-
81
- # Returns the 20 most recent retweets posted by the authenticating user
82
- #
83
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
84
- # @note This method can only return up to 3,200 Tweets.
85
- # @rate_limited Yes
86
- # @authentication Requires user context
87
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
88
- # @return [Array<Twitter::Tweet>]
89
- # @param options [Hash] A customizable set of options.
90
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
91
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
92
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
93
- # @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.
94
- # @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.
95
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
96
- # @example Return the 20 most recent retweets posted by the authenticating user
97
- # Twitter.retweeted_by_me
98
- def retweeted_by_me(options={})
99
- retweets_from_timeline(options) do |opts|
100
- user_timeline(opts)
101
- end
102
- end
103
-
104
- # Returns the 20 most recent Tweets, including retweets if they exist, posted by the authenticating user and the users they follow
105
- #
106
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline
107
- # @note This method can only return up to 800 Tweets, including retweets.
108
- # @rate_limited Yes
109
- # @authentication Requires user context
110
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
111
- # @return [Array<Twitter::Tweet>]
112
- # @param options [Hash] A customizable set of options.
113
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
114
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
115
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
116
- # @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.
117
- # @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.
118
- # @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.
119
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
120
- # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
121
- # @example Return the 20 most recent Tweets, including retweets if they exist, posted by the authenticating user and the users they follow
122
- # Twitter.home_timeline
123
- def home_timeline(options={})
124
- objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/home_timeline.json", options)
125
- end
126
-
127
- # Returns the 20 most recent retweets posted by users the authenticating user follow.
128
- #
129
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline
130
- # @note This method can only return up to 800 Tweets, including retweets.
131
- # @rate_limited Yes
132
- # @authentication Requires user context
133
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
134
- # @return [Array<Twitter::Tweet>]
135
- # @param options [Hash] A customizable set of options.
136
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
137
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
138
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
139
- # @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.
140
- # @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.
141
- # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
142
- # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
143
- # @example Return the 20 most recent retweets posted by users followed by the authenticating user
144
- # Twitter.retweeted_to_me
145
- def retweeted_to_me(options={})
146
- retweets_from_timeline(options) do |opts|
147
- home_timeline(opts)
148
- end
149
- end
150
-
151
- # Returns the 20 most recent tweets of the authenticated user that have been retweeted by others
152
- #
153
- # @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets_of_me
154
- # @rate_limited Yes
155
- # @authentication Requires user context
156
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
157
- # @return [Array<Twitter::Tweet>]
158
- # @param options [Hash] A customizable set of options.
159
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
160
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
161
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
162
- # @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.
163
- # @option options [Boolean, String, Integer] :include_entities The tweet entities node will be disincluded when set to false.
164
- # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false.
165
- # @example Return the 20 most recent tweets of the authenticated user that have been retweeted by others
166
- # Twitter.retweets_of_me
167
- def retweets_of_me(options={})
168
- objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/retweets_of_me.json", options)
169
- end
170
-
171
- private
172
-
173
- # @param collection [Array]
174
- # @param max_id [Integer, NilClass]
175
- # @return [Array]
176
- def collect_with_max_id(collection=[], max_id=nil, &block)
177
- tweets = yield(max_id)
178
- return collection if tweets.nil?
179
- collection += tweets
180
- tweets.empty? ? collection.flatten : collect_with_max_id(collection, tweets.last.id - 1, &block)
181
- end
182
-
183
- # @param count [Integer]
184
- # @return [Array]
185
- def collect_with_count(count, &block)
186
- options = {}
187
- options[:count] = MAX_TWEETS_PER_REQUEST
188
- collect_with_max_id do |max_id|
189
- options[:max_id] = max_id unless max_id.nil?
190
- if count > 0
191
- tweets = yield(options)
192
- count -= tweets.length
193
- tweets
194
- end
195
- end.flatten.compact[0...count]
196
- end
197
-
198
- def retweets_from_timeline(options)
199
- options[:include_rts] = true
200
- count = options[:count] || DEFAULT_TWEETS_PER_REQUEST
201
- collect_with_count(count) do |count_options|
202
- select_retweets(yield(options.merge(count_options)))
203
- end
204
- end
205
-
206
- # @param tweets [Array]
207
- # @return [Array]
208
- def select_retweets(tweets)
209
- tweets.select(&:retweet?)
210
- end
211
-
212
- end
213
- end
214
- end