twitter 4.8.1 → 5.0.0.rc.1

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