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,58 @@
1
+ require 'twitter/rest/api/utils'
2
+ require 'twitter/place'
3
+ require 'twitter/trend_results'
4
+
5
+ module Twitter
6
+ module REST
7
+ module API
8
+ module Trends
9
+ include Twitter::REST::API::Utils
10
+
11
+ # Returns the top 10 trending topics for a specific WOEID
12
+ #
13
+ # @see https://dev.twitter.com/docs/api/1.1/get/trends/place
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 id [Integer] The {https://developer.yahoo.com/geo/geoplanet Yahoo! Where On Earth ID} of the location to return trending information for. WOEIDs can be retrieved by calling {Twitter::REST::API::Trends#trend_locations}. Global information is available by using 1 as the WOEID.
18
+ # @param options [Hash] A customizable set of options.
19
+ # @option options [String] :exclude Setting this equal to 'hashtags' will remove all hashtags from the trends list.
20
+ # @return [Array<Twitter::Trend>]
21
+ def trends(id=1, options={})
22
+ options[:id] = id
23
+ object_from_response(Twitter::TrendResults, :get, "/1.1/trends/place.json", options)
24
+ end
25
+ alias local_trends trends
26
+ alias trends_place trends
27
+
28
+ # Returns the locations that Twitter has trending topic information for
29
+ #
30
+ # @see https://dev.twitter.com/docs/api/1.1/get/trends/available
31
+ # @rate_limited Yes
32
+ # @authentication Requires user context
33
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
34
+ # @param options [Hash] A customizable set of options.
35
+ # @return [Array<Twitter::Place>]
36
+ def trends_available(options={})
37
+ objects_from_response(Twitter::Place, :get, "/1.1/trends/available.json", options)
38
+ end
39
+ alias trend_locations trends_available
40
+
41
+ # Returns the locations that Twitter has trending topic information for, closest to a specified location.
42
+ #
43
+ # @see https://dev.twitter.com/docs/api/1.1/get/trends/closest
44
+ # @rate_limited Yes
45
+ # @authentication Requires user context
46
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
47
+ # @param options [Hash] A customizable set of options.
48
+ # @option options [Float] :lat If provided with a :long option the available trend locations will be sorted by distance, nearest to furthest, to the co-ordinate pair. The valid ranges for latitude are -90.0 to +90.0 (North is positive) inclusive.
49
+ # @option options [Float] :long If provided with a :lat option the available trend locations will be sorted by distance, nearest to furthest, to the co-ordinate pair. The valid ranges for longitude are -180.0 to +180.0 (East is positive) inclusive.
50
+ # @return [Array<Twitter::Place>]
51
+ def trends_closest(options={})
52
+ objects_from_response(Twitter::Place, :get, "/1.1/trends/closest.json", options)
53
+ end
54
+
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,293 @@
1
+ require 'twitter/arguments'
2
+ require 'twitter/error/already_posted'
3
+ require 'twitter/error/already_retweeted'
4
+ require 'twitter/error/forbidden'
5
+ require 'twitter/oembed'
6
+ require 'twitter/rest/api/utils'
7
+ require 'twitter/tweet'
8
+
9
+ module Twitter
10
+ module REST
11
+ module API
12
+ module Tweets
13
+ include Twitter::REST::API::Utils
14
+
15
+ # Returns up to 100 of the first retweets of a given tweet
16
+ #
17
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/:id
18
+ # @rate_limited Yes
19
+ # @authentication Requires user context
20
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
21
+ # @return [Array<Twitter::Tweet>]
22
+ # @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object.
23
+ # @param options [Hash] A customizable set of options.
24
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
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 retweets(tweet, options={})
27
+ id = extract_id(tweet)
28
+ objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/retweets/#{id}.json", options)
29
+ end
30
+
31
+ # Show up to 100 users who retweeted the Tweet
32
+ #
33
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/:id
34
+ # @rate_limited Yes
35
+ # @authentication Requires user context
36
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
37
+ # @return [Array]
38
+ # @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object.
39
+ # @param options [Hash] A customizable set of options.
40
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
41
+ # @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.
42
+ # @option options [Boolean] :ids_only ('false') Only return user ids instead of full user objects.
43
+ def retweeters_of(tweet, options={})
44
+ ids_only = !!options.delete(:ids_only)
45
+ retweeters = retweets(tweet, options).map(&:user)
46
+ if ids_only
47
+ retweeters.map(&:id)
48
+ else
49
+ retweeters
50
+ end
51
+ end
52
+
53
+ # Returns a Tweet
54
+ #
55
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/show/:id
56
+ # @rate_limited Yes
57
+ # @authentication Requires user context
58
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
59
+ # @raise [Twitter::Error::Forbidden] Error raised when supplied status is over 140 characters.
60
+ # @return [Twitter::Tweet] The requested Tweet.
61
+ # @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object.
62
+ # @param options [Hash] A customizable set of options.
63
+ # @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.
64
+ def status(tweet, options={})
65
+ id = extract_id(tweet)
66
+ object_from_response(Twitter::Tweet, :get, "/1.1/statuses/show/#{id}.json", options)
67
+ end
68
+
69
+ # Returns Tweets
70
+ #
71
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/show/:id
72
+ # @rate_limited Yes
73
+ # @authentication Requires user context
74
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
75
+ # @return [Array<Twitter::Tweet>] The requested Tweets.
76
+ # @overload statuses(*tweets)
77
+ # @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
78
+ # @overload statuses(*tweets, options)
79
+ # @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
80
+ # @param options [Hash] A customizable set of options.
81
+ # @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.
82
+ def statuses(*args)
83
+ threaded_tweets_from_response(:get, "/1.1/statuses/show", args)
84
+ end
85
+
86
+ # Destroys the specified Tweets
87
+ #
88
+ # @see https://dev.twitter.com/docs/api/1.1/post/statuses/destroy/:id
89
+ # @note The authenticating user must be the author of the specified Tweets.
90
+ # @rate_limited No
91
+ # @authentication Requires user context
92
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
93
+ # @return [Array<Twitter::Tweet>] The deleted Tweets.
94
+ # @overload status_destroy(*tweets)
95
+ # @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
96
+ # @overload status_destroy(*tweets, options)
97
+ # @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
98
+ # @param options [Hash] A customizable set of options.
99
+ # @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.
100
+ def status_destroy(*args)
101
+ threaded_tweets_from_response(:post, "/1.1/statuses/destroy", args)
102
+ end
103
+ alias tweet_destroy status_destroy
104
+
105
+ # Updates the authenticating user's status
106
+ #
107
+ # @see https://dev.twitter.com/docs/api/1.1/post/statuses/update
108
+ # @note A status update with text identical to the authenticating user's current status will be ignored to prevent duplicates.
109
+ # @rate_limited No
110
+ # @authentication Requires user context
111
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
112
+ # @return [Twitter::Tweet] The created Tweet.
113
+ # @param status [String] The text of your status update, up to 140 characters.
114
+ # @param options [Hash] A customizable set of options.
115
+ # @option options [Integer] :in_reply_to_status_id The ID of an existing status that the update is in reply to.
116
+ # @option options [Float] :lat The latitude of the location this tweet refers to. 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.
117
+ # @option options [Float] :long The longitude of the location this tweet refers to. The valid ranges 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.
118
+ # @option options [String] :place_id A place in the world. These IDs can be retrieved from {Twitter::REST::API::PlacesAndGeo#reverse_geocode}.
119
+ # @option options [String] :display_coordinates Whether or not to put a pin on the exact coordinates a tweet has been sent from.
120
+ # @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.
121
+ def update(status, options={})
122
+ object_from_response(Twitter::Tweet, :post, "/1.1/statuses/update.json", options.merge(:status => status))
123
+ rescue Twitter::Error::Forbidden => error
124
+ handle_forbidden_error(Twitter::Error::AlreadyPosted, error)
125
+ end
126
+
127
+ # Retweets the specified Tweets as the authenticating user
128
+ #
129
+ # @see https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/:id
130
+ # @rate_limited Yes
131
+ # @authentication Requires user context
132
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
133
+ # @return [Array<Twitter::Tweet>] The original tweets with retweet details embedded.
134
+ # @overload retweet(*tweets)
135
+ # @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
136
+ # @overload retweet(*tweets, options)
137
+ # @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
138
+ # @param options [Hash] A customizable set of options.
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
+ def retweet(*args)
141
+ arguments = Twitter::Arguments.new(args)
142
+ arguments.flatten.threaded_map do |tweet|
143
+ id = extract_id(tweet)
144
+ begin
145
+ post_retweet(id, arguments.options)
146
+ rescue Twitter::Error::Forbidden => error
147
+ raise unless error.message == Twitter::Error::AlreadyRetweeted::MESSAGE
148
+ end
149
+ end.compact
150
+ end
151
+
152
+ # Retweets the specified Tweets as the authenticating user and raises an error if one has already been retweeted
153
+ #
154
+ # @see https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/:id
155
+ # @rate_limited Yes
156
+ # @authentication Requires user context
157
+ # @raise [Twitter::Error::AlreadyRetweeted] Error raised when tweet has already been retweeted.
158
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
159
+ # @return [Array<Twitter::Tweet>] The original tweets with retweet details embedded.
160
+ # @overload retweet!(*tweets)
161
+ # @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
162
+ # @overload retweet!(*tweets, options)
163
+ # @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
164
+ # @param options [Hash] A customizable set of options.
165
+ # @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.
166
+ def retweet!(*args)
167
+ arguments = Twitter::Arguments.new(args)
168
+ arguments.flatten.threaded_map do |tweet|
169
+ id = extract_id(tweet)
170
+ begin
171
+ post_retweet(id, arguments.options)
172
+ rescue Twitter::Error::Forbidden => error
173
+ handle_forbidden_error(Twitter::Error::AlreadyRetweeted, error)
174
+ end
175
+ end.compact
176
+ end
177
+
178
+ # Updates the authenticating user's status with media
179
+ #
180
+ # @see https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media
181
+ # @note A status update with text/media identical to the authenticating user's current status will NOT be ignored
182
+ # @rate_limited No
183
+ # @authentication Requires user context
184
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
185
+ # @return [Twitter::Tweet] The created Tweet.
186
+ # @param status [String] The text of your status update, up to 140 characters.
187
+ # @param media [File, Hash] A File object with your picture (PNG, JPEG or GIF)
188
+ # @param options [Hash] A customizable set of options.
189
+ # @option options [Integer] :in_reply_to_status_id The ID of an existing Tweet that the update is in reply to.
190
+ # @option options [Float] :lat The latitude of the location this tweet refers to. 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.
191
+ # @option options [Float] :long The longitude of the location this tweet refers to. The valid ranges 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.
192
+ # @option options [String] :place_id A place in the world. These IDs can be retrieved from {Twitter::REST::API::PlacesAndGeo#reverse_geocode}.
193
+ # @option options [String] :display_coordinates Whether or not to put a pin on the exact coordinates a tweet has been sent from.
194
+ # @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.
195
+ def update_with_media(status, media, options={})
196
+ object_from_response(Twitter::Tweet, :post, "/1.1/statuses/update_with_media.json", options.merge('media[]' => media, 'status' => status))
197
+ rescue Twitter::Error::Forbidden => error
198
+ handle_forbidden_error(Twitter::Error::AlreadyPosted, error)
199
+ end
200
+
201
+ # Returns oEmbed for a Tweet
202
+ #
203
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/oembed
204
+ # @rate_limited Yes
205
+ # @authentication Requires user context
206
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
207
+ # @return [Twitter::OEmbed] OEmbed for the requested Tweet.
208
+ # @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object.
209
+ # @param options [Hash] A customizable set of options.
210
+ # @option options [Integer] :maxwidth The maximum width in pixels that the embed should be rendered at. This value is constrained to be between 250 and 550 pixels.
211
+ # @option options [Boolean, String, Integer] :hide_media Specifies whether the embedded Tweet should automatically expand images which were uploaded via {https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media POST statuses/update_with_media}. When set to either true, t or 1 images will not be expanded. Defaults to false.
212
+ # @option options [Boolean, String, Integer] :hide_thread Specifies whether the embedded Tweet should automatically show the original message in the case that the embedded Tweet is a reply. When set to either true, t or 1 the original Tweet will not be shown. Defaults to false.
213
+ # @option options [Boolean, String, Integer] :omit_script Specifies whether the embedded Tweet HTML should include a `<script>` element pointing to widgets.js. In cases where a page already includes widgets.js, setting this value to true will prevent a redundant script element from being included. When set to either true, t or 1 the `<script>` element will not be included in the embed HTML, meaning that pages must include a reference to widgets.js manually. Defaults to false.
214
+ # @option options [String] :align Specifies whether the embedded Tweet should be left aligned, right aligned, or centered in the page. Valid values are left, right, center, and none. Defaults to none, meaning no alignment styles are specified for the Tweet.
215
+ # @option options [String] :related A value for the TWT related parameter, as described in {https://dev.twitter.com/docs/intents Web Intents}. This value will be forwarded to all Web Intents calls.
216
+ # @option options [String] :lang Language code for the rendered embed. This will affect the text and localization of the rendered HTML.
217
+ def oembed(tweet, options={})
218
+ options[:id] = extract_id(tweet)
219
+ object_from_response(Twitter::OEmbed, :get, "/1.1/statuses/oembed.json", options)
220
+ end
221
+
222
+ # Returns oEmbeds for Tweets
223
+ #
224
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/oembed
225
+ # @rate_limited Yes
226
+ # @authentication Requires user context
227
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
228
+ # @return [Array<Twitter::OEmbed>] OEmbeds for the requested Tweets.
229
+ # @overload oembed(*tweets)
230
+ # @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
231
+ # @overload oembed(*tweets, options)
232
+ # @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
233
+ # @param options [Hash] A customizable set of options.
234
+ # @option options [Integer] :maxwidth The maximum width in pixels that the embed should be rendered at. This value is constrained to be between 250 and 550 pixels.
235
+ # @option options [Boolean, String, Integer] :hide_media Specifies whether the embedded Tweet should automatically expand images which were uploaded via {https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media POST statuses/update_with_media}. When set to either true, t or 1 images will not be expanded. Defaults to false.
236
+ # @option options [Boolean, String, Integer] :hide_thread Specifies whether the embedded Tweet should automatically show the original message in the case that the embedded Tweet is a reply. When set to either true, t or 1 the original Tweet will not be shown. Defaults to false.
237
+ # @option options [Boolean, String, Integer] :omit_script Specifies whether the embedded Tweet HTML should include a `<script>` element pointing to widgets.js. In cases where a page already includes widgets.js, setting this value to true will prevent a redundant script element from being included. When set to either true, t or 1 the `<script>` element will not be included in the embed HTML, meaning that pages must include a reference to widgets.js manually. Defaults to false.
238
+ # @option options [String] :align Specifies whether the embedded Tweet should be left aligned, right aligned, or centered in the page. Valid values are left, right, center, and none. Defaults to none, meaning no alignment styles are specified for the Tweet.
239
+ # @option options [String] :related A value for the TWT related parameter, as described in {https://dev.twitter.com/docs/intents Web Intents}. This value will be forwarded to all Web Intents calls.
240
+ # @option options [String] :lang Language code for the rendered embed. This will affect the text and localization of the rendered HTML.
241
+ def oembeds(*args)
242
+ arguments = Twitter::Arguments.new(args)
243
+ arguments.flatten.threaded_map do |tweet|
244
+ id = extract_id(tweet)
245
+ oembed(id, arguments.options)
246
+ end
247
+ end
248
+
249
+ # Returns a collection of up to 100 user IDs belonging to users who have retweeted the tweet specified by the id parameter.
250
+ #
251
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweeters/ids
252
+ # @rate_limited Yes
253
+ # @authentication Required
254
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
255
+ # @return [Array<Integer>]
256
+ # @overload retweeters_ids(options)
257
+ # @param options [Hash] A customizable set of options.
258
+ # @overload retweeters_ids(id, options={})
259
+ # @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object.
260
+ # @param options [Hash] A customizable set of options.
261
+ def retweeters_ids(*args)
262
+ arguments = Twitter::Arguments.new(args)
263
+ arguments.options[:id] ||= extract_id(arguments.first)
264
+ cursor_from_response(:ids, nil, :get, "/1.1/statuses/retweeters/ids.json", arguments.options)
265
+ end
266
+
267
+ private
268
+
269
+ # @param request_method [Symbol]
270
+ # @param path [String]
271
+ # @param args [Array]
272
+ # @return [Array<Twitter::Tweet>]
273
+ def threaded_tweets_from_response(request_method, path, args)
274
+ arguments = Twitter::Arguments.new(args)
275
+ arguments.flatten.threaded_map do |tweet|
276
+ id = extract_id(tweet)
277
+ object_from_response(Twitter::Tweet, request_method, path + "/#{id}.json", arguments.options)
278
+ end
279
+ end
280
+
281
+ def post_retweet(tweet, options)
282
+ id = extract_id(tweet)
283
+ response = post("/1.1/statuses/retweet/#{id}.json", options)
284
+ retweeted_status = response.dup
285
+ retweeted_status[:body] = response[:body].delete(:retweeted_status)
286
+ retweeted_status[:body][:retweeted_status] = response[:body]
287
+ Twitter::Tweet.from_response(retweeted_status)
288
+ end
289
+
290
+ end
291
+ end
292
+ end
293
+ end
@@ -0,0 +1,52 @@
1
+ require 'twitter/arguments'
2
+ require 'twitter/cursor'
3
+ require 'twitter/rest/api/utils'
4
+ require 'twitter/tweet'
5
+ require 'twitter/user'
6
+
7
+ module Twitter
8
+ module REST
9
+ module API
10
+ module Undocumented
11
+ include Twitter::REST::API::Utils
12
+
13
+ # @note Undocumented
14
+ # @rate_limited Yes
15
+ # @authentication Requires user context
16
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
17
+ #
18
+ # @overload following_followers_of(options={})
19
+ # Returns users following followers of the specified user
20
+ #
21
+ # @param options [Hash] A customizable set of options.
22
+ # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
23
+ # @return [Twitter::Cursor]
24
+ #
25
+ # @overload following_followers_of(user, options={})
26
+ # Returns users following followers of the authenticated user
27
+ #
28
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
29
+ # @param options [Hash] A customizable set of options.
30
+ # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
31
+ # @return [Twitter::Cursor]
32
+ def following_followers_of(*args)
33
+ cursor_from_response_with_user(:users, Twitter::User, :get, "/users/following_followers_of.json", args)
34
+ end
35
+
36
+ # Returns Tweets count for a URI
37
+ #
38
+ # @note Undocumented
39
+ # @rate_limited No
40
+ # @authentication Not required
41
+ # @return [Integer]
42
+ # @param uri [String, URI] A URI.
43
+ # @param options [Hash] A customizable set of options.
44
+ def tweet_count(uri, options={})
45
+ connection = Faraday.new("https://cdn.api.twitter.com", connection_options.merge(:builder => middleware))
46
+ connection.get("/1/urls/count.json", options.merge(:url => uri.to_s)).body[:count]
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,383 @@
1
+ require 'twitter/arguments'
2
+ require 'twitter/core_ext/enumerable'
3
+ require 'twitter/error/not_found'
4
+ require 'twitter/profile_banner'
5
+ require 'twitter/rest/api/utils'
6
+ require 'twitter/settings'
7
+ require 'twitter/user'
8
+
9
+ module Twitter
10
+ module REST
11
+ module API
12
+ module Users
13
+ include Twitter::REST::API::Utils
14
+ MAX_USERS_PER_REQUEST = 100
15
+
16
+ # Updates the authenticating user's settings.
17
+ # Or, if no options supplied, returns settings (including current trend, geo and sleep time information) for the authenticating user.
18
+ #
19
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/settings
20
+ # @see https://dev.twitter.com/docs/api/1.1/get/account/settings
21
+ # @rate_limited Yes
22
+ # @authentication Requires user context
23
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
24
+ # @return [Twitter::Settings]
25
+ # @param options [Hash] A customizable set of options.
26
+ # @option options [Integer] :trend_location_woeid The Yahoo! Where On Earth ID to use as the user's default trend location. Global information is available by using 1 as the WOEID. The woeid must be one of the locations returned by {https://dev.twitter.com/docs/api/1.1/get/trends/available GET trends/available}.
27
+ # @option options [Boolean, String, Integer] :sleep_time_enabled When set to true, 't' or 1, will enable sleep time for the user. Sleep time is the time when push or SMS notifications should not be sent to the user.
28
+ # @option options [Integer] :start_sleep_time The hour that sleep time should begin if it is enabled. The value for this parameter should be provided in {http://en.wikipedia.org/wiki/ISO_8601 ISO8601} format (i.e. 00-23). The time is considered to be in the same timezone as the user's time_zone setting.
29
+ # @option options [Integer] :end_sleep_time The hour that sleep time should end if it is enabled. The value for this parameter should be provided in {http://en.wikipedia.org/wiki/ISO_8601 ISO8601} format (i.e. 00-23). The time is considered to be in the same timezone as the user's time_zone setting.
30
+ # @option options [String] :time_zone The timezone dates and times should be displayed in for the user. The timezone must be one of the {http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html Rails TimeZone} names.
31
+ # @option options [String] :lang The language which Twitter should render in for this user. The language must be specified by the appropriate two letter ISO 639-1 representation. Currently supported languages are provided by {https://dev.twitter.com/docs/api/1.1/get/help/languages GET help/languages}.
32
+ def settings(options={})
33
+ request_method = options.size.zero? ? :get : :post
34
+ settings = object_from_response(Twitter::Settings, request_method, "/1.1/account/settings.json", options)
35
+ # https://dev.twitter.com/issues/59
36
+ trend_location = Array(settings.attrs[:trend_location]).first
37
+ settings.update(:trend_location => trend_location)
38
+ settings
39
+ end
40
+
41
+ # Returns the requesting user if authentication was successful, otherwise raises {Twitter::Error::Unauthorized}
42
+ #
43
+ # @see https://dev.twitter.com/docs/api/1.1/get/account/verify_credentials
44
+ # @rate_limited Yes
45
+ # @authentication Requires user context
46
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
47
+ # @return [Twitter::User] The authenticated user.
48
+ # @param options [Hash] A customizable set of options.
49
+ # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1.
50
+ def verify_credentials(options={})
51
+ object_from_response(Twitter::User, :get, "/1.1/account/verify_credentials.json", options)
52
+ end
53
+ alias current_user verify_credentials
54
+
55
+ # Sets which device Twitter delivers updates to for the authenticating user
56
+ #
57
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/update_delivery_device
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::User] The authenticated user.
62
+ # @param device [String] Must be one of: 'sms', 'none'.
63
+ # @param options [Hash] A customizable set of options.
64
+ def update_delivery_device(device, options={})
65
+ object_from_response(Twitter::User, :post, "/1.1/account/update_delivery_device.json", options.merge(:device => device))
66
+ end
67
+
68
+ # Sets values that users are able to set under the "Account" tab of their settings page
69
+ #
70
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile
71
+ # @note Only the options specified will be updated.
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 [Twitter::User] The authenticated user.
76
+ # @param options [Hash] A customizable set of options.
77
+ # @option options [String] :name Full name associated with the profile. Maximum of 20 characters.
78
+ # @option options [String] :url URL associated with the profile. Will be prepended with "http://" if not present. Maximum of 100 characters.
79
+ # @option options [String] :location The city or country describing where the user of the account is located. The contents are not normalized or geocoded in any way. Maximum of 30 characters.
80
+ # @option options [String] :description A description of the user owning the account. Maximum of 160 characters.
81
+ def update_profile(options={})
82
+ object_from_response(Twitter::User, :post, "/1.1/account/update_profile.json", options)
83
+ end
84
+
85
+ # Updates the authenticating user's profile background image
86
+ #
87
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_background_image
88
+ # @rate_limited No
89
+ # @authentication Requires user context
90
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
91
+ # @return [Twitter::User] The authenticated user.
92
+ # @param image [File] The background image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 800 kilobytes in size. Images with width larger than 2048 pixels will be forcibly scaled down. The image must be provided as raw multipart data, not a URL.
93
+ # @param options [Hash] A customizable set of options.
94
+ # @option options [Boolean] :tile Whether or not to tile the background image. If set to true the background image will be displayed tiled. The image will not be tiled otherwise.
95
+ def update_profile_background_image(image, options={})
96
+ object_from_response(Twitter::User, :post, "/1.1/account/update_profile_background_image.json", options.merge(:image => image))
97
+ end
98
+
99
+ # Sets one or more hex values that control the color scheme of the authenticating user's profile
100
+ #
101
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_colors
102
+ # @rate_limited No
103
+ # @authentication Requires user context
104
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
105
+ # @return [Twitter::User] The authenticated user.
106
+ # @param options [Hash] A customizable set of options.
107
+ # @option options [String] :profile_background_color Profile background color.
108
+ # @option options [String] :profile_text_color Profile text color.
109
+ # @option options [String] :profile_link_color Profile link color.
110
+ # @option options [String] :profile_sidebar_fill_color Profile sidebar's background color.
111
+ # @option options [String] :profile_sidebar_border_color Profile sidebar's border color.
112
+ def update_profile_colors(options={})
113
+ object_from_response(Twitter::User, :post, "/1.1/account/update_profile_colors.json", options)
114
+ end
115
+
116
+ # Updates the authenticating user's profile image
117
+ #
118
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_image
119
+ # @note Updates the authenticating user's profile image. Note that this method expects raw multipart data, not a URL to an image.
120
+ # @note This method asynchronously processes the uploaded file before updating the user's profile image URL. You can either update your local cache the next time you request the user's information, or, at least 5 seconds after uploading the image, ask for the updated URL using GET users/show.
121
+ # @rate_limited No
122
+ # @authentication Requires user context
123
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
124
+ # @return [Twitter::User] The authenticated user.
125
+ # @param image [File] The avatar image for the profile, base64-encoded. Must be a valid GIF, JPG, or PNG image of less than 700 kilobytes in size. Images with width larger than 500 pixels will be scaled down. Animated GIFs will be converted to a static GIF of the first frame, removing the animation.
126
+ # @param options [Hash] A customizable set of options.
127
+ def update_profile_image(image, options={})
128
+ object_from_response(Twitter::User, :post, "/1.1/account/update_profile_image.json", options.merge(:image => image))
129
+ end
130
+
131
+ # Returns an array of user objects that the authenticating user is blocking
132
+ #
133
+ # @see https://dev.twitter.com/docs/api/1.1/get/blocks/list
134
+ # @rate_limited Yes
135
+ # @authentication Requires user context
136
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
137
+ # @return [Array<Twitter::User>] User objects that the authenticating user is blocking.
138
+ # @param options [Hash] A customizable set of options.
139
+ # @option options [Integer] :page Specifies the page of results to retrieve.
140
+ def blocking(options={})
141
+ cursor_from_response(:users, Twitter::User, :get, "/1.1/blocks/list.json", options)
142
+ end
143
+
144
+ # Returns an array of numeric user ids the authenticating user is blocking
145
+ #
146
+ # @see https://dev.twitter.com/docs/api/1.1/get/blocks/ids
147
+ # @rate_limited Yes
148
+ # @authentication Requires user context
149
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
150
+ # @return [Array] Numeric user ids the authenticating user is blocking.
151
+ # @overload block(options={})
152
+ # @param options [Hash] A customizable set of options.
153
+ def blocked_ids(*args)
154
+ arguments = Twitter::Arguments.new(args)
155
+ merge_user!(arguments.options, arguments.pop)
156
+ cursor_from_response(:ids, nil, :get, "/1.1/blocks/ids.json", arguments.options)
157
+ end
158
+
159
+ # Returns true if the authenticating user is blocking a target user
160
+ #
161
+ # @see https://dev.twitter.com/docs/api/1.1/get/blocks/ids
162
+ # @rate_limited Yes
163
+ # @authentication Requires user context
164
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
165
+ # @return [Boolean] true if the authenticating user is blocking the target user, otherwise false.
166
+ # @param user [Integer, String, URI, Twitter::User] A Twitter user ID, screen name, URI, or object.
167
+ # @param options [Hash] A customizable set of options.
168
+ def block?(user, options={})
169
+ merge_default_cursor!(options)
170
+ user_id = case user
171
+ when Integer
172
+ user
173
+ when String, URI
174
+ user(user).id
175
+ when Twitter::User
176
+ user.id
177
+ end
178
+ blocked_ids(options).map(&:to_i).include?(user_id)
179
+ end
180
+
181
+ # Blocks the users specified by the authenticating user
182
+ #
183
+ # @see https://dev.twitter.com/docs/api/1.1/post/blocks/create
184
+ # @note Destroys a friendship to the blocked user if it exists.
185
+ # @rate_limited Yes
186
+ # @authentication Requires user context
187
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
188
+ # @return [Array<Twitter::User>] The blocked users.
189
+ # @overload block(*users)
190
+ # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
191
+ # @overload block(*users, options)
192
+ # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
193
+ # @param options [Hash] A customizable set of options.
194
+ def block(*args)
195
+ threaded_user_objects_from_response(:post, "/1.1/blocks/create.json", args)
196
+ end
197
+
198
+ # Un-blocks the users specified by the authenticating user
199
+ #
200
+ # @see https://dev.twitter.com/docs/api/1.1/post/blocks/destroy
201
+ # @rate_limited No
202
+ # @authentication Requires user context
203
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
204
+ # @return [Array<Twitter::User>] The un-blocked users.
205
+ # @overload unblock(*users)
206
+ # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
207
+ # @overload unblock(*users, options)
208
+ # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
209
+ # @param options [Hash] A customizable set of options.
210
+ def unblock(*args)
211
+ threaded_user_objects_from_response(:post, "/1.1/blocks/destroy.json", args)
212
+ end
213
+
214
+ # Returns extended information for up to 100 users
215
+ #
216
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/lookup
217
+ # @rate_limited Yes
218
+ # @authentication Requires user context
219
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
220
+ # @return [Array<Twitter::User>] The requested users.
221
+ # @overload users(*users)
222
+ # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
223
+ # @overload users(*users, options)
224
+ # @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
225
+ # @param options [Hash] A customizable set of options.
226
+ # @option options [Symbol, String] :method Requests users via a GET request instead of the standard POST request if set to ':get'.
227
+ # @option options [Boolean] :include_entities The tweet entities node will be disincluded when set to false.
228
+ def users(*args)
229
+ arguments = Twitter::Arguments.new(args)
230
+ method = arguments.options.delete(:method) || :post
231
+ arguments.flatten.each_slice(MAX_USERS_PER_REQUEST).threaded_map do |users|
232
+ objects_from_response(Twitter::User, method, "/1.1/users/lookup.json", merge_users(arguments.options, users))
233
+ end.flatten
234
+ end
235
+
236
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/show
237
+ # @rate_limited Yes
238
+ # @authentication Requires user context
239
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
240
+ # @return [Twitter::User] The requested user.
241
+ # @overload user(options={})
242
+ # Returns extended information for the authenticated user
243
+ #
244
+ # @param options [Hash] A customizable set of options.
245
+ # @option options [Boolean] :include_entities The tweet entities node will be disincluded when set to false.
246
+ # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1.
247
+ # @overload user(user, options={})
248
+ # Returns extended information for a given user
249
+ #
250
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
251
+ # @param options [Hash] A customizable set of options.
252
+ # @option options [Boolean] :include_entities The tweet entities node will be disincluded when set to false.
253
+ # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1.
254
+ def user(*args)
255
+ arguments = Twitter::Arguments.new(args)
256
+ if user = arguments.pop
257
+ merge_user!(arguments.options, user)
258
+ object_from_response(Twitter::User, :get, "/1.1/users/show.json", arguments.options)
259
+ else
260
+ verify_credentials(arguments.options)
261
+ end
262
+ end
263
+
264
+ # Returns true if the specified user exists
265
+ #
266
+ # @rate_limited Yes
267
+ # @authentication Requires user context
268
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
269
+ # @return [Boolean] true if the user exists, otherwise false.
270
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
271
+ def user?(user, options={})
272
+ merge_user!(options, user)
273
+ get("/1.1/users/show.json", options)
274
+ true
275
+ rescue Twitter::Error::NotFound
276
+ false
277
+ end
278
+
279
+ # Returns users that match the given query
280
+ #
281
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/search
282
+ # @rate_limited Yes
283
+ # @authentication Requires user context
284
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
285
+ # @return [Array<Twitter::User>]
286
+ # @param query [String] The search query to run against people search.
287
+ # @param options [Hash] A customizable set of options.
288
+ # @option options [Integer] :count The number of people to retrieve. Maxiumum of 20 allowed per page.
289
+ # @option options [Integer] :page Specifies the page of results to retrieve.
290
+ def user_search(query, options={})
291
+ objects_from_response(Twitter::User, :get, "/1.1/users/search.json", options.merge(:q => query))
292
+ end
293
+
294
+ # Returns an array of users that the specified user can contribute to
295
+ #
296
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/contributees
297
+ # @rate_limited Yes
298
+ # @authentication Requires user context
299
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
300
+ # @return [Array<Twitter::User>]
301
+ # @overload contributees(options={})
302
+ # @param options [Hash] A customizable set of options.
303
+ # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
304
+ # @overload contributees(user, options={})
305
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
306
+ # @param options [Hash] A customizable set of options.
307
+ # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
308
+ def contributees(*args)
309
+ user_objects_from_response(:get, "/1.1/users/contributees.json", args)
310
+ end
311
+
312
+ # Returns an array of users who can contribute to the specified account
313
+ #
314
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/contributors
315
+ # @rate_limited Yes
316
+ # @authentication Requires user context
317
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
318
+ # @return [Array<Twitter::User>]
319
+ # @overload contributors(options={})
320
+ # @param options [Hash] A customizable set of options.
321
+ # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
322
+ # @overload contributors(user, options={})
323
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
324
+ # @param options [Hash] A customizable set of options.
325
+ # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
326
+ def contributors(*args)
327
+ user_objects_from_response(:get, "/1.1/users/contributors.json", args)
328
+ end
329
+
330
+ # Removes the authenticating user's profile banner image
331
+ #
332
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/remove_profile_banner
333
+ # @rate_limited No
334
+ # @authentication Requires user context
335
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
336
+ # @return [nil]
337
+ # @param options [Hash] A customizable set of options.
338
+ def remove_profile_banner(options={})
339
+ post("/1.1/account/remove_profile_banner.json", options)[:body]
340
+ end
341
+
342
+ # Updates the authenticating user's profile banner image
343
+ #
344
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_banner
345
+ # @note Uploads a profile banner on behalf of the authenticating user. For best results, upload an <5MB image that is exactly 1252px by 626px. Images will be resized for a number of display options. Users with an uploaded profile banner will have a profile_banner_url node in their Users objects. More information about sizing variations can be found in User Profile Images and Banners.
346
+ # @note Profile banner images are processed asynchronously. The profile_banner_url and its variant sizes will not necessary be available directly after upload.
347
+ # @rate_limited No
348
+ # @authentication Requires user context
349
+ # @raise [Twitter::Error::BadRequest] Error raised when either an image was not provided or the image data could not be processed.
350
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
351
+ # @raise [Twitter::Error::UnprocessableEntity] Error raised when the image could not be resized or is too large.
352
+ # @return [nil]
353
+ # @param banner [File] The Base64-encoded or raw image data being uploaded as the user's new profile banner.
354
+ # @param options [Hash] A customizable set of options.
355
+ # @option options [Integer] :width The width of the preferred section of the image being uploaded in pixels. Use with height, offset_left, and offset_top to select the desired region of the image to use.
356
+ # @option options [Integer] :height The height of the preferred section of the image being uploaded in pixels. Use with width, offset_left, and offset_top to select the desired region of the image to use.
357
+ # @option options [Integer] :offset_left The number of pixels by which to offset the uploaded image from the left. Use with height, width, and offset_top to select the desired region of the image to use.
358
+ # @option options [Integer] :offset_top The number of pixels by which to offset the uploaded image from the top. Use with height, width, and offset_left to select the desired region of the image to use.
359
+ def update_profile_banner(banner, options={})
360
+ post("/1.1/account/update_profile_banner.json", options.merge(:banner => banner))[:body]
361
+ end
362
+
363
+ # Returns the available size variations of the specified user's profile banner.
364
+ #
365
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/profile_banner
366
+ # @note If the user has not uploaded a profile banner, a HTTP 404 will be served instead.
367
+ # @rate_limited Yes
368
+ # @authentication Requires user context
369
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
370
+ # @return [Twitter::ProfileBanner]
371
+ # @overload profile_banner(options={})
372
+ # @overload profile_banner(user, options={})
373
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
374
+ def profile_banner(*args)
375
+ arguments = Twitter::Arguments.new(args)
376
+ merge_user!(arguments.options, arguments.pop || screen_name) unless arguments.options[:user_id] || arguments.options[:screen_name]
377
+ object_from_response(Twitter::ProfileBanner, :get, "/1.1/users/profile_banner.json", arguments.options)
378
+ end
379
+
380
+ end
381
+ end
382
+ end
383
+ end