twitter 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. data/CHANGELOG.md +673 -0
  2. data/LICENSE.md +20 -0
  3. data/README.md +415 -0
  4. data/Rakefile +11 -0
  5. data/lib/twitter.rb +29 -0
  6. data/lib/twitter/action/favorite.rb +19 -0
  7. data/lib/twitter/action/follow.rb +31 -0
  8. data/lib/twitter/action/list_member_added.rb +41 -0
  9. data/lib/twitter/action/mention.rb +48 -0
  10. data/lib/twitter/action/reply.rb +27 -0
  11. data/lib/twitter/action/retweet.rb +27 -0
  12. data/lib/twitter/action/tweet.rb +22 -0
  13. data/lib/twitter/action_factory.rb +22 -0
  14. data/lib/twitter/api.rb +2442 -0
  15. data/lib/twitter/base.rb +119 -0
  16. data/lib/twitter/basic_user.rb +8 -0
  17. data/lib/twitter/client.rb +96 -0
  18. data/lib/twitter/configurable.rb +67 -0
  19. data/lib/twitter/configuration.rb +20 -0
  20. data/lib/twitter/core_ext/array.rb +7 -0
  21. data/lib/twitter/core_ext/enumerable.rb +11 -0
  22. data/lib/twitter/core_ext/hash.rb +100 -0
  23. data/lib/twitter/core_ext/kernel.rb +15 -0
  24. data/lib/twitter/core_ext/string.rb +10 -0
  25. data/lib/twitter/creatable.rb +20 -0
  26. data/lib/twitter/cursor.rb +87 -0
  27. data/lib/twitter/default.rb +101 -0
  28. data/lib/twitter/direct_message.rb +21 -0
  29. data/lib/twitter/entity.rb +7 -0
  30. data/lib/twitter/entity/hashtag.rb +9 -0
  31. data/lib/twitter/entity/url.rb +9 -0
  32. data/lib/twitter/entity/user_mention.rb +9 -0
  33. data/lib/twitter/error.rb +34 -0
  34. data/lib/twitter/error/bad_gateway.rb +11 -0
  35. data/lib/twitter/error/bad_request.rb +10 -0
  36. data/lib/twitter/error/client_error.rb +35 -0
  37. data/lib/twitter/error/decode_error.rb +9 -0
  38. data/lib/twitter/error/forbidden.rb +10 -0
  39. data/lib/twitter/error/gateway_timeout.rb +11 -0
  40. data/lib/twitter/error/identity_map_key_error.rb +9 -0
  41. data/lib/twitter/error/internal_server_error.rb +11 -0
  42. data/lib/twitter/error/not_acceptable.rb +10 -0
  43. data/lib/twitter/error/not_found.rb +10 -0
  44. data/lib/twitter/error/rate_limited.rb +11 -0
  45. data/lib/twitter/error/server_error.rb +28 -0
  46. data/lib/twitter/error/service_unavailable.rb +11 -0
  47. data/lib/twitter/error/unauthorized.rb +10 -0
  48. data/lib/twitter/factory.rb +21 -0
  49. data/lib/twitter/geo.rb +15 -0
  50. data/lib/twitter/geo/point.rb +22 -0
  51. data/lib/twitter/geo/polygon.rb +8 -0
  52. data/lib/twitter/geo_factory.rb +18 -0
  53. data/lib/twitter/identity.rb +50 -0
  54. data/lib/twitter/identity_map.rb +22 -0
  55. data/lib/twitter/language.rb +7 -0
  56. data/lib/twitter/list.rb +18 -0
  57. data/lib/twitter/media/photo.rb +22 -0
  58. data/lib/twitter/media_factory.rb +17 -0
  59. data/lib/twitter/metadata.rb +7 -0
  60. data/lib/twitter/oembed.rb +8 -0
  61. data/lib/twitter/place.rb +34 -0
  62. data/lib/twitter/rate_limit.rb +45 -0
  63. data/lib/twitter/relationship.rb +36 -0
  64. data/lib/twitter/request/multipart_with_file.rb +41 -0
  65. data/lib/twitter/response/parse_json.rb +25 -0
  66. data/lib/twitter/response/raise_error.rb +30 -0
  67. data/lib/twitter/saved_search.rb +9 -0
  68. data/lib/twitter/search_results.rb +48 -0
  69. data/lib/twitter/settings.rb +17 -0
  70. data/lib/twitter/size.rb +24 -0
  71. data/lib/twitter/source_user.rb +15 -0
  72. data/lib/twitter/suggestion.rb +22 -0
  73. data/lib/twitter/target_user.rb +8 -0
  74. data/lib/twitter/trend.rb +14 -0
  75. data/lib/twitter/tweet.rb +145 -0
  76. data/lib/twitter/user.rb +97 -0
  77. data/lib/twitter/version.rb +18 -0
  78. data/spec/fixtures/about_me.json +1 -0
  79. data/spec/fixtures/activity_summary.json +1 -0
  80. data/spec/fixtures/all.json +1 -0
  81. data/spec/fixtures/bad_gateway.json +1 -0
  82. data/spec/fixtures/bad_request.json +1 -0
  83. data/spec/fixtures/by_friends.json +1 -0
  84. data/spec/fixtures/category.json +1 -0
  85. data/spec/fixtures/configuration.json +1 -0
  86. data/spec/fixtures/contributees.json +1 -0
  87. data/spec/fixtures/contributors.json +1 -0
  88. data/spec/fixtures/direct_message.json +1 -0
  89. data/spec/fixtures/direct_messages.json +1 -0
  90. data/spec/fixtures/end_session.json +1 -0
  91. data/spec/fixtures/enhance_your_calm.text +11 -0
  92. data/spec/fixtures/favorites.json +1 -0
  93. data/spec/fixtures/following.json +1 -0
  94. data/spec/fixtures/forbidden.json +1 -0
  95. data/spec/fixtures/friendships.json +1 -0
  96. data/spec/fixtures/ids.json +1 -0
  97. data/spec/fixtures/ids_list.json +1 -0
  98. data/spec/fixtures/ids_list2.json +1 -0
  99. data/spec/fixtures/image_facets.json +1 -0
  100. data/spec/fixtures/internal_server_error.json +1 -0
  101. data/spec/fixtures/languages.json +1 -0
  102. data/spec/fixtures/list.json +1 -0
  103. data/spec/fixtures/lists.json +1 -0
  104. data/spec/fixtures/locations.json +1 -0
  105. data/spec/fixtures/matching_trends.json +1 -0
  106. data/spec/fixtures/me.jpeg +0 -0
  107. data/spec/fixtures/media_timeline.json +1 -0
  108. data/spec/fixtures/members.json +1 -0
  109. data/spec/fixtures/no_user_matches.json +1 -0
  110. data/spec/fixtures/not_acceptable.json +1 -0
  111. data/spec/fixtures/not_following.json +1 -0
  112. data/spec/fixtures/not_found.json +1 -0
  113. data/spec/fixtures/oembed.json +1 -0
  114. data/spec/fixtures/pbjt.gif +0 -0
  115. data/spec/fixtures/pengwynn.json +1 -0
  116. data/spec/fixtures/phoenix_search.phoenix +1 -0
  117. data/spec/fixtures/place.json +1 -0
  118. data/spec/fixtures/places.json +1 -0
  119. data/spec/fixtures/privacy.json +1 -0
  120. data/spec/fixtures/profile_image.text +24 -0
  121. data/spec/fixtures/rate_limit_status.json +1 -0
  122. data/spec/fixtures/recommendations.json +1 -0
  123. data/spec/fixtures/related_results.json +1 -0
  124. data/spec/fixtures/resolve.json +1 -0
  125. data/spec/fixtures/retweet.json +1 -0
  126. data/spec/fixtures/retweeted_status.json +1 -0
  127. data/spec/fixtures/retweeters_of.json +1 -0
  128. data/spec/fixtures/retweets.json +1 -0
  129. data/spec/fixtures/saved_search.json +1 -0
  130. data/spec/fixtures/saved_searches.json +1 -0
  131. data/spec/fixtures/search.json +1 -0
  132. data/spec/fixtures/search_malformed.json +1 -0
  133. data/spec/fixtures/service_unavailable.json +1 -0
  134. data/spec/fixtures/settings.json +1 -0
  135. data/spec/fixtures/sferik.json +1 -0
  136. data/spec/fixtures/status.json +1 -0
  137. data/spec/fixtures/status_with_media.json +104 -0
  138. data/spec/fixtures/statuses.json +1 -0
  139. data/spec/fixtures/suggestions.json +1 -0
  140. data/spec/fixtures/tos.json +1 -0
  141. data/spec/fixtures/totals.json +1 -0
  142. data/spec/fixtures/trends.json +1 -0
  143. data/spec/fixtures/trends_current.json +1 -0
  144. data/spec/fixtures/trends_daily.json +1 -0
  145. data/spec/fixtures/trends_weekly.json +1 -0
  146. data/spec/fixtures/unauthorized.json +1 -0
  147. data/spec/fixtures/user_search.json +1 -0
  148. data/spec/fixtures/user_timeline.json +1 -0
  149. data/spec/fixtures/users.json +1 -0
  150. data/spec/fixtures/users_list.json +1 -0
  151. data/spec/fixtures/video_facets.json +1 -0
  152. data/spec/fixtures/we_concept_bg2.png +0 -0
  153. data/spec/fixtures/wildcomet2.jpe +0 -0
  154. data/spec/helper.rb +53 -0
  155. data/spec/twitter/action/favorite_spec.rb +29 -0
  156. data/spec/twitter/action/follow_spec.rb +29 -0
  157. data/spec/twitter/action/list_member_added_spec.rb +41 -0
  158. data/spec/twitter/action/mention_spec.rb +52 -0
  159. data/spec/twitter/action/reply_spec.rb +41 -0
  160. data/spec/twitter/action/retweet_spec.rb +41 -0
  161. data/spec/twitter/action_factory_spec.rb +37 -0
  162. data/spec/twitter/action_spec.rb +16 -0
  163. data/spec/twitter/api/account_spec.rb +148 -0
  164. data/spec/twitter/api/activity_spec.rb +41 -0
  165. data/spec/twitter/api/blocks_spec.rb +167 -0
  166. data/spec/twitter/api/direct_messages_spec.rb +142 -0
  167. data/spec/twitter/api/friendships_spec.rb +567 -0
  168. data/spec/twitter/api/geo_spec.rb +100 -0
  169. data/spec/twitter/api/help_spec.rb +76 -0
  170. data/spec/twitter/api/lists_spec.rb +900 -0
  171. data/spec/twitter/api/report_spam_spec.rb +29 -0
  172. data/spec/twitter/api/saved_searches_spec.rb +100 -0
  173. data/spec/twitter/api/search_spec.rb +68 -0
  174. data/spec/twitter/api/statuses_spec.rb +559 -0
  175. data/spec/twitter/api/trends_spec.rb +80 -0
  176. data/spec/twitter/api/users_spec.rb +419 -0
  177. data/spec/twitter/base_spec.rb +113 -0
  178. data/spec/twitter/basic_user_spec.rb +23 -0
  179. data/spec/twitter/client_spec.rb +175 -0
  180. data/spec/twitter/configuration_spec.rb +17 -0
  181. data/spec/twitter/cursor_spec.rb +102 -0
  182. data/spec/twitter/direct_message_spec.rb +56 -0
  183. data/spec/twitter/error/client_error_spec.rb +40 -0
  184. data/spec/twitter/error/server_error_spec.rb +24 -0
  185. data/spec/twitter/error_spec.rb +20 -0
  186. data/spec/twitter/geo/point_spec.rb +41 -0
  187. data/spec/twitter/geo/polygon_spec.rb +29 -0
  188. data/spec/twitter/geo_factory_spec.rb +21 -0
  189. data/spec/twitter/geo_spec.rb +29 -0
  190. data/spec/twitter/identifiable_spec.rb +54 -0
  191. data/spec/twitter/list_spec.rb +45 -0
  192. data/spec/twitter/media/photo_spec.rb +35 -0
  193. data/spec/twitter/media_factory_spec.rb +17 -0
  194. data/spec/twitter/oembed_spec.rb +146 -0
  195. data/spec/twitter/place_spec.rb +75 -0
  196. data/spec/twitter/rate_limit_spec.rb +76 -0
  197. data/spec/twitter/relationship_spec.rb +35 -0
  198. data/spec/twitter/saved_search_spec.rb +34 -0
  199. data/spec/twitter/search_results_spec.rb +89 -0
  200. data/spec/twitter/settings_spec.rb +16 -0
  201. data/spec/twitter/size_spec.rb +38 -0
  202. data/spec/twitter/source_user_spec.rb +23 -0
  203. data/spec/twitter/suggestion_spec.rb +50 -0
  204. data/spec/twitter/target_user_spec.rb +23 -0
  205. data/spec/twitter/trend_spec.rb +38 -0
  206. data/spec/twitter/tweet_spec.rb +307 -0
  207. data/spec/twitter/user_spec.rb +127 -0
  208. data/spec/twitter_spec.rb +93 -0
  209. data/twitter.gemspec +30 -0
  210. metadata +584 -0
@@ -0,0 +1,19 @@
1
+ require 'twitter/action/tweet'
2
+
3
+ module Twitter
4
+ module Action
5
+ class Favorite < Twitter::Action::Tweet
6
+ attr_reader :target_objects
7
+
8
+ # A collection containing the favorited tweet
9
+ #
10
+ # @return [Array<Twitter::Tweet>]
11
+ def targets
12
+ @targets = Array(@attrs[:targets]).map do |tweet|
13
+ Twitter::Tweet.fetch_or_new(tweet)
14
+ end
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ require 'twitter/base'
2
+ require 'twitter/creatable'
3
+ require 'twitter/user'
4
+
5
+ module Twitter
6
+ module Action
7
+ class Follow < Twitter::Base
8
+ include Twitter::Creatable
9
+ attr_reader :max_position, :min_position, :target_objects
10
+
11
+ # A collection of users who followed a user
12
+ #
13
+ # @return [Array<Twitter::User>]
14
+ def sources
15
+ @sources = Array(@attrs[:sources]).map do |user|
16
+ Twitter::User.fetch_or_new(user)
17
+ end
18
+ end
19
+
20
+ # A collection containing the followed user
21
+ #
22
+ # @return [Array<Twitter::User>]
23
+ def targets
24
+ @targets = Array(@attrs[:targets]).map do |user|
25
+ Twitter::User.fetch_or_new(user)
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,41 @@
1
+ require 'twitter/base'
2
+ require 'twitter/creatable'
3
+ require 'twitter/list'
4
+ require 'twitter/user'
5
+
6
+ module Twitter
7
+ module Action
8
+ class ListMemberAdded < Twitter::Base
9
+ include Twitter::Creatable
10
+ attr_reader :max_position, :min_position
11
+
12
+ # A collection of users who added a user to a list
13
+ #
14
+ # @return [Array<Twitter::User>]
15
+ def sources
16
+ @sources = Array(@attrs[:sources]).map do |user|
17
+ Twitter::User.fetch_or_new(user)
18
+ end
19
+ end
20
+
21
+ # A collection of lists that were added to
22
+ #
23
+ # @return [Array<Twitter::List>]
24
+ def target_objects
25
+ @target_objects = Array(@attrs[:target_objects]).map do |list|
26
+ Twitter::List.fetch_or_new(list)
27
+ end
28
+ end
29
+
30
+ # A collection of users who were added to a list
31
+ #
32
+ # @return [Array<Twitter::User>]
33
+ def targets
34
+ @targets = Array(@attrs[:targets]).map do |user|
35
+ Twitter::User.fetch_or_new(user)
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,48 @@
1
+ require 'twitter/base'
2
+ require 'twitter/creatable'
3
+ require 'twitter/tweet'
4
+ require 'twitter/user'
5
+
6
+ module Twitter
7
+ module Action
8
+ class Mention < Twitter::Base
9
+ include Twitter::Creatable
10
+ attr_reader :max_position, :min_position
11
+
12
+ # A collection of users who mentioned a user
13
+ #
14
+ # @return [Array<Twitter::User>]
15
+ def sources
16
+ @sources = Array(@attrs[:sources]).map do |user|
17
+ Twitter::User.fetch_or_new(user)
18
+ end
19
+ end
20
+
21
+ # The user who mentioned a user
22
+ #
23
+ # @return [Twitter::User]
24
+ def source
25
+ @source = sources.first
26
+ end
27
+
28
+ # A collection of tweets that mention a user
29
+ #
30
+ # @return [Array<Twitter::Tweet>]
31
+ def target_objects
32
+ @target_objects = Array(@attrs[:target_objects]).map do |tweet|
33
+ Twitter::Tweet.fetch_or_new(tweet)
34
+ end
35
+ end
36
+
37
+ # A collection containing the mentioned user
38
+ #
39
+ # @return [Array<Twitter::User>]
40
+ def targets
41
+ @targets = Array(@attrs[:targets]).map do |user|
42
+ Twitter::User.fetch_or_new(user)
43
+ end
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,27 @@
1
+ require 'twitter/action/tweet'
2
+
3
+ module Twitter
4
+ module Action
5
+ class Reply < Twitter::Action::Tweet
6
+
7
+ # A collection of tweets that reply to a user
8
+ #
9
+ # @return [Array<Twitter::Tweet>]
10
+ def target_objects
11
+ @target_objects = Array(@attrs[:target_objects]).map do |tweet|
12
+ Twitter::Tweet.fetch_or_new(tweet)
13
+ end
14
+ end
15
+
16
+ # A collection that contains the replied-to tweets
17
+ #
18
+ # @return [Array<Twitter::Tweet>]
19
+ def targets
20
+ @targets = Array(@attrs[:targets]).map do |tweet|
21
+ Twitter::Tweet.fetch_or_new(tweet)
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'twitter/action/tweet'
2
+
3
+ module Twitter
4
+ module Action
5
+ class Retweet < Twitter::Action::Tweet
6
+
7
+ # A collection of retweets
8
+ #
9
+ # @return [Array<Twitter::Tweet>]
10
+ def target_objects
11
+ @target_objects = Array(@attrs[:target_objects]).map do |tweet|
12
+ Twitter::Tweet.fetch_or_new(tweet)
13
+ end
14
+ end
15
+
16
+ # A collection containing the retweeted user
17
+ #
18
+ # @return [Array<Twitter::User>]
19
+ def targets
20
+ @targets = Array(@attrs[:targets]).map do |user|
21
+ Twitter::User.fetch_or_new(user)
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ require 'twitter/base'
2
+ require 'twitter/creatable'
3
+ require 'twitter/tweet'
4
+ require 'twitter/user'
5
+
6
+ module Twitter
7
+ module Action
8
+ class Tweet < Twitter::Base
9
+ include Twitter::Creatable
10
+ attr_reader :max_position, :min_position
11
+
12
+ # @return [Array<Twitter::User>]
13
+ def sources
14
+ @sources = Array(@attrs[:sources]).map do |user|
15
+ Twitter::User.fetch_or_new(user)
16
+ end
17
+ end
18
+
19
+ end
20
+ Status = Tweet
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'twitter/action/favorite'
2
+ require 'twitter/action/follow'
3
+ require 'twitter/action/list_member_added'
4
+ require 'twitter/action/mention'
5
+ require 'twitter/action/reply'
6
+ require 'twitter/action/retweet'
7
+ require 'twitter/factory'
8
+
9
+ module Twitter
10
+ class ActionFactory < Twitter::Factory
11
+
12
+ # Instantiates a new action object
13
+ #
14
+ # @param attrs [Hash]
15
+ # @raise [ArgumentError] Error raised when supplied argument is missing an :action key.
16
+ # @return [Twitter::Action]
17
+ def self.fetch_or_new(attrs={})
18
+ super(:action, Twitter::Action, attrs)
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,2442 @@
1
+ require 'twitter/action_factory'
2
+ require 'twitter/configuration'
3
+ require 'twitter/core_ext/array'
4
+ require 'twitter/core_ext/enumerable'
5
+ require 'twitter/core_ext/hash'
6
+ require 'twitter/core_ext/kernel'
7
+ require 'twitter/cursor'
8
+ require 'twitter/direct_message'
9
+ require 'twitter/error/forbidden'
10
+ require 'twitter/error/not_found'
11
+ require 'twitter/language'
12
+ require 'twitter/list'
13
+ require 'twitter/oembed'
14
+ require 'twitter/place'
15
+ require 'twitter/relationship'
16
+ require 'twitter/saved_search'
17
+ require 'twitter/search_results'
18
+ require 'twitter/settings'
19
+ require 'twitter/suggestion'
20
+ require 'twitter/trend'
21
+ require 'twitter/tweet'
22
+ require 'twitter/user'
23
+
24
+ module Twitter
25
+ module API
26
+ DEFAULT_CURSOR = -1
27
+ DEFAULT_TWEETS_PER_REQUEST = 20
28
+ MAX_USERS_PER_REQUEST = 100
29
+ MAX_TWEETS_PER_REQUEST = 200
30
+
31
+ # Returns the requesting user if authentication was successful, otherwise raises {Twitter::Error::Unauthorized}
32
+ #
33
+ # @see https://dev.twitter.com/docs/api/1.1/get/account/verify_credentials
34
+ # @rate_limited Yes
35
+ # @authentication_required Requires user context
36
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
37
+ # @return [Twitter::User] The authenticated user.
38
+ # @param options [Hash] A customizable set of options.
39
+ # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1.
40
+ # @example Return the requesting user if authentication was successful
41
+ # Twitter.verify_credentials
42
+ def verify_credentials(options={})
43
+ object_from_response(Twitter::User, :get, "/1.1/account/verify_credentials.json", options)
44
+ end
45
+ alias current_user verify_credentials
46
+
47
+ # Sets which device Twitter delivers updates to for the authenticating user
48
+ #
49
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/update_delivery_device
50
+ # @rate_limited No
51
+ # @authentication_required Requires user context
52
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
53
+ # @return [Twitter::User] The authenticated user.
54
+ # @param device [String] Must be one of: 'sms', 'none'.
55
+ # @param options [Hash] A customizable set of options.
56
+ # @example Turn SMS updates on for the authenticating user
57
+ # Twitter.update_delivery_device('sms')
58
+ def update_delivery_device(device, options={})
59
+ object_from_response(Twitter::User, :post, "/1.1/account/update_delivery_device.json", options.merge(:device => device))
60
+ end
61
+
62
+ # Sets values that users are able to set under the "Account" tab of their settings page
63
+ #
64
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile
65
+ # @note Only the options specified will be updated.
66
+ # @rate_limited No
67
+ # @authentication_required Requires user context
68
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
69
+ # @return [Twitter::User] The authenticated user.
70
+ # @param options [Hash] A customizable set of options.
71
+ # @option options [String] :name Full name associated with the profile. Maximum of 20 characters.
72
+ # @option options [String] :url URL associated with the profile. Will be prepended with "http://" if not present. Maximum of 100 characters.
73
+ # @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.
74
+ # @option options [String] :description A description of the user owning the account. Maximum of 160 characters.
75
+ # @example Set authenticating user's name to Erik Michaels-Ober
76
+ # Twitter.update_profile(:name => "Erik Michaels-Ober")
77
+ def update_profile(options={})
78
+ object_from_response(Twitter::User, :post, "/1.1/account/update_profile.json", options)
79
+ end
80
+
81
+ # Updates the authenticating user's profile background image
82
+ #
83
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_background_image
84
+ # @rate_limited No
85
+ # @authentication_required Requires user context
86
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
87
+ # @return [Twitter::User] The authenticated user.
88
+ # @param image [File, Hash] The background image for the profile. 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 scaled down.
89
+ # @param options [Hash] A customizable set of options.
90
+ # @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.
91
+ # @example Update the authenticating user's profile background image
92
+ # Twitter.update_profile_background_image(File.new("we_concept_bg2.png"))
93
+ def update_profile_background_image(image, options={})
94
+ object_from_response(Twitter::User, :post, "/1.1/account/update_profile_background_image.json", options.merge(:image => image))
95
+ end
96
+
97
+ # Sets one or more hex values that control the color scheme of the authenticating user's profile
98
+ #
99
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/update_profile_colors
100
+ # @rate_limited No
101
+ # @authentication_required Requires user context
102
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
103
+ # @return [Twitter::User] The authenticated user.
104
+ # @param options [Hash] A customizable set of options.
105
+ # @option options [String] :profile_background_color Profile background color.
106
+ # @option options [String] :profile_text_color Profile text color.
107
+ # @option options [String] :profile_link_color Profile link color.
108
+ # @option options [String] :profile_sidebar_fill_color Profile sidebar's background color.
109
+ # @option options [String] :profile_sidebar_border_color Profile sidebar's border color.
110
+ # @example Set authenticating user's profile background to black
111
+ # Twitter.update_profile_colors(:profile_background_color => '000000')
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 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 {Twitter::User#profile_image_url}.
120
+ # @rate_limited No
121
+ # @authentication_required Requires user context
122
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
123
+ # @return [Twitter::User] The authenticated user.
124
+ # @param image [File, Hash] The avatar image for the profile. 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.
125
+ # @param options [Hash] A customizable set of options.
126
+ # @example Update the authenticating user's profile image
127
+ # Twitter.update_profile_image(File.new("me.jpeg"))
128
+ def update_profile_image(image, options={})
129
+ object_from_response(Twitter::User, :post, "/1.1/account/update_profile_image.json", options.merge(:image => image))
130
+ end
131
+
132
+ # Updates the authenticating user's settings.
133
+ # Or, if no options supplied, returns settings (including current trend, geo and sleep time information) for the authenticating user.
134
+ #
135
+ # @see https://dev.twitter.com/docs/api/1.1/post/account/settings
136
+ # @see https://dev.twitter.com/docs/api/1.1/get/account/settings
137
+ # @rate_limited Yes
138
+ # @authentication_required Requires user context
139
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
140
+ # @return [Twitter::Settings]
141
+ # @param options [Hash] A customizable set of options.
142
+ # @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}.
143
+ # @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.
144
+ # @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.
145
+ # @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.
146
+ # @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.
147
+ # @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}.
148
+ # @example Return the settings for the authenticating user.
149
+ # Twitter.settings
150
+ def settings(options={})
151
+ request_method = options.size.zero? ? :get : :post
152
+ object_from_response(Twitter::Settings, request_method, "/1.1/account/settings.json", options)
153
+ end
154
+
155
+ # Returns activity about me
156
+ #
157
+ # @note Undocumented
158
+ # @rate_limited Yes
159
+ # @authentication_required Requires user context
160
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
161
+ # @return [Array] An array of actions
162
+ # @param options [Hash] A customizable set of options.
163
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
164
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
165
+ # @example Return activity about me
166
+ # Twitter.activity_about_me
167
+ def activity_about_me(options={})
168
+ collection_from_response(Twitter::ActionFactory, :get, "/i/activity/about_me.json", options)
169
+ end
170
+
171
+ # Returns activity by friends
172
+ #
173
+ # @note Undocumented
174
+ # @rate_limited Yes
175
+ # @authentication_required Requires user context
176
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid./
177
+ # @return [Array] An array of actions
178
+ # @param options [Hash] A customizable set of options.
179
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
180
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
181
+ # @example Return activity by friends
182
+ # Twitter.activity_by_friends
183
+ def activity_by_friends(options={})
184
+ collection_from_response(Twitter::ActionFactory, :get, "/i/activity/by_friends.json", options)
185
+ end
186
+
187
+ # Returns the 20 most recent direct messages sent to the authenticating user
188
+ #
189
+ # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages
190
+ # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
191
+ # @rate_limited Yes
192
+ # @authentication_required Requires user context
193
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
194
+ # @return [Array<Twitter::DirectMessage>] Direct messages sent to the authenticating user.
195
+ # @param options [Hash] A customizable set of options.
196
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
197
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
198
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
199
+ # @option options [Integer] :page Specifies the page of results to retrieve.
200
+ # @example Return the 20 most recent direct messages sent to the authenticating user
201
+ # Twitter.direct_messages_received
202
+ def direct_messages_received(options={})
203
+ collection_from_response(Twitter::DirectMessage, :get, "/1.1/direct_messages.json", options)
204
+ end
205
+
206
+ # Returns the 20 most recent direct messages sent by the authenticating user
207
+ #
208
+ # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/sent
209
+ # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
210
+ # @rate_limited Yes
211
+ # @authentication_required Requires user context
212
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
213
+ # @return [Array<Twitter::DirectMessage>] Direct messages sent by the authenticating user.
214
+ # @param options [Hash] A customizable set of options.
215
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
216
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
217
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
218
+ # @option options [Integer] :page Specifies the page of results to retrieve.
219
+ # @example Return the 20 most recent direct messages sent by the authenticating user
220
+ # Twitter.direct_messages_sent
221
+ def direct_messages_sent(options={})
222
+ collection_from_response(Twitter::DirectMessage, :get, "/1.1/direct_messages/sent.json", options)
223
+ end
224
+
225
+ # Destroys direct messages
226
+ #
227
+ # @see https://dev.twitter.com/docs/api/1.1/post/direct_messages/destroy
228
+ # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
229
+ # @rate_limited No
230
+ # @authentication_required Requires user context
231
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
232
+ # @return [Array<Twitter::DirectMessage>] Deleted direct message.
233
+ # @overload direct_message_destroy(*ids)
234
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
235
+ # @example Destroys the direct message with the ID 1825785544
236
+ # Twitter.direct_message_destroy(1825785544)
237
+ # @overload direct_message_destroy(*ids, options)
238
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
239
+ # @param options [Hash] A customizable set of options.
240
+ def direct_message_destroy(*args)
241
+ options = args.extract_options!
242
+ args.flatten.threaded_map do |id|
243
+ object_from_response(Twitter::DirectMessage, :post, "/1.1/direct_messages/destroy.json", options.merge(:id => id))
244
+ end
245
+ end
246
+
247
+ # Sends a new direct message to the specified user from the authenticating user
248
+ #
249
+ # @see https://dev.twitter.com/docs/api/1.1/post/direct_messages/new
250
+ # @rate_limited No
251
+ # @authentication_required Requires user context
252
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
253
+ # @return [Twitter::DirectMessage] The sent message.
254
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
255
+ # @param text [String] The text of your direct message, up to 140 characters.
256
+ # @param options [Hash] A customizable set of options.
257
+ # @example Send a direct message to @sferik from the authenticating user
258
+ # Twitter.direct_message_create('sferik', "I'm sending you this message via @gem!")
259
+ # Twitter.direct_message_create(7505382, "I'm sending you this message via @gem!") # Same as above
260
+ def direct_message_create(user, text, options={})
261
+ options.merge_user!(user)
262
+ options[:text] = text
263
+ object_from_response(Twitter::DirectMessage, :post, "/1.1/direct_messages/new.json", options)
264
+ end
265
+ alias d direct_message_create
266
+ alias m direct_message_create
267
+
268
+ # Returns a direct message
269
+ #
270
+ # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show
271
+ # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
272
+ # @rate_limited Yes
273
+ # @authentication_required Requires user context
274
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
275
+ # @return [Twitter::DirectMessage] The requested messages.
276
+ # @param id [Integer] A Tweet IDs.
277
+ # @param options [Hash] A customizable set of options.
278
+ # @example Return the direct message with the id 1825786345
279
+ # Twitter.direct_message(1825786345)
280
+ def direct_message(id, options={})
281
+ options[:id] = id
282
+ object_from_response(Twitter::DirectMessage, :get, "/1.1/direct_messages/show.json", options)
283
+ end
284
+
285
+ # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
286
+ # @rate_limited Yes
287
+ # @authentication_required Requires user context
288
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
289
+ # @return [Array<Twitter::DirectMessage>] The requested messages.
290
+ # @overload direct_messages(options={})
291
+ # Returns the 20 most recent direct messages sent to the authenticating user
292
+ #
293
+ # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages
294
+ # @param options [Hash] A customizable set of options.
295
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
296
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
297
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
298
+ # @option options [Integer] :page Specifies the page of results to retrieve.
299
+ # @example Return the 20 most recent direct messages sent to the authenticating user
300
+ # Twitter.direct_messages
301
+ # @overload direct_messages(*ids)
302
+ # Returns direct messages
303
+ #
304
+ # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show
305
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
306
+ # @example Return the direct message with the id 1825786345
307
+ # Twitter.direct_messages(1825786345)
308
+ # @overload direct_messages(*ids, options)
309
+ # Returns direct messages
310
+ #
311
+ # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show
312
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
313
+ # @param options [Hash] A customizable set of options.
314
+ def direct_messages(*args)
315
+ options = args.extract_options!
316
+ if args.empty?
317
+ direct_messages_received(options)
318
+ else
319
+ args.flatten.threaded_map do |id|
320
+ direct_message(id, options)
321
+ end
322
+ end
323
+ end
324
+
325
+ # @see https://dev.twitter.com/docs/api/1.1/get/followers/ids
326
+ # @rate_limited Yes
327
+ # @authentication_required Requires user context
328
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
329
+ # @return [Twitter::Cursor]
330
+ # @overload follower_ids(options={})
331
+ # Returns an array of numeric IDs for every user following the authenticated user
332
+ #
333
+ # @param options [Hash] A customizable set of options.
334
+ # @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.
335
+ # @example Return the authenticated user's followers' IDs
336
+ # Twitter.follower_ids
337
+ # @overload follower_ids(user, options={})
338
+ # Returns an array of numeric IDs for every user following the specified user
339
+ #
340
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
341
+ # @param options [Hash] A customizable set of options.
342
+ # @option options [Integer] :cursor (-1) Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1 to begin paging. Provide values as returned in the response body's next_cursor and previous_cursor attributes to page back and forth in the list.
343
+ # @example Return @sferik's followers' IDs
344
+ # Twitter.follower_ids('sferik')
345
+ # Twitter.follower_ids(7505382) # Same as above
346
+ def follower_ids(*args)
347
+ ids_from_response(:get, "/1.1/followers/ids.json", args)
348
+ end
349
+
350
+ # @see https://dev.twitter.com/docs/api/1.1/get/friends/ids
351
+ # @rate_limited Yes
352
+ # @authentication_required Requires user context
353
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
354
+ # @return [Twitter::Cursor]
355
+ # @overload friend_ids(options={})
356
+ # Returns an array of numeric IDs for every user the authenticated user is following
357
+ #
358
+ # @param options [Hash] A customizable set of options.
359
+ # @option options [Integer] :cursor (-1) Breaks the results into pages. This is recommended for users who are following many users. Provide a value of -1 to begin paging. Provide values as returned in the response body's next_cursor and previous_cursor attributes to page back and forth in the list.
360
+ # @example Return the authenticated user's friends' IDs
361
+ # Twitter.friend_ids
362
+ # @overload friend_ids(user, options={})
363
+ # Returns an array of numeric IDs for every user the specified user is following
364
+ #
365
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
366
+ # @param options [Hash] A customizable set of options.
367
+ # @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.
368
+ # @example Return @sferik's friends' IDs
369
+ # Twitter.friend_ids('sferik')
370
+ # Twitter.friend_ids(7505382) # Same as above
371
+ def friend_ids(*args)
372
+ ids_from_response(:get, "/1.1/friends/ids.json", args)
373
+ end
374
+
375
+ # Test for the existence of friendship between two users
376
+ #
377
+ # @see https://dev.twitter.com/docs/api/1.1/get/friendships/show
378
+ # @rate_limited Yes
379
+ # @authentication_required Requires user context
380
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
381
+ # @return [Boolean] true if user_a follows user_b, otherwise false.
382
+ # @param source [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the source user.
383
+ # @param target [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the target user.
384
+ # @param options [Hash] A customizable set of options.
385
+ # @example Return true if @sferik follows @pengwynn
386
+ # Twitter.friendship?('sferik', 'pengwynn')
387
+ # Twitter.friendship?('sferik', 14100886) # Same as above
388
+ # Twitter.friendship?(7505382, 14100886) # Same as above
389
+ def friendship?(source, target, options={})
390
+ friendship(source, target, options).source.following?
391
+ end
392
+
393
+ # Returns an array of numeric IDs for every user who has a pending request to follow the authenticating user
394
+ #
395
+ # @see https://dev.twitter.com/docs/api/1.1/get/friendships/incoming
396
+ # @rate_limited Yes
397
+ # @authentication_required Requires user context
398
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
399
+ # @return [Twitter::Cursor]
400
+ # @param options [Hash] A customizable set of options.
401
+ # @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.
402
+ # @example Return an array of numeric IDs for every user who has a pending request to follow the authenticating user
403
+ # Twitter.friendships_incoming
404
+ def friendships_incoming(options={})
405
+ merge_default_cursor!(options)
406
+ cursor_from_response(:ids, nil, :get, "/1.1/friendships/incoming.json", options)
407
+ end
408
+
409
+ # Returns an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request
410
+ #
411
+ # @see https://dev.twitter.com/docs/api/1.1/get/friendships/outgoing
412
+ # @rate_limited Yes
413
+ # @authentication_required Requires user context
414
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
415
+ # @return [Twitter::Cursor]
416
+ # @param options [Hash] A customizable set of options.
417
+ # @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.
418
+ # @example Return an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request
419
+ # Twitter.friendships_outgoing
420
+ def friendships_outgoing(options={})
421
+ merge_default_cursor!(options)
422
+ cursor_from_response(:ids, nil, :get, "/1.1/friendships/outgoing.json", options)
423
+ end
424
+
425
+ # Returns detailed information about the relationship between two users
426
+ #
427
+ # @see https://dev.twitter.com/docs/api/1.1/get/friendships/show
428
+ # @rate_limited Yes
429
+ # @authentication_required Requires user context
430
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
431
+ # @return [Twitter::Relationship]
432
+ # @param source [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the source user.
433
+ # @param target [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the target user.
434
+ # @param options [Hash] A customizable set of options.
435
+ # @example Return the relationship between @sferik and @pengwynn
436
+ # Twitter.friendship('sferik', 'pengwynn')
437
+ # Twitter.friendship('sferik', 14100886) # Same as above
438
+ # Twitter.friendship(7505382, 14100886) # Same as above
439
+ def friendship(source, target, options={})
440
+ options.merge_user!(source, "source")
441
+ options[:source_id] = options.delete(:source_user_id) unless options[:source_user_id].nil?
442
+ options.merge_user!(target, "target")
443
+ options[:target_id] = options.delete(:target_user_id) unless options[:target_user_id].nil?
444
+ object_from_response(Twitter::Relationship, :get, "/1.1/friendships/show.json", options)
445
+ end
446
+ alias friendship_show friendship
447
+ alias relationship friendship
448
+
449
+ # Allows the authenticating user to follow the specified users, unless they are already followed
450
+ #
451
+ # @see https://dev.twitter.com/docs/api/1.1/post/friendships/create
452
+ # @rate_limited No
453
+ # @authentication_required Requires user context
454
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
455
+ # @return [Array<Twitter::User>] The followed users.
456
+ # @overload(*users)
457
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
458
+ # @example Follow @sferik
459
+ # Twitter.follow('sferik')
460
+ # @overload(*users, options)
461
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
462
+ # @param options [Hash] A customizable set of options.
463
+ # @option options [Boolean] :follow (false) Enable notifications for the target user.
464
+ def follow(*args)
465
+ options = args.extract_options!
466
+ # Twitter always turns on notifications if the "follow" option is present, even if it's set to false
467
+ # so only send follow if it's true
468
+ options[:follow] = true if !!options.delete(:follow)
469
+ existing_friends = Thread.new do
470
+ friend_ids.ids
471
+ end
472
+ new_friends = Thread.new do
473
+ users(args).map(&:id)
474
+ end
475
+ follow!(new_friends.value - existing_friends.value, options)
476
+ end
477
+ alias friendship_create follow
478
+
479
+ # Allows the authenticating user to follow the specified users
480
+ #
481
+ # @see https://dev.twitter.com/docs/api/1.1/post/friendships/create
482
+ # @rate_limited No
483
+ # @authentication_required Requires user context
484
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
485
+ # @return [Array<Twitter::User>] The followed users.
486
+ # @overload follow!(*users)
487
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
488
+ # @example Follow @sferik
489
+ # Twitter.follow!('sferik')
490
+ # @overload follow!(*users, options)
491
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
492
+ # @param options [Hash] A customizable set of options.
493
+ # @option options [Boolean] :follow (false) Enable notifications for the target user.
494
+ def follow!(*args)
495
+ options = args.extract_options!
496
+ # Twitter always turns on notifications if the "follow" option is present, even if it's set to false
497
+ # so only send follow if it's true
498
+ options[:follow] = true if !!options.delete(:follow)
499
+ args.flatten.threaded_map do |user|
500
+ begin
501
+ options.merge_user!(user)
502
+ object_from_response(Twitter::User, :post, "/1.1/friendships/create.json", options)
503
+ rescue Twitter::Error::Forbidden
504
+ # This error will be raised if the user doesn't have permission to
505
+ # follow list_member, for whatever reason.
506
+ end
507
+ end.compact
508
+ end
509
+ alias friendship_create! follow!
510
+
511
+ # Allows the authenticating user to unfollow the specified users
512
+ #
513
+ # @see https://dev.twitter.com/docs/api/1.1/post/friendships/destroy
514
+ # @rate_limited No
515
+ # @authentication_required Requires user context
516
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
517
+ # @return [Array<Twitter::User>] The unfollowed users.
518
+ # @overload unfollow(*users)
519
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
520
+ # @example Unfollow @sferik
521
+ # Twitter.unfollow('sferik')
522
+ # @overload unfollow(*users)
523
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
524
+ # @param options [Hash] A customizable set of options.
525
+ def unfollow(*args)
526
+ threaded_users_from_response(:post, "/1.1/friendships/destroy.json", args)
527
+ end
528
+ alias friendship_destroy unfollow
529
+
530
+ # Returns the relationship of the authenticating user to the comma separated list of up to 100 screen_names or user_ids provided. Values for connections can be: following, following_requested, followed_by, none.
531
+ #
532
+ # @see https://dev.twitter.com/docs/api/1.1/get/friendships/lookup
533
+ # @rate_limited Yes
534
+ # @authentication_required Requires user context
535
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
536
+ # @return [Array<Twitter::User>] The requested users.
537
+ # @overload friendships(*users)
538
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
539
+ # @example Return extended information for @sferik and @pengwynn
540
+ # Twitter.friendships('sferik', 'pengwynn')
541
+ # Twitter.friendships('sferik', 14100886) # Same as above
542
+ # Twitter.friendships(7505382, 14100886) # Same as above
543
+ # @overload friendships(*users, options)
544
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
545
+ # @param options [Hash] A customizable set of options.
546
+ def friendships(*args)
547
+ options = args.extract_options!
548
+ options.merge_users!(Array(args))
549
+ collection_from_response(Twitter::User, :get, "/1.1/friendships/lookup.json", options)
550
+ end
551
+
552
+ # Allows one to enable or disable retweets and device notifications from the specified user.
553
+ #
554
+ # @see https://dev.twitter.com/docs/api/1.1/post/friendships/update
555
+ # @rate_limited No
556
+ # @authentication_required Requires user context
557
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
558
+ # @return [Twitter::Relationship]
559
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
560
+ # @param options [Hash] A customizable set of options.
561
+ # @option options [Boolean] :device Enable/disable device notifications from the target user.
562
+ # @option options [Boolean] :retweets Enable/disable retweets from the target user.
563
+ # @example Enable rewteets and devise notifications for @sferik
564
+ # Twitter.friendship_update('sferik', :device => true, :retweets => true)
565
+ def friendship_update(user, options={})
566
+ options.merge_user!(user)
567
+ object_from_response(Twitter::Relationship, :post, "/1.1/friendships/update.json", options)
568
+ end
569
+
570
+ # Search for places that can be attached to a {Twitter::API::Statuses#update}
571
+ #
572
+ # @see https://dev.twitter.com/docs/api/1.1/get/geo/search
573
+ # @rate_limited Yes
574
+ # @authentication_required Requires user context
575
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
576
+ # @param options [Hash] A customizable set of options.
577
+ # @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.
578
+ # @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.
579
+ # @option options [String] :query Free-form text to match against while executing a geo-based query, best suited for finding nearby locations by name.
580
+ # @option options [String] :ip An IP address. Used when attempting to fix geolocation based off of the user's IP address.
581
+ # @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'.
582
+ # @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.).
583
+ # @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.
584
+ # @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.
585
+ # @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.
586
+ # @return [Array<Twitter::Place>]
587
+ # @example Return an array of places near the IP address 74.125.19.104
588
+ # Twitter.places_nearby(:ip => "74.125.19.104")
589
+ def places_nearby(options={})
590
+ geo_collection_from_response(:get, "/1.1/geo/search.json", options)
591
+ end
592
+ alias geo_search places_nearby
593
+
594
+ # Locates places near the given coordinates which are similar in name
595
+ #
596
+ # @see https://dev.twitter.com/docs/api/1.1/get/geo/similar_places
597
+ # @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::Geo#place} to create a new one. The token contained in the response is the token necessary to create a new place.
598
+ # @rate_limited Yes
599
+ # @authentication_required Requires user context
600
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
601
+ # @param options [Hash] A customizable set of options.
602
+ # @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.
603
+ # @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.
604
+ # @option options [String] :name The name a place is known as.
605
+ # @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.
606
+ # @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.
607
+ # @return [Array<Twitter::Place>]
608
+ # @example Return an array of places similar to Twitter HQ
609
+ # Twitter.places_similar(:lat => "37.7821120598956", :long => "-122.400612831116", :name => "Twitter HQ")
610
+ def places_similar(options={})
611
+ geo_collection_from_response(:get, "/1.1/geo/similar_places.json", options)
612
+ end
613
+
614
+ # Searches for up to 20 places that can be used as a place_id
615
+ #
616
+ # @see https://dev.twitter.com/docs/api/1.1/get/geo/reverse_geocode
617
+ # @note This request is an informative call and will deliver generalized results about geography.
618
+ # @rate_limited Yes
619
+ # @authentication_required Requires user context
620
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
621
+ # @param options [Hash] A customizable set of options.
622
+ # @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.
623
+ # @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.
624
+ # @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.).
625
+ # @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'.
626
+ # @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.
627
+ # @return [Array<Twitter::Place>]
628
+ # @example Return an array of places within the specified region
629
+ # Twitter.reverse_geocode(:lat => "37.7821120598956", :long => "-122.400612831116")
630
+ def reverse_geocode(options={})
631
+ geo_collection_from_response(:get, "/1.1/geo/reverse_geocode.json", options)
632
+ end
633
+
634
+ # Returns all the information about a known place
635
+ #
636
+ # @see https://dev.twitter.com/docs/api/1.1/get/geo/id/:place_id
637
+ # @rate_limited Yes
638
+ # @authentication_required Requires user context
639
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
640
+ # @param place_id [String] A place in the world. These IDs can be retrieved from {Twitter::API::Geo#reverse_geocode}.
641
+ # @param options [Hash] A customizable set of options.
642
+ # @return [Twitter::Place] The requested place.
643
+ # @example Return all the information about Twitter HQ
644
+ # Twitter.place("247f43d441defc03")
645
+ def place(place_id, options={})
646
+ object_from_response(Twitter::Place, :get, "/1.1/geo/id/#{place_id}.json", options)
647
+ end
648
+
649
+ # Creates a new place at the given latitude and longitude
650
+ #
651
+ # @see https://dev.twitter.com/docs/api/1.1/post/geo/place
652
+ # @rate_limited Yes
653
+ # @authentication_required Requires user context
654
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
655
+ # @param options [Hash] A customizable set of options.
656
+ # @option options [String] :name The name a place is known as.
657
+ # @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.
658
+ # @option options [String] :token The token found in the response from {Twitter::API::Geo#places_similar}.
659
+ # @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.
660
+ # @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.
661
+ # @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.
662
+ # @return [Twitter::Place] The created place.
663
+ # @example Create a new place
664
+ # Twitter.place_create(:name => "@sferik's Apartment", :token => "22ff5b1f7159032cf69218c4d8bb78bc", :contained_within => "41bcb736f84a799e", :lat => "37.783699", :long => "-122.393581")
665
+ def place_create(options={})
666
+ object_from_response(Twitter::Place, :post, "/1.1/geo/place.json", options)
667
+ end
668
+
669
+ # Returns the current configuration used by Twitter
670
+ #
671
+ # @see https://dev.twitter.com/docs/api/1.1/get/help/configuration
672
+ # @rate_limited Yes
673
+ # @authentication_required Requires user context
674
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
675
+ # @return [Twitter::Configuration] Twitter's configuration.
676
+ # @example Return the current configuration used by Twitter
677
+ # Twitter.configuration
678
+ def configuration(options={})
679
+ object_from_response(Twitter::Configuration, :get, "/1.1/help/configuration.json", options)
680
+ end
681
+
682
+ # Returns the list of languages supported by Twitter
683
+ #
684
+ # @see https://dev.twitter.com/docs/api/1.1/get/help/languages
685
+ # @rate_limited Yes
686
+ # @authentication_required Requires user context
687
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
688
+ # @return [Array<Twitter::Language>]
689
+ # @example Return the list of languages Twitter supports
690
+ # Twitter.languages
691
+ def languages(options={})
692
+ collection_from_response(Twitter::Language, :get, "/1.1/help/languages.json", options)
693
+ end
694
+
695
+ # Returns {https://twitter.com/privacy Twitter's Privacy Policy}
696
+ #
697
+ # @see https://dev.twitter.com/docs/api/1.1/get/help/privacy
698
+ # @rate_limited Yes
699
+ # @authentication_required Requires user context
700
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
701
+ # @return [String]
702
+ # @example Return {https://twitter.com/privacy Twitter's Privacy Policy}
703
+ # Twitter.privacy
704
+ def privacy(options={})
705
+ get("/1.1/help/privacy.json", options)[:body][:privacy]
706
+ end
707
+
708
+ # Returns {https://twitter.com/tos Twitter's Terms of Service}
709
+ #
710
+ # @see https://dev.twitter.com/docs/api/1.1/get/help/tos
711
+ # @rate_limited Yes
712
+ # @authentication_required Requires user context
713
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
714
+ # @return [String]
715
+ # @example Return {https://twitter.com/tos Twitter's Terms of Service}
716
+ # Twitter.tos
717
+ def tos(options={})
718
+ get("/1.1/help/tos.json", options)[:body][:tos]
719
+ end
720
+
721
+ # Show tweet timeline for members of the specified list
722
+ #
723
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/statuses
724
+ # @rate_limited Yes
725
+ # @authentication_required Requires user context
726
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
727
+ # @return [Array<Twitter::Tweet>]
728
+ # @overload list_timeline(list, options={})
729
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
730
+ # @param options [Hash] A customizable set of options.
731
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
732
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
733
+ # @option options [Integer] :count The number of results to retrieve.
734
+ # @example Show tweet timeline for members of the authenticated user's "presidents" list
735
+ # Twitter.list_timeline('presidents')
736
+ # Twitter.list_timeline(8863586)
737
+ # @overload list_timeline(user, list, options={})
738
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
739
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
740
+ # @param options [Hash] A customizable set of options.
741
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
742
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
743
+ # @option options [Integer] :count The number of results to retrieve.
744
+ # @example Show tweet timeline for members of @sferik's "presidents" list
745
+ # Twitter.list_timeline('sferik', 'presidents')
746
+ # Twitter.list_timeline('sferik', 8863586)
747
+ # Twitter.list_timeline(7505382, 'presidents')
748
+ # Twitter.list_timeline(7505382, 8863586)
749
+ def list_timeline(*args)
750
+ options = args.extract_options!
751
+ options.merge_list!(args.pop)
752
+ options.merge_owner!(args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
753
+ collection_from_response(Twitter::Tweet, :get, "/1.1/lists/statuses.json", options)
754
+ end
755
+
756
+ # Removes the specified member from the list
757
+ #
758
+ # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy
759
+ # @rate_limited No
760
+ # @authentication_required Requires user context
761
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
762
+ # @return [Twitter::List] The list.
763
+ # @overload list_remove_member(list, user_to_remove, options={})
764
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
765
+ # @param user_to_remove [Integer, String] The user id or screen name of the list member to remove.
766
+ # @param options [Hash] A customizable set of options.
767
+ # @example Remove @BarackObama from the authenticated user's "presidents" list
768
+ # Twitter.list_remove_member('presidents', 813286)
769
+ # Twitter.list_remove_member('presidents', 'BarackObama')
770
+ # Twitter.list_remove_member(8863586, 'BarackObama')
771
+ # @overload list_remove_member(user, list, user_to_remove, options={})
772
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
773
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
774
+ # @param user_to_remove [Integer, String] The user id or screen name of the list member to remove.
775
+ # @param options [Hash] A customizable set of options.
776
+ # @example Remove @BarackObama from @sferik's "presidents" list
777
+ # Twitter.list_remove_member('sferik', 'presidents', 813286)
778
+ # Twitter.list_remove_member('sferik', 'presidents', 'BarackObama')
779
+ # Twitter.list_remove_member('sferik', 8863586, 'BarackObama')
780
+ # Twitter.list_remove_member(7505382, 'presidents', 813286)
781
+ def list_remove_member(*args)
782
+ list_modify_member(:post, "/1.1/lists/members/destroy.json", args)
783
+ end
784
+
785
+ # List the lists the specified user has been added to
786
+ #
787
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/memberships
788
+ # @rate_limited Yes
789
+ # @authentication_required Requires user context
790
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
791
+ # @return [Twitter::Cursor]
792
+ # @overload memberships(options={})
793
+ # @param options [Hash] A customizable set of options.
794
+ # @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.
795
+ # @example List the lists the authenticated user has been added to
796
+ # Twitter.memberships
797
+ # @overload memberships(user, options={})
798
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
799
+ # @param options [Hash] A customizable set of options.
800
+ # @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.
801
+ # @example List the lists that @sferik has been added to
802
+ # Twitter.memberships('sferik')
803
+ # Twitter.memberships(7505382)
804
+ def memberships(*args)
805
+ lists_from_response(:get, "/1.1/lists/memberships.json", args)
806
+ end
807
+
808
+ # Returns the subscribers of the specified list
809
+ #
810
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/subscribers
811
+ # @rate_limited Yes
812
+ # @authentication_required Requires user context
813
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
814
+ # @return [Twitter::Cursor] The subscribers of the specified list.
815
+ # @overload list_subscribers(list, options={})
816
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
817
+ # @param options [Hash] A customizable set of options.
818
+ # @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.
819
+ # @example Return the subscribers of the authenticated user's "presidents" list
820
+ # Twitter.list_subscribers('presidents')
821
+ # Twitter.list_subscribers(8863586)
822
+ # @overload list_subscribers(user, list, options={})
823
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
824
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
825
+ # @param options [Hash] A customizable set of options.
826
+ # @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.
827
+ # @example Return the subscribers of @sferik's "presidents" list
828
+ # Twitter.list_subscribers('sferik', 'presidents')
829
+ # Twitter.list_subscribers('sferik', 8863586)
830
+ # Twitter.list_subscribers(7505382, 'presidents')
831
+ def list_subscribers(*args)
832
+ list_users(:get, "/1.1/lists/subscribers.json", args)
833
+ end
834
+
835
+ # List the lists the specified user follows
836
+ #
837
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/subscriptions
838
+ # @rate_limited Yes
839
+ # @authentication_required Requires user context
840
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
841
+ # @return [Twitter::Cursor]
842
+ # @overload subscriptions(options={})
843
+ # @param options [Hash] A customizable set of options.
844
+ # @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.
845
+ # @example List the lists the authenticated user follows
846
+ # Twitter.subscriptions
847
+ # @overload subscriptions(user, options={})
848
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
849
+ # @param options [Hash] A customizable set of options.
850
+ # @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.
851
+ # @example List the lists that @sferik follows
852
+ # Twitter.subscriptions('sferik')
853
+ # Twitter.subscriptions(7505382)
854
+ def subscriptions(*args)
855
+ lists_from_response(:get, "/1.1/lists/subscriptions.json", args)
856
+ end
857
+
858
+ # Make the authenticated user follow the specified list
859
+ #
860
+ # @see https://dev.twitter.com/docs/api/1.1/post/lists/subscribers/create
861
+ # @rate_limited No
862
+ # @authentication_required Requires user context
863
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
864
+ # @return [Twitter::List] The specified list.
865
+ # @overload list_subscribe(list, options={})
866
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
867
+ # @param options [Hash] A customizable set of options.
868
+ # @example Subscribe to the authenticated user's "presidents" list
869
+ # Twitter.list_subscribe('presidents')
870
+ # Twitter.list_subscribe(8863586)
871
+ # @overload list_subscribe(user, list, options={})
872
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
873
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
874
+ # @param options [Hash] A customizable set of options.
875
+ # @example Subscribe to @sferik's "presidents" list
876
+ # Twitter.list_subscribe('sferik', 'presidents')
877
+ # Twitter.list_subscribe('sferik', 8863586)
878
+ # Twitter.list_subscribe(7505382, 'presidents')
879
+ def list_subscribe(*args)
880
+ list_from_response(:post, "/1.1/lists/subscribers/create.json", args)
881
+ end
882
+
883
+ # Check if a user is a subscriber of the specified list
884
+ #
885
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/subscribers/show
886
+ # @rate_limited Yes
887
+ # @authentication_required Requires user context
888
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
889
+ # @return [Boolean] true if user is a subscriber of the specified list, otherwise false.
890
+ # @overload list_subscriber?(list, user_to_check, options={})
891
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
892
+ # @param user_to_check [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
893
+ # @param options [Hash] A customizable set of options.
894
+ # @example Check if @BarackObama is a subscriber of the authenticated user's "presidents" list
895
+ # Twitter.list_subscriber?('presidents', 813286)
896
+ # Twitter.list_subscriber?(8863586, 813286)
897
+ # Twitter.list_subscriber?('presidents', 'BarackObama')
898
+ # @overload list_subscriber?(user, list, user_to_check, options={})
899
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
900
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
901
+ # @param user_to_check [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
902
+ # @param options [Hash] A customizable set of options.
903
+ # @example Check if @BarackObama is a subscriber of @sferik's "presidents" list
904
+ # Twitter.list_subscriber?('sferik', 'presidents', 813286)
905
+ # Twitter.list_subscriber?('sferik', 8863586, 813286)
906
+ # Twitter.list_subscriber?(7505382, 'presidents', 813286)
907
+ # Twitter.list_subscriber?('sferik', 'presidents', 'BarackObama')
908
+ # @return [Boolean] true if user is a subscriber of the specified list, otherwise false.
909
+ def list_subscriber?(*args)
910
+ list_user?(:get, "/1.1/lists/subscribers/show.json", args)
911
+ end
912
+
913
+ # Unsubscribes the authenticated user form the specified list
914
+ #
915
+ # @see https://dev.twitter.com/docs/api/1.1/post/lists/subscribers/destroy
916
+ # @rate_limited No
917
+ # @authentication_required Requires user context
918
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
919
+ # @return [Twitter::List] The specified list.
920
+ # @overload list_unsubscribe(list, options={})
921
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
922
+ # @param options [Hash] A customizable set of options.
923
+ # @example Unsubscribe from the authenticated user's "presidents" list
924
+ # Twitter.list_unsubscribe('presidents')
925
+ # Twitter.list_unsubscribe(8863586)
926
+ # @overload list_unsubscribe(user, list, options={})
927
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
928
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
929
+ # @param options [Hash] A customizable set of options.
930
+ # @example Unsubscribe from @sferik's "presidents" list
931
+ # Twitter.list_unsubscribe('sferik', 'presidents')
932
+ # Twitter.list_unsubscribe('sferik', 8863586)
933
+ # Twitter.list_unsubscribe(7505382, 'presidents')
934
+ def list_unsubscribe(*args)
935
+ list_from_response(:post, "/1.1/lists/subscribers/destroy.json", args)
936
+ end
937
+
938
+ # Adds specified members to a list
939
+ #
940
+ # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/create_all
941
+ # @note Lists are limited to having 500 members, and you are limited to adding up to 100 members to a list at a time with this method.
942
+ # @rate_limited No
943
+ # @authentication_required Requires user context
944
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
945
+ # @return [Twitter::List] The list.
946
+ # @overload list_add_members(list, users, options={})
947
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
948
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
949
+ # @param options [Hash] A customizable set of options.
950
+ # @example Add @BarackObama and @pengwynn to the authenticated user's "presidents" list
951
+ # Twitter.list_add_members('presidents', ['BarackObama', 'pengwynn'])
952
+ # Twitter.list_add_members('presidents', [813286, 18755393])
953
+ # Twitter.list_add_members(8863586, ['BarackObama', 'pengwynn'])
954
+ # Twitter.list_add_members(8863586, [813286, 18755393])
955
+ # @overload list_add_members(user, list, users, options={})
956
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
957
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
958
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
959
+ # @param options [Hash] A customizable set of options.
960
+ # @example Add @BarackObama and @pengwynn to @sferik's "presidents" list
961
+ # Twitter.list_add_members('sferik', 'presidents', ['BarackObama', 'pengwynn'])
962
+ # Twitter.list_add_members('sferik', 'presidents', [813286, 18755393])
963
+ # Twitter.list_add_members(7505382, 'presidents', ['BarackObama', 'pengwynn'])
964
+ # Twitter.list_add_members(7505382, 'presidents', [813286, 18755393])
965
+ # Twitter.list_add_members(7505382, 8863586, ['BarackObama', 'pengwynn'])
966
+ # Twitter.list_add_members(7505382, 8863586, [813286, 18755393])
967
+ def list_add_members(*args)
968
+ list_modify_members(:post, "/1.1/lists/members/create_all.json", args)
969
+ end
970
+
971
+ # Removes specified members from the list
972
+ #
973
+ # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy_all
974
+ # @rate_limited No
975
+ # @authentication_required Requires user context
976
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
977
+ # @return [Twitter::List] The list.
978
+ # @overload list_remove_members(list, users, options={})
979
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
980
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
981
+ # @param options [Hash] A customizable set of options.
982
+ # @example Remove @BarackObama and @pengwynn from the authenticated user's "presidents" list
983
+ # Twitter.list_remove_members('presidents', ['BarackObama', 'pengwynn'])
984
+ # Twitter.list_remove_members('presidents', [813286, 18755393])
985
+ # Twitter.list_remove_members(8863586, ['BarackObama', 'pengwynn'])
986
+ # Twitter.list_remove_members(8863586, [813286, 18755393])
987
+ # @overload list_remove_members(user, list, users, options={})
988
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
989
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
990
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
991
+ # @param options [Hash] A customizable set of options.
992
+ # @example Remove @BarackObama and @pengwynn from @sferik's "presidents" list
993
+ # Twitter.list_remove_members('sferik', 'presidents', ['BarackObama', 'pengwynn'])
994
+ # Twitter.list_remove_members('sferik', 'presidents', [813286, 18755393])
995
+ # Twitter.list_remove_members(7505382, 'presidents', ['BarackObama', 'pengwynn'])
996
+ # Twitter.list_remove_members(7505382, 'presidents', [813286, 18755393])
997
+ # Twitter.list_remove_members(7505382, 8863586, ['BarackObama', 'pengwynn'])
998
+ # Twitter.list_remove_members(7505382, 8863586, [813286, 18755393])
999
+ def list_remove_members(*args)
1000
+ list_modify_members(:post, "/1.1/lists/members/destroy_all.json", args)
1001
+ end
1002
+
1003
+ # Check if a user is a member of the specified list
1004
+ #
1005
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/members/show
1006
+ # @authentication_required Requires user context
1007
+ # @rate_limited Yes
1008
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1009
+ # @return [Boolean] true if user is a member of the specified list, otherwise false.
1010
+ # @overload list_member?(list, user_to_check, options={})
1011
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1012
+ # @param user_to_check [Integer, String] The user ID or screen name of the list member.
1013
+ # @param options [Hash] A customizable set of options.
1014
+ # @example Check if @BarackObama is a member of the authenticated user's "presidents" list
1015
+ # Twitter.list_member?('presidents', 813286)
1016
+ # Twitter.list_member?(8863586, 'BarackObama')
1017
+ # @overload list_member?(user, list, user_to_check, options={})
1018
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1019
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1020
+ # @param user_to_check [Integer, String] The user ID or screen name of the list member.
1021
+ # @param options [Hash] A customizable set of options.
1022
+ # @example Check if @BarackObama is a member of @sferik's "presidents" list
1023
+ # Twitter.list_member?('sferik', 'presidents', 813286)
1024
+ # Twitter.list_member?('sferik', 8863586, 'BarackObama')
1025
+ # Twitter.list_member?(7505382, 'presidents', 813286)
1026
+ def list_member?(*args)
1027
+ list_user?(:get, "/1.1/lists/members/show.json", args)
1028
+ end
1029
+
1030
+ # Returns the members of the specified list
1031
+ #
1032
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/members
1033
+ # @rate_limited Yes
1034
+ # @authentication_required Requires user context
1035
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1036
+ # @return [Twitter::Cursor]
1037
+ # @overload list_members(list, options={})
1038
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1039
+ # @param options [Hash] A customizable set of options.
1040
+ # @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.
1041
+ # @example Return the members of the authenticated user's "presidents" list
1042
+ # Twitter.list_members('presidents')
1043
+ # Twitter.list_members(8863586)
1044
+ # @overload list_members(user, list, options={})
1045
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1046
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1047
+ # @param options [Hash] A customizable set of options.
1048
+ # @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.
1049
+ # @example Return the members of @sferik's "presidents" list
1050
+ # Twitter.list_members('sferik', 'presidents')
1051
+ # Twitter.list_members('sferik', 8863586)
1052
+ # Twitter.list_members(7505382, 'presidents')
1053
+ # Twitter.list_members(7505382, 8863586)
1054
+ def list_members(*args)
1055
+ list_users(:get, "/1.1/lists/members.json", args)
1056
+ end
1057
+
1058
+ # Add a member to a list
1059
+ #
1060
+ # @see https://dev.twitter.com/docs/api/1.1/post/lists/members/create
1061
+ # @note Lists are limited to having 500 members.
1062
+ # @rate_limited No
1063
+ # @authentication_required Requires user context
1064
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1065
+ # @return [Twitter::List] The list.
1066
+ # @overload list_add_member(list, user_to_add, options={})
1067
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1068
+ # @param user_to_add [Integer, String] The user id or screen name to add to the list.
1069
+ # @param options [Hash] A customizable set of options.
1070
+ # @example Add @BarackObama to the authenticated user's "presidents" list
1071
+ # Twitter.list_add_member('presidents', 813286)
1072
+ # Twitter.list_add_member(8863586, 813286)
1073
+ # @overload list_add_member(user, list, user_to_add, options={})
1074
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1075
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1076
+ # @param user_to_add [Integer, String] The user id or screen name to add to the list.
1077
+ # @param options [Hash] A customizable set of options.
1078
+ # @example Add @BarackObama to @sferik's "presidents" list
1079
+ # Twitter.list_add_member('sferik', 'presidents', 813286)
1080
+ # Twitter.list_add_member('sferik', 8863586, 813286)
1081
+ # Twitter.list_add_member(7505382, 'presidents', 813286)
1082
+ # Twitter.list_add_member(7505382, 8863586, 813286)
1083
+ def list_add_member(*args)
1084
+ list_modify_member(:post, "/1.1/lists/members/create.json", args)
1085
+ end
1086
+
1087
+ # Deletes the specified list
1088
+ #
1089
+ # @see https://dev.twitter.com/docs/api/1.1/post/lists/destroy
1090
+ # @note Must be owned by the authenticated user.
1091
+ # @rate_limited No
1092
+ # @authentication_required Requires user context
1093
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1094
+ # @return [Twitter::List] The deleted list.
1095
+ # @overload list_destroy(list, options={})
1096
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1097
+ # @param options [Hash] A customizable set of options.
1098
+ # @example Delete the authenticated user's "presidents" list
1099
+ # Twitter.list_destroy('presidents')
1100
+ # Twitter.list_destroy(8863586)
1101
+ # @overload list_destroy(user, list, options={})
1102
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1103
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1104
+ # @param options [Hash] A customizable set of options.
1105
+ # @example Delete @sferik's "presidents" list
1106
+ # Twitter.list_destroy('sferik', 'presidents')
1107
+ # Twitter.list_destroy('sferik', 8863586)
1108
+ # Twitter.list_destroy(7505382, 'presidents')
1109
+ # Twitter.list_destroy(7505382, 8863586)
1110
+ def list_destroy(*args)
1111
+ list_from_response(:post, "/1.1/lists/destroy.json", args)
1112
+ end
1113
+
1114
+ # Updates the specified list
1115
+ #
1116
+ # @see https://dev.twitter.com/docs/api/1.1/post/lists/update
1117
+ # @rate_limited No
1118
+ # @authentication_required Requires user context
1119
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1120
+ # @return [Twitter::List] The created list.
1121
+ # @overload list_update(list, options={})
1122
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1123
+ # @param options [Hash] A customizable set of options.
1124
+ # @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
1125
+ # @option options [String] :description The description to give the list.
1126
+ # @example Update the authenticated user's "presidents" list to have the description "Presidents of the United States of America"
1127
+ # Twitter.list_update('presidents', :description => "Presidents of the United States of America")
1128
+ # Twitter.list_update(8863586, :description => "Presidents of the United States of America")
1129
+ # @overload list_update(user, list, options={})
1130
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1131
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1132
+ # @param options [Hash] A customizable set of options.
1133
+ # @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
1134
+ # @option options [String] :description The description to give the list.
1135
+ # @example Update the @sferik's "presidents" list to have the description "Presidents of the United States of America"
1136
+ # Twitter.list_update('sferik', 'presidents', :description => "Presidents of the United States of America")
1137
+ # Twitter.list_update(7505382, 'presidents', :description => "Presidents of the United States of America")
1138
+ # Twitter.list_update('sferik', 8863586, :description => "Presidents of the United States of America")
1139
+ # Twitter.list_update(7505382, 8863586, :description => "Presidents of the United States of America")
1140
+ def list_update(*args)
1141
+ list_from_response(:post, "/1.1/lists/update.json", args)
1142
+ end
1143
+
1144
+ # Creates a new list for the authenticated user
1145
+ #
1146
+ # @see https://dev.twitter.com/docs/api/1.1/post/lists/create
1147
+ # @note Accounts are limited to 20 lists.
1148
+ # @rate_limited No
1149
+ # @authentication_required Requires user context
1150
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1151
+ # @return [Twitter::List] The created list.
1152
+ # @param name [String] The name for the list.
1153
+ # @param options [Hash] A customizable set of options.
1154
+ # @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
1155
+ # @option options [String] :description The description to give the list.
1156
+ # @example Create a list named 'presidents'
1157
+ # Twitter.list_create('presidents')
1158
+ def list_create(name, options={})
1159
+ object_from_response(Twitter::List, :post, "/1.1/lists/create.json", options.merge(:name => name))
1160
+ end
1161
+
1162
+ # List the lists of the specified user
1163
+ # Returns all lists the authenticating or specified user subscribes to, including their own.
1164
+ #
1165
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/list
1166
+ # @rate_limited Yes
1167
+ # @authentication_required Requires user context
1168
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1169
+ # @return [Twitter::Cursor]
1170
+ # @param options [Hash] A customizable set of options.
1171
+ # @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.
1172
+ # @example List the authenticated user's lists
1173
+ # Twitter.lists
1174
+ def lists(*args)
1175
+ lists_from_response(:get, "/1.1/lists/list.json", args)
1176
+ end
1177
+ alias lists_subscribed_to lists
1178
+
1179
+ # Show the specified list
1180
+ #
1181
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/show
1182
+ # @note Private lists will only be shown if the authenticated user owns the specified list.
1183
+ # @rate_limited Yes
1184
+ # @authentication_required Requires user context
1185
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1186
+ # @return [Twitter::List] The specified list.
1187
+ # @overload list(list, options={})
1188
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1189
+ # @param options [Hash] A customizable set of options.
1190
+ # @example Show the authenticated user's "presidents" list
1191
+ # Twitter.list('presidents')
1192
+ # Twitter.list(8863586)
1193
+ # @overload list(user, list, options={})
1194
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1195
+ # @param list [Integer, String, Twitter::List] A Twitter list ID, slug, or object.
1196
+ # @param options [Hash] A customizable set of options.
1197
+ # @example Show @sferik's "presidents" list
1198
+ # Twitter.list('sferik', 'presidents')
1199
+ # Twitter.list('sferik', 8863586)
1200
+ # Twitter.list(7505382, 'presidents')
1201
+ # Twitter.list(7505382, 8863586)
1202
+ def list(*args)
1203
+ list_from_response(:get, "/1.1/lists/show.json", args)
1204
+ end
1205
+
1206
+ # The users specified are blocked by the authenticated user and reported as spammers
1207
+ #
1208
+ # @see https://dev.twitter.com/docs/api/1.1/post/report_spam
1209
+ # @rate_limited Yes
1210
+ # @authentication_required Requires user context
1211
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1212
+ # @return [Array<Twitter::User>] The reported users.
1213
+ # @overload report_spam(*users)
1214
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
1215
+ # @example Report @spam for spam
1216
+ # Twitter.report_spam("spam")
1217
+ # Twitter.report_spam(14589771) # Same as above
1218
+ # @overload report_spam(*users, options)
1219
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
1220
+ # @param options [Hash] A customizable set of options.
1221
+ def report_spam(*args)
1222
+ threaded_users_from_response(:post, "/1.1/report_spam.json", args)
1223
+ end
1224
+
1225
+ # @rate_limited Yes
1226
+ # @authentication_required Requires user context
1227
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1228
+ # @return [Array<Twitter::SavedSearch>] The saved searches.
1229
+ # @overload saved_search(options={})
1230
+ # Returns the authenticated user's saved search queries
1231
+ #
1232
+ # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/list
1233
+ # @param options [Hash] A customizable set of options.
1234
+ # @example Return the authenticated user's saved search queries
1235
+ # Twitter.saved_searches
1236
+ # @overload saved_search(*ids)
1237
+ # Retrieve the data for saved searches owned by the authenticating user
1238
+ #
1239
+ # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/:id
1240
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1241
+ # @example Retrieve the data for a saved search owned by the authenticating user with the ID 16129012
1242
+ # Twitter.saved_search(16129012)
1243
+ # @overload saved_search(*ids, options)
1244
+ # Retrieve the data for saved searches owned by the authenticating user
1245
+ #
1246
+ # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/:id
1247
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1248
+ # @param options [Hash] A customizable set of options.
1249
+ def saved_searches(*args)
1250
+ options = args.extract_options!
1251
+ if args.empty?
1252
+ collection_from_response(Twitter::SavedSearch, :get, "/1.1/saved_searches/list.json", options)
1253
+ else
1254
+ args.flatten.threaded_map do |id|
1255
+ object_from_response(Twitter::SavedSearch, :get, "/1.1/saved_searches/show/#{id}.json", options)
1256
+ end
1257
+ end
1258
+ end
1259
+
1260
+ # Retrieve the data for saved searches owned by the authenticating user
1261
+ #
1262
+ # @see https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/:id
1263
+ # @rate_limited Yes
1264
+ # @authentication_required Requires user context
1265
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1266
+ # @return [Twitter::SavedSearch] The saved searches.
1267
+ # @param id [Integer] A Tweet IDs.
1268
+ # @param options [Hash] A customizable set of options.
1269
+ # @example Retrieve the data for a saved search owned by the authenticating user with the ID 16129012
1270
+ # Twitter.saved_search(16129012)
1271
+ def saved_search(id, options={})
1272
+ object_from_response(Twitter::SavedSearch, :get, "/1.1/saved_searches/show/#{id}.json", options)
1273
+ end
1274
+
1275
+ # Creates a saved search for the authenticated user
1276
+ #
1277
+ # @see https://dev.twitter.com/docs/api/1.1/post/saved_searches/create
1278
+ # @rate_limited No
1279
+ # @authentication_required Requires user context
1280
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1281
+ # @return [Twitter::SavedSearch] The created saved search.
1282
+ # @param query [String] The query of the search the user would like to save.
1283
+ # @param options [Hash] A customizable set of options.
1284
+ # @example Create a saved search for the authenticated user with the query "twitter"
1285
+ # Twitter.saved_search_create("twitter")
1286
+ def saved_search_create(query, options={})
1287
+ object_from_response(Twitter::SavedSearch, :post, "/1.1/saved_searches/create.json", options.merge(:query => query))
1288
+ end
1289
+
1290
+ # Destroys saved searches for the authenticated user
1291
+ #
1292
+ # @see https://dev.twitter.com/docs/api/1.1/post/saved_searches/destroy/:id
1293
+ # @note The search specified by ID must be owned by the authenticating user.
1294
+ # @rate_limited No
1295
+ # @authentication_required Requires user context
1296
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1297
+ # @return [Array<Twitter::SavedSearch>] The deleted saved searches.
1298
+ # @overload saved_search_destroy(*ids)
1299
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1300
+ # @example Destroys a saved search for the authenticated user with the ID 16129012
1301
+ # Twitter.saved_search_destroy(16129012)
1302
+ # @overload saved_search_destroy(*ids, options)
1303
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1304
+ # @param options [Hash] A customizable set of options.
1305
+ def saved_search_destroy(*args)
1306
+ options = args.extract_options!
1307
+ args.flatten.threaded_map do |id|
1308
+ object_from_response(Twitter::SavedSearch, :post, "/1.1/saved_searches/destroy/#{id}.json", options)
1309
+ end
1310
+ end
1311
+
1312
+ # Returns tweets that match a specified query.
1313
+ #
1314
+ # @see https://dev.twitter.com/docs/api/1.1/get/search/tweets
1315
+ # @see https://dev.twitter.com/docs/using-search
1316
+ # @see https://dev.twitter.com/docs/history-rest-search-api
1317
+ # @note As of April 1st 2010, the Search API provides an option to retrieve "popular tweets" in addition to real-time search results. In an upcoming release, this will become the default and clients that don't want to receive popular tweets in their search results will have to explicitly opt-out. See the result_type parameter below for more information.
1318
+ # @rate_limited Yes
1319
+ # @authentication_required Requires user context
1320
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1321
+ # @param q [String] A search term.
1322
+ # @param options [Hash] A customizable set of options.
1323
+ # @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.
1324
+ # @option options [String] :lang Restricts tweets to the given language, given by an ISO 639-1 code.
1325
+ # @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.
1326
+ # @option options [Integer] :page The page number (starting at 1) to return, up to a max of roughly 1500 results (based on rpp * page).
1327
+ # @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."
1328
+ # @option options [Integer] :rpp The number of tweets to return per page, up to a max of 100.
1329
+ # @option options [String] :until Optional. Returns tweets generated before the given date. Date should be formatted as YYYY-MM-DD.
1330
+ # @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.
1331
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
1332
+ # @option options [Boolean, String, Integer] :with_twitter_user_id When set to either true, t or 1, the from_user_id and to_user_id values in the response will map to "official" user IDs which will match those returned by the REST API.
1333
+ # @return [Twitter::SearchResults] Return tweets that match a specified query with search metadata
1334
+ # @example Returns tweets related to twitter
1335
+ # Twitter.search('twitter')
1336
+ def search(q, options={})
1337
+ object_from_response(Twitter::SearchResults, :get, "/1.1/search/tweets.json", options.merge(:q => q))
1338
+ end
1339
+
1340
+ # Returns recent Tweets related to a query with images and videos embedded
1341
+ #
1342
+ # @note Undocumented
1343
+ # @rate_limited Yes
1344
+ # @authentication_required No
1345
+ # @param q [String] A search term.
1346
+ # @param options [Hash] A customizable set of options.
1347
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
1348
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1349
+ # @return [Array<Twitter::Tweet>] An array of Tweets that contain videos
1350
+ # @example Return recent Tweets related to twitter with images and videos embedded
1351
+ # Twitter.phoenix_search('twitter')
1352
+ def phoenix_search(q, options={})
1353
+ search_collection_from_response(:get, "/phoenix_search.phoenix", options.merge(:q => q))
1354
+ end
1355
+
1356
+ # @see https://dev.twitter.com/docs/api/1.1/get/favorites/list
1357
+ # @rate_limited Yes
1358
+ # @authentication_required Requires user context
1359
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1360
+ # @return [Array<Twitter::Tweet>] favorite Tweets.
1361
+ # @overload favorites(options={})
1362
+ # Returns the 20 most recent favorite Tweets for the authenticating user
1363
+ #
1364
+ # @param options [Hash] A customizable set of options.
1365
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
1366
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1367
+ # @example Return the 20 most recent favorite Tweets for the authenticating user
1368
+ # Twitter.favorites
1369
+ # @overload favorites(user, options={})
1370
+ # Returns the 20 most recent favorite Tweets for the specified user
1371
+ #
1372
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1373
+ # @param options [Hash] A customizable set of options.
1374
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
1375
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1376
+ # @example Return the 20 most recent favorite Tweets for @sferik
1377
+ # Twitter.favorites('sferik')
1378
+ def favorites(*args)
1379
+ options = args.extract_options!
1380
+ if user = args.pop
1381
+ options.merge_user!(user)
1382
+ end
1383
+ collection_from_response(Twitter::Tweet, :get, "/1.1/favorites/list.json", options)
1384
+ end
1385
+
1386
+ # Favorites the specified Tweets as the authenticating user
1387
+ #
1388
+ # @see https://dev.twitter.com/docs/api/1.1/post/favorites/create
1389
+ # @rate_limited No
1390
+ # @authentication_required Requires user context
1391
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1392
+ # @return [Array<Twitter::Tweet>] The favorited Tweets.
1393
+ # @overload favorite(*ids)
1394
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1395
+ # @example Favorite the Tweet with the ID 25938088801
1396
+ # Twitter.favorite(25938088801)
1397
+ # @overload favorite(*ids, options)
1398
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1399
+ # @param options [Hash] A customizable set of options.
1400
+ def favorite(*args)
1401
+ options = args.extract_options!
1402
+ args.flatten.threaded_map do |id|
1403
+ object_from_response(Twitter::Tweet, :post, "/1.1/favorites/create.json", options.merge(:id => id))
1404
+ end
1405
+ end
1406
+ alias fav favorite
1407
+ alias fave favorite
1408
+ alias favorite_create favorite
1409
+
1410
+ # Un-favorites the specified Tweets as the authenticating user
1411
+ #
1412
+ # @see https://dev.twitter.com/docs/api/1.1/post/favorites/destroy
1413
+ # @rate_limited No
1414
+ # @authentication_required Requires user context
1415
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1416
+ # @return [Array<Twitter::Tweet>] The un-favorited Tweets.
1417
+ # @overload unfavorite(*ids)
1418
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1419
+ # @example Un-favorite the tweet with the ID 25938088801
1420
+ # Twitter.unfavorite(25938088801)
1421
+ # @overload unfavorite(*ids, options)
1422
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1423
+ # @param options [Hash] A customizable set of options.
1424
+ def unfavorite(*args)
1425
+ options = args.extract_options!
1426
+ args.flatten.threaded_map do |id|
1427
+ object_from_response(Twitter::Tweet, :post, "/1.1/favorites/destroy.json", options.merge(:id => id))
1428
+ end
1429
+ end
1430
+ alias favorite_destroy unfavorite
1431
+
1432
+ # Returns the 20 most recent Tweets, including retweets if they exist, posted by the authenticating user and the users they follow
1433
+ #
1434
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline
1435
+ # @note This method can only return up to 800 Tweets, including retweets.
1436
+ # @rate_limited Yes
1437
+ # @authentication_required Requires user context
1438
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1439
+ # @return [Array<Twitter::Tweet>]
1440
+ # @param options [Hash] A customizable set of options.
1441
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1442
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
1443
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
1444
+ # @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.
1445
+ # @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.
1446
+ # @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.
1447
+ # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
1448
+ # @option options [Boolean, String, Integer] :include_entities Specifies that each tweet should include an 'entities' node including metadata about the tweet such as: user_mentions, urls, and hashtags.
1449
+ # @example Return the 20 most recent Tweets, including retweets if they exist, posted by the authenticating user and the users they follow
1450
+ # Twitter.home_timeline
1451
+ def home_timeline(options={})
1452
+ collection_from_response(Twitter::Tweet, :get, "/1.1/statuses/home_timeline.json", options)
1453
+ end
1454
+
1455
+ # Returns the 20 most recent mentions (statuses containing @username) for the authenticating user
1456
+ #
1457
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/mentions_timeline
1458
+ # @note This method can only return up to 800 Tweets.
1459
+ # @rate_limited Yes
1460
+ # @authentication_required Requires user context
1461
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1462
+ # @return [Array<Twitter::Tweet>]
1463
+ # @param options [Hash] A customizable set of options.
1464
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1465
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
1466
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
1467
+ # @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.
1468
+ # @example Return the 20 most recent mentions (statuses containing @username) for the authenticating user
1469
+ # Twitter.mentions
1470
+ def mentions_timeline(options={})
1471
+ collection_from_response(Twitter::Tweet, :get, "/1.1/statuses/mentions_timeline.json", options)
1472
+ end
1473
+ alias mentions mentions_timeline
1474
+
1475
+ # Returns the 20 most recent retweets posted by the specified user
1476
+ #
1477
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
1478
+ # @note This method can only return up to 3,200 Tweets.
1479
+ # @rate_limited Yes
1480
+ # @authentication_required Requires user context
1481
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1482
+ # @return [Array<Twitter::Tweet>]
1483
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1484
+ # @param options [Hash] A customizable set of options.
1485
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1486
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
1487
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
1488
+ # @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.
1489
+ # @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.
1490
+ # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
1491
+ # @example Return the 20 most recent retweets posted by @sferik
1492
+ # Twitter.retweeted_by_user('sferik')
1493
+ def retweeted_by_user(user, options={})
1494
+ options[:include_rts] = true
1495
+ count = options[:count] || DEFAULT_TWEETS_PER_REQUEST
1496
+ collect_with_count(count) do |count_options|
1497
+ select_retweets(user_timeline(user, options.merge(count_options)))
1498
+ end
1499
+ end
1500
+ alias retweeted_by retweeted_by_user
1501
+
1502
+ # Returns the 20 most recent retweets posted by the authenticating user
1503
+ #
1504
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
1505
+ # @note This method can only return up to 3,200 Tweets.
1506
+ # @rate_limited Yes
1507
+ # @authentication_required Requires user context
1508
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1509
+ # @return [Array<Twitter::Tweet>]
1510
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1511
+ # @param options [Hash] A customizable set of options.
1512
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1513
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
1514
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
1515
+ # @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.
1516
+ # @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.
1517
+ # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
1518
+ # @example Return the 20 most recent retweets posted by the authenticating user
1519
+ # Twitter.retweeted_by_me
1520
+ def retweeted_by_me(options={})
1521
+ options[:include_rts] = true
1522
+ count = options[:count] || DEFAULT_TWEETS_PER_REQUEST
1523
+ collect_with_count(count) do |count_options|
1524
+ select_retweets(user_timeline(options.merge(count_options)))
1525
+ end
1526
+ end
1527
+
1528
+ # Returns the 20 most recent retweets posted by users the authenticating user follow.
1529
+ #
1530
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline
1531
+ # @note This method can only return up to 800 Tweets, including retweets.
1532
+ # @rate_limited Yes
1533
+ # @authentication_required Requires user context
1534
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1535
+ # @return [Array<Twitter::Tweet>]
1536
+ # @param options [Hash] A customizable set of options.
1537
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1538
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
1539
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
1540
+ # @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.
1541
+ # @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.
1542
+ # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
1543
+ # @option options [Boolean, String, Integer] :include_entities Specifies that each tweet should include an 'entities' node including metadata about the tweet such as: user_mentions, urls, and hashtags.
1544
+ # @example Return the 20 most recent retweets posted by users followed by the authenticating user
1545
+ # Twitter.retweeted_to_me
1546
+ def retweeted_to_me(options={})
1547
+ options[:include_rts] = true
1548
+ count = options[:count] || DEFAULT_TWEETS_PER_REQUEST
1549
+ collect_with_count(count) do |count_options|
1550
+ select_retweets(home_timeline(options.merge(count_options)))
1551
+ end
1552
+ end
1553
+
1554
+ # Returns the 20 most recent tweets of the authenticated user that have been retweeted by others
1555
+ #
1556
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
1557
+ # @note This method can only return up to 3,200 Tweets.
1558
+ # @rate_limited Yes
1559
+ # @authentication_required Requires user context
1560
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1561
+ # @return [Array<Twitter::Tweet>]
1562
+ # @param options [Hash] A customizable set of options.
1563
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1564
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
1565
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
1566
+ # @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.
1567
+ # @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.
1568
+ # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
1569
+ # @example Return the 20 most recent tweets of the authenticated user that have been retweeted by others
1570
+ # Twitter.retweets_of_me
1571
+ def retweets_of_me(options={})
1572
+ options[:include_rts] = false
1573
+ count = options[:count] || DEFAULT_TWEETS_PER_REQUEST
1574
+ collect_with_count(count) do |count_options|
1575
+ user_timeline(options.merge(count_options)).select{|tweet| tweet.retweet_count.to_i > 0}
1576
+ end
1577
+ end
1578
+
1579
+ # Returns the 20 most recent Tweets posted by the specified user
1580
+ #
1581
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
1582
+ # @note This method can only return up to 3,200 Tweets.
1583
+ # @rate_limited Yes
1584
+ # @authentication_required Requires user context
1585
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1586
+ # @return [Array<Twitter::Tweet>]
1587
+ # @overload user_timeline(user, options={})
1588
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1589
+ # @param options [Hash] A customizable set of options.
1590
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
1591
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
1592
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
1593
+ # @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.
1594
+ # @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.
1595
+ # @option options [Boolean, String, Integer] :contributor_details Specifies that the contributors element should be enhanced to include the screen_name of the contributor.
1596
+ # @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.
1597
+ # @example Return the 20 most recent Tweets posted by @sferik
1598
+ # Twitter.user_timeline('sferik')
1599
+ def user_timeline(*args)
1600
+ objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/user_timeline.json", args)
1601
+ end
1602
+
1603
+ # Returns the 20 most recent images posted by the specified user
1604
+ #
1605
+ # @see https://support.twitter.com/articles/20169409
1606
+ # @note This method can only return up to the 100 most recent images.
1607
+ # @note Images will not be returned from tweets posted before January 1, 2010.
1608
+ # @rate_limited Yes
1609
+ # @authentication_required Requires user context
1610
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1611
+ # @return [Array<Twitter::Tweet>]
1612
+ # @overload media_timeline(user, options={})
1613
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1614
+ # @param options [Hash] A customizable set of options.
1615
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
1616
+ # @option options [Boolean] :filter Include possibly sensitive media when set to false, 'f' or 0.
1617
+ # @example Return the 20 most recent Tweets posted by @sferik
1618
+ # Twitter.media_timeline('sferik')
1619
+ def media_timeline(*args)
1620
+ objects_from_response(Twitter::Tweet, :get, "/1.1/statuses/media_timeline.json", args)
1621
+ end
1622
+
1623
+ # Show up to 100 users who retweeted the Tweet
1624
+ #
1625
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/:id
1626
+ # @rate_limited Yes
1627
+ # @authentication_required Requires user context
1628
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1629
+ # @return [Array]
1630
+ # @param id [Integer] The numerical ID of the desired Tweet.
1631
+ # @param options [Hash] A customizable set of options.
1632
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
1633
+ # @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.
1634
+ # @option options [Boolean] :ids_only ('false') Only return user ids instead of full user objects.
1635
+ # @example Show up to 100 users who retweeted the Tweet with the ID 28561922516
1636
+ # Twitter.retweeters_of(28561922516)
1637
+ def retweeters_of(id, options={})
1638
+ if ids_only = !!options.delete(:ids_only)
1639
+ retweets(id, options).map(&:user).map(&:id)
1640
+ else
1641
+ retweets(id, options).map(&:user)
1642
+ end
1643
+ end
1644
+
1645
+ # Returns up to 100 of the first retweets of a given tweet
1646
+ #
1647
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/:id
1648
+ # @rate_limited Yes
1649
+ # @authentication_required Requires user context
1650
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1651
+ # @return [Array<Twitter::Tweet>]
1652
+ # @param id [Integer] The numerical ID of the desired Tweet.
1653
+ # @param options [Hash] A customizable set of options.
1654
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
1655
+ # @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.
1656
+ # @example Return up to 100 of the first retweets of the Tweet with the ID 28561922516
1657
+ # Twitter.retweets(28561922516)
1658
+ def retweets(id, options={})
1659
+ collection_from_response(Twitter::Tweet, :get, "/1.1/statuses/retweets/#{id}.json", options)
1660
+ end
1661
+
1662
+ # Returns a Tweet
1663
+ #
1664
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/show/:id
1665
+ # @rate_limited Yes
1666
+ # @authentication_required Requires user context
1667
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1668
+ # @return [Twitter::Tweet] The requested Tweet.
1669
+ # @param id [Integer] A Tweet ID.
1670
+ # @param options [Hash] A customizable set of options.
1671
+ # @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.
1672
+ # @example Return the Tweet with the ID 25938088801
1673
+ # Twitter.status(25938088801)
1674
+ def status(id, options={})
1675
+ object_from_response(Twitter::Tweet, :get, "/1.1/statuses/show/#{id}.json", options)
1676
+ end
1677
+
1678
+ # Returns Tweets
1679
+ #
1680
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/show/:id
1681
+ # @rate_limited Yes
1682
+ # @authentication_required Requires user context
1683
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1684
+ # @return [Array<Twitter::Tweet>] The requested Tweets.
1685
+ # @overload statuses(*ids)
1686
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1687
+ # @example Return the Tweet with the ID 25938088801
1688
+ # Twitter.statuses(25938088801)
1689
+ # @overload statuses(*ids, options)
1690
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1691
+ # @param options [Hash] A customizable set of options.
1692
+ # @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.
1693
+ def statuses(*args)
1694
+ threaded_tweets_from_response(:get, "/1.1/statuses/show", args)
1695
+ end
1696
+
1697
+ # Returns activity summary for a Tweet
1698
+ #
1699
+ # @note Undocumented
1700
+ # @rate_limited Yes
1701
+ # @authentication_required Requires user context
1702
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1703
+ # @return [Twitter::Tweet] The requested Tweet.
1704
+ # @param id [Integer] A Tweet ID.
1705
+ # @param options [Hash] A customizable set of options.
1706
+ # @example Return activity summary for the Tweet with the ID 25938088801
1707
+ # Twitter.status_activity(25938088801)
1708
+ def status_activity(id, options={})
1709
+ response = get("/i/statuses/#{id}/activity/summary.json", options)
1710
+ response[:body].merge!(:id => id) if response[:body]
1711
+ Twitter::Tweet.from_response(response)
1712
+ end
1713
+ alias tweet_activity status_activity
1714
+
1715
+ # Returns activity summary for Tweets
1716
+ #
1717
+ # @note Undocumented
1718
+ # @rate_limited Yes
1719
+ # @authentication_required Requires user context
1720
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1721
+ # @return [Array<Twitter::Tweet>] The requested Tweets.
1722
+ # @overload statuses_activity(*ids)
1723
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1724
+ # @example Return activity summary for the Tweet with the ID 25938088801
1725
+ # Twitter.statuses_activity(25938088801)
1726
+ # @overload statuses_activity(*ids, options)
1727
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1728
+ # @param options [Hash] A customizable set of options.
1729
+ def statuses_activity(*args)
1730
+ options = args.extract_options!
1731
+ args.flatten.threaded_map do |id|
1732
+ status_activity(id, options)
1733
+ end
1734
+ end
1735
+
1736
+ # Returns oEmbed for a Tweet
1737
+ #
1738
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/oembed
1739
+ # @rate_limited Yes
1740
+ # @authentication_required Requires user context
1741
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1742
+ # @return [Twitter::OEmbed] OEmbed for the requested Tweet.
1743
+ # @param id [Integer, String] A Tweet ID.
1744
+ # @param options [Hash] A customizable set of options.
1745
+ # @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.
1746
+ # @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.
1747
+ # @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.
1748
+ # @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.
1749
+ # @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.
1750
+ # @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.
1751
+ # @option options [String] :lang Language code for the rendered embed. This will affect the text and localization of the rendered HTML.
1752
+ # @example Return oEmbeds for Tweet with the ID 25938088801
1753
+ # Twitter.status_with_activity(25938088801)
1754
+ def oembed(id, options={})
1755
+ object_from_response(Twitter::OEmbed, :get, "/1.1/statuses/oembed.json?id=#{id}", options)
1756
+ end
1757
+
1758
+ # Returns oEmbeds for Tweets
1759
+ #
1760
+ # @see https://dev.twitter.com/docs/api/1.1/get/statuses/oembed
1761
+ # @rate_limited Yes
1762
+ # @authentication_required Requires user context
1763
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1764
+ # @return [Array<Twitter::OEmbed>] OEmbeds for the requested Tweets.
1765
+ # @overload oembed(*ids_or_urls)
1766
+ # @param ids_or_urls [Array<Integer, String>, Set<Integer, String>] An array of Tweet IDs or URLs.
1767
+ # @example Return oEmbeds for Tweets with the ID 25938088801
1768
+ # Twitter.status_with_activity(25938088801)
1769
+ # @overload oembed(*ids_or_urls, options)
1770
+ # @param ids_or_urls [Array<Integer, String>, Set<Integer, String>] An array of Tweet IDs or URLs.
1771
+ # @param options [Hash] A customizable set of options.
1772
+ # @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.
1773
+ # @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.
1774
+ # @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.
1775
+ # @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.
1776
+ # @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.
1777
+ # @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.
1778
+ # @option options [String] :lang Language code for the rendered embed. This will affect the text and localization of the rendered HTML.
1779
+ def oembeds(*args)
1780
+ options = args.extract_options!
1781
+ args.flatten.threaded_map do |id|
1782
+ object_from_response(Twitter::OEmbed, :get, "/1.1/statuses/oembed.json?id=#{id}", options)
1783
+ end
1784
+ end
1785
+
1786
+ # Destroys the specified Tweets
1787
+ #
1788
+ # @see https://dev.twitter.com/docs/api/1.1/post/statuses/destroy/:id
1789
+ # @note The authenticating user must be the author of the specified Tweets.
1790
+ # @rate_limited No
1791
+ # @authentication_required Requires user context
1792
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1793
+ # @return [Array<Twitter::Tweet>] The deleted Tweets.
1794
+ # @overload status_destroy(*ids)
1795
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1796
+ # @example Destroy the Tweet with the ID 25938088801
1797
+ # Twitter.status_destroy(25938088801)
1798
+ # @overload status_destroy(*ids, options)
1799
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1800
+ # @param options [Hash] A customizable set of options.
1801
+ # @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.
1802
+ def status_destroy(*args)
1803
+ threaded_tweets_from_response(:post, "/1.1/statuses/destroy", args)
1804
+ end
1805
+ alias tweet_destroy status_destroy
1806
+
1807
+ # Retweets tweets
1808
+ #
1809
+ # @see https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/:id
1810
+ # @rate_limited Yes
1811
+ # @authentication_required Requires user context
1812
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1813
+ # @return [Array<Twitter::Tweet>] The original tweets with retweet details embedded.
1814
+ # @overload retweet(*ids)
1815
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1816
+ # @example Retweet the Tweet with the ID 28561922516
1817
+ # Twitter.retweet(28561922516)
1818
+ # @overload retweet(*ids, options)
1819
+ # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
1820
+ # @param options [Hash] A customizable set of options.
1821
+ # @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.
1822
+ def retweet(*args)
1823
+ options = args.extract_options!
1824
+ args.flatten.threaded_map do |id|
1825
+ response = post("/1.1/statuses/retweet/#{id}.json", options)
1826
+ retweeted_status = response.dup
1827
+ retweeted_status[:body] = response[:body].delete(:retweeted_status)
1828
+ retweeted_status[:body][:retweeted_status] = response[:body]
1829
+ Twitter::Tweet.from_response(retweeted_status)
1830
+ end
1831
+ end
1832
+
1833
+ # Updates the authenticating user's status
1834
+ #
1835
+ # @see https://dev.twitter.com/docs/api/1.1/post/statuses/update
1836
+ # @note A status update with text identical to the authenticating user's current status will be ignored to prevent duplicates.
1837
+ # @rate_limited No
1838
+ # @authentication_required Requires user context
1839
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1840
+ # @return [Twitter::Tweet] The created Tweet.
1841
+ # @param status [String] The text of your status update, up to 140 characters.
1842
+ # @param options [Hash] A customizable set of options.
1843
+ # @option options [Integer] :in_reply_to_status_id The ID of an existing status that the update is in reply to.
1844
+ # @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.
1845
+ # @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.
1846
+ # @option options [String] :place_id A place in the world. These IDs can be retrieved from {Twitter::API::Geo#reverse_geocode}.
1847
+ # @option options [String] :display_coordinates Whether or not to put a pin on the exact coordinates a tweet has been sent from.
1848
+ # @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.
1849
+ # @example Update the authenticating user's status
1850
+ # Twitter.update("I'm tweeting with @gem!")
1851
+ def update(status, options={})
1852
+ object_from_response(Twitter::Tweet, :post, "/1.1/statuses/update.json", options.merge(:status => status))
1853
+ end
1854
+
1855
+ # Updates the authenticating user's status with media
1856
+ #
1857
+ # @see https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media
1858
+ # @note A status update with text/media identical to the authenticating user's current status will NOT be ignored
1859
+ # @rate_limited No
1860
+ # @authentication_required Requires user context
1861
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1862
+ # @return [Twitter::Tweet] The created Tweet.
1863
+ # @param status [String] The text of your status update, up to 140 characters.
1864
+ # @param media [File, Hash] A File object with your picture (PNG, JPEG or GIF)
1865
+ # @param options [Hash] A customizable set of options.
1866
+ # @option options [Integer] :in_reply_to_status_id The ID of an existing Tweet that the update is in reply to.
1867
+ # @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.
1868
+ # @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.
1869
+ # @option options [String] :place_id A place in the world. These IDs can be retrieved from {Twitter::API::Geo#reverse_geocode}.
1870
+ # @option options [String] :display_coordinates Whether or not to put a pin on the exact coordinates a tweet has been sent from.
1871
+ # @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.
1872
+ # @example Update the authenticating user's status
1873
+ # Twitter.update_with_media("I'm tweeting with @gem!", File.new('my_awesome_pic.jpeg'))
1874
+ def update_with_media(status, media, options={})
1875
+ object_from_response(Twitter::Tweet, :post, "/1.1/statuses/update_with_media.json", options.merge('media[]' => media, 'status' => status))
1876
+ end
1877
+
1878
+ # Returns the top 10 trending topics for a specific WOEID
1879
+ #
1880
+ # @see https://dev.twitter.com/docs/api/1.1/get/trends/place
1881
+ # @rate_limited Yes
1882
+ # @authentication_required Requires user context
1883
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1884
+ # @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::API::Trends#trend_locations}. Global information is available by using 1 as the WOEID.
1885
+ # @param options [Hash] A customizable set of options.
1886
+ # @option options [String] :exclude Setting this equal to 'hashtags' will remove all hashtags from the trends list.
1887
+ # @return [Array<Twitter::Trend>]
1888
+ # @example Return the top 10 trending topics for San Francisco
1889
+ # Twitter.trends(2487956)
1890
+ def trends(id=1, options={})
1891
+ options[:id] = id
1892
+ response = get("/1.1/trends/place.json", options)
1893
+ collection_from_array(Twitter::Trend, response[:body].first[:trends])
1894
+ end
1895
+ alias local_trends trends
1896
+ alias trends_place trends
1897
+
1898
+ # Returns the locations that Twitter has trending topic information for
1899
+ #
1900
+ # @see https://dev.twitter.com/docs/api/1.1/get/trends/available
1901
+ # @rate_limited Yes
1902
+ # @authentication_required Requires user context
1903
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1904
+ # @param options [Hash] A customizable set of options.
1905
+ # @return [Array<Twitter::Place>]
1906
+ # @example Return the locations that Twitter has trending topic information for
1907
+ # Twitter.trends_available
1908
+ def trends_available(options={})
1909
+ collection_from_response(Twitter::Place, :get, "/1.1/trends/available.json", options)
1910
+ end
1911
+ alias trend_locations trends_available
1912
+
1913
+ # Returns the locations that Twitter has trending topic information for, closest to a specified location.
1914
+ #
1915
+ # @see https://dev.twitter.com/docs/api/1.1/get/trends/closest
1916
+ # @rate_limited Yes
1917
+ # @authentication_required Requires user context
1918
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1919
+ # @param options [Hash] A customizable set of options.
1920
+ # @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.
1921
+ # @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.
1922
+ # @return [Array<Twitter::Place>]
1923
+ # @example Return the locations that Twitter has trending topic information for
1924
+ # Twitter.trends_closest
1925
+ def trends_closest(options={})
1926
+ collection_from_response(Twitter::Place, :get, "/1.1/trends/closest.json", options)
1927
+ end
1928
+
1929
+ # Returns an array of user objects that the authenticating user is blocking
1930
+ #
1931
+ # @see https://dev.twitter.com/docs/api/1.1/get/blocks/list
1932
+ # @rate_limited Yes
1933
+ # @authentication_required Requires user context
1934
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1935
+ # @return [Array<Twitter::User>] User objects that the authenticating user is blocking.
1936
+ # @param options [Hash] A customizable set of options.
1937
+ # @option options [Integer] :page Specifies the page of results to retrieve.
1938
+ # @example Return an array of user objects that the authenticating user is blocking
1939
+ # Twitter.blocking
1940
+ def blocking(options={})
1941
+ merge_default_cursor!(options)
1942
+ cursor_from_response(:users, Twitter::User, :get, "/1.1/blocks/list.json", options)
1943
+ end
1944
+
1945
+ # Returns an array of numeric user ids the authenticating user is blocking
1946
+ #
1947
+ # @see https://dev.twitter.com/docs/api/1.1/get/blocks/ids
1948
+ # @rate_limited Yes
1949
+ # @authentication_required Requires user context
1950
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1951
+ # @return [Array] Numeric user ids the authenticating user is blocking.
1952
+ # @param options [Hash] A customizable set of options.
1953
+ # @example Return an array of numeric user ids the authenticating user is blocking
1954
+ # Twitter.blocking_ids
1955
+ def blocked_ids(*args)
1956
+ ids_from_response(:get, "/1.1/blocks/ids.json", args)
1957
+ end
1958
+
1959
+ # Returns true if the authenticating user is blocking a target user
1960
+ #
1961
+ # @see https://dev.twitter.com/docs/api/1.1/get/blocks/ids
1962
+ # @rate_limited Yes
1963
+ # @authentication_required Requires user context
1964
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1965
+ # @return [Boolean] true if the authenticating user is blocking the target user, otherwise false.
1966
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
1967
+ # @param options [Hash] A customizable set of options.
1968
+ # @example Check whether the authenticating user is blocking @sferik
1969
+ # Twitter.block?('sferik')
1970
+ # Twitter.block?(7505382) # Same as above
1971
+ def block?(user, options={})
1972
+ merge_default_cursor!(options)
1973
+ user_id = case user
1974
+ when Integer
1975
+ user
1976
+ when String
1977
+ user(user).id
1978
+ when Twitter::User
1979
+ user.id
1980
+ end
1981
+ blocked_ids(options).all.map(&:to_i).include?(user_id)
1982
+ end
1983
+
1984
+ # Blocks the users specified by the authenticating user
1985
+ #
1986
+ # @see https://dev.twitter.com/docs/api/1.1/post/blocks/create
1987
+ # @note Destroys a friendship to the blocked user if it exists.
1988
+ # @rate_limited Yes
1989
+ # @authentication_required Requires user context
1990
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
1991
+ # @return [Array<Twitter::User>] The blocked users.
1992
+ # @overload block(*users)
1993
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
1994
+ # @example Block and unfriend @sferik as the authenticating user
1995
+ # Twitter.block('sferik')
1996
+ # Twitter.block(7505382) # Same as above
1997
+ # @overload block(*users, options)
1998
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
1999
+ # @param options [Hash] A customizable set of options.
2000
+ def block(*args)
2001
+ threaded_users_from_response(:post, "/1.1/blocks/create.json", args)
2002
+ end
2003
+
2004
+ # Un-blocks the users specified by the authenticating user
2005
+ #
2006
+ # @see https://dev.twitter.com/docs/api/1.1/post/blocks/destroy
2007
+ # @rate_limited No
2008
+ # @authentication_required Requires user context
2009
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2010
+ # @return [Array<Twitter::User>] The un-blocked users.
2011
+ # @overload unblock(*users)
2012
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
2013
+ # @example Un-block @sferik as the authenticating user
2014
+ # Twitter.unblock('sferik')
2015
+ # Twitter.unblock(7505382) # Same as above
2016
+ # @overload unblock(*users, options)
2017
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
2018
+ # @param options [Hash] A customizable set of options.
2019
+ def unblock(*args)
2020
+ threaded_users_from_response(:post, "/1.1/blocks/destroy.json", args)
2021
+ end
2022
+
2023
+ # @return [Array<Twitter::Suggestion>]
2024
+ # @rate_limited Yes
2025
+ # @authentication_required Requires user context
2026
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2027
+ # @overload suggestions(options={})
2028
+ # Returns the list of suggested user categories
2029
+ #
2030
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions
2031
+ # @param options [Hash] A customizable set of options.
2032
+ # @example Return the list of suggested user categories
2033
+ # Twitter.suggestions
2034
+ # @overload suggestions(slug, options={})
2035
+ # Returns the users in a given category
2036
+ #
2037
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions/:slug
2038
+ # @param slug [String] The short name of list or a category.
2039
+ # @param options [Hash] A customizable set of options.
2040
+ # @example Return the users in the Art & Design category
2041
+ # Twitter.suggestions("art-design")
2042
+ def suggestions(*args)
2043
+ options = args.extract_options!
2044
+ if slug = args.pop
2045
+ object_from_response(Twitter::Suggestion, :get, "/1.1/users/suggestions/#{slug}.json", options)
2046
+ else
2047
+ collection_from_response(Twitter::Suggestion, :get, "/1.1/users/suggestions.json", options)
2048
+ end
2049
+ end
2050
+
2051
+ # 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
2052
+ #
2053
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/suggestions/:slug/members
2054
+ # @rate_limited Yes
2055
+ # @authentication_required Requires user context
2056
+ # @param slug [String] The short name of list or a category.
2057
+ # @param options [Hash] A customizable set of options.
2058
+ # @return [Array<Twitter::User>]
2059
+ # @example Return the users in the Art & Design category and their most recent Tweet if they are not a protected user
2060
+ # Twitter.suggest_users("art-design")
2061
+ def suggest_users(slug, options={})
2062
+ collection_from_response(Twitter::User, :get, "/1.1/users/suggestions/#{slug}/members.json", options)
2063
+ end
2064
+
2065
+ # Returns extended information for up to 100 users
2066
+ #
2067
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/lookup
2068
+ # @rate_limited Yes
2069
+ # @authentication_required Requires user context
2070
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2071
+ # @return [Array<Twitter::User>] The requested users.
2072
+ # @overload users(*users)
2073
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
2074
+ # @example Return extended information for @sferik and @pengwynn
2075
+ # Twitter.users('sferik', 'pengwynn')
2076
+ # Twitter.users(7505382, 14100886) # Same as above
2077
+ # @overload users(*users, options)
2078
+ # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
2079
+ # @param options [Hash] A customizable set of options.
2080
+ def users(*args)
2081
+ options = args.extract_options!
2082
+ args.flatten.each_slice(MAX_USERS_PER_REQUEST).threaded_map do |users|
2083
+ collection_from_response(Twitter::User, :post, "/1.1/users/lookup.json", options.merge_users(users))
2084
+ end.flatten
2085
+ end
2086
+
2087
+ # Returns users that match the given query
2088
+ #
2089
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/search
2090
+ # @rate_limited Yes
2091
+ # @authentication_required Requires user context
2092
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2093
+ # @return [Array<Twitter::User>]
2094
+ # @param query [String] The search query to run against people search.
2095
+ # @param options [Hash] A customizable set of options.
2096
+ # @option options [Integer] :count The number of people to retrieve. Maxiumum of 20 allowed per page.
2097
+ # @option options [Integer] :page Specifies the page of results to retrieve.
2098
+ # @example Return users that match "Erik Michaels-Ober"
2099
+ # Twitter.user_search("Erik Michaels-Ober")
2100
+ def user_search(query, options={})
2101
+ collection_from_response(Twitter::User, :get, "/1.1/users/search.json", options.merge(:q => query))
2102
+ end
2103
+
2104
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/show
2105
+ # @rate_limited Yes
2106
+ # @authentication_required Requires user context
2107
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2108
+ # @return [Twitter::User] The requested user.
2109
+ # @overload user(options={})
2110
+ # Returns extended information for the authenticated user
2111
+ #
2112
+ # @param options [Hash] A customizable set of options.
2113
+ # @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1.
2114
+ # @example Return extended information for the authenticated user
2115
+ # Twitter.user
2116
+ # @overload user(user, options={})
2117
+ # Returns extended information for a given user
2118
+ #
2119
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
2120
+ # @param options [Hash] A customizable set of options.
2121
+ # @example Return extended information for @sferik
2122
+ # Twitter.user('sferik')
2123
+ # Twitter.user(7505382) # Same as above
2124
+ def user(*args)
2125
+ options = args.extract_options!
2126
+ if user = args.pop
2127
+ options.merge_user!(user)
2128
+ object_from_response(Twitter::User, :get, "/1.1/users/show.json", options)
2129
+ else
2130
+ verify_credentials(options)
2131
+ end
2132
+ end
2133
+
2134
+ # Returns true if the specified user exists
2135
+ #
2136
+ # @rate_limited Yes
2137
+ # @authentication_required Requires user context
2138
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2139
+ # @return [Boolean] true if the user exists, otherwise false.
2140
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
2141
+ # @example Return true if @sferik exists
2142
+ # Twitter.user?('sferik')
2143
+ # Twitter.user?(7505382) # Same as above
2144
+ def user?(user, options={})
2145
+ options.merge_user!(user)
2146
+ get("/1.1/users/show.json", options)
2147
+ true
2148
+ rescue Twitter::Error::NotFound
2149
+ false
2150
+ end
2151
+
2152
+ # Returns an array of users that the specified user can contribute to
2153
+ #
2154
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/contributees
2155
+ # @rate_limited Yes
2156
+ # @authentication_required Requires user context
2157
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2158
+ # @return [Array<Twitter::User>]
2159
+ # @overload contributees(options={})
2160
+ # @param options [Hash] A customizable set of options.
2161
+ # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
2162
+ # @example Return the authenticated user's contributees
2163
+ # Twitter.contributees
2164
+ # @overload contributees(user, options={})
2165
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
2166
+ # @param options [Hash] A customizable set of options.
2167
+ # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
2168
+ # @example Return users @sferik can contribute to
2169
+ # Twitter.contributees('sferik')
2170
+ # Twitter.contributees(7505382) # Same as above
2171
+ def contributees(*args)
2172
+ users_from_response(:get, "/1.1/users/contributees.json", args)
2173
+ end
2174
+
2175
+ # Returns an array of users who can contribute to the specified account
2176
+ #
2177
+ # @see https://dev.twitter.com/docs/api/1.1/get/users/contributors
2178
+ # @rate_limited Yes
2179
+ # @authentication_required Requires user context
2180
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2181
+ # @return [Array<Twitter::User>]
2182
+ # @overload contributors(options={})
2183
+ # @param options [Hash] A customizable set of options.
2184
+ # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
2185
+ # @example Return the authenticated user's contributors
2186
+ # Twitter.contributors
2187
+ # @overload contributors(user, options={})
2188
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
2189
+ # @param options [Hash] A customizable set of options.
2190
+ # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
2191
+ # @example Return users who can contribute to @sferik's account
2192
+ # Twitter.contributors('sferik')
2193
+ # Twitter.contributors(7505382) # Same as above
2194
+ def contributors(*args)
2195
+ users_from_response(:get, "/1.1/users/contributors.json", args)
2196
+ end
2197
+
2198
+ # @note Undocumented
2199
+ # @rate_limited Yes
2200
+ # @authentication_required Requires user context
2201
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
2202
+ #
2203
+ # @overload following_followers_of(options={})
2204
+ # Returns users following followers of the specified user
2205
+ #
2206
+ # @param options [Hash] A customizable set of options.
2207
+ # @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.
2208
+ # @return [Twitter::Cursor]
2209
+ # @example Return users follow followers of @sferik
2210
+ # Twitter.following_followers_of
2211
+ #
2212
+ # @overload following_followers_of(user, options={})
2213
+ # Returns users following followers of the authenticated user
2214
+ #
2215
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
2216
+ # @param options [Hash] A customizable set of options.
2217
+ # @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.
2218
+ # @return [Twitter::Cursor]
2219
+ # @example Return users follow followers of @sferik
2220
+ # Twitter.following_followers_of('sferik')
2221
+ # Twitter.following_followers_of(7505382) # Same as above
2222
+ def following_followers_of(*args)
2223
+ options = args.extract_options!
2224
+ merge_default_cursor!(options)
2225
+ options.merge_user!(args.pop || screen_name)
2226
+ cursor_from_response(:users, Twitter::User, :get, "/users/following_followers_of.json", options)
2227
+ end
2228
+
2229
+ private
2230
+
2231
+ # @param tweets [Array]
2232
+ # @return [Array]
2233
+ def select_retweets(tweets)
2234
+ tweets.select(&:retweet?)
2235
+ end
2236
+
2237
+ # @param collection [Array]
2238
+ # @param max_id [Integer, NilClass]
2239
+ # @return [Array]
2240
+ def collect_with_max_id(collection=[], max_id=nil, &block)
2241
+ tweets = yield(max_id)
2242
+ return collection if tweets.nil?
2243
+ collection += tweets
2244
+ tweets.empty? ? collection.flatten : collect_with_max_id(collection, tweets.last.id - 1, &block)
2245
+ end
2246
+
2247
+ # @param count [Integer]
2248
+ # @return [Array]
2249
+ def collect_with_count(count, &block)
2250
+ options = {}
2251
+ options[:count] = MAX_TWEETS_PER_REQUEST
2252
+ collect_with_max_id do |max_id|
2253
+ options[:max_id] = max_id unless max_id.nil?
2254
+ if count > 0
2255
+ tweets = yield(options)
2256
+ count -= tweets.length
2257
+ tweets
2258
+ end
2259
+ end.flatten.compact[0...count]
2260
+ end
2261
+
2262
+ # @param klass [Class]
2263
+ # @param array [Array]
2264
+ # @return [Array]
2265
+ def collection_from_array(klass, array)
2266
+ array.map do |element|
2267
+ klass.fetch_or_new(element)
2268
+ end
2269
+ end
2270
+
2271
+ # @param klass [Class]
2272
+ # @param request_method [Symbol]
2273
+ # @param url [String]
2274
+ # @param params [Hash]
2275
+ # @param options [Hash]
2276
+ # @return [Array]
2277
+ def collection_from_response(klass, request_method, url, params={}, options={})
2278
+ collection_from_array(klass, send(request_method.to_sym, url, params, options)[:body])
2279
+ end
2280
+
2281
+ # @param request_method [Symbol]
2282
+ # @param url [String]
2283
+ # @param options [Hash]
2284
+ # @return [Array]
2285
+ def geo_collection_from_response(request_method, url, options)
2286
+ collection_from_array(Twitter::Place, send(request_method.to_sym, url, options)[:body][:result][:places])
2287
+ end
2288
+
2289
+ # @param request_method [Symbol]
2290
+ # @param url [String]
2291
+ # @param options [Hash]
2292
+ # @return [Array]
2293
+ def search_collection_from_response(request_method, url, options)
2294
+ collection_from_array(Twitter::Tweet, send(request_method.to_sym, url, options)[:body][:statuses])
2295
+ end
2296
+
2297
+ # @param klass [Class]
2298
+ # @param request_method [Symbol]
2299
+ # @param url [String]
2300
+ # @param params [Hash]
2301
+ # @param options [Hash]
2302
+ # @return [Object]
2303
+ def object_from_response(klass, request_method, url, params={}, options={})
2304
+ response = send(request_method.to_sym, url, params, options)
2305
+ klass.from_response(response)
2306
+ end
2307
+
2308
+ # @param klass [Class]
2309
+ # @param request_method [Symbol]
2310
+ # @param url [String]
2311
+ # @param args [Array]
2312
+ # @return [Array]
2313
+ def objects_from_response(klass, request_method, url, args)
2314
+ options = args.extract_options!
2315
+ options.merge_user!(args.pop)
2316
+ collection_from_response(klass, request_method, url, options)
2317
+ end
2318
+
2319
+ # @param request_method [Symbol]
2320
+ # @param url [String]
2321
+ # @param args [Array]
2322
+ # @return [Array<Integer>]
2323
+ def ids_from_response(request_method, url, args)
2324
+ options = args.extract_options!
2325
+ merge_default_cursor!(options)
2326
+ options.merge_user!(args.pop)
2327
+ cursor_from_response(:ids, nil, request_method, url, options, {}, calling_method)
2328
+ end
2329
+
2330
+ # @param collection_name [Symbol]
2331
+ # @param klass [Class]
2332
+ # @param request_method [Symbol]
2333
+ # @param url [String]
2334
+ # @param params [Hash]
2335
+ # @param options [Hash]
2336
+ # @return [Twitter::Cursor]
2337
+ def cursor_from_response(collection_name, klass, request_method, url, params={}, options={}, method_name=calling_method)
2338
+ response = send(request_method.to_sym, url, params, options)
2339
+ Twitter::Cursor.from_response(response, collection_name.to_sym, klass, self, method_name, params)
2340
+ end
2341
+
2342
+ # @param request_method [Symbol]
2343
+ # @param url [String]
2344
+ # @param args [Array]
2345
+ # @return [Array<Twitter::User>]
2346
+ def list_from_response(request_method, url, args)
2347
+ options = args.extract_options!
2348
+ options.merge_list!(args.pop)
2349
+ options.merge_owner!(args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
2350
+ object_from_response(Twitter::List, request_method, url, options)
2351
+ end
2352
+
2353
+ # @param request_method [Symbol]
2354
+ # @param url [String]
2355
+ # @param args [Array]
2356
+ # @return [Array<Twitter::List>]
2357
+ def lists_from_response(request_method, url, args)
2358
+ options = args.extract_options!
2359
+ merge_default_cursor!(options)
2360
+ options.merge_user!(args.pop)
2361
+ cursor_from_response(:lists, Twitter::List, request_method, url, options, {}, calling_method)
2362
+ end
2363
+
2364
+ # @param request_method [Symbol]
2365
+ # @param url [String]
2366
+ # @param args [Array]
2367
+ # @return [Array<Twitter::User>]
2368
+ def users_from_response(request_method, url, args)
2369
+ options = args.extract_options!
2370
+ options.merge_user!(args.pop || screen_name)
2371
+ collection_from_response(Twitter::User, request_method, url, options)
2372
+ end
2373
+
2374
+ # @param request_method [Symbol]
2375
+ # @param url [String]
2376
+ # @param args [Array]
2377
+ # @return [Array<Twitter::Tweet>]
2378
+ def threaded_tweets_from_response(request_method, url, args)
2379
+ options = args.extract_options!
2380
+ args.flatten.threaded_map do |id|
2381
+ object_from_response(Twitter::Tweet, request_method, url + "/#{id}.json", options)
2382
+ end
2383
+ end
2384
+
2385
+ # @param request_method [Symbol]
2386
+ # @param url [String]
2387
+ # @param args [Array]
2388
+ # @return [Array<Twitter::User>]
2389
+ def threaded_users_from_response(request_method, url, args)
2390
+ options = args.extract_options!
2391
+ args.flatten.threaded_map do |user|
2392
+ object_from_response(Twitter::User, request_method, url, options.merge_user(user))
2393
+ end
2394
+ end
2395
+
2396
+ def list_users(request_method, url, args)
2397
+ options = args.extract_options!
2398
+ merge_default_cursor!(options)
2399
+ options.merge_list!(args.pop)
2400
+ options.merge_owner!(args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
2401
+ cursor_from_response(:users, Twitter::User, request_method, url, options, {}, calling_method)
2402
+ end
2403
+
2404
+ def list_user?(request_method, url, args)
2405
+ options = args.extract_options!
2406
+ options.merge_user!(args.pop)
2407
+ options.merge_list!(args.pop)
2408
+ options.merge_owner!(args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
2409
+ send(request_method.to_sym, url, options)
2410
+ true
2411
+ rescue Twitter::Error::NotFound, Twitter::Error::Forbidden
2412
+ false
2413
+ end
2414
+
2415
+ def list_modify_member(request_method, url, args)
2416
+ options = args.extract_options!
2417
+ options.merge_user!(args.pop)
2418
+ options.merge_list!(args.pop)
2419
+ options.merge_owner!(args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
2420
+ object_from_response(Twitter::List, request_method, url, options)
2421
+ end
2422
+
2423
+ def list_modify_members(request_method, url, args)
2424
+ options = args.extract_options!
2425
+ members = args.pop
2426
+ options.merge_list!(args.pop)
2427
+ options.merge_owner!(args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
2428
+ members.flatten.each_slice(MAX_USERS_PER_REQUEST).threaded_map do |users|
2429
+ object_from_response(Twitter::List, request_method, url, options.merge_users(users))
2430
+ end.last
2431
+ end
2432
+
2433
+ def merge_default_cursor!(options)
2434
+ options[:cursor] = DEFAULT_CURSOR unless options[:cursor]
2435
+ end
2436
+
2437
+ def screen_name
2438
+ @screen_name ||= verify_credentials.screen_name
2439
+ end
2440
+
2441
+ end
2442
+ end