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,265 @@
1
+ require 'twitter/core_ext/hash'
2
+ require 'twitter/status'
3
+
4
+ module Twitter
5
+ class Client
6
+ # Defines methods related to timelines
7
+ module Timelines
8
+
9
+ # Returns the 20 most recent statuses, including retweets if they exist, posted by the authenticating user and the users they follow
10
+ #
11
+ # @see https://dev.twitter.com/docs/api/1/get/statuses/home_timeline
12
+ # @note This method can only return up to 800 statuses, including retweets.
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] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
21
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
22
+ # @option options [Boolean, String, Integer] :exclude_replies This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets — this is because the count parameter retrieves that many tweets before filtering out retweets and replies.
23
+ # @return [Array<Twitter::Status>]
24
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
25
+ # @example Return the 20 most recent statuses, including retweets if they exist, posted by the authenticating user and the users they follow
26
+ # Twitter.home_timeline
27
+ def home_timeline(options={})
28
+ get("/1/statuses/home_timeline.json", options).map do |status|
29
+ Twitter::Status.new(status)
30
+ end
31
+ end
32
+
33
+ # Returns the 20 most recent mentions (statuses containing @username) for the authenticating user
34
+ #
35
+ # @see https://dev.twitter.com/docs/api/1/get/statuses/mentions
36
+ # @note This method can only return up to 800 statuses. If the :include_rts option is set, only 800 statuses, including retweets if they exist, can be returned.
37
+ # @rate_limited Yes
38
+ # @requires_authentication Yes
39
+ # @param options [Hash] A customizable set of options.
40
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
41
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
42
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
43
+ # @option options [Integer] :page Specifies the page of results to retrieve.
44
+ # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
45
+ # @option options [Boolean, String, Integer] :include_rts The timeline will contain native retweets (if they exist) in addition to the standard stream of tweets when set to true, 't' or 1.
46
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
47
+ # @return [Array<Twitter::Status>]
48
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
49
+ # @example Return the 20 most recent mentions (statuses containing @username) for the authenticating user
50
+ # Twitter.mentions
51
+ def mentions(options={})
52
+ get("/1/statuses/mentions.json", options).map do |status|
53
+ Twitter::Status.new(status)
54
+ end
55
+ end
56
+
57
+ # Returns the 20 most recent statuses, including retweets if they exist, from non-protected users
58
+ #
59
+ # @see https://dev.twitter.com/docs/api/1/get/statuses/public_timeline
60
+ # @note The public timeline is cached for 60 seconds. Requesting more frequently than that will not return any more data, and will count against your rate limit usage.
61
+ # @rate_limited Yes
62
+ # @requires_authentication No
63
+ # @param options [Hash] A customizable set of options.
64
+ # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
65
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
66
+ # @return [Array<Twitter::Status>]
67
+ # @example Return the 20 most recent statuses, including retweets if they exist, from non-protected users
68
+ # Twitter.public_timeline
69
+ def public_timeline(options={})
70
+ get("/1/statuses/public_timeline.json", options).map do |status|
71
+ Twitter::Status.new(status)
72
+ end
73
+ end
74
+
75
+ # Returns the 20 most recent retweets posted by the specified user
76
+ #
77
+ # @see https://dev.twitter.com/docs/api/1/get/statuses/retweeted_by_me
78
+ # @see https://dev.twitter.com/docs/api/1/get/statuses/retweeted_by_user
79
+ # @rate_limited Yes
80
+ # @requires_authentication Supported
81
+ # @overload retweeted_by(options={})
82
+ # @param options [Hash] A customizable set of options.
83
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
84
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
85
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
86
+ # @option options [Integer] :page Specifies the page of results to retrieve.
87
+ # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
88
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
89
+ # @return [Array<Twitter::Status>]
90
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
91
+ # @example Return the 20 most recent retweets posted by the authenticating user
92
+ # Twitter.retweeted_by("sferik")
93
+ # @overload retweeted_by(user, options={})
94
+ # @param user [Integer, String] A Twitter user ID or screen name.
95
+ # @param options [Hash] A customizable set of options.
96
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
97
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
98
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
99
+ # @option options [Integer] :page Specifies the page of results to retrieve.
100
+ # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
101
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
102
+ # @return [Array<Twitter::Status>]
103
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
104
+ # @example Return the 20 most recent retweets posted by the authenticating user
105
+ # Twitter.retweeted_by
106
+ def retweeted_by(*args)
107
+ options = args.last.is_a?(Hash) ? args.pop : {}
108
+ if user = args.pop
109
+ options.merge_user!(user)
110
+ get("/1/statuses/retweeted_by_user.json", options)
111
+ else
112
+ get("/1/statuses/retweeted_by_me.json", options)
113
+ end.map do |status|
114
+ Twitter::Status.new(status)
115
+ end
116
+ end
117
+
118
+ # Returns the 20 most recent retweets posted by users the specified user follows
119
+ #
120
+ # @see https://dev.twitter.com/docs/api/1/get/statuses/retweeted_to_me
121
+ # @see https://dev.twitter.com/docs/api/1/get/statuses/retweeted_to_user
122
+ # @rate_limited Yes
123
+ # @requires_authentication Supported
124
+ # @overload retweeted_to(options={})
125
+ # @param options [Hash] A customizable set of options.
126
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
127
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
128
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
129
+ # @option options [Integer] :page Specifies the page of results to retrieve.
130
+ # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
131
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
132
+ # @return [Array<Twitter::Status>]
133
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
134
+ # @example Return the 20 most recent retweets posted by users followed by the authenticating user
135
+ # Twitter.retweeted_to
136
+ # @overload retweeted_to(user, options={})
137
+ # @param user [Integer, String] A Twitter user ID or screen name.
138
+ # @param options [Hash] A customizable set of options.
139
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
140
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
141
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
142
+ # @option options [Integer] :page Specifies the page of results to retrieve.
143
+ # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
144
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
145
+ # @return [Array<Twitter::Status>]
146
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
147
+ # @example Return the 20 most recent retweets posted by users followed by the authenticating user
148
+ # Twitter.retweeted_to("sferik")
149
+ def retweeted_to(*args)
150
+ options = args.last.is_a?(Hash) ? args.pop : {}
151
+ if user = args.pop
152
+ options.merge_user!(user)
153
+ get("/1/statuses/retweeted_to_user.json", options)
154
+ else
155
+ get("/1/statuses/retweeted_to_me.json", options)
156
+ end.map do |status|
157
+ Twitter::Status.new(status)
158
+ end
159
+ end
160
+
161
+ # Returns the 20 most recent tweets of the authenticated user that have been retweeted by others
162
+ #
163
+ # @see https://dev.twitter.com/docs/api/1/get/statuses/retweets_of_me
164
+ # @rate_limited Yes
165
+ # @requires_authentication Yes
166
+ # @param options [Hash] A customizable set of options.
167
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
168
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
169
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
170
+ # @option options [Integer] :page Specifies the page of results to retrieve.
171
+ # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
172
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
173
+ # @return [Array<Twitter::Status>]
174
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
175
+ # @example Return the 20 most recent tweets of the authenticated user that have been retweeted by others
176
+ # Twitter.retweets_of_me
177
+ def retweets_of_me(options={})
178
+ get("/1/statuses/retweets_of_me.json", options).map do |status|
179
+ Twitter::Status.new(status)
180
+ end
181
+ end
182
+
183
+ # Returns the 20 most recent statuses posted by the specified user
184
+ #
185
+ # @see https://dev.twitter.com/docs/api/1/get/statuses/user_timeline
186
+ # @note This method can only return up to 3200 statuses. If the :include_rts option is set, only 3200 statuses, including retweets if they exist, can be returned.
187
+ # @rate_limited Yes
188
+ # @requires_authentication No unless the user whose timeline you're trying to view is protected
189
+ # @overload user_timeline(user, options={})
190
+ # @param user [Integer, String] A Twitter user ID or screen name.
191
+ # @param options [Hash] A customizable set of options.
192
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
193
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
194
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
195
+ # @option options [Integer] :page Specifies the page of results to retrieve.
196
+ # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
197
+ # @option options [Boolean, String, Integer] :include_rts The timeline will contain native retweets (if they exist) in addition to the standard stream of tweets when set to true, 't' or 1.
198
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
199
+ # @option options [Boolean, String, Integer] :exclude_replies This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets — this is because the count parameter retrieves that many tweets before filtering out retweets and replies.
200
+ # @return [Array<Twitter::Status>]
201
+ # @example Return the 20 most recent statuses posted by @sferik
202
+ # Twitter.user_timeline("sferik")
203
+ def user_timeline(*args)
204
+ options = args.last.is_a?(Hash) ? args.pop : {}
205
+ if user = args.pop
206
+ options.merge_user!(user)
207
+ end
208
+ get("/1/statuses/user_timeline.json", options).map do |status|
209
+ Twitter::Status.new(status)
210
+ end
211
+ end
212
+
213
+ # Returns the 20 most recent images posted by the specified user
214
+ #
215
+ # @see https://support.twitter.com/articles/20169409
216
+ # @note This method can only return up to the 100 most recent images.
217
+ # @note Images will not be returned from tweets posted before January 1, 2010.
218
+ # @rate_limited Yes
219
+ # @requires_authentication No unless the user whose timeline you're trying to view is protected
220
+ # @overload media_timeline(user, options={})
221
+ # @param user [Integer, String] A Twitter user ID or screen name.
222
+ # @param options [Hash] A customizable set of options.
223
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
224
+ # @option options [Integer] :page Specifies the page of results to retrieve.
225
+ # @option options [Boolean] :filter Include possibly sensitive media when set to false, 'f' or 0.
226
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
227
+ # @return [Array<Twitter::Status>]
228
+ # @example Return the 20 most recent statuses posted by @sferik
229
+ # Twitter.media_timeline("sferik")
230
+ def media_timeline(*args)
231
+ options = args.last.is_a?(Hash) ? args.pop : {}
232
+ if user = args.pop
233
+ options.merge_user!(user)
234
+ end
235
+ get("/1/statuses/media_timeline.json", options).map do |status|
236
+ Twitter::Status.new(status)
237
+ end
238
+ end
239
+
240
+ # Returns the 20 most recent statuses from the authenticating user's network
241
+ #
242
+ # @note Undocumented
243
+ # @rate_limited Yes
244
+ # @requires_authentication Yes
245
+ # @param options [Hash] A customizable set of options.
246
+ # @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
247
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
248
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
249
+ # @option options [Integer] :page Specifies the page of results to retrieve.
250
+ # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
251
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
252
+ # @option options [Boolean, String, Integer] :exclude_replies This parameter will prevent replies from appearing in the returned timeline. Using exclude_replies with the count parameter will mean you will receive up-to count tweets — this is because the count parameter retrieves that many tweets before filtering out retweets and replies.
253
+ # @return [Array<Twitter::Status>]
254
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
255
+ # @example Return the 20 most recent statuses from the authenticating user's network
256
+ # Twitter.network_timeline
257
+ def network_timeline(options={})
258
+ get("/i/statuses/network_timeline.json", options).map do |status|
259
+ Twitter::Status.new(status)
260
+ end
261
+ end
262
+
263
+ end
264
+ end
265
+ end
@@ -0,0 +1,55 @@
1
+ require 'twitter/trend'
2
+
3
+ module Twitter
4
+ class Client
5
+ # Defines methods related to global trends
6
+ # @see Twitter::Client::LocalTrends
7
+ module Trends
8
+
9
+ # Returns the top 20 trending topics for each hour in a given day
10
+ #
11
+ # @see https://dev.twitter.com/docs/api/1/get/trends/daily
12
+ # @rate_limited Yes
13
+ # @requires_authentication No
14
+ # @param date [Date] The start date for the report. A 404 error will be thrown if the date is older than the available search index (7-10 days). Dates in the future will be forced to the current date.
15
+ # @param options [Hash] A customizable set of options.
16
+ # @option options [String] :exclude Setting this equal to 'hashtags' will remove all hashtags from the trends list.
17
+ # @return [Hash]
18
+ # @example Return the top 20 trending topics for each hour of October 24, 2010
19
+ # Twitter.trends_daily(Date.parse("2010-10-24"))
20
+ def trends_daily(date=Date.today, options={})
21
+ trends = {}
22
+ get("/1/trends/daily.json", options.merge(:date => date.strftime('%Y-%m-%d')))['trends'].each do |key, value|
23
+ trends[key] = []
24
+ value.each do |trend|
25
+ trends[key] << Twitter::Trend.new(trend)
26
+ end
27
+ end
28
+ trends
29
+ end
30
+
31
+ # Returns the top 30 trending topics for each day in a given week
32
+ #
33
+ # @see https://dev.twitter.com/docs/api/1/get/trends/weekly
34
+ # @rate_limited Yes
35
+ # @requires_authentication No
36
+ # @param date [Date] The start date for the report. A 404 error will be thrown if the date is older than the available search index (7-10 days). Dates in the future will be forced to the current date.
37
+ # @param options [Hash] A customizable set of options.
38
+ # @option options [String] :exclude Setting this equal to 'hashtags' will remove all hashtags from the trends list.
39
+ # @return [Hash]
40
+ # @example Return the top ten topics that are currently trending on Twitter
41
+ # Twitter.trends_weekly(Date.parse("2010-10-24"))
42
+ def trends_weekly(date=Date.today, options={})
43
+ trends = {}
44
+ get("/1/trends/weekly.json", options.merge(:date => date.strftime('%Y-%m-%d')))['trends'].each do |key, value|
45
+ trends[key] = []
46
+ value.each do |trend|
47
+ trends[key] << Twitter::Trend.new(trend)
48
+ end
49
+ end
50
+ trends
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,191 @@
1
+ require 'twitter/status'
2
+ require 'twitter/oembed'
3
+
4
+ module Twitter
5
+ class Client
6
+ # Defines methods related to tweets
7
+ module Tweets
8
+
9
+ # Show up to 100 users who retweeted the status
10
+ #
11
+ # @see https://dev.twitter.com/docs/api/1/get/statuses/:id/retweeted_by
12
+ # @see https://dev.twitter.com/docs/api/1/get/statuses/:id/retweeted_by/ids
13
+ # @rate_limited Yes
14
+ # @requires_authentication Yes
15
+ # @param id [Integer] The numerical ID of the desired status.
16
+ # @param options [Hash] A customizable set of options.
17
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
18
+ # @option options [Integer] :page Specifies the page of results to retrieve.
19
+ # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
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
+ # @option options [Boolean] :ids_only ('false') Only return user ids instead of full user objects.
22
+ # @return [Array]
23
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
24
+ # @example Show up to 100 users who retweeted the status with the ID 28561922516
25
+ # Twitter.retweeters_of(28561922516)
26
+ def retweeters_of(id, options={})
27
+ if ids_only = !!options.delete(:ids_only)
28
+ get("/1/statuses/#{id}/retweeted_by/ids.json", options)
29
+ else
30
+ get("/1/statuses/#{id}/retweeted_by.json", options).map do |user|
31
+ Twitter::User.new(user)
32
+ end
33
+ end
34
+ end
35
+
36
+ # Returns up to 100 of the first retweets of a given tweet
37
+ #
38
+ # @see https://dev.twitter.com/docs/api/1/get/statuses/retweets/:id
39
+ # @rate_limited Yes
40
+ # @requires_authentication Yes
41
+ # @param id [Integer] The numerical ID of the desired status.
42
+ # @param options [Hash] A customizable set of options.
43
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
44
+ # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
45
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
46
+ # @return [Array<Twitter::Status>]
47
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
48
+ # @example Return up to 100 of the first retweets of the status with the ID 28561922516
49
+ # Twitter.retweets(28561922516)
50
+ def retweets(id, options={})
51
+ get("/1/statuses/retweets/#{id}.json", options).map do |status|
52
+ Twitter::Status.new(status)
53
+ end
54
+ end
55
+
56
+ # Returns a single status, specified by ID
57
+ #
58
+ # @see https://dev.twitter.com/docs/api/1/get/statuses/show/:id
59
+ # @rate_limited Yes
60
+ # @requires_authentication No unless the author of the status is protected
61
+ # @param id [Integer] The numerical ID of the desired status.
62
+ # @param options [Hash] A customizable set of options.
63
+ # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
64
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
65
+ # @return [Twitter::Status] The requested status.
66
+ # @example Return the status with the ID 25938088801
67
+ # Twitter.status(25938088801)
68
+ def status(id, options={})
69
+ status = get("/1/statuses/show/#{id}.json", options)
70
+ Twitter::Status.new(status)
71
+ end
72
+
73
+ # Returns an oEmbed version of a single status, specified by ID or url to the tweet
74
+ #
75
+ # @see https://dev.twitter.com/docs/api/1/get/statuses/oembed
76
+ # @rate_limited Yes
77
+ # @requires_authentication No unless the author of the status is protected
78
+ # @param id [Integer] The numerical ID of the desired status to be embedded.
79
+ # @param url [String] The url to the status to be embedded. ex: https://twitter.com/#!/twitter/status/25938088801
80
+ # @param options [Hash] A customizable set of options.
81
+ # @option options [Integer] :maxwidth The maximum width in pixels that the embed should be rendered at. This value is constrained to be between 250 and 550 pixels.
82
+ # @option options [Boolean, String, Integer] :hide_media Specifies whether the embedded Tweet should automatically expand images which were uploaded via {https://dev.twitter.com/docs/api/1/post/statuses/update_with_media POST statuses/update_with_media}. When set to either true, t or 1 images will not be expanded. Defaults to false.
83
+ # @option options [Boolean, String, Integer] :hide_thread Specifies whether the embedded Tweet should automatically show the original message in the case that the embedded Tweet is a reply. When set to either true, t or 1 the original Tweet will not be shown. Defaults to false.
84
+ # @option options [Boolean, String, Integer] :omit_script Specifies whether the embedded Tweet HTML should include a `<script>` element pointing to widgets.js. In cases where a page already includes widgets.js, setting this value to true will prevent a redundant script element from being included. When set to either true, t or 1 the `<script>` element will not be included in the embed HTML, meaning that pages must include a reference to widgets.js manually. Defaults to false.
85
+ # @option options [String] :align Specifies whether the embedded Tweet should be left aligned, right aligned, or centered in the page. Valid values are left, right, center, and none. Defaults to none, meaning no alignment styles are specified for the Tweet.
86
+ # @option options [String] :related A value for the TWT related parameter, as described in {https://dev.twitter.com/docs/intents Web Intents}. This value will be forwarded to all Web Intents calls.
87
+ # @option options [String] :lang Language code for the rendered embed. This will affect the text and localization of the rendered HTML.
88
+ def oembed(id_or_url, options={})
89
+ case id_or_url
90
+ when Integer
91
+ id = id_or_url
92
+ oembed = get("/1/statuses/oembed.json?id=#{id}", options)
93
+ when String
94
+ url = id_or_url
95
+ escaped_url = URI.escape(url, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
96
+ oembed = get("/1/statuses/oembed.json?url=#{escaped_url}", options)
97
+ end
98
+ Twitter::OEmbed.new(oembed)
99
+ end
100
+ # Destroys the specified status
101
+ #
102
+ # @see https://dev.twitter.com/docs/api/1/post/statuses/destroy/:id
103
+ # @note The authenticating user must be the author of the specified status.
104
+ # @rate_limited No
105
+ # @requires_authentication Yes
106
+ # @param id [Integer] The numerical ID of the desired status.
107
+ # @param options [Hash] A customizable set of options.
108
+ # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
109
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
110
+ # @return [Twitter::Status] The deleted status.
111
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
112
+ # @example Destroy the status with the ID 25938088801
113
+ # Twitter.status_destroy(25938088801)
114
+ def status_destroy(id, options={})
115
+ status = delete("/1/statuses/destroy/#{id}.json", options)
116
+ Twitter::Status.new(status)
117
+ end
118
+
119
+ # Retweets a tweet
120
+ #
121
+ # @see https://dev.twitter.com/docs/api/1/post/statuses/retweet/:id
122
+ # @rate_limited Yes
123
+ # @requires_authentication Yes
124
+ # @param id [Integer] The numerical ID of the desired status.
125
+ # @param options [Hash] A customizable set of options.
126
+ # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
127
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
128
+ # @return [Twitter::Status] The original tweet with retweet details embedded.
129
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
130
+ # @example Retweet the status with the ID 28561922516
131
+ # Twitter.retweet(28561922516)
132
+ def retweet(id, options={})
133
+ new_status = post("/1/statuses/retweet/#{id}.json", options)
134
+ orig_status = new_status.delete('retweeted_status')
135
+ orig_status['retweeted_status'] = new_status
136
+ Twitter::Status.new(orig_status)
137
+ end
138
+
139
+ # Updates the authenticating user's status
140
+ #
141
+ # @see https://dev.twitter.com/docs/api/1/post/statuses/update
142
+ # @note A status update with text identical to the authenticating user's current status will be ignored to prevent duplicates.
143
+ # @rate_limited No
144
+ # @requires_authentication Yes
145
+ # @param status [String] The text of your status update, up to 140 characters.
146
+ # @param options [Hash] A customizable set of options.
147
+ # @option options [Integer] :in_reply_to_status_id The ID of an existing status that the update is in reply to.
148
+ # @option options [Float] :lat The latitude of the location this tweet refers to. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
149
+ # @option options [Float] :long The longitude of the location this tweet refers to. The valid ranges for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
150
+ # @option options [String] :place_id A place in the world. These IDs can be retrieved from {Twitter::Client::Geo#reverse_geocode}.
151
+ # @option options [String] :display_coordinates Whether or not to put a pin on the exact coordinates a tweet has been sent from.
152
+ # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
153
+ # @option options [Boolean, String, Integer] :include_entities Include {https://dev.twitter.com/docs/tweet-entities Tweet Entities} when set to true, 't' or 1.
154
+ # @return [Twitter::Status] The created status.
155
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
156
+ # @example Update the authenticating user's status
157
+ # Twitter.update("I'm tweeting with @gem!")
158
+ def update(status, options={})
159
+ status = post("/1/statuses/update.json", options.merge(:status => status))
160
+ Twitter::Status.new(status)
161
+ end
162
+
163
+ # Updates with media the authenticating user's status
164
+ #
165
+ # @see http://dev.twitter.com/docs/api/1/post/statuses/update_with_media
166
+ # @note A status update with text/media identical to the authenticating user's current status will NOT be ignored
167
+ # @requires_authentication Yes
168
+ # @rate_limited No
169
+ # @param status [String] The text of your status update, up to 140 characters.
170
+ # @param media [File] A File object with your picture (PNG, JPEG or GIF)
171
+ # @param options [Hash] A customizable set of options.
172
+ # @option options [Integer] :in_reply_to_status_id The ID of an existing status that the update is in reply to.
173
+ # @option options [Float] :lat The latitude of the location this tweet refers to. This option will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding :long option.
174
+ # @option options [Float] :long The longitude of the location this tweet refers to. The valid ranges for longitude is -180.0 to +180.0 (East is positive) inclusive. This option will be ignored if outside that range, if it is not a number, if geo_enabled is disabled, or if there not a corresponding :lat option.
175
+ # @option options [String] :place_id A place in the world. These IDs can be retrieved from {Twitter::Client::Geo#reverse_geocode}.
176
+ # @option options [String] :display_coordinates Whether or not to put a pin on the exact coordinates a tweet has been sent from.
177
+ # @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
178
+ # @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1.
179
+ # @return [Twitter::Status] The created status.
180
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
181
+ # @example Update the authenticating user's status
182
+ # Twitter.update_with_media("I'm tweeting with @gem!", File.new('my_awesome_pic.jpeg'))
183
+ # Twitter.update_with_media("I'm tweeting with @gem!", {'io' => StringIO.new(pic), 'type' => 'jpg'})
184
+ def update_with_media(status, image, options={})
185
+ status = post("/1/statuses/update_with_media.json", options.merge('media[]' => image, 'status' => status), :endpoint => media_endpoint)
186
+ Twitter::Status.new(status)
187
+ end
188
+
189
+ end
190
+ end
191
+ end