twitter 4.8.1 → 5.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG.md +30 -0
  3. data/LICENSE.md +1 -1
  4. data/README.md +386 -266
  5. data/lib/twitter.rb +4 -39
  6. data/lib/twitter/arguments.rb +11 -0
  7. data/lib/twitter/base.rb +89 -68
  8. data/lib/twitter/client.rb +69 -110
  9. data/lib/twitter/configuration.rb +7 -3
  10. data/lib/twitter/creatable.rb +2 -4
  11. data/lib/twitter/cursor.rb +50 -42
  12. data/lib/twitter/direct_message.rb +2 -11
  13. data/lib/twitter/entity/uri.rb +13 -0
  14. data/lib/twitter/enumerable.rb +15 -0
  15. data/lib/twitter/error.rb +55 -7
  16. data/lib/twitter/error/already_favorited.rb +1 -1
  17. data/lib/twitter/error/already_posted.rb +10 -0
  18. data/lib/twitter/error/already_retweeted.rb +1 -1
  19. data/lib/twitter/error/bad_gateway.rb +2 -3
  20. data/lib/twitter/error/bad_request.rb +2 -2
  21. data/lib/twitter/error/forbidden.rb +2 -2
  22. data/lib/twitter/error/gateway_timeout.rb +2 -3
  23. data/lib/twitter/error/internal_server_error.rb +2 -3
  24. data/lib/twitter/error/not_acceptable.rb +2 -2
  25. data/lib/twitter/error/not_found.rb +2 -2
  26. data/lib/twitter/error/service_unavailable.rb +2 -3
  27. data/lib/twitter/error/too_many_requests.rb +2 -2
  28. data/lib/twitter/error/unauthorized.rb +2 -2
  29. data/lib/twitter/error/unprocessable_entity.rb +2 -2
  30. data/lib/twitter/factory.rb +2 -8
  31. data/lib/twitter/geo_factory.rb +2 -2
  32. data/lib/twitter/geo_results.rb +36 -0
  33. data/lib/twitter/identity.rb +0 -22
  34. data/lib/twitter/list.rb +18 -4
  35. data/lib/twitter/media/photo.rb +3 -3
  36. data/lib/twitter/media_factory.rb +2 -2
  37. data/lib/twitter/null_object.rb +24 -0
  38. data/lib/twitter/oembed.rb +3 -2
  39. data/lib/twitter/place.rb +15 -9
  40. data/lib/twitter/profile_banner.rb +5 -3
  41. data/lib/twitter/rate_limit.rb +1 -17
  42. data/lib/twitter/relationship.rb +2 -10
  43. data/lib/twitter/rest/api/direct_messages.rb +135 -0
  44. data/lib/twitter/rest/api/favorites.rb +120 -0
  45. data/lib/twitter/rest/api/friends_and_followers.rb +290 -0
  46. data/lib/twitter/rest/api/help.rb +58 -0
  47. data/lib/twitter/rest/api/lists.rb +491 -0
  48. data/lib/twitter/rest/api/oauth.rb +45 -0
  49. data/lib/twitter/rest/api/places_and_geo.rb +104 -0
  50. data/lib/twitter/rest/api/saved_searches.rb +91 -0
  51. data/lib/twitter/rest/api/search.rb +37 -0
  52. data/lib/twitter/rest/api/spam_reporting.rb +29 -0
  53. data/lib/twitter/rest/api/suggested_users.rb +51 -0
  54. data/lib/twitter/rest/api/timelines.rb +202 -0
  55. data/lib/twitter/rest/api/trends.rb +58 -0
  56. data/lib/twitter/rest/api/tweets.rb +293 -0
  57. data/lib/twitter/rest/api/undocumented.rb +52 -0
  58. data/lib/twitter/rest/api/users.rb +383 -0
  59. data/lib/twitter/rest/api/utils.rb +219 -0
  60. data/lib/twitter/rest/client.rb +193 -0
  61. data/lib/twitter/rest/request/multipart_with_file.rb +36 -0
  62. data/lib/twitter/rest/response/parse_json.rb +27 -0
  63. data/lib/twitter/{response → rest/response}/raise_error.rb +8 -11
  64. data/lib/twitter/search_results.rb +33 -21
  65. data/lib/twitter/settings.rb +1 -6
  66. data/lib/twitter/size.rb +1 -1
  67. data/lib/twitter/streaming/client.rb +77 -0
  68. data/lib/twitter/streaming/connection.rb +22 -0
  69. data/lib/twitter/streaming/response.rb +30 -0
  70. data/lib/twitter/suggestion.rb +4 -2
  71. data/lib/twitter/token.rb +8 -0
  72. data/lib/twitter/trend.rb +2 -1
  73. data/lib/twitter/trend_results.rb +59 -0
  74. data/lib/twitter/tweet.rb +41 -85
  75. data/lib/twitter/user.rb +51 -41
  76. data/lib/twitter/version.rb +4 -4
  77. data/spec/fixtures/already_posted.json +1 -0
  78. data/spec/fixtures/ids_list.json +1 -1
  79. data/spec/fixtures/ids_list2.json +1 -1
  80. data/spec/fixtures/search.json +1 -1
  81. data/spec/fixtures/search_malformed.json +1 -1
  82. data/spec/fixtures/track_streaming.json +3 -0
  83. data/spec/helper.rb +8 -13
  84. data/spec/twitter/base_spec.rb +25 -99
  85. data/spec/twitter/configuration_spec.rb +1 -1
  86. data/spec/twitter/cursor_spec.rb +13 -31
  87. data/spec/twitter/direct_message_spec.rb +41 -8
  88. data/spec/twitter/entity/uri_spec.rb +74 -0
  89. data/spec/twitter/error_spec.rb +59 -11
  90. data/spec/twitter/geo/point_spec.rb +1 -1
  91. data/spec/twitter/geo_factory_spec.rb +3 -3
  92. data/spec/twitter/geo_results_spec.rb +35 -0
  93. data/spec/twitter/identifiable_spec.rb +0 -21
  94. data/spec/twitter/list_spec.rb +51 -8
  95. data/spec/twitter/media/photo_spec.rb +118 -3
  96. data/spec/twitter/media_factory_spec.rb +2 -2
  97. data/spec/twitter/null_object_spec.rb +26 -0
  98. data/spec/twitter/oembed_spec.rb +69 -45
  99. data/spec/twitter/place_spec.rb +68 -12
  100. data/spec/twitter/profile_banner_spec.rb +1 -1
  101. data/spec/twitter/rate_limit_spec.rb +12 -12
  102. data/spec/twitter/relationship_spec.rb +31 -9
  103. data/spec/twitter/{api → rest/api}/direct_messages_spec.rb +22 -9
  104. data/spec/twitter/{api → rest/api}/favorites_spec.rb +80 -7
  105. data/spec/twitter/{api → rest/api}/friends_and_followers_spec.rb +104 -65
  106. data/spec/twitter/{api → rest/api}/geo_spec.rb +10 -10
  107. data/spec/twitter/{api → rest/api}/help_spec.rb +6 -6
  108. data/spec/twitter/{api → rest/api}/lists_spec.rb +77 -56
  109. data/spec/twitter/{api → rest/api}/oauth_spec.rb +6 -6
  110. data/spec/twitter/{api → rest/api}/saved_searches_spec.rb +7 -7
  111. data/spec/twitter/{api → rest/api}/search_spec.rb +8 -9
  112. data/spec/twitter/{api → rest/api}/spam_reporting_spec.rb +3 -3
  113. data/spec/twitter/{api → rest/api}/suggested_users_spec.rb +5 -5
  114. data/spec/twitter/{api → rest/api}/timelines_spec.rb +9 -9
  115. data/spec/twitter/{api → rest/api}/trends_spec.rb +6 -6
  116. data/spec/twitter/rest/api/tweets_spec.rb +503 -0
  117. data/spec/twitter/{api → rest/api}/undocumented_spec.rb +19 -45
  118. data/spec/twitter/{api → rest/api}/users_spec.rb +60 -35
  119. data/spec/twitter/rest/client_spec.rb +193 -0
  120. data/spec/twitter/saved_search_spec.rb +11 -0
  121. data/spec/twitter/search_results_spec.rb +29 -42
  122. data/spec/twitter/settings_spec.rb +17 -6
  123. data/spec/twitter/streaming/client_spec.rb +75 -0
  124. data/spec/twitter/token_spec.rb +16 -0
  125. data/spec/twitter/trend_results_spec.rb +89 -0
  126. data/spec/twitter/trend_spec.rb +23 -0
  127. data/spec/twitter/tweet_spec.rb +122 -115
  128. data/spec/twitter/user_spec.rb +136 -77
  129. data/spec/twitter_spec.rb +0 -119
  130. data/twitter.gemspec +8 -5
  131. metadata +148 -141
  132. metadata.gz.sig +0 -0
  133. data/lib/twitter/action/favorite.rb +0 -19
  134. data/lib/twitter/action/follow.rb +0 -30
  135. data/lib/twitter/action/list_member_added.rb +0 -39
  136. data/lib/twitter/action/mention.rb +0 -46
  137. data/lib/twitter/action/reply.rb +0 -27
  138. data/lib/twitter/action/retweet.rb +0 -27
  139. data/lib/twitter/action/tweet.rb +0 -20
  140. data/lib/twitter/action_factory.rb +0 -22
  141. data/lib/twitter/api/arguments.rb +0 -13
  142. data/lib/twitter/api/direct_messages.rb +0 -148
  143. data/lib/twitter/api/favorites.rb +0 -126
  144. data/lib/twitter/api/friends_and_followers.rb +0 -334
  145. data/lib/twitter/api/help.rb +0 -64
  146. data/lib/twitter/api/lists.rb +0 -618
  147. data/lib/twitter/api/oauth.rb +0 -44
  148. data/lib/twitter/api/places_and_geo.rb +0 -121
  149. data/lib/twitter/api/saved_searches.rb +0 -99
  150. data/lib/twitter/api/search.rb +0 -37
  151. data/lib/twitter/api/spam_reporting.rb +0 -30
  152. data/lib/twitter/api/suggested_users.rb +0 -55
  153. data/lib/twitter/api/timelines.rb +0 -214
  154. data/lib/twitter/api/trends.rb +0 -63
  155. data/lib/twitter/api/tweets.rb +0 -304
  156. data/lib/twitter/api/undocumented.rb +0 -97
  157. data/lib/twitter/api/users.rb +0 -439
  158. data/lib/twitter/api/utils.rb +0 -187
  159. data/lib/twitter/configurable.rb +0 -96
  160. data/lib/twitter/default.rb +0 -102
  161. data/lib/twitter/entity/url.rb +0 -9
  162. data/lib/twitter/error/client_error.rb +0 -35
  163. data/lib/twitter/error/decode_error.rb +0 -9
  164. data/lib/twitter/error/identity_map_key_error.rb +0 -9
  165. data/lib/twitter/error/server_error.rb +0 -28
  166. data/lib/twitter/exceptable.rb +0 -36
  167. data/lib/twitter/identity_map.rb +0 -22
  168. data/lib/twitter/request/multipart_with_file.rb +0 -34
  169. data/lib/twitter/response/parse_json.rb +0 -25
  170. data/spec/fixtures/about_me.json +0 -1
  171. data/spec/fixtures/activity_summary.json +0 -1
  172. data/spec/fixtures/bad_gateway.json +0 -1
  173. data/spec/fixtures/bad_request.json +0 -1
  174. data/spec/fixtures/by_friends.json +0 -1
  175. data/spec/fixtures/end_session.json +0 -1
  176. data/spec/fixtures/forbidden.json +0 -1
  177. data/spec/fixtures/internal_server_error.json +0 -1
  178. data/spec/fixtures/not_acceptable.json +0 -1
  179. data/spec/fixtures/phoenix_search.phoenix +0 -1
  180. data/spec/fixtures/resolve.json +0 -1
  181. data/spec/fixtures/service_unavailable.json +0 -1
  182. data/spec/fixtures/totals.json +0 -1
  183. data/spec/fixtures/trends.json +0 -1
  184. data/spec/fixtures/unauthorized.json +0 -1
  185. data/spec/fixtures/video_facets.json +0 -1
  186. data/spec/twitter/action/favorite_spec.rb +0 -29
  187. data/spec/twitter/action/follow_spec.rb +0 -29
  188. data/spec/twitter/action/list_member_added_spec.rb +0 -41
  189. data/spec/twitter/action/mention_spec.rb +0 -52
  190. data/spec/twitter/action/reply_spec.rb +0 -41
  191. data/spec/twitter/action/retweet_spec.rb +0 -41
  192. data/spec/twitter/action_factory_spec.rb +0 -35
  193. data/spec/twitter/action_spec.rb +0 -16
  194. data/spec/twitter/api/tweets_spec.rb +0 -285
  195. data/spec/twitter/client_spec.rb +0 -223
  196. data/spec/twitter/error/client_error_spec.rb +0 -23
  197. data/spec/twitter/error/server_error_spec.rb +0 -20
metadata.gz.sig CHANGED
Binary file
@@ -1,19 +0,0 @@
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
@@ -1,30 +0,0 @@
1
- require 'twitter/base'
2
- require 'twitter/creatable'
3
-
4
- module Twitter
5
- module Action
6
- class Follow < Twitter::Base
7
- include Twitter::Creatable
8
- attr_reader :max_position, :min_position, :target_objects
9
-
10
- # A collection of users who followed a user
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
- # A collection containing the followed user
20
- #
21
- # @return [Array<Twitter::User>]
22
- def targets
23
- @targets = Array(@attrs[:targets]).map do |user|
24
- Twitter::User.fetch_or_new(user)
25
- end
26
- end
27
-
28
- end
29
- end
30
- end
@@ -1,39 +0,0 @@
1
- require 'twitter/base'
2
- require 'twitter/creatable'
3
-
4
- module Twitter
5
- module Action
6
- class ListMemberAdded < Twitter::Base
7
- include Twitter::Creatable
8
- attr_reader :max_position, :min_position
9
-
10
- # A collection of users who added a user to a list
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
- # A collection of lists that were added to
20
- #
21
- # @return [Array<Twitter::List>]
22
- def target_objects
23
- @target_objects = Array(@attrs[:target_objects]).map do |list|
24
- Twitter::List.fetch_or_new(list)
25
- end
26
- end
27
-
28
- # A collection of users who were added to a list
29
- #
30
- # @return [Array<Twitter::User>]
31
- def targets
32
- @targets = Array(@attrs[:targets]).map do |user|
33
- Twitter::User.fetch_or_new(user)
34
- end
35
- end
36
-
37
- end
38
- end
39
- end
@@ -1,46 +0,0 @@
1
- require 'twitter/base'
2
- require 'twitter/creatable'
3
-
4
- module Twitter
5
- module Action
6
- class Mention < Twitter::Base
7
- include Twitter::Creatable
8
- attr_reader :max_position, :min_position
9
-
10
- # A collection of users who mentioned a user
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
- # The user who mentioned a user
20
- #
21
- # @return [Twitter::User]
22
- def source
23
- @source = sources.first
24
- end
25
-
26
- # A collection of tweets that mention a user
27
- #
28
- # @return [Array<Twitter::Tweet>]
29
- def target_objects
30
- @target_objects = Array(@attrs[:target_objects]).map do |tweet|
31
- Twitter::Tweet.fetch_or_new(tweet)
32
- end
33
- end
34
-
35
- # A collection containing the mentioned user
36
- #
37
- # @return [Array<Twitter::User>]
38
- def targets
39
- @targets = Array(@attrs[:targets]).map do |user|
40
- Twitter::User.fetch_or_new(user)
41
- end
42
- end
43
-
44
- end
45
- end
46
- end
@@ -1,27 +0,0 @@
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
@@ -1,27 +0,0 @@
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
@@ -1,20 +0,0 @@
1
- require 'twitter/base'
2
- require 'twitter/creatable'
3
-
4
- module Twitter
5
- module Action
6
- class Tweet < Twitter::Base
7
- include Twitter::Creatable
8
- attr_reader :max_position, :min_position
9
-
10
- # @return [Array<Twitter::User>]
11
- def sources
12
- @sources = Array(@attrs[:sources]).map do |user|
13
- Twitter::User.fetch_or_new(user)
14
- end
15
- end
16
-
17
- end
18
- Status = Tweet
19
- end
20
- end
@@ -1,22 +0,0 @@
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
@@ -1,13 +0,0 @@
1
- module Twitter
2
- module API
3
- class Arguments < Array
4
- attr_reader :options
5
-
6
- def initialize(args)
7
- @options = args.last.is_a?(::Hash) ? args.pop : {}
8
- super(args)
9
- end
10
-
11
- end
12
- end
13
- end
@@ -1,148 +0,0 @@
1
- require 'twitter/api/arguments'
2
- require 'twitter/api/utils'
3
- require 'twitter/direct_message'
4
- require 'twitter/user'
5
-
6
- module Twitter
7
- module API
8
- module DirectMessages
9
- include Twitter::API::Utils
10
-
11
- # Returns the 20 most recent direct messages sent to the authenticating user
12
- #
13
- # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages
14
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
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::DirectMessage>] Direct messages sent to the authenticating user.
19
- # @param options [Hash] A customizable set of options.
20
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
21
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
22
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
23
- # @option options [Integer] :page Specifies the page of results to retrieve.
24
- # @example Return the 20 most recent direct messages sent to the authenticating user
25
- # Twitter.direct_messages_received
26
- def direct_messages_received(options={})
27
- objects_from_response(Twitter::DirectMessage, :get, "/1.1/direct_messages.json", options)
28
- end
29
-
30
- # Returns the 20 most recent direct messages sent by the authenticating user
31
- #
32
- # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/sent
33
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
34
- # @rate_limited Yes
35
- # @authentication Requires user context
36
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
37
- # @return [Array<Twitter::DirectMessage>] Direct messages sent by the authenticating user.
38
- # @param options [Hash] A customizable set of options.
39
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
40
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
41
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
42
- # @option options [Integer] :page Specifies the page of results to retrieve.
43
- # @example Return the 20 most recent direct messages sent by the authenticating user
44
- # Twitter.direct_messages_sent
45
- def direct_messages_sent(options={})
46
- objects_from_response(Twitter::DirectMessage, :get, "/1.1/direct_messages/sent.json", options)
47
- end
48
-
49
- # Returns a direct message
50
- #
51
- # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show
52
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
53
- # @rate_limited Yes
54
- # @authentication Requires user context
55
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
56
- # @return [Twitter::DirectMessage] The requested messages.
57
- # @param id [Integer] A Tweet IDs.
58
- # @param options [Hash] A customizable set of options.
59
- # @example Return the direct message with the id 1825786345
60
- # Twitter.direct_message(1825786345)
61
- def direct_message(id, options={})
62
- options[:id] = id
63
- object_from_response(Twitter::DirectMessage, :get, "/1.1/direct_messages/show.json", options)
64
- end
65
-
66
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
67
- # @rate_limited Yes
68
- # @authentication Requires user context
69
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
70
- # @return [Array<Twitter::DirectMessage>] The requested messages.
71
- # @overload direct_messages(options={})
72
- # Returns the 20 most recent direct messages sent to the authenticating user
73
- #
74
- # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages
75
- # @param options [Hash] A customizable set of options.
76
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
77
- # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
78
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
79
- # @option options [Integer] :page Specifies the page of results to retrieve.
80
- # @example Return the 20 most recent direct messages sent to the authenticating user
81
- # Twitter.direct_messages
82
- # @overload direct_messages(*ids)
83
- # Returns direct messages
84
- #
85
- # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show
86
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
87
- # @example Return the direct message with the id 1825786345
88
- # Twitter.direct_messages(1825786345)
89
- # @overload direct_messages(*ids, options)
90
- # Returns direct messages
91
- #
92
- # @see https://dev.twitter.com/docs/api/1.1/get/direct_messages/show
93
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
94
- # @param options [Hash] A customizable set of options.
95
- def direct_messages(*args)
96
- arguments = Twitter::API::Arguments.new(args)
97
- if arguments.empty?
98
- direct_messages_received(arguments.options)
99
- else
100
- arguments.flatten.threaded_map do |id|
101
- direct_message(id, arguments.options)
102
- end
103
- end
104
- end
105
-
106
- # Destroys direct messages
107
- #
108
- # @see https://dev.twitter.com/docs/api/1.1/post/direct_messages/destroy
109
- # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
110
- # @rate_limited No
111
- # @authentication Requires user context
112
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
113
- # @return [Array<Twitter::DirectMessage>] Deleted direct message.
114
- # @overload direct_message_destroy(*ids)
115
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
116
- # @example Destroys the direct message with the ID 1825785544
117
- # Twitter.direct_message_destroy(1825785544)
118
- # @overload direct_message_destroy(*ids, options)
119
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
120
- # @param options [Hash] A customizable set of options.
121
- def direct_message_destroy(*args)
122
- threaded_object_from_response(Twitter::DirectMessage, :post, "/1.1/direct_messages/destroy.json", args)
123
- end
124
-
125
- # Sends a new direct message to the specified user from the authenticating user
126
- #
127
- # @see https://dev.twitter.com/docs/api/1.1/post/direct_messages/new
128
- # @rate_limited No
129
- # @authentication Requires user context
130
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
131
- # @return [Twitter::DirectMessage] The sent message.
132
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
133
- # @param text [String] The text of your direct message, up to 140 characters.
134
- # @param options [Hash] A customizable set of options.
135
- # @example Send a direct message to @sferik from the authenticating user
136
- # Twitter.direct_message_create('sferik', "I'm sending you this message via @gem!")
137
- # Twitter.direct_message_create(7505382, "I'm sending you this message via @gem!") # Same as above
138
- def direct_message_create(user, text, options={})
139
- merge_user!(options, user)
140
- options[:text] = text
141
- object_from_response(Twitter::DirectMessage, :post, "/1.1/direct_messages/new.json", options)
142
- end
143
- alias d direct_message_create
144
- alias m direct_message_create
145
-
146
- end
147
- end
148
- end
@@ -1,126 +0,0 @@
1
- require 'twitter/api/arguments'
2
- require 'twitter/api/utils'
3
- require 'twitter/error/already_favorited'
4
- require 'twitter/error/forbidden'
5
- require 'twitter/tweet'
6
- require 'twitter/user'
7
-
8
- module Twitter
9
- module API
10
- module Favorites
11
- include Twitter::API::Utils
12
-
13
- # @see https://dev.twitter.com/docs/api/1.1/get/favorites/list
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 [Array<Twitter::Tweet>] favorite Tweets.
18
- # @overload favorites(options={})
19
- # Returns the 20 most recent favorite Tweets for the authenticating user
20
- #
21
- # @param options [Hash] A customizable set of options.
22
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
23
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
24
- # @example Return the 20 most recent favorite Tweets for the authenticating user
25
- # Twitter.favorites
26
- # @overload favorites(user, options={})
27
- # Returns the 20 most recent favorite Tweets for the specified user
28
- #
29
- # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
30
- # @param options [Hash] A customizable set of options.
31
- # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
32
- # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
33
- # @example Return the 20 most recent favorite Tweets for @sferik
34
- # Twitter.favorites('sferik')
35
- def favorites(*args)
36
- arguments = Twitter::API::Arguments.new(args)
37
- if user = arguments.pop
38
- merge_user!(arguments.options, user)
39
- end
40
- objects_from_response(Twitter::Tweet, :get, "/1.1/favorites/list.json", arguments.options)
41
- end
42
- alias favourites favorites
43
-
44
- # Un-favorites the specified Tweets as the authenticating user
45
- #
46
- # @see https://dev.twitter.com/docs/api/1.1/post/favorites/destroy
47
- # @rate_limited No
48
- # @authentication Requires user context
49
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
50
- # @return [Array<Twitter::Tweet>] The un-favorited Tweets.
51
- # @overload unfavorite(*ids)
52
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
53
- # @example Un-favorite the tweet with the ID 25938088801
54
- # Twitter.unfavorite(25938088801)
55
- # @overload unfavorite(*ids, options)
56
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
57
- # @param options [Hash] A customizable set of options.
58
- def unfavorite(*args)
59
- threaded_object_from_response(Twitter::Tweet, :post, "/1.1/favorites/destroy.json", args)
60
- end
61
- alias favorite_destroy unfavorite
62
- alias favourite_destroy unfavorite
63
- alias unfavourite unfavorite
64
-
65
- # Favorites the specified Tweets as the authenticating user
66
- #
67
- # @see https://dev.twitter.com/docs/api/1.1/post/favorites/create
68
- # @rate_limited No
69
- # @authentication Requires user context
70
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
71
- # @return [Array<Twitter::Tweet>] The favorited Tweets.
72
- # @overload favorite(*ids)
73
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
74
- # @example Favorite the Tweet with the ID 25938088801
75
- # Twitter.favorite(25938088801)
76
- # @overload favorite(*ids, options)
77
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
78
- # @param options [Hash] A customizable set of options.
79
- def favorite(*args)
80
- arguments = Twitter::API::Arguments.new(args)
81
- arguments.flatten.threaded_map do |id|
82
- begin
83
- object_from_response(Twitter::Tweet, :post, "/1.1/favorites/create.json", arguments.options.merge(:id => id))
84
- rescue Twitter::Error::Forbidden => error
85
- raise unless error.message == Twitter::Error::AlreadyFavorited::MESSAGE
86
- end
87
- end.compact
88
- end
89
- alias fav favorite
90
- alias fave favorite
91
- alias favorite_create favorite
92
- alias favourite_create favorite
93
-
94
- # Favorites the specified Tweets as the authenticating user and raises an error if one has already been favorited
95
- #
96
- # @see https://dev.twitter.com/docs/api/1.1/post/favorites/create
97
- # @rate_limited No
98
- # @authentication Requires user context
99
- # @raise [Twitter::Error::AlreadyFavorited] Error raised when tweet has already been favorited.
100
- # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
101
- # @return [Array<Twitter::Tweet>] The favorited Tweets.
102
- # @overload favorite(*ids)
103
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
104
- # @example Favorite the Tweet with the ID 25938088801
105
- # Twitter.favorite(25938088801)
106
- # @overload favorite(*ids, options)
107
- # @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
108
- # @param options [Hash] A customizable set of options.
109
- def favorite!(*args)
110
- arguments = Twitter::API::Arguments.new(args)
111
- arguments.flatten.threaded_map do |id|
112
- begin
113
- object_from_response(Twitter::Tweet, :post, "/1.1/favorites/create.json", arguments.options.merge(:id => id))
114
- rescue Twitter::Error::Forbidden => error
115
- handle_forbidden_error(Twitter::Error::AlreadyFavorited, error)
116
- end
117
- end
118
- end
119
- alias fav! favorite!
120
- alias fave! favorite!
121
- alias favorite_create! favorite!
122
- alias favourite_create! favorite!
123
-
124
- end
125
- end
126
- end