twitter 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. data/CHANGELOG.md +673 -0
  2. data/LICENSE.md +20 -0
  3. data/README.md +415 -0
  4. data/Rakefile +11 -0
  5. data/lib/twitter.rb +29 -0
  6. data/lib/twitter/action/favorite.rb +19 -0
  7. data/lib/twitter/action/follow.rb +31 -0
  8. data/lib/twitter/action/list_member_added.rb +41 -0
  9. data/lib/twitter/action/mention.rb +48 -0
  10. data/lib/twitter/action/reply.rb +27 -0
  11. data/lib/twitter/action/retweet.rb +27 -0
  12. data/lib/twitter/action/tweet.rb +22 -0
  13. data/lib/twitter/action_factory.rb +22 -0
  14. data/lib/twitter/api.rb +2442 -0
  15. data/lib/twitter/base.rb +119 -0
  16. data/lib/twitter/basic_user.rb +8 -0
  17. data/lib/twitter/client.rb +96 -0
  18. data/lib/twitter/configurable.rb +67 -0
  19. data/lib/twitter/configuration.rb +20 -0
  20. data/lib/twitter/core_ext/array.rb +7 -0
  21. data/lib/twitter/core_ext/enumerable.rb +11 -0
  22. data/lib/twitter/core_ext/hash.rb +100 -0
  23. data/lib/twitter/core_ext/kernel.rb +15 -0
  24. data/lib/twitter/core_ext/string.rb +10 -0
  25. data/lib/twitter/creatable.rb +20 -0
  26. data/lib/twitter/cursor.rb +87 -0
  27. data/lib/twitter/default.rb +101 -0
  28. data/lib/twitter/direct_message.rb +21 -0
  29. data/lib/twitter/entity.rb +7 -0
  30. data/lib/twitter/entity/hashtag.rb +9 -0
  31. data/lib/twitter/entity/url.rb +9 -0
  32. data/lib/twitter/entity/user_mention.rb +9 -0
  33. data/lib/twitter/error.rb +34 -0
  34. data/lib/twitter/error/bad_gateway.rb +11 -0
  35. data/lib/twitter/error/bad_request.rb +10 -0
  36. data/lib/twitter/error/client_error.rb +35 -0
  37. data/lib/twitter/error/decode_error.rb +9 -0
  38. data/lib/twitter/error/forbidden.rb +10 -0
  39. data/lib/twitter/error/gateway_timeout.rb +11 -0
  40. data/lib/twitter/error/identity_map_key_error.rb +9 -0
  41. data/lib/twitter/error/internal_server_error.rb +11 -0
  42. data/lib/twitter/error/not_acceptable.rb +10 -0
  43. data/lib/twitter/error/not_found.rb +10 -0
  44. data/lib/twitter/error/rate_limited.rb +11 -0
  45. data/lib/twitter/error/server_error.rb +28 -0
  46. data/lib/twitter/error/service_unavailable.rb +11 -0
  47. data/lib/twitter/error/unauthorized.rb +10 -0
  48. data/lib/twitter/factory.rb +21 -0
  49. data/lib/twitter/geo.rb +15 -0
  50. data/lib/twitter/geo/point.rb +22 -0
  51. data/lib/twitter/geo/polygon.rb +8 -0
  52. data/lib/twitter/geo_factory.rb +18 -0
  53. data/lib/twitter/identity.rb +50 -0
  54. data/lib/twitter/identity_map.rb +22 -0
  55. data/lib/twitter/language.rb +7 -0
  56. data/lib/twitter/list.rb +18 -0
  57. data/lib/twitter/media/photo.rb +22 -0
  58. data/lib/twitter/media_factory.rb +17 -0
  59. data/lib/twitter/metadata.rb +7 -0
  60. data/lib/twitter/oembed.rb +8 -0
  61. data/lib/twitter/place.rb +34 -0
  62. data/lib/twitter/rate_limit.rb +45 -0
  63. data/lib/twitter/relationship.rb +36 -0
  64. data/lib/twitter/request/multipart_with_file.rb +41 -0
  65. data/lib/twitter/response/parse_json.rb +25 -0
  66. data/lib/twitter/response/raise_error.rb +30 -0
  67. data/lib/twitter/saved_search.rb +9 -0
  68. data/lib/twitter/search_results.rb +48 -0
  69. data/lib/twitter/settings.rb +17 -0
  70. data/lib/twitter/size.rb +24 -0
  71. data/lib/twitter/source_user.rb +15 -0
  72. data/lib/twitter/suggestion.rb +22 -0
  73. data/lib/twitter/target_user.rb +8 -0
  74. data/lib/twitter/trend.rb +14 -0
  75. data/lib/twitter/tweet.rb +145 -0
  76. data/lib/twitter/user.rb +97 -0
  77. data/lib/twitter/version.rb +18 -0
  78. data/spec/fixtures/about_me.json +1 -0
  79. data/spec/fixtures/activity_summary.json +1 -0
  80. data/spec/fixtures/all.json +1 -0
  81. data/spec/fixtures/bad_gateway.json +1 -0
  82. data/spec/fixtures/bad_request.json +1 -0
  83. data/spec/fixtures/by_friends.json +1 -0
  84. data/spec/fixtures/category.json +1 -0
  85. data/spec/fixtures/configuration.json +1 -0
  86. data/spec/fixtures/contributees.json +1 -0
  87. data/spec/fixtures/contributors.json +1 -0
  88. data/spec/fixtures/direct_message.json +1 -0
  89. data/spec/fixtures/direct_messages.json +1 -0
  90. data/spec/fixtures/end_session.json +1 -0
  91. data/spec/fixtures/enhance_your_calm.text +11 -0
  92. data/spec/fixtures/favorites.json +1 -0
  93. data/spec/fixtures/following.json +1 -0
  94. data/spec/fixtures/forbidden.json +1 -0
  95. data/spec/fixtures/friendships.json +1 -0
  96. data/spec/fixtures/ids.json +1 -0
  97. data/spec/fixtures/ids_list.json +1 -0
  98. data/spec/fixtures/ids_list2.json +1 -0
  99. data/spec/fixtures/image_facets.json +1 -0
  100. data/spec/fixtures/internal_server_error.json +1 -0
  101. data/spec/fixtures/languages.json +1 -0
  102. data/spec/fixtures/list.json +1 -0
  103. data/spec/fixtures/lists.json +1 -0
  104. data/spec/fixtures/locations.json +1 -0
  105. data/spec/fixtures/matching_trends.json +1 -0
  106. data/spec/fixtures/me.jpeg +0 -0
  107. data/spec/fixtures/media_timeline.json +1 -0
  108. data/spec/fixtures/members.json +1 -0
  109. data/spec/fixtures/no_user_matches.json +1 -0
  110. data/spec/fixtures/not_acceptable.json +1 -0
  111. data/spec/fixtures/not_following.json +1 -0
  112. data/spec/fixtures/not_found.json +1 -0
  113. data/spec/fixtures/oembed.json +1 -0
  114. data/spec/fixtures/pbjt.gif +0 -0
  115. data/spec/fixtures/pengwynn.json +1 -0
  116. data/spec/fixtures/phoenix_search.phoenix +1 -0
  117. data/spec/fixtures/place.json +1 -0
  118. data/spec/fixtures/places.json +1 -0
  119. data/spec/fixtures/privacy.json +1 -0
  120. data/spec/fixtures/profile_image.text +24 -0
  121. data/spec/fixtures/rate_limit_status.json +1 -0
  122. data/spec/fixtures/recommendations.json +1 -0
  123. data/spec/fixtures/related_results.json +1 -0
  124. data/spec/fixtures/resolve.json +1 -0
  125. data/spec/fixtures/retweet.json +1 -0
  126. data/spec/fixtures/retweeted_status.json +1 -0
  127. data/spec/fixtures/retweeters_of.json +1 -0
  128. data/spec/fixtures/retweets.json +1 -0
  129. data/spec/fixtures/saved_search.json +1 -0
  130. data/spec/fixtures/saved_searches.json +1 -0
  131. data/spec/fixtures/search.json +1 -0
  132. data/spec/fixtures/search_malformed.json +1 -0
  133. data/spec/fixtures/service_unavailable.json +1 -0
  134. data/spec/fixtures/settings.json +1 -0
  135. data/spec/fixtures/sferik.json +1 -0
  136. data/spec/fixtures/status.json +1 -0
  137. data/spec/fixtures/status_with_media.json +104 -0
  138. data/spec/fixtures/statuses.json +1 -0
  139. data/spec/fixtures/suggestions.json +1 -0
  140. data/spec/fixtures/tos.json +1 -0
  141. data/spec/fixtures/totals.json +1 -0
  142. data/spec/fixtures/trends.json +1 -0
  143. data/spec/fixtures/trends_current.json +1 -0
  144. data/spec/fixtures/trends_daily.json +1 -0
  145. data/spec/fixtures/trends_weekly.json +1 -0
  146. data/spec/fixtures/unauthorized.json +1 -0
  147. data/spec/fixtures/user_search.json +1 -0
  148. data/spec/fixtures/user_timeline.json +1 -0
  149. data/spec/fixtures/users.json +1 -0
  150. data/spec/fixtures/users_list.json +1 -0
  151. data/spec/fixtures/video_facets.json +1 -0
  152. data/spec/fixtures/we_concept_bg2.png +0 -0
  153. data/spec/fixtures/wildcomet2.jpe +0 -0
  154. data/spec/helper.rb +53 -0
  155. data/spec/twitter/action/favorite_spec.rb +29 -0
  156. data/spec/twitter/action/follow_spec.rb +29 -0
  157. data/spec/twitter/action/list_member_added_spec.rb +41 -0
  158. data/spec/twitter/action/mention_spec.rb +52 -0
  159. data/spec/twitter/action/reply_spec.rb +41 -0
  160. data/spec/twitter/action/retweet_spec.rb +41 -0
  161. data/spec/twitter/action_factory_spec.rb +37 -0
  162. data/spec/twitter/action_spec.rb +16 -0
  163. data/spec/twitter/api/account_spec.rb +148 -0
  164. data/spec/twitter/api/activity_spec.rb +41 -0
  165. data/spec/twitter/api/blocks_spec.rb +167 -0
  166. data/spec/twitter/api/direct_messages_spec.rb +142 -0
  167. data/spec/twitter/api/friendships_spec.rb +567 -0
  168. data/spec/twitter/api/geo_spec.rb +100 -0
  169. data/spec/twitter/api/help_spec.rb +76 -0
  170. data/spec/twitter/api/lists_spec.rb +900 -0
  171. data/spec/twitter/api/report_spam_spec.rb +29 -0
  172. data/spec/twitter/api/saved_searches_spec.rb +100 -0
  173. data/spec/twitter/api/search_spec.rb +68 -0
  174. data/spec/twitter/api/statuses_spec.rb +559 -0
  175. data/spec/twitter/api/trends_spec.rb +80 -0
  176. data/spec/twitter/api/users_spec.rb +419 -0
  177. data/spec/twitter/base_spec.rb +113 -0
  178. data/spec/twitter/basic_user_spec.rb +23 -0
  179. data/spec/twitter/client_spec.rb +175 -0
  180. data/spec/twitter/configuration_spec.rb +17 -0
  181. data/spec/twitter/cursor_spec.rb +102 -0
  182. data/spec/twitter/direct_message_spec.rb +56 -0
  183. data/spec/twitter/error/client_error_spec.rb +40 -0
  184. data/spec/twitter/error/server_error_spec.rb +24 -0
  185. data/spec/twitter/error_spec.rb +20 -0
  186. data/spec/twitter/geo/point_spec.rb +41 -0
  187. data/spec/twitter/geo/polygon_spec.rb +29 -0
  188. data/spec/twitter/geo_factory_spec.rb +21 -0
  189. data/spec/twitter/geo_spec.rb +29 -0
  190. data/spec/twitter/identifiable_spec.rb +54 -0
  191. data/spec/twitter/list_spec.rb +45 -0
  192. data/spec/twitter/media/photo_spec.rb +35 -0
  193. data/spec/twitter/media_factory_spec.rb +17 -0
  194. data/spec/twitter/oembed_spec.rb +146 -0
  195. data/spec/twitter/place_spec.rb +75 -0
  196. data/spec/twitter/rate_limit_spec.rb +76 -0
  197. data/spec/twitter/relationship_spec.rb +35 -0
  198. data/spec/twitter/saved_search_spec.rb +34 -0
  199. data/spec/twitter/search_results_spec.rb +89 -0
  200. data/spec/twitter/settings_spec.rb +16 -0
  201. data/spec/twitter/size_spec.rb +38 -0
  202. data/spec/twitter/source_user_spec.rb +23 -0
  203. data/spec/twitter/suggestion_spec.rb +50 -0
  204. data/spec/twitter/target_user_spec.rb +23 -0
  205. data/spec/twitter/trend_spec.rb +38 -0
  206. data/spec/twitter/tweet_spec.rb +307 -0
  207. data/spec/twitter/user_spec.rb +127 -0
  208. data/spec/twitter_spec.rb +93 -0
  209. data/twitter.gemspec +30 -0
  210. metadata +584 -0
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2006-2012 John Nunemaker, Wynn Netherland, Erik Michaels-Ober, Steve Richert
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,415 @@
1
+ # The Twitter Ruby Gem
2
+ [![Build Status](https://secure.travis-ci.org/sferik/twitter.png?branch=master)][travis]
3
+ [![Dependency Status](https://gemnasium.com/sferik/twitter.png?travis)][gemnasium]
4
+ [![Code Climate](https://codeclimate.com/badge.png)][codeclimate]
5
+
6
+ [travis]: http://travis-ci.org/sferik/twitter
7
+ [gemnasium]: https://gemnasium.com/sferik/twitter
8
+ [codeclimate]: https://codeclimate.com/github/sferik/twitter
9
+
10
+ #### A Ruby interface to the Twitter API.
11
+
12
+ ## Installation
13
+ ```sh
14
+ gem install twitter
15
+ ```
16
+
17
+ Looking for the Twitter command-line interface? It was [removed][] from this
18
+ gem in version 0.5.0 and now exists as a [separate project][separate]:
19
+
20
+ ```sh
21
+ gem install t
22
+ ```
23
+ [removed]: https://github.com/sferik/twitter/commit/dd2445e3e2c97f38b28a3f32ea902536b3897adf
24
+ [separate]: https://github.com/sferik/t
25
+
26
+ ## Documentation
27
+ [http://rdoc.info/gems/twitter][documentation]
28
+
29
+ [documentation]: http://rdoc.info/gems/twitter
30
+
31
+ ## Announcements
32
+ You should [follow @gem][follow] on Twitter for announcements and updates about
33
+ this library.
34
+
35
+ [follow]: https://twitter.com/gem
36
+
37
+ ## Mailing List
38
+ Please direct questions about this library to the [mailing list].
39
+
40
+ [mailing list]: https://groups.google.com/group/ruby-twitter-gem
41
+
42
+ ## Apps Wiki
43
+ Does your project or organization use this gem? Add it to the [apps
44
+ wiki][apps]!
45
+
46
+ [apps]: https://github.com/sferik/twitter/wiki/apps
47
+
48
+ ## What's new in version 4?
49
+
50
+ ### Twitter API v1.1
51
+
52
+ Version 4 of this library targets Twitter API v1.1. To understand the
53
+ implications of this change, please read the following announcements from
54
+ Twitter:
55
+
56
+ * [Changes coming in Version 1.1 of the Twitter API][coming]
57
+ * [Current status: API v1.1][status]
58
+ * [Overview: Version 1.1 of the Twitter API][overview]
59
+
60
+ [coming]: https://dev.twitter.com/blog/changes-coming-to-twitter-api
61
+ [status]: https://dev.twitter.com/blog/current-status-api-v1.1
62
+ [overview]: https://dev.twitter.com/docs/api/1.1/overview
63
+
64
+ Despite the removal of certain underlying functionality in Twitter API v1.1,
65
+ this library aims to preserve backward-compatibility wherever possible. For
66
+ example, despite the remove of the [`GET
67
+ statuses/retweeted_by_user`][retweeted_by_user] resource, the
68
+ `Twitter::API#retweeted_by_user` method continues to exist, implemented by
69
+ making multiple requests to the [`GET statuses/user_timeline`][user_timeline]
70
+ resource. As a result, there is no longer a one-to-one correlation between
71
+ method calls and Twitter API requests. In fact, it's possible for a single
72
+ method call to exceed the Twitter API rate limit for a resource. If you think
73
+ this might cause a problem for your application, feel free to [join the
74
+ discussion][discussion].
75
+
76
+ [retweeted_by_user]: https://dev.twitter.com/docs/api/1/get/statuses/retweeted_by_user
77
+ [user_timeline]: https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
78
+ [discussion]: https://dev.twitter.com/discussions/10644
79
+
80
+ ### Rate Limiting
81
+
82
+ Another consequence of Twitter API v1.1 is that the
83
+ `Twitter::Client#rate_limit` method has been removed, since the concept of a
84
+ client-wide rate limit no longer exists. Rate limits are now applied on a
85
+ per-resource level, however, since there is no longer a one-to-one mapping
86
+ between methods and Twitter API resources, it's not entirely obvious how rate
87
+ limit information should be exposed. I've decided to go back to the pre-3.0.0
88
+ behavior of including rate limit information on `Twitter::Error` objects.
89
+ Here's an example of how to handle rate limits:
90
+
91
+ ```ruby
92
+ MAX_ATTEMPTS = 3
93
+ num_attempts = 0
94
+ begin
95
+ num_attempts += 1
96
+ retweets = Twitter.retweeted_by_user("sferik")
97
+ rescue Twitter::Error::RateLimited => error
98
+ if num_attempts <= MAX_ATTEMPTS
99
+ # NOTE: Your process could go to sleep for up to 15 minutes but if you
100
+ # retry any sooner, it will almost certainly fail with the same exception.
101
+ sleep error.rate_limit.reset_in
102
+ retry
103
+ else
104
+ raise
105
+ end
106
+ end
107
+ ```
108
+ ### Methods Missing
109
+
110
+ As a consequence of moving to Twitter API v1.1, the following methods from
111
+ version 3 are no longer available in version 4:
112
+
113
+ * `Twitter::API#accept`
114
+ * `Twitter::API#deny`
115
+ * `Twitter::API#disable_notifications`
116
+ * `Twitter::API#enable_notifications`
117
+ * `Twitter::API#end_session`
118
+ * `Twitter::API#no_retweet_ids`
119
+ * `Twitter::API#rate_limit_status`
120
+ * `Twitter::API#rate_limited?`
121
+ * `Twitter::API#recommendations`
122
+ * `Twitter::API#related_results`
123
+ * `Twitter::API#retweeted_to_user`
124
+ * `Twitter::API#trends_daily`
125
+ * `Twitter::API#trends_weekly`
126
+ * `Twitter::Client#rate_limit`
127
+ * `Twitter::RateLimit#class`
128
+
129
+ ### Custom Endpoints
130
+
131
+ The `Twitter::API#update_with_media` method no longer uses the custom
132
+ `upload.twitter.com` endpoint, so `media_endpoint` configuration has been
133
+ removed. Likewise, the `Twitter::API#search` method no longer uses the custom
134
+ `search.twitter.com` endpoint, so `search_endpoint` configuration has also been
135
+ removed.
136
+
137
+ ### Errors
138
+
139
+ It's worth mentioning two new error classes:
140
+
141
+ * `Twitter::Error::GatewayTimeout`
142
+ * `Twitter::Error::RateLimited`
143
+
144
+ In previous versions of this library, rate limit errors were indicated by
145
+ raising either `Twitter::Error::BadRequest` or
146
+ `Twitter::Error::EnhanceYourCalm` (for the Search API). As of version 4, the
147
+ library will raise `Twitter::Error::RateLimited` for all rate limit errors. The
148
+ `Twitter::Error::EnhanceYourCalm` class has been aliased to
149
+ `Twitter::Error::RateLimited`.
150
+
151
+ ### Identity Map
152
+
153
+ In version 4, the identity map is [disabled by default][disabled]. If you want
154
+ to enable this feature, you can use the [default identity map][default] or
155
+ [write a custom identity map][custom].
156
+
157
+ ```ruby
158
+ Twitter.identity_map = Twitter::IdentityMap
159
+ ```
160
+
161
+ [disabled]: https://github.com/sferik/twitter/commit/c6c5960bea998abdc3e82cbb8dd68766a2df52e1
162
+ [default]: https://github.com/sferik/twitter/blob/master/lib/twitter/identity_map.rb
163
+ [custom]: https://github.com/sferik/twitter/blob/master/etc/sqlite_identity_map.rb
164
+
165
+ ## Configuration
166
+
167
+ Applications that make requests on behalf of one Twitter user at a time can
168
+ pass global configuration options as a block to the `Twitter.configure` method.
169
+
170
+ ```ruby
171
+ Twitter.configure do |config|
172
+ config.consumer_key = YOUR_CONSUMER_KEY
173
+ config.consumer_secret = YOUR_CONSUMER_SECRET
174
+ config.oauth_token = YOUR_OAUTH_TOKEN
175
+ config.oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET
176
+ end
177
+ ```
178
+
179
+ Alternately, you can set the following environment variables:
180
+
181
+ ```sh
182
+ TWITTER_CONSUMER_KEY
183
+ TWITTER_CONSUMER_SECRET
184
+ TWITTER_OAUTH_TOKEN
185
+ TWITTER_OAUTH_TOKEN_SECRET
186
+ ```
187
+
188
+ After configuration, requests can be made like so:
189
+
190
+ ```ruby
191
+ Twitter.update("I'm tweeting with @gem!")
192
+ ```
193
+
194
+ ### Threadsafe Configuration
195
+
196
+ Applications that make requests on behalf of multiple Twitter users should
197
+ avoid using global configuration. Instead, instantiate a `Twitter::Client` for
198
+ each user, passing in the user's token/secret pair as a `Hash`.
199
+
200
+ You can still specify the `consumer_key` and `consumer_secret` globally. (In a
201
+ Rails application, this could go in `config/initiliazers/twitter.rb`.)
202
+
203
+ ```ruby
204
+ Twitter.configure do |config|
205
+ config.consumer_key = YOUR_CONSUMER_KEY
206
+ config.consumer_secret = YOUR_CONSUMER_SECRET
207
+ end
208
+ ```
209
+
210
+ Then, for each user's token/secret pair, instantiate a `Twitter::Client`:
211
+
212
+ ```ruby
213
+ @erik = Twitter::Client.new(
214
+ :oauth_token => "Erik's OAuth token",
215
+ :oauth_token_secret => "Erik's OAuth secret"
216
+ )
217
+
218
+ @john = Twitter::Client.new(
219
+ :oauth_token => "John's OAuth token",
220
+ :oauth_token_secret => "John's OAuth secret"
221
+ )
222
+ ```
223
+
224
+ You can now make threadsafe requests as the authenticated user like so:
225
+
226
+ ```ruby
227
+ @erik.update("Tweeting as Erik!")
228
+ @john.update("Tweeting as John!")
229
+ ```
230
+
231
+ Or, if you prefer, you can specify all configuration options when instantiating
232
+ a `Twitter::Client`:
233
+
234
+ ```ruby
235
+ @client = Twitter::Client.new(
236
+ :consumer_key => "a consumer key",
237
+ :consumer_secret => "a consumer secret",
238
+ :oauth_token => "a user's OAuth token",
239
+ :oauth_token_secret => "a user's OAuth secret"
240
+ )
241
+ ```
242
+
243
+ This may be useful if you're using multiple consumer key/secret pairs.
244
+
245
+ ### Middleware
246
+
247
+ The Faraday middleware stack is fully configurable and is exposed as a
248
+ `Faraday::Builder` object. You can modify the default middleware in-place:
249
+
250
+ ```ruby
251
+ Twitter.middleware.insert_after Twitter::Response::RaiseClientError, CustomMiddleware
252
+ ```
253
+
254
+ A custom adapter may be set as part of a custom middleware stack:
255
+
256
+ ```ruby
257
+ Twitter.middleware = Faraday::Builder.new(
258
+ &Proc.new do |builder|
259
+ # Specify a middleware stack here
260
+ builder.adapter :some_other_adapter
261
+ end
262
+ )
263
+ ```
264
+
265
+ ## Usage Examples
266
+ ###### Return a user's location
267
+ ```ruby
268
+ Twitter.user("sferik").location
269
+ ```
270
+ ###### Return a user's most recent Tweet
271
+ ```ruby
272
+ Twitter.user_timeline("sferik").first.text
273
+ ```
274
+ ###### Return the text of a Tweet
275
+ ```ruby
276
+ Twitter.status(27558893223).text
277
+ ```
278
+ ###### Find the 3 most recent marriage proposals to @justinbieber
279
+ ```ruby
280
+ Twitter.search("to:justinbieber marry me", :count => 3, :result_type => "recent").results.map do |status|
281
+ "#{status.from_user}: #{status.text}"
282
+ end
283
+ ```
284
+ ###### Find a Japanese-language Tweet tagged #ruby (excluding retweets)
285
+ ```ruby
286
+ Twitter.search("#ruby -rt", :lang => "ja", :count => 1).results.first.text
287
+ ```
288
+ ###### Update your status
289
+ ```ruby
290
+ Twitter.update("I'm tweeting with @gem!")
291
+ ```
292
+ ###### Read the most recent Tweet in your timeline
293
+ ```ruby
294
+ Twitter.home_timeline.first.text
295
+
296
+ For more usage examples, please see the full [documentation][].
297
+ ```
298
+
299
+ ## Performance
300
+ You can improve performance by loading a faster JSON parsing library. By
301
+ default, JSON will be parsed with [okjson][]. For faster JSON parsing, we
302
+ recommend [Oj][].
303
+
304
+ [okjson]: https://github.com/ddollar/okjson
305
+ [oj]: https://rubygems.org/gems/oj
306
+
307
+ ## Additional Notes
308
+ This will be the last major version of this library to support Ruby 1.8.
309
+ Requiring Ruby 1.9 will allow us to [remove][class_variable_get]
310
+ [various][each_with_object] [hacks][singleton_class] put in place to maintain
311
+ Ruby 1.8 compatibility. [The first stable version of Ruby 1.9 was released on
312
+ August 19, 2010.][ruby192] If you haven't found the opportunity to upgrade your
313
+ Ruby interpreter since then, let this be your nudge. Once version 5 of this
314
+ library is released, all previous versions will cease to be supported, even if
315
+ critical security vulnerabilities are discovered.
316
+
317
+ [class_variable_get]: https://github.com/sferik/twitter/commit/88c5a0513d1b58a1d4ae1a1e3deeb012c9d19547
318
+ [each_with_object]: https://github.com/sferik/twitter/commit/6052252a07baf7aefe0f100bba0abd2cbb7139bb
319
+ [singleton_class]: https://github.com/sferik/twitter/commit/2ed9db21c87d1218b15373e42a36ad536b07dcbb
320
+ [ruby192]: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/367983
321
+
322
+ ## Stats
323
+
324
+ Here are some fun facts about this library:
325
+
326
+ * It is implemented in just 2,000 lines of Ruby code
327
+ * With over 5,000 lines of specs, the spec-to-code ratio is over 2.5:1
328
+ * The spec suite contains over 600 examples and runs in under 2 seconds
329
+ * It has 100% C0 code coverage (the tests execute every line of
330
+ source code at least once)
331
+ * It is comprehensive: you can request all documented Twitter REST API resources (over 100 resources)
332
+ * This gem works on every major Ruby implementation, including JRuby and
333
+ Rubinius
334
+ * The first version was released on November 26, 2006
335
+ * This gem has just three runtime dependencies: `faraday`, `multi_json`, and
336
+ `simple_oauth`
337
+ * Previous versions of this gem have been [downloaded over half a million
338
+ times][stats]
339
+
340
+ [stats]: https://rubygems.org/gems/twitter
341
+
342
+ ## Contributing
343
+ In the spirit of [free software][free-sw], **everyone** is encouraged to help
344
+ improve this project.
345
+
346
+ [free-sw]: http://www.fsf.org/licensing/essays/free-sw.html
347
+
348
+ Here are some ways *you* can contribute:
349
+
350
+ * by using alpha, beta, and prerelease versions
351
+ * by reporting bugs
352
+ * by suggesting new features
353
+ * by writing or editing documentation
354
+ * by writing specifications
355
+ * by writing code (**no patch is too small**: fix typos, add comments, clean up
356
+ inconsistent whitespace)
357
+ * by refactoring code
358
+ * by fixing [issues][]
359
+ * by reviewing patches
360
+
361
+ [issues]: https://github.com/sferik/twitter/issues
362
+
363
+ ## Submitting an Issue
364
+ We use the [GitHub issue tracker][issues] to track bugs and features. Before
365
+ submitting a bug report or feature request, check to make sure it hasn't
366
+ already been submitted. When submitting a bug report, please include a [Gist][]
367
+ that includes a stack trace and any details that may be necessary to reproduce
368
+ the bug, including your gem version, Ruby version, and operating system.
369
+ Ideally, a bug report should include a pull request with failing specs.
370
+
371
+ [gist]: https://gist.github.com/
372
+
373
+ ## Submitting a Pull Request
374
+ 1. [Fork the repository.][fork]
375
+ 2. [Create a topic branch.][branch]
376
+ 3. Add specs for your unimplemented feature or bug fix.
377
+ 4. Run `bundle exec rake spec`. If your specs pass, return to step 3.
378
+ 5. Implement your feature or bug fix.
379
+ 6. Run `bundle exec rake spec`. If your specs fail, return to step 5.
380
+ 7. Run `open coverage/index.html`. If your changes are not completely covered
381
+ by your tests, return to step 3.
382
+ 8. Add documentation for your feature or bug fix.
383
+ 9. Run `bundle exec rake yard`. If your changes are not 100% documented, go
384
+ back to step 8.
385
+ 10. Add, commit, and push your changes.
386
+ 11. [Submit a pull request.][pr]
387
+
388
+ [fork]: http://help.github.com/fork-a-repo/
389
+ [branch]: http://learn.github.com/p/branching.html
390
+ [pr]: http://help.github.com/send-pull-requests/
391
+
392
+ ## Supported Ruby Versions
393
+ This library aims to support and is [tested against][travis] the following Ruby
394
+ version:
395
+
396
+ * Ruby 1.8.7
397
+ * Ruby 1.9.2
398
+ * Ruby 1.9.3
399
+
400
+ This library may inadvertently work (or seem to work) on other Ruby
401
+ implementations, however support will only be provided for the versions listed
402
+ above.
403
+
404
+ If you would like this library to support another Ruby version, you may
405
+ volunteer to be a maintainer. Being a maintainer entails making sure all tests
406
+ run and pass on that implementation. When something breaks on your
407
+ implementation, you will be personally responsible for providing patches in a
408
+ timely fashion. If critical issues for a particular implementation exist at the
409
+ time of a major release, support for that Ruby version may be dropped.
410
+
411
+ ## Copyright
412
+ Copyright (c) 2006-2012 John Nunemaker, Wynn Netherland, Erik Michaels-Ober, Steve Richert.
413
+ See [LICENSE][] for details.
414
+
415
+ [license]: https://github.com/sferik/twitter/blob/master/LICENSE.md
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :test => :spec
8
+ task :default => :spec
9
+
10
+ require 'yard'
11
+ YARD::Rake::YardocTask.new
@@ -0,0 +1,29 @@
1
+ require 'twitter/client'
2
+ require 'twitter/configurable'
3
+
4
+ module Twitter
5
+ class << self
6
+ include Twitter::Configurable
7
+
8
+ # Delegate to a Twitter::Client
9
+ #
10
+ # @return [Twitter::Client]
11
+ def client
12
+ @client = Twitter::Client.new(options) unless defined?(@client) && @client.cache_key == options.hash
13
+ @client
14
+ end
15
+
16
+ def respond_to_missing?(method_name, include_private=false); client.respond_to?(method_name, include_private); end if RUBY_VERSION >= "1.9"
17
+ def respond_to?(method_name, include_private=false); client.respond_to?(method_name, include_private) || super; end if RUBY_VERSION < "1.9"
18
+
19
+ private
20
+
21
+ def method_missing(method_name, *args, &block)
22
+ return super unless client.respond_to?(method_name)
23
+ client.send(method_name, *args, &block)
24
+ end
25
+
26
+ end
27
+ end
28
+
29
+ Twitter.setup