ifttt-twitter 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +9 -0
  5. data/.yardopts +8 -0
  6. data/Gemfile +7 -0
  7. data/HISTORY.md +520 -0
  8. data/LICENSE.md +20 -0
  9. data/README.md +251 -0
  10. data/Rakefile +13 -0
  11. data/lib/twitter.rb +24 -0
  12. data/lib/twitter/action.rb +9 -0
  13. data/lib/twitter/action_factory.rb +28 -0
  14. data/lib/twitter/authenticatable.rb +24 -0
  15. data/lib/twitter/base.rb +40 -0
  16. data/lib/twitter/client.rb +126 -0
  17. data/lib/twitter/client/accounts.rb +180 -0
  18. data/lib/twitter/client/activity.rb +48 -0
  19. data/lib/twitter/client/block.rb +104 -0
  20. data/lib/twitter/client/direct_messages.rb +110 -0
  21. data/lib/twitter/client/favorites.rb +82 -0
  22. data/lib/twitter/client/friends_and_followers.rb +293 -0
  23. data/lib/twitter/client/help.rb +38 -0
  24. data/lib/twitter/client/legal.rb +32 -0
  25. data/lib/twitter/client/lists.rb +643 -0
  26. data/lib/twitter/client/local_trends.rb +46 -0
  27. data/lib/twitter/client/notification.rb +49 -0
  28. data/lib/twitter/client/places_and_geo.rb +113 -0
  29. data/lib/twitter/client/saved_searches.rb +73 -0
  30. data/lib/twitter/client/search.rb +94 -0
  31. data/lib/twitter/client/spam_reporting.rb +30 -0
  32. data/lib/twitter/client/suggested_users.rb +60 -0
  33. data/lib/twitter/client/timelines.rb +265 -0
  34. data/lib/twitter/client/trends.rb +55 -0
  35. data/lib/twitter/client/tweets.rb +191 -0
  36. data/lib/twitter/client/urls.rb +26 -0
  37. data/lib/twitter/client/users.rb +203 -0
  38. data/lib/twitter/config.rb +106 -0
  39. data/lib/twitter/configuration.rb +20 -0
  40. data/lib/twitter/connection.rb +43 -0
  41. data/lib/twitter/core_ext/hash.rb +81 -0
  42. data/lib/twitter/creatable.rb +14 -0
  43. data/lib/twitter/cursor.rb +44 -0
  44. data/lib/twitter/direct_message.rb +27 -0
  45. data/lib/twitter/error.rb +37 -0
  46. data/lib/twitter/error/bad_gateway.rb +7 -0
  47. data/lib/twitter/error/bad_request.rb +7 -0
  48. data/lib/twitter/error/client_error.rb +7 -0
  49. data/lib/twitter/error/enhance_your_calm.rb +13 -0
  50. data/lib/twitter/error/forbidden.rb +7 -0
  51. data/lib/twitter/error/internal_server_error.rb +7 -0
  52. data/lib/twitter/error/not_acceptable.rb +7 -0
  53. data/lib/twitter/error/not_found.rb +7 -0
  54. data/lib/twitter/error/server_error.rb +7 -0
  55. data/lib/twitter/error/service_unavailable.rb +7 -0
  56. data/lib/twitter/error/unauthorized.rb +7 -0
  57. data/lib/twitter/favorite.rb +28 -0
  58. data/lib/twitter/follow.rb +27 -0
  59. data/lib/twitter/geo_factory.rb +22 -0
  60. data/lib/twitter/language.rb +7 -0
  61. data/lib/twitter/list.rb +22 -0
  62. data/lib/twitter/list_member_added.rb +36 -0
  63. data/lib/twitter/media_factory.rb +21 -0
  64. data/lib/twitter/mention.rb +43 -0
  65. data/lib/twitter/metadata.rb +7 -0
  66. data/lib/twitter/oembed.rb +8 -0
  67. data/lib/twitter/photo.rb +24 -0
  68. data/lib/twitter/place.rb +36 -0
  69. data/lib/twitter/point.rb +27 -0
  70. data/lib/twitter/polygon.rb +14 -0
  71. data/lib/twitter/rate_limit_status.rb +15 -0
  72. data/lib/twitter/relationship.rb +18 -0
  73. data/lib/twitter/reply.rb +36 -0
  74. data/lib/twitter/request.rb +38 -0
  75. data/lib/twitter/request/gateway.rb +20 -0
  76. data/lib/twitter/request/multipart_with_file.rb +37 -0
  77. data/lib/twitter/request/oauth.rb +26 -0
  78. data/lib/twitter/request/phoenix.rb +22 -0
  79. data/lib/twitter/response/parse_json.rb +28 -0
  80. data/lib/twitter/response/raise_client_error.rb +49 -0
  81. data/lib/twitter/response/raise_server_error.rb +23 -0
  82. data/lib/twitter/retweet.rb +36 -0
  83. data/lib/twitter/saved_search.rb +16 -0
  84. data/lib/twitter/settings.rb +17 -0
  85. data/lib/twitter/size.rb +16 -0
  86. data/lib/twitter/status.rb +80 -0
  87. data/lib/twitter/suggestion.rb +22 -0
  88. data/lib/twitter/trend.rb +14 -0
  89. data/lib/twitter/user.rb +65 -0
  90. data/lib/twitter/version.rb +30 -0
  91. data/spec/faraday/request_spec.rb +25 -0
  92. data/spec/faraday/response_spec.rb +68 -0
  93. data/spec/fixtures/about_me.json +1 -0
  94. data/spec/fixtures/all.json +1 -0
  95. data/spec/fixtures/bad_gateway.json +1 -0
  96. data/spec/fixtures/bad_request.json +1 -0
  97. data/spec/fixtures/by_friends.json +1 -0
  98. data/spec/fixtures/category.json +1 -0
  99. data/spec/fixtures/configuration.json +1 -0
  100. data/spec/fixtures/contributees.json +1 -0
  101. data/spec/fixtures/contributors.json +1 -0
  102. data/spec/fixtures/direct_message.json +1 -0
  103. data/spec/fixtures/direct_messages.json +1 -0
  104. data/spec/fixtures/end_session.json +1 -0
  105. data/spec/fixtures/enhance_your_calm.text +11 -0
  106. data/spec/fixtures/false.json +1 -0
  107. data/spec/fixtures/favorites.json +1 -0
  108. data/spec/fixtures/forbidden.json +1 -0
  109. data/spec/fixtures/friendships.json +1 -0
  110. data/spec/fixtures/id_list.json +1 -0
  111. data/spec/fixtures/ids.json +1 -0
  112. data/spec/fixtures/image_facets.json +1 -0
  113. data/spec/fixtures/internal_server_error.json +1 -0
  114. data/spec/fixtures/languages.json +1 -0
  115. data/spec/fixtures/list.json +1 -0
  116. data/spec/fixtures/lists.json +1 -0
  117. data/spec/fixtures/locations.json +1 -0
  118. data/spec/fixtures/matching_trends.json +1 -0
  119. data/spec/fixtures/me.jpeg +0 -0
  120. data/spec/fixtures/media_timeline.json +1 -0
  121. data/spec/fixtures/members.json +1 -0
  122. data/spec/fixtures/n605431196_2079896_558_normal.jpg +0 -0
  123. data/spec/fixtures/no_user_matches.json +1 -0
  124. data/spec/fixtures/not_acceptable.json +1 -0
  125. data/spec/fixtures/not_found.json +1 -0
  126. data/spec/fixtures/oembed.json +1 -0
  127. data/spec/fixtures/pengwynn.json +1 -0
  128. data/spec/fixtures/phoenix_search.phoenix +1 -0
  129. data/spec/fixtures/place.json +1 -0
  130. data/spec/fixtures/places.json +1 -0
  131. data/spec/fixtures/privacy.json +1 -0
  132. data/spec/fixtures/profile_image.text +24 -0
  133. data/spec/fixtures/rate_limit_status.json +1 -0
  134. data/spec/fixtures/recommendations.json +1 -0
  135. data/spec/fixtures/relationship.json +1 -0
  136. data/spec/fixtures/resolve.json +1 -0
  137. data/spec/fixtures/retweet.json +1 -0
  138. data/spec/fixtures/retweeters_of.json +1 -0
  139. data/spec/fixtures/retweets.json +1 -0
  140. data/spec/fixtures/saved_search.json +1 -0
  141. data/spec/fixtures/saved_searches.json +1 -0
  142. data/spec/fixtures/search.json +1 -0
  143. data/spec/fixtures/service_unavailable.json +1 -0
  144. data/spec/fixtures/settings.json +1 -0
  145. data/spec/fixtures/sferik.json +1 -0
  146. data/spec/fixtures/status.json +1 -0
  147. data/spec/fixtures/status_with_media.json +104 -0
  148. data/spec/fixtures/statuses.json +1 -0
  149. data/spec/fixtures/suggestions.json +1 -0
  150. data/spec/fixtures/tos.json +1 -0
  151. data/spec/fixtures/totals.json +1 -0
  152. data/spec/fixtures/trends.json +1 -0
  153. data/spec/fixtures/trends_current.json +1 -0
  154. data/spec/fixtures/trends_daily.json +1 -0
  155. data/spec/fixtures/trends_weekly.json +1 -0
  156. data/spec/fixtures/true.json +1 -0
  157. data/spec/fixtures/unauthorized.json +1 -0
  158. data/spec/fixtures/user_search.json +1 -0
  159. data/spec/fixtures/user_timeline.json +1 -0
  160. data/spec/fixtures/users.json +1 -0
  161. data/spec/fixtures/users_list.json +1 -0
  162. data/spec/fixtures/video_facets.json +1 -0
  163. data/spec/fixtures/we_concept_bg2.png +0 -0
  164. data/spec/helper.rb +49 -0
  165. data/spec/twitter/action_factory_spec.rb +37 -0
  166. data/spec/twitter/action_spec.rb +16 -0
  167. data/spec/twitter/base_spec.rb +29 -0
  168. data/spec/twitter/client/accounts_spec.rb +181 -0
  169. data/spec/twitter/client/activity_spec.rb +43 -0
  170. data/spec/twitter/client/block_spec.rb +106 -0
  171. data/spec/twitter/client/direct_messages_spec.rb +98 -0
  172. data/spec/twitter/client/favorites_spec.rb +80 -0
  173. data/spec/twitter/client/friends_and_followers_spec.rb +478 -0
  174. data/spec/twitter/client/help_spec.rb +44 -0
  175. data/spec/twitter/client/legal_spec.rb +41 -0
  176. data/spec/twitter/client/lists_spec.rb +1104 -0
  177. data/spec/twitter/client/local_trends_spec.rb +58 -0
  178. data/spec/twitter/client/notification_spec.rb +47 -0
  179. data/spec/twitter/client/places_and_geo_spec.rb +100 -0
  180. data/spec/twitter/client/saved_searches_spec.rb +80 -0
  181. data/spec/twitter/client/search_spec.rb +92 -0
  182. data/spec/twitter/client/spam_reporting_spec.rb +28 -0
  183. data/spec/twitter/client/suggested_users_spec.rb +65 -0
  184. data/spec/twitter/client/timelines_spec.rb +231 -0
  185. data/spec/twitter/client/trends_spec.rb +51 -0
  186. data/spec/twitter/client/tweets_spec.rb +189 -0
  187. data/spec/twitter/client/urls_spec.rb +31 -0
  188. data/spec/twitter/client/users_spec.rb +323 -0
  189. data/spec/twitter/client_spec.rb +94 -0
  190. data/spec/twitter/configuration_spec.rb +17 -0
  191. data/spec/twitter/cursor_spec.rb +43 -0
  192. data/spec/twitter/direct_message_spec.rb +56 -0
  193. data/spec/twitter/favorite_spec.rb +29 -0
  194. data/spec/twitter/follow_spec.rb +29 -0
  195. data/spec/twitter/geo_factory_spec.rb +21 -0
  196. data/spec/twitter/list_spec.rb +34 -0
  197. data/spec/twitter/media_factory_spec.rb +17 -0
  198. data/spec/twitter/mention_spec.rb +52 -0
  199. data/spec/twitter/oembed_spec.rb +145 -0
  200. data/spec/twitter/photo_spec.rb +35 -0
  201. data/spec/twitter/place_spec.rb +75 -0
  202. data/spec/twitter/point_spec.rb +32 -0
  203. data/spec/twitter/polygon_spec.rb +18 -0
  204. data/spec/twitter/rate_limit_status_spec.rb +16 -0
  205. data/spec/twitter/relationship_spec.rb +27 -0
  206. data/spec/twitter/reply_spec.rb +41 -0
  207. data/spec/twitter/retweet_spec.rb +41 -0
  208. data/spec/twitter/saved_search_spec.rb +34 -0
  209. data/spec/twitter/settings_spec.rb +16 -0
  210. data/spec/twitter/size_spec.rb +18 -0
  211. data/spec/twitter/status_spec.rb +148 -0
  212. data/spec/twitter/suggestion_spec.rb +20 -0
  213. data/spec/twitter/trend_spec.rb +20 -0
  214. data/spec/twitter/user_spec.rb +50 -0
  215. data/spec/twitter_spec.rb +91 -0
  216. data/twitter.gemspec +42 -0
  217. metadata +564 -0
@@ -0,0 +1,180 @@
1
+ require 'twitter/rate_limit_status'
2
+ require 'twitter/settings'
3
+ require 'twitter/user'
4
+
5
+ module Twitter
6
+ class Client
7
+ # Defines methods related to a user's account
8
+ module Accounts
9
+
10
+ # Returns the remaining number of API requests available to the requesting user
11
+ #
12
+ # @see https://dev.twitter.com/docs/api/1/get/account/rate_limit_status
13
+ # @rate_limited No
14
+ # @requires_authentication No
15
+ #
16
+ # This will return the requesting IP's rate limit status. If you want the authenticating user's rate limit status you must authenticate.
17
+ # @param options [Hash] A customizable set of options.
18
+ # @return [Twitter::RateLimitStatus]
19
+ # @example Return the remaining number of API requests available to the requesting user
20
+ # Twitter.rate_limit_status
21
+ def rate_limit_status(options={})
22
+ rate_limit_status = get("/1/account/rate_limit_status.json", options)
23
+ Twitter::RateLimitStatus.new(rate_limit_status)
24
+ end
25
+
26
+ # Returns the requesting user if authentication was successful, otherwise raises {Twitter::Error::Unauthorized}
27
+ #
28
+ # @see https://dev.twitter.com/docs/api/1/get/account/verify_credentials
29
+ # @rate_limited Yes
30
+ # @requires_authentication Yes
31
+ # @param options [Hash] A customizable set of options.
32
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
33
+ # @return [Twitter::User] The authenticated user.
34
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
35
+ # @example Return the requesting user if authentication was successful
36
+ # Twitter.verify_credentials
37
+ def verify_credentials(options={})
38
+ user = get("/1/account/verify_credentials.json", options)
39
+ Twitter::User.new(user)
40
+ end
41
+
42
+ # Ends the session of the authenticating user
43
+ #
44
+ # @see https://dev.twitter.com/docs/api/1/post/account/end_session
45
+ # @rate_limited No
46
+ # @requires_authentication Yes
47
+ # @param options [Hash] A customizable set of options.
48
+ # @return [Hash]
49
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
50
+ # @example End the session of the authenticating user
51
+ # Twitter.end_session
52
+ def end_session(options={})
53
+ post("/1/account/end_session.json", options)
54
+ end
55
+
56
+ # Sets which device Twitter delivers updates to for the authenticating user
57
+ #
58
+ # @see https://dev.twitter.com/docs/api/1/post/account/update_delivery_device
59
+ # @rate_limited No
60
+ # @requires_authentication Yes
61
+ # @param device [String] Must be one of: 'sms', 'none'.
62
+ # @param options [Hash] A customizable set of options.
63
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
64
+ # @return [Twitter::User] The authenticated user.
65
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
66
+ # @example Turn SMS updates on for the authenticating user
67
+ # Twitter.update_delivery_device('sms')
68
+ def update_delivery_device(device, options={})
69
+ user = post("/1/account/update_delivery_device.json", options.merge(:device => device))
70
+ Twitter::User.new(user)
71
+ end
72
+
73
+ # Sets values that users are able to set under the "Account" tab of their settings page
74
+ #
75
+ # @see https://dev.twitter.com/docs/api/1/post/account/update_profile
76
+ # @note Only the options specified will be updated.
77
+ # @rate_limited No
78
+ # @requires_authentication Yes
79
+ # @param options [Hash] A customizable set of options.
80
+ # @option options [String] :name Full name associated with the profile. Maximum of 20 characters.
81
+ # @option options [String] :url URL associated with the profile. Will be prepended with "http://" if not present. Maximum of 100 characters.
82
+ # @option options [String] :location The city or country describing where the user of the account is located. The contents are not normalized or geocoded in any way. Maximum of 30 characters.
83
+ # @option options [String] :description A description of the user owning the account. Maximum of 160 characters.
84
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
85
+ # @return [Twitter::User] The authenticated user.
86
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
87
+ # @example Set authenticating user's name to Erik Michaels-Ober
88
+ # Twitter.update_profile(:name => "Erik Michaels-Ober")
89
+ def update_profile(options={})
90
+ user = post("/1/account/update_profile.json", options)
91
+ Twitter::User.new(user)
92
+ end
93
+
94
+ # Updates the authenticating user's profile background image
95
+ #
96
+ # @see https://dev.twitter.com/docs/api/1/post/account/update_profile_background_image
97
+ # @rate_limited No
98
+ # @requires_authentication Yes
99
+ # @param image [String] The background image for the profile. Must be a valid GIF, JPG, or PNG image of less than 800 kilobytes in size. Images with width larger than 2048 pixels will be scaled down.
100
+ # @param options [Hash] A customizable set of options.
101
+ # @option options [Boolean] :tile Whether or not to tile the background image. If set to true the background image will be displayed tiled. The image will not be tiled otherwise.
102
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
103
+ # @return [Twitter::User] The authenticated user.
104
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
105
+ # @example Update the authenticating user's profile background image
106
+ # Twitter.update_profile_background_image(File.new("we_concept_bg2.png"))
107
+ def update_profile_background_image(image, options={})
108
+ user = post("/1/account/update_profile_background_image.json", options.merge(:image => image))
109
+ Twitter::User.new(user)
110
+ end
111
+
112
+ # Sets one or more hex values that control the color scheme of the authenticating user's profile
113
+ #
114
+ # @see https://dev.twitter.com/docs/api/1/post/account/update_profile_colors
115
+ # @rate_limited No
116
+ # @requires_authentication Yes
117
+ # @param options [Hash] A customizable set of options.
118
+ # @option options [String] :profile_background_color Profile background color.
119
+ # @option options [String] :profile_text_color Profile text color.
120
+ # @option options [String] :profile_link_color Profile link color.
121
+ # @option options [String] :profile_sidebar_fill_color Profile sidebar's background color.
122
+ # @option options [String] :profile_sidebar_border_color Profile sidebar's border color.
123
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
124
+ # @return [Twitter::User] The authenticated user.
125
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
126
+ # @example Set authenticating user's profile background to black
127
+ # Twitter.update_profile_colors(:profile_background_color => '000000')
128
+ def update_profile_colors(options={})
129
+ user = post("/1/account/update_profile_colors.json", options)
130
+ Twitter::User.new(user)
131
+ end
132
+
133
+ # Updates the authenticating user's profile image
134
+ #
135
+ # @see https://dev.twitter.com/docs/api/1/post/account/update_profile_image
136
+ # @note This method asynchronously processes the uploaded file before updating the user's profile image URL. You can either update your local cache the next time you request the user's information, or, at least 5 seconds after uploading the image, ask for the updated URL using {Twitter::Client::User#profile_image}.
137
+ # @rate_limited No
138
+ # @requires_authentication Yes
139
+ # @param image [String] The avatar image for the profile. Must be a valid GIF, JPG, or PNG image of less than 700 kilobytes in size. Images with width larger than 500 pixels will be scaled down. Animated GIFs will be converted to a static GIF of the first frame, removing the animation.
140
+ # @param options [Hash] A customizable set of options.
141
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
142
+ # @return [Twitter::User] The authenticated user.
143
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
144
+ # @example Update the authenticating user's profile image
145
+ # Twitter.update_profile_image(File.new("me.jpeg"))
146
+ def update_profile_image(image, options={})
147
+ user = post("/1/account/update_profile_image.json", options.merge(:image => image))
148
+ Twitter::User.new(user)
149
+ end
150
+
151
+ # Updates the authenticating user's settings.
152
+ # Or, if no options supplied, returns settings (including current trend, geo and sleep time information) for the authenticating user.
153
+ #
154
+ # @see https://dev.twitter.com/docs/api/1/post/account/settings
155
+ # @see https://dev.twitter.com/docs/api/1/get/account/settings
156
+ # @rate_limited Yes
157
+ # @requires_authentication Yes
158
+ # @param options [Hash] A customizable set of options.
159
+ # @option options [Integer] :trend_location_woeid The Yahoo! Where On Earth ID to use as the user's default trend location. Global information is available by using 1 as the WOEID. The woeid must be one of the locations returned by {https://dev.twitter.com/docs/api/1/get/trends/available GET trends/available}.
160
+ # @option options [Boolean, String, Integer] :sleep_time_enabled When set to true, 't' or 1, will enable sleep time for the user. Sleep time is the time when push or SMS notifications should not be sent to the user.
161
+ # @option options [Integer] :start_sleep_time The hour that sleep time should begin if it is enabled. The value for this parameter should be provided in {http://en.wikipedia.org/wiki/ISO_8601 ISO8601} format (i.e. 00-23). The time is considered to be in the same timezone as the user's time_zone setting.
162
+ # @option options [Integer] :end_sleep_time The hour that sleep time should end if it is enabled. The value for this parameter should be provided in {http://en.wikipedia.org/wiki/ISO_8601 ISO8601} format (i.e. 00-23). The time is considered to be in the same timezone as the user's time_zone setting.
163
+ # @option options [String] :time_zone The timezone dates and times should be displayed in for the user. The timezone must be one of the {http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html Rails TimeZone} names.
164
+ # @option options [String] :lang The language which Twitter should render in for this user. The language must be specified by the appropriate two letter ISO 639-1 representation. Currently supported languages are provided by {https://dev.twitter.com/docs/api/1/get/help/languages GET help/languages}.
165
+ # @return [Twitter::Settings]
166
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
167
+ # @example Return the settings for the authenticating user.
168
+ # Twitter.settings
169
+ def settings(options={})
170
+ settings = if options.size.zero?
171
+ get("/1/account/settings.json", options)
172
+ else
173
+ post("/1/account/settings.json", options)
174
+ end
175
+ Twitter::Settings.new(settings)
176
+ end
177
+
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,48 @@
1
+ require 'twitter/action_factory'
2
+
3
+ module Twitter
4
+ class Client
5
+ # Defines methods related to URLs
6
+ module Activity
7
+
8
+ # Returns activity about me
9
+ #
10
+ # @note Undocumented
11
+ # @rate_limited Yes
12
+ # @requires_authentication Yes
13
+ # @param options [Hash] A customizable set of options.
14
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
15
+ # @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1.
16
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
17
+ # @return [Array] An array of actions
18
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
19
+ # @example Return activity about me
20
+ # Twitter.activity_about_me
21
+ def activity_about_me(options={})
22
+ get("/i/activity/about_me.json", options, :phoenix => true).map do |action|
23
+ Twitter::ActionFactory.new(action)
24
+ end
25
+ end
26
+
27
+ # Returns activity by friends
28
+ #
29
+ # @note Undocumented
30
+ # @rate_limited Yes
31
+ # @requires_authentication Yes
32
+ # @param options [Hash] A customizable set of options.
33
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
34
+ # @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1.
35
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
36
+ # @return [Array] An array of actions
37
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid./
38
+ # @example Return activity by friends
39
+ # Twitter.activity_by_friends
40
+ def activity_by_friends(options={})
41
+ get("/i/activity/by_friends.json", options, :phoenix => true).map do |action|
42
+ Twitter::ActionFactory.new(action)
43
+ end
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,104 @@
1
+ require 'twitter/core_ext/hash'
2
+ require 'twitter/error/not_found'
3
+ require 'twitter/user'
4
+
5
+ module Twitter
6
+ class Client
7
+ # Defines methods related to blocking and unblocking users
8
+ # @see Twitter::Client::SpamReporting
9
+ module Block
10
+
11
+ # Returns an array of user objects that the authenticating user is blocking
12
+ #
13
+ # @see https://dev.twitter.com/docs/api/1/get/blocks/blocking
14
+ # @rate_limited Yes
15
+ # @requires_authentication Yes
16
+ # @param options [Hash] A customizable set of options.
17
+ # @option options [Integer] :page Specifies the page of results to retrieve.
18
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
19
+ # @return [Array<Twitter::User>] User objects that the authenticating user is blocking.
20
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
21
+ # @example Return an array of user objects that the authenticating user is blocking
22
+ # Twitter.blocking
23
+ def blocking(options={})
24
+ get("/1/blocks/blocking.json", options).map do |user|
25
+ Twitter::User.new(user)
26
+ end
27
+ end
28
+
29
+ # Returns an array of numeric user ids the authenticating user is blocking
30
+ #
31
+ # @see https://dev.twitter.com/docs/api/1/get/blocks/blocking/ids
32
+ # @rate_limited Yes
33
+ # @requires_authentication Yes
34
+ # @param options [Hash] A customizable set of options.
35
+ # @return [Array] Numeric user ids the authenticating user is blocking.
36
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
37
+ # @example Return an array of numeric user ids the authenticating user is blocking
38
+ # Twitter.blocking_ids
39
+ def blocked_ids(options={})
40
+ get("/1/blocks/blocking/ids.json", options)
41
+ end
42
+
43
+ # Returns true if the authenticating user is blocking a target user
44
+ #
45
+ # @see https://dev.twitter.com/docs/api/1/get/blocks/exists
46
+ # @requires_authentication Yes
47
+ # @rate_limited Yes
48
+ # @param user [Integer, String] A Twitter user ID or screen name.
49
+ # @param options [Hash] A customizable set of options.
50
+ # @return [Boolean] true if the authenticating user is blocking the target user, otherwise false.
51
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
52
+ # @example Check whether the authenticating user is blocking @sferik
53
+ # Twitter.block?("sferik")
54
+ # Twitter.block?(7505382) # Same as above
55
+ def block?(user, options={})
56
+ options.merge_user!(user)
57
+ get("/1/blocks/exists.json", options, :raw => true)
58
+ true
59
+ rescue Twitter::Error::NotFound
60
+ false
61
+ end
62
+
63
+ # Blocks the user specified by the authenticating user
64
+ #
65
+ # @see https://dev.twitter.com/docs/api/1/post/blocks/create
66
+ # @note Destroys a friendship to the blocked user if it exists.
67
+ # @rate_limited Yes
68
+ # @requires_authentication Yes
69
+ # @param user [Integer, String] A Twitter user ID or screen name.
70
+ # @param options [Hash] A customizable set of options.
71
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
72
+ # @return [Twitter::User] The blocked user.
73
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
74
+ # @example Block and unfriend @sferik as the authenticating user
75
+ # Twitter.block("sferik")
76
+ # Twitter.block(7505382) # Same as above
77
+ def block(user, options={})
78
+ options.merge_user!(user)
79
+ user = post("/1/blocks/create.json", options)
80
+ Twitter::User.new(user)
81
+ end
82
+
83
+ # Un-blocks the user specified by the authenticating user
84
+ #
85
+ # @see https://dev.twitter.com/docs/api/1/post/blocks/destroy
86
+ # @rate_limited No
87
+ # @requires_authentication Yes
88
+ # @param user [Integer, String] A Twitter user ID or screen name.
89
+ # @param options [Hash] A customizable set of options.
90
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
91
+ # @return [Twitter::User] The un-blocked user.
92
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
93
+ # @example Un-block @sferik as the authenticating user
94
+ # Twitter.unblock("sferik")
95
+ # Twitter.unblock(7505382) # Same as above
96
+ def unblock(user, options={})
97
+ options.merge_user!(user)
98
+ user = delete("/1/blocks/destroy.json", options)
99
+ Twitter::User.new(user)
100
+ end
101
+
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,110 @@
1
+ require 'twitter/core_ext/hash'
2
+ require 'twitter/direct_message'
3
+
4
+ module Twitter
5
+ class Client
6
+ # Defines methods related to direct messages
7
+ module DirectMessages
8
+
9
+ # Returns the 20 most recent direct messages sent to the authenticating user
10
+ #
11
+ # @see https://dev.twitter.com/docs/api/1/get/direct_messages
12
+ # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
13
+ # @rate_limited Yes
14
+ # @requires_authentication Yes
15
+ # @param options [Hash] A customizable set of options.
16
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
17
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
18
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
19
+ # @option options [Integer] :page Specifies the page of results to retrieve.
20
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
21
+ # @return [Array<Twitter::DirectMessage>] Direct messages sent to the authenticating user.
22
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
23
+ # @example Return the 20 most recent direct messages sent to the authenticating user
24
+ # Twitter.direct_messages
25
+ def direct_messages(options={})
26
+ get("/1/direct_messages.json", options).map do |direct_message|
27
+ Twitter::DirectMessage.new(direct_message)
28
+ end
29
+ end
30
+
31
+ # Returns the 20 most recent direct messages sent by the authenticating user
32
+ #
33
+ # @see https://dev.twitter.com/docs/api/1/get/direct_messages/sent
34
+ # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
35
+ # @rate_limited Yes
36
+ # @requires_authentication Yes
37
+ # @param options [Hash] A customizable set of options.
38
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
39
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
40
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
41
+ # @option options [Integer] :page Specifies the page of results to retrieve.
42
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
43
+ # @return [Array<Twitter::DirectMessage>] Direct messages sent by the authenticating user.
44
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
45
+ # @example Return the 20 most recent direct messages sent by the authenticating user
46
+ # Twitter.direct_messages_sent
47
+ def direct_messages_sent(options={})
48
+ get("/1/direct_messages/sent.json", options).map do |direct_message|
49
+ Twitter::DirectMessage.new(direct_message)
50
+ end
51
+ end
52
+
53
+ # Destroys a direct message
54
+ #
55
+ # @see https://dev.twitter.com/docs/api/1/post/direct_messages/destroy/:id
56
+ # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
57
+ # @rate_limited No
58
+ # @requires_authentication Yes
59
+ # @param id [Integer] The ID of the direct message to delete.
60
+ # @param options [Hash] A customizable set of options.
61
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
62
+ # @return [Twitter::DirectMessage] The deleted message.
63
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
64
+ # @example Destroys the direct message with the ID 1825785544
65
+ # Twitter.direct_message_destroy(1825785544)
66
+ def direct_message_destroy(id, options={})
67
+ direct_message = delete("/1/direct_messages/destroy/#{id}.json", options)
68
+ Twitter::DirectMessage.new(direct_message)
69
+ end
70
+
71
+ # Sends a new direct message to the specified user from the authenticating user
72
+ #
73
+ # @see https://dev.twitter.com/docs/api/1/post/direct_messages/new
74
+ # @rate_limited No
75
+ # @requires_authentication Yes
76
+ # @param user [Integer, String] A Twitter user ID or screen name.
77
+ # @param text [String] The text of your direct message, up to 140 characters.
78
+ # @param options [Hash] A customizable set of options.
79
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
80
+ # @return [Twitter::DirectMessage] The sent message.
81
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
82
+ # @example Send a direct message to @sferik from the authenticating user
83
+ # Twitter.direct_message_create("sferik", "I'm sending you this message via the Twitter Ruby Gem!")
84
+ # Twitter.direct_message_create(7505382, "I'm sending you this message via the Twitter Ruby Gem!") # Same as above
85
+ def direct_message_create(user, text, options={})
86
+ options.merge_user!(user)
87
+ direct_message = post("/1/direct_messages/new.json", options.merge(:text => text))
88
+ Twitter::DirectMessage.new(direct_message)
89
+ end
90
+ alias :d :direct_message_create
91
+
92
+ # Returns a single direct message, specified by id.
93
+ #
94
+ # @see https://dev.twitter.com/docs/api/1/get/direct_messages/show/%3Aid
95
+ # @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
96
+ # @rate_limited Yes
97
+ # @requires_authentication Yes
98
+ # @param id [Integer] The ID of the direct message to retrieve.
99
+ # @param options [Hash] A customizable set of options.
100
+ # @return [Twitter::DirectMessage] The requested message.
101
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
102
+ # @example Return the direct message with the id 1825786345
103
+ # Twitter.direct_message(1825786345)
104
+ def direct_message(id, options={})
105
+ direct_message = get("/1/direct_messages/show/#{id}.json", options)
106
+ Twitter::DirectMessage.new(direct_message)
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,82 @@
1
+ require 'twitter/status'
2
+
3
+ module Twitter
4
+ class Client
5
+ # Defines methods related to favorites (or favourites)
6
+ module Favorites
7
+
8
+ # @see https://dev.twitter.com/docs/api/1/get/favorites
9
+ # @rate_limited Yes
10
+ # @requires_authentication No
11
+ # @overload favorites(options={})
12
+ # Returns the 20 most recent favorite statuses for the authenticating user
13
+ #
14
+ # @param options [Hash] A customizable set of options.
15
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
16
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
17
+ # @option options [Integer] :page Specifies the page of results to retrieve.
18
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
19
+ # @return [Array<Twitter::Status>] favorite statuses.
20
+ # @example Return the 20 most recent favorite statuses for the authenticating user
21
+ # Twitter.favorites
22
+ # @overload favorites(user, options={})
23
+ # Returns the 20 most recent favorite statuses for the specified user
24
+ #
25
+ # @param user [Integer, String] A Twitter user ID or screen name.
26
+ # @param options [Hash] A customizable set of options.
27
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
28
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
29
+ # @option options [Integer] :page Specifies the page of results to retrieve.
30
+ # @return [Array<Twitter::Status>] favorite statuses.
31
+ # @example Return the 20 most recent favorite statuses for @sferik
32
+ # Twitter.favorites("sferik")
33
+ def favorites(*args)
34
+ options = args.last.is_a?(Hash) ? args.pop : {}
35
+ if user = args.first
36
+ get("/1/favorites/#{user}.json", options)
37
+ else
38
+ get("/1/favorites.json", options)
39
+ end.map do |status|
40
+ Twitter::Status.new(status)
41
+ end
42
+ end
43
+
44
+ # Favorites the specified status as the authenticating user
45
+ #
46
+ # @see https://dev.twitter.com/docs/api/1/post/favorites/create/:id
47
+ # @rate_limited No
48
+ # @requires_authentication Yes
49
+ # @param id [Integer] The numerical ID of the desired status.
50
+ # @param options [Hash] A customizable set of options.
51
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
52
+ # @return [Twitter::Status] The favorited status.
53
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
54
+ # @example Favorite the status with the ID 25938088801
55
+ # Twitter.favorite(25938088801)
56
+ def favorite(id, options={})
57
+ status = post("/1/favorites/create/#{id}.json", options)
58
+ Twitter::Status.new(status)
59
+ end
60
+ alias :favorite_create :favorite
61
+
62
+ # Un-favorites the specified status as the authenticating user
63
+ #
64
+ # @see https://dev.twitter.com/docs/api/1/post/favorites/destroy/:id
65
+ # @rate_limited No
66
+ # @requires_authentication Yes
67
+ # @param id [Integer] The numerical ID of the desired status.
68
+ # @param options [Hash] A customizable set of options.
69
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
70
+ # @return [Twitter::Status] The un-favorited status.
71
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
72
+ # @example Un-favorite the status with the ID 25938088801
73
+ # Twitter.unfavorite(25938088801)
74
+ def unfavorite(id, options={})
75
+ status = delete("/1/favorites/destroy/#{id}.json", options)
76
+ Twitter::Status.new(status)
77
+ end
78
+ alias :favorite_destroy :unfavorite
79
+
80
+ end
81
+ end
82
+ end