twitter 4.8.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. data/CHANGELOG.md +36 -0
  2. data/CONTRIBUTING.md +13 -15
  3. data/LICENSE.md +1 -1
  4. data/README.md +401 -261
  5. data/Rakefile +6 -0
  6. data/lib/twitter/arguments.rb +14 -0
  7. data/lib/twitter/base.rb +109 -89
  8. data/lib/twitter/client.rb +38 -115
  9. data/lib/twitter/configuration.rb +5 -2
  10. data/lib/twitter/core_ext/kernel.rb +5 -1
  11. data/lib/twitter/creatable.rb +7 -4
  12. data/lib/twitter/cursor.rb +57 -45
  13. data/lib/twitter/direct_message.rb +2 -11
  14. data/lib/twitter/entity/uri.rb +14 -0
  15. data/lib/twitter/enumerable.rb +15 -0
  16. data/lib/twitter/error/already_favorited.rb +1 -1
  17. data/lib/twitter/error/already_posted.rb +10 -0
  18. data/lib/twitter/error/already_retweeted.rb +1 -1
  19. data/lib/twitter/error/bad_gateway.rb +2 -3
  20. data/lib/twitter/error/bad_request.rb +2 -2
  21. data/lib/twitter/error/forbidden.rb +2 -2
  22. data/lib/twitter/error/gateway_timeout.rb +2 -3
  23. data/lib/twitter/error/internal_server_error.rb +2 -3
  24. data/lib/twitter/error/not_acceptable.rb +2 -2
  25. data/lib/twitter/error/not_found.rb +2 -2
  26. data/lib/twitter/error/service_unavailable.rb +2 -3
  27. data/lib/twitter/error/too_many_requests.rb +2 -2
  28. data/lib/twitter/error/unauthorized.rb +2 -2
  29. data/lib/twitter/error/unprocessable_entity.rb +2 -2
  30. data/lib/twitter/error.rb +65 -14
  31. data/lib/twitter/factory.rb +13 -12
  32. data/lib/twitter/geo.rb +2 -7
  33. data/lib/twitter/geo_factory.rb +11 -7
  34. data/lib/twitter/geo_results.rb +40 -0
  35. data/lib/twitter/identity.rb +4 -34
  36. data/lib/twitter/list.rb +21 -4
  37. data/lib/twitter/media/photo.rb +6 -4
  38. data/lib/twitter/media_factory.rb +11 -7
  39. data/lib/twitter/null_object.rb +25 -0
  40. data/lib/twitter/oembed.rb +3 -2
  41. data/lib/twitter/place.rb +15 -15
  42. data/lib/twitter/profile_banner.rb +3 -2
  43. data/lib/twitter/rate_limit.rb +4 -17
  44. data/lib/twitter/relationship.rb +2 -19
  45. data/lib/twitter/rest/api/direct_messages.rb +138 -0
  46. data/lib/twitter/rest/api/favorites.rb +115 -0
  47. data/lib/twitter/rest/api/friends_and_followers.rb +287 -0
  48. data/lib/twitter/rest/api/help.rb +58 -0
  49. data/lib/twitter/rest/api/lists.rb +498 -0
  50. data/lib/twitter/rest/api/oauth.rb +62 -0
  51. data/lib/twitter/rest/api/places_and_geo.rb +86 -0
  52. data/lib/twitter/rest/api/saved_searches.rb +93 -0
  53. data/lib/twitter/rest/api/search.rb +37 -0
  54. data/lib/twitter/rest/api/spam_reporting.rb +29 -0
  55. data/lib/twitter/rest/api/suggested_users.rb +51 -0
  56. data/lib/twitter/rest/api/timelines.rb +202 -0
  57. data/lib/twitter/rest/api/trends.rb +58 -0
  58. data/lib/twitter/rest/api/tweets.rb +291 -0
  59. data/lib/twitter/rest/api/undocumented.rb +52 -0
  60. data/lib/twitter/rest/api/users.rb +383 -0
  61. data/lib/twitter/rest/api/utils.rb +246 -0
  62. data/lib/twitter/rest/client.rb +175 -0
  63. data/lib/twitter/rest/request/multipart_with_file.rb +36 -0
  64. data/lib/twitter/rest/response/parse_error_json.rb +15 -0
  65. data/lib/twitter/rest/response/parse_json.rb +31 -0
  66. data/lib/twitter/{response → rest/response}/raise_error.rb +8 -11
  67. data/lib/twitter/search_results.rb +37 -21
  68. data/lib/twitter/settings.rb +1 -6
  69. data/lib/twitter/size.rb +2 -15
  70. data/lib/twitter/streaming/client.rb +89 -0
  71. data/lib/twitter/streaming/connection.rb +22 -0
  72. data/lib/twitter/streaming/event.rb +35 -0
  73. data/lib/twitter/streaming/friend_list.rb +13 -0
  74. data/lib/twitter/streaming/message_parser.rb +18 -0
  75. data/lib/twitter/streaming/response.rb +34 -0
  76. data/lib/twitter/suggestion.rb +5 -8
  77. data/lib/twitter/token.rb +11 -1
  78. data/lib/twitter/trend.rb +4 -8
  79. data/lib/twitter/trend_results.rb +65 -0
  80. data/lib/twitter/tweet.rb +43 -92
  81. data/lib/twitter/user.rb +72 -47
  82. data/lib/twitter/version.rb +4 -4
  83. data/lib/twitter.rb +4 -39
  84. data/spec/fixtures/already_posted.json +1 -0
  85. data/spec/fixtures/ids_list.json +1 -1
  86. data/spec/fixtures/ids_list2.json +1 -1
  87. data/spec/fixtures/request_token.txt +6 -0
  88. data/spec/fixtures/search.json +1 -1
  89. data/spec/fixtures/search_malformed.json +1 -1
  90. data/spec/fixtures/track_streaming.json +3 -0
  91. data/spec/fixtures/track_streaming_user.json +5 -0
  92. data/spec/helper.rb +8 -13
  93. data/spec/twitter/base_spec.rb +13 -103
  94. data/spec/twitter/basic_user_spec.rb +3 -3
  95. data/spec/twitter/configuration_spec.rb +1 -1
  96. data/spec/twitter/cursor_spec.rb +17 -35
  97. data/spec/twitter/direct_message_spec.rb +44 -11
  98. data/spec/twitter/entity/uri_spec.rb +75 -0
  99. data/spec/twitter/error_spec.rb +59 -11
  100. data/spec/twitter/geo/point_spec.rb +6 -6
  101. data/spec/twitter/geo/polygon_spec.rb +5 -5
  102. data/spec/twitter/geo_factory_spec.rb +4 -4
  103. data/spec/twitter/geo_results_spec.rb +35 -0
  104. data/spec/twitter/geo_spec.rb +6 -6
  105. data/spec/twitter/identifiable_spec.rb +5 -26
  106. data/spec/twitter/list_spec.rb +54 -11
  107. data/spec/twitter/media/photo_spec.rb +122 -6
  108. data/spec/twitter/media_factory_spec.rb +3 -3
  109. data/spec/twitter/null_object_spec.rb +27 -0
  110. data/spec/twitter/oembed_spec.rb +69 -45
  111. data/spec/twitter/place_spec.rb +84 -28
  112. data/spec/twitter/profile_banner_spec.rb +1 -1
  113. data/spec/twitter/rate_limit_spec.rb +8 -25
  114. data/spec/twitter/relationship_spec.rb +26 -12
  115. data/spec/twitter/{api → rest/api}/direct_messages_spec.rb +28 -15
  116. data/spec/twitter/{api → rest/api}/favorites_spec.rb +80 -7
  117. data/spec/twitter/{api → rest/api}/friends_and_followers_spec.rb +121 -152
  118. data/spec/twitter/{api → rest/api}/geo_spec.rb +9 -23
  119. data/spec/twitter/{api → rest/api}/help_spec.rb +6 -6
  120. data/spec/twitter/{api → rest/api}/lists_spec.rb +116 -95
  121. data/spec/twitter/{api → rest/api}/oauth_spec.rb +21 -10
  122. data/spec/twitter/{api → rest/api}/saved_searches_spec.rb +13 -13
  123. data/spec/twitter/{api → rest/api}/search_spec.rb +8 -9
  124. data/spec/twitter/{api → rest/api}/spam_reporting_spec.rb +3 -3
  125. data/spec/twitter/{api → rest/api}/suggested_users_spec.rb +5 -5
  126. data/spec/twitter/{api → rest/api}/timelines_spec.rb +9 -9
  127. data/spec/twitter/{api → rest/api}/trends_spec.rb +6 -6
  128. data/spec/twitter/rest/api/tweets_spec.rb +503 -0
  129. data/spec/twitter/{api → rest/api}/undocumented_spec.rb +19 -45
  130. data/spec/twitter/{api → rest/api}/users_spec.rb +64 -39
  131. data/spec/twitter/rest/client_spec.rb +193 -0
  132. data/spec/twitter/saved_search_spec.rb +14 -3
  133. data/spec/twitter/search_results_spec.rb +32 -45
  134. data/spec/twitter/settings_spec.rb +17 -6
  135. data/spec/twitter/size_spec.rb +5 -15
  136. data/spec/twitter/source_user_spec.rb +3 -3
  137. data/spec/twitter/streaming/client_spec.rb +92 -0
  138. data/spec/twitter/streaming/event_spec.rb +45 -0
  139. data/spec/twitter/suggestion_spec.rb +5 -15
  140. data/spec/twitter/target_user_spec.rb +3 -3
  141. data/spec/twitter/token_spec.rb +16 -0
  142. data/spec/twitter/trend_results_spec.rb +89 -0
  143. data/spec/twitter/trend_spec.rb +26 -13
  144. data/spec/twitter/tweet_spec.rb +137 -124
  145. data/spec/twitter/user_spec.rb +139 -80
  146. data/spec/twitter_spec.rb +0 -119
  147. data/twitter.gemspec +12 -6
  148. data.tar.gz.sig +0 -0
  149. metadata +197 -138
  150. metadata.gz.sig +0 -0
  151. data/lib/twitter/action/favorite.rb +0 -19
  152. data/lib/twitter/action/follow.rb +0 -30
  153. data/lib/twitter/action/list_member_added.rb +0 -39
  154. data/lib/twitter/action/mention.rb +0 -46
  155. data/lib/twitter/action/reply.rb +0 -27
  156. data/lib/twitter/action/retweet.rb +0 -27
  157. data/lib/twitter/action/tweet.rb +0 -20
  158. data/lib/twitter/action_factory.rb +0 -22
  159. data/lib/twitter/api/arguments.rb +0 -13
  160. data/lib/twitter/api/direct_messages.rb +0 -148
  161. data/lib/twitter/api/favorites.rb +0 -126
  162. data/lib/twitter/api/friends_and_followers.rb +0 -334
  163. data/lib/twitter/api/help.rb +0 -64
  164. data/lib/twitter/api/lists.rb +0 -618
  165. data/lib/twitter/api/oauth.rb +0 -44
  166. data/lib/twitter/api/places_and_geo.rb +0 -121
  167. data/lib/twitter/api/saved_searches.rb +0 -99
  168. data/lib/twitter/api/search.rb +0 -37
  169. data/lib/twitter/api/spam_reporting.rb +0 -30
  170. data/lib/twitter/api/suggested_users.rb +0 -55
  171. data/lib/twitter/api/timelines.rb +0 -214
  172. data/lib/twitter/api/trends.rb +0 -63
  173. data/lib/twitter/api/tweets.rb +0 -304
  174. data/lib/twitter/api/undocumented.rb +0 -97
  175. data/lib/twitter/api/users.rb +0 -439
  176. data/lib/twitter/api/utils.rb +0 -187
  177. data/lib/twitter/configurable.rb +0 -96
  178. data/lib/twitter/default.rb +0 -102
  179. data/lib/twitter/entity/url.rb +0 -9
  180. data/lib/twitter/error/client_error.rb +0 -35
  181. data/lib/twitter/error/decode_error.rb +0 -9
  182. data/lib/twitter/error/identity_map_key_error.rb +0 -9
  183. data/lib/twitter/error/server_error.rb +0 -28
  184. data/lib/twitter/exceptable.rb +0 -36
  185. data/lib/twitter/identity_map.rb +0 -22
  186. data/lib/twitter/request/multipart_with_file.rb +0 -34
  187. data/lib/twitter/response/parse_json.rb +0 -25
  188. data/spec/fixtures/about_me.json +0 -1
  189. data/spec/fixtures/activity_summary.json +0 -1
  190. data/spec/fixtures/bad_gateway.json +0 -1
  191. data/spec/fixtures/bad_request.json +0 -1
  192. data/spec/fixtures/by_friends.json +0 -1
  193. data/spec/fixtures/end_session.json +0 -1
  194. data/spec/fixtures/forbidden.json +0 -1
  195. data/spec/fixtures/internal_server_error.json +0 -1
  196. data/spec/fixtures/not_acceptable.json +0 -1
  197. data/spec/fixtures/phoenix_search.phoenix +0 -1
  198. data/spec/fixtures/resolve.json +0 -1
  199. data/spec/fixtures/service_unavailable.json +0 -1
  200. data/spec/fixtures/totals.json +0 -1
  201. data/spec/fixtures/trends.json +0 -1
  202. data/spec/fixtures/unauthorized.json +0 -1
  203. data/spec/fixtures/video_facets.json +0 -1
  204. data/spec/twitter/action/favorite_spec.rb +0 -29
  205. data/spec/twitter/action/follow_spec.rb +0 -29
  206. data/spec/twitter/action/list_member_added_spec.rb +0 -41
  207. data/spec/twitter/action/mention_spec.rb +0 -52
  208. data/spec/twitter/action/reply_spec.rb +0 -41
  209. data/spec/twitter/action/retweet_spec.rb +0 -41
  210. data/spec/twitter/action_factory_spec.rb +0 -35
  211. data/spec/twitter/action_spec.rb +0 -16
  212. data/spec/twitter/api/tweets_spec.rb +0 -285
  213. data/spec/twitter/client_spec.rb +0 -223
  214. data/spec/twitter/error/client_error_spec.rb +0 -23
  215. data/spec/twitter/error/server_error_spec.rb +0 -20
@@ -1,334 +0,0 @@
1
- require 'twitter/api/arguments'
2
- require 'twitter/api/utils'
3
- require 'twitter/cursor'
4
- require 'twitter/error/forbidden'
5
- require 'twitter/relationship'
6
- require 'twitter/user'
7
-
8
- module Twitter
9
- module API
10
- module FriendsAndFollowers
11
- include Twitter::API::Utils
12
-
13
- # @see https://dev.twitter.com/docs/api/1.1/get/friends/ids
14
- # @rate_limited Yes
15
- # @authentication Requires user context
16
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
17
- # @return [Twitter::Cursor]
18
- # @overload friend_ids(options={})
19
- # Returns an array of numeric IDs for every user the authenticated user is following
20
- #
21
- # @param options [Hash] A customizable set of options.
22
- # @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.
23
- # @example Return the authenticated user's friends' IDs
24
- # Twitter.friend_ids
25
- # @overload friend_ids(user, options={})
26
- # Returns an array of numeric IDs for every user the specified user is following
27
- #
28
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
29
- # @param options [Hash] A customizable set of options.
30
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
31
- # @example Return @sferik's friends' IDs
32
- # Twitter.friend_ids('sferik')
33
- # Twitter.friend_ids(7505382) # Same as above
34
- def friend_ids(*args)
35
- cursor_from_response_with_user(:ids, nil, :get, "/1.1/friends/ids.json", args, :friend_ids)
36
- end
37
-
38
- # @see https://dev.twitter.com/docs/api/1.1/get/followers/ids
39
- # @rate_limited Yes
40
- # @authentication Requires user context
41
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
42
- # @return [Twitter::Cursor]
43
- # @overload follower_ids(options={})
44
- # Returns an array of numeric IDs for every user following the authenticated user
45
- #
46
- # @param options [Hash] A customizable set of options.
47
- # @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.
48
- # @example Return the authenticated user's followers' IDs
49
- # Twitter.follower_ids
50
- # @overload follower_ids(user, options={})
51
- # Returns an array of numeric IDs for every user following the specified user
52
- #
53
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
54
- # @param options [Hash] A customizable set of options.
55
- # @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.
56
- # @example Return @sferik's followers' IDs
57
- # Twitter.follower_ids('sferik')
58
- # Twitter.follower_ids(7505382) # Same as above
59
- def follower_ids(*args)
60
- cursor_from_response_with_user(:ids, nil, :get, "/1.1/followers/ids.json", args, :follower_ids)
61
- end
62
-
63
- # 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.
64
- #
65
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/lookup
66
- # @rate_limited Yes
67
- # @authentication Requires user context
68
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
69
- # @return [Array<Twitter::User>] The requested users.
70
- # @overload friendships(*users)
71
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
72
- # @example Return extended information for @sferik and @pengwynn
73
- # Twitter.friendships('sferik', 'pengwynn')
74
- # Twitter.friendships('sferik', 14100886) # Same as above
75
- # Twitter.friendships(7505382, 14100886) # Same as above
76
- # @overload friendships(*users, options)
77
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
78
- # @param options [Hash] A customizable set of options.
79
- def friendships(*args)
80
- arguments = Twitter::API::Arguments.new(args)
81
- merge_users!(arguments.options, arguments)
82
- objects_from_response(Twitter::User, :get, "/1.1/friendships/lookup.json", arguments.options)
83
- end
84
-
85
- # Returns an array of numeric IDs for every user who has a pending request to follow the authenticating user
86
- #
87
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/incoming
88
- # @rate_limited Yes
89
- # @authentication Requires user context
90
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
91
- # @return [Twitter::Cursor]
92
- # @param options [Hash] A customizable set of options.
93
- # @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.
94
- # @example Return an array of numeric IDs for every user who has a pending request to follow the authenticating user
95
- # Twitter.friendships_incoming
96
- def friendships_incoming(options={})
97
- cursor_from_response(:ids, nil, :get, "/1.1/friendships/incoming.json", options, :friendships_incoming)
98
- end
99
-
100
- # Returns an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request
101
- #
102
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/outgoing
103
- # @rate_limited Yes
104
- # @authentication Requires user context
105
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
106
- # @return [Twitter::Cursor]
107
- # @param options [Hash] A customizable set of options.
108
- # @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.
109
- # @example Return an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request
110
- # Twitter.friendships_outgoing
111
- def friendships_outgoing(options={})
112
- cursor_from_response(:ids, nil, :get, "/1.1/friendships/outgoing.json", options, :friendships_outgoing)
113
- end
114
-
115
- # Allows the authenticating user to follow the specified users, unless they are already followed
116
- #
117
- # @see https://dev.twitter.com/docs/api/1.1/post/friendships/create
118
- # @rate_limited Yes
119
- # @authentication Requires user context
120
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
121
- # @return [Array<Twitter::User>] The followed users.
122
- # @overload follow(*users)
123
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
124
- # @example Follow @sferik
125
- # Twitter.follow('sferik')
126
- # @overload follow(*users, options)
127
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
128
- # @param options [Hash] A customizable set of options.
129
- # @option options [Boolean] :follow (false) Enable notifications for the target user.
130
- def follow(*args)
131
- arguments = Twitter::API::Arguments.new(args)
132
- # Twitter always turns on notifications if the "follow" option is present, even if it's set to false
133
- # so only send follow if it's true
134
- arguments.options[:follow] = true if !!arguments.options.delete(:follow)
135
- existing_friends = Thread.new do
136
- friend_ids.ids
137
- end
138
- new_friends = Thread.new do
139
- users(args).map(&:id)
140
- end
141
- follow!(new_friends.value - existing_friends.value, arguments.options)
142
- end
143
- alias friendship_create follow
144
-
145
- # Allows the authenticating user to follow the specified users
146
- #
147
- # @see https://dev.twitter.com/docs/api/1.1/post/friendships/create
148
- # @rate_limited No
149
- # @authentication Requires user context
150
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
151
- # @return [Array<Twitter::User>] The followed users.
152
- # @overload follow!(*users)
153
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
154
- # @example Follow @sferik
155
- # Twitter.follow!('sferik')
156
- # @overload follow!(*users, options)
157
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
158
- # @param options [Hash] A customizable set of options.
159
- # @option options [Boolean] :follow (false) Enable notifications for the target user.
160
- def follow!(*args)
161
- arguments = Twitter::API::Arguments.new(args)
162
- # Twitter always turns on notifications if the "follow" option is present, even if it's set to false
163
- # so only send follow if it's true
164
- arguments.options[:follow] = true if !!arguments.options.delete(:follow)
165
- arguments.flatten.threaded_map do |user|
166
- begin
167
- object_from_response(Twitter::User, :post, "/1.1/friendships/create.json", merge_user(arguments.options, user))
168
- rescue Twitter::Error::Forbidden
169
- # This error will be raised if the user doesn't have permission to
170
- # follow list_member, for whatever reason.
171
- end
172
- end.compact
173
- end
174
- alias friendship_create! follow!
175
-
176
- # Allows the authenticating user to unfollow the specified users
177
- #
178
- # @see https://dev.twitter.com/docs/api/1.1/post/friendships/destroy
179
- # @rate_limited No
180
- # @authentication Requires user context
181
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
182
- # @return [Array<Twitter::User>] The unfollowed users.
183
- # @overload unfollow(*users)
184
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
185
- # @example Unfollow @sferik
186
- # Twitter.unfollow('sferik')
187
- # @overload unfollow(*users, options)
188
- # @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
189
- # @param options [Hash] A customizable set of options.
190
- def unfollow(*args)
191
- threaded_user_objects_from_response(:post, "/1.1/friendships/destroy.json", args)
192
- end
193
- alias friendship_destroy unfollow
194
-
195
- # Allows one to enable or disable retweets and device notifications from the specified user.
196
- #
197
- # @see https://dev.twitter.com/docs/api/1.1/post/friendships/update
198
- # @rate_limited No
199
- # @authentication Requires user context
200
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
201
- # @return [Twitter::Relationship]
202
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
203
- # @param options [Hash] A customizable set of options.
204
- # @option options [Boolean] :device Enable/disable device notifications from the target user.
205
- # @option options [Boolean] :retweets Enable/disable retweets from the target user.
206
- # @example Enable rewteets and devise notifications for @sferik
207
- # Twitter.friendship_update('sferik', :device => true, :retweets => true)
208
- def friendship_update(user, options={})
209
- merge_user!(options, user)
210
- object_from_response(Twitter::Relationship, :post, "/1.1/friendships/update.json", options)
211
- end
212
-
213
- # Returns detailed information about the relationship between two users
214
- #
215
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/show
216
- # @rate_limited Yes
217
- # @authentication Requires user context
218
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
219
- # @return [Twitter::Relationship]
220
- # @param source [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the source user.
221
- # @param target [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the target user.
222
- # @param options [Hash] A customizable set of options.
223
- # @example Return the relationship between @sferik and @pengwynn
224
- # Twitter.friendship('sferik', 'pengwynn')
225
- # Twitter.friendship('sferik', 14100886) # Same as above
226
- # Twitter.friendship(7505382, 14100886) # Same as above
227
- def friendship(source, target, options={})
228
- merge_user!(options, source, "source")
229
- options[:source_id] = options.delete(:source_user_id) unless options[:source_user_id].nil?
230
- merge_user!(options, target, "target")
231
- options[:target_id] = options.delete(:target_user_id) unless options[:target_user_id].nil?
232
- object_from_response(Twitter::Relationship, :get, "/1.1/friendships/show.json", options)
233
- end
234
- alias friendship_show friendship
235
- alias relationship friendship
236
-
237
- # Test for the existence of friendship between two users
238
- #
239
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/show
240
- # @rate_limited Yes
241
- # @authentication Requires user context
242
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
243
- # @return [Boolean] true if user_a follows user_b, otherwise false.
244
- # @param source [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the source user.
245
- # @param target [Integer, String, Twitter::User] The Twitter user ID, screen name, or object of the target user.
246
- # @param options [Hash] A customizable set of options.
247
- # @example Return true if @sferik follows @pengwynn
248
- # Twitter.friendship?('sferik', 'pengwynn')
249
- # Twitter.friendship?('sferik', 14100886) # Same as above
250
- # Twitter.friendship?(7505382, 14100886) # Same as above
251
- def friendship?(source, target, options={})
252
- friendship(source, target, options).source.following?
253
- end
254
-
255
- # Returns a cursored collection of user objects for users following the specified user.
256
- #
257
- # @see https://dev.twitter.com/docs/api/1.1/get/followers/list
258
- # @rate_limited Yes
259
- # @authentication Requires user context
260
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
261
- # @return [Twitter::Cursor]
262
- # @overload followers(options={})
263
- # Returns a cursored collection of user objects for users following the authenticated user.
264
- #
265
- # @param options [Hash] A customizable set of options.
266
- # @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.
267
- # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
268
- # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false.
269
- # @example Return the authenticated user's friends' IDs
270
- # Twitter.followers
271
- # @overload followers(user, options={})
272
- # Returns a cursored collection of user objects for users following the specified user.
273
- #
274
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
275
- # @param options [Hash] A customizable set of options.
276
- # @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.
277
- # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
278
- # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false.
279
- # @example Return the cursored collection of users following @sferik
280
- # Twitter.followers('sferik')
281
- # Twitter.followers(7505382) # Same as above
282
- def followers(*args)
283
- cursor_from_response_with_user(:users, Twitter::User, :get, "/1.1/followers/list.json", args, :followers)
284
- end
285
-
286
- # Returns a cursored collection of user objects for every user the specified user is following (otherwise known as their "friends").
287
- #
288
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/show
289
- # @rate_limited Yes
290
- # @authentication Requires user context
291
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
292
- # @return [Twitter::Cursor]
293
- # @overload friends(options={})
294
- # Returns a cursored collection of user objects for every user the authenticated user is following (otherwise known as their "friends").
295
- #
296
- # @param options [Hash] A customizable set of options.
297
- # @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.
298
- # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
299
- # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false.
300
- # @example Return the authenticated user's friends' IDs
301
- # Twitter.friends
302
- # @overload friends(user, options={})
303
- # Returns a cursored collection of user objects for every user the specified user is following (otherwise known as their "friends").
304
- #
305
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
306
- # @param options [Hash] A customizable set of options.
307
- # @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.
308
- # @option options [Boolean, String, Integer] :skip_status Do not include contributee's Tweets when set to true, 't' or 1.
309
- # @option options [Boolean, String, Integer] :include_user_entities The user entities node will be disincluded when set to false.
310
- # @example Return the cursored collection of users @sferik is following
311
- # Twitter.friends('sferik')
312
- # Twitter.friends(7505382) # Same as above
313
- def friends(*args)
314
- cursor_from_response_with_user(:users, Twitter::User, :get, "/1.1/friends/list.json", args, :friends)
315
- end
316
- alias following friends
317
-
318
- # Returns a collection of user IDs that the currently authenticated user does not want to receive retweets from.
319
- # @see https://dev.twitter.com/docs/api/1.1/get/friendships/no_retweets/ids
320
- # @rate_limited Yes
321
- # @authentication Requires user context
322
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
323
- # @return [Array<Integer>]
324
- # @param options [Hash] A customizable set of options.
325
- # @example Return a collection of user IDs that the currently authenticated user does not want to receive retweets from
326
- # Twitter.no_retweet_ids
327
- def no_retweet_ids(options={})
328
- get("/1.1/friendships/no_retweets/ids.json", options)[:body].map(&:to_i)
329
- end
330
- alias no_retweets_ids no_retweet_ids
331
-
332
- end
333
- end
334
- end
@@ -1,64 +0,0 @@
1
- require 'twitter/api/utils'
2
- require 'twitter/configuration'
3
- require 'twitter/language'
4
-
5
- module Twitter
6
- module API
7
- module Help
8
- include Twitter::API::Utils
9
-
10
- # Returns the current configuration used by Twitter
11
- #
12
- # @see https://dev.twitter.com/docs/api/1.1/get/help/configuration
13
- # @rate_limited Yes
14
- # @authentication Requires user context
15
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
16
- # @return [Twitter::Configuration] Twitter's configuration.
17
- # @example Return the current configuration used by Twitter
18
- # Twitter.configuration
19
- def configuration(options={})
20
- object_from_response(Twitter::Configuration, :get, "/1.1/help/configuration.json", options)
21
- end
22
-
23
- # Returns the list of languages supported by Twitter
24
- #
25
- # @see https://dev.twitter.com/docs/api/1.1/get/help/languages
26
- # @rate_limited Yes
27
- # @authentication Requires user context
28
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
29
- # @return [Array<Twitter::Language>]
30
- # @example Return the list of languages Twitter supports
31
- # Twitter.languages
32
- def languages(options={})
33
- objects_from_response(Twitter::Language, :get, "/1.1/help/languages.json", options)
34
- end
35
-
36
- # Returns {https://twitter.com/privacy Twitter's Privacy Policy}
37
- #
38
- # @see https://dev.twitter.com/docs/api/1.1/get/help/privacy
39
- # @rate_limited Yes
40
- # @authentication Requires user context
41
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
42
- # @return [String]
43
- # @example Return {https://twitter.com/privacy Twitter's Privacy Policy}
44
- # Twitter.privacy
45
- def privacy(options={})
46
- get("/1.1/help/privacy.json", options)[:body][:privacy]
47
- end
48
-
49
- # Returns {https://twitter.com/tos Twitter's Terms of Service}
50
- #
51
- # @see https://dev.twitter.com/docs/api/1.1/get/help/tos
52
- # @rate_limited Yes
53
- # @authentication Requires user context
54
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
55
- # @return [String]
56
- # @example Return {https://twitter.com/tos Twitter's Terms of Service}
57
- # Twitter.tos
58
- def tos(options={})
59
- get("/1.1/help/tos.json", options)[:body][:tos]
60
- end
61
-
62
- end
63
- end
64
- end