ifttt-twitter 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/.yardopts +8 -0
- data/Gemfile +7 -0
- data/HISTORY.md +520 -0
- data/LICENSE.md +20 -0
- data/README.md +251 -0
- data/Rakefile +13 -0
- data/lib/twitter.rb +24 -0
- data/lib/twitter/action.rb +9 -0
- data/lib/twitter/action_factory.rb +28 -0
- data/lib/twitter/authenticatable.rb +24 -0
- data/lib/twitter/base.rb +40 -0
- data/lib/twitter/client.rb +126 -0
- data/lib/twitter/client/accounts.rb +180 -0
- data/lib/twitter/client/activity.rb +48 -0
- data/lib/twitter/client/block.rb +104 -0
- data/lib/twitter/client/direct_messages.rb +110 -0
- data/lib/twitter/client/favorites.rb +82 -0
- data/lib/twitter/client/friends_and_followers.rb +293 -0
- data/lib/twitter/client/help.rb +38 -0
- data/lib/twitter/client/legal.rb +32 -0
- data/lib/twitter/client/lists.rb +643 -0
- data/lib/twitter/client/local_trends.rb +46 -0
- data/lib/twitter/client/notification.rb +49 -0
- data/lib/twitter/client/places_and_geo.rb +113 -0
- data/lib/twitter/client/saved_searches.rb +73 -0
- data/lib/twitter/client/search.rb +94 -0
- data/lib/twitter/client/spam_reporting.rb +30 -0
- data/lib/twitter/client/suggested_users.rb +60 -0
- data/lib/twitter/client/timelines.rb +265 -0
- data/lib/twitter/client/trends.rb +55 -0
- data/lib/twitter/client/tweets.rb +191 -0
- data/lib/twitter/client/urls.rb +26 -0
- data/lib/twitter/client/users.rb +203 -0
- data/lib/twitter/config.rb +106 -0
- data/lib/twitter/configuration.rb +20 -0
- data/lib/twitter/connection.rb +43 -0
- data/lib/twitter/core_ext/hash.rb +81 -0
- data/lib/twitter/creatable.rb +14 -0
- data/lib/twitter/cursor.rb +44 -0
- data/lib/twitter/direct_message.rb +27 -0
- data/lib/twitter/error.rb +37 -0
- data/lib/twitter/error/bad_gateway.rb +7 -0
- data/lib/twitter/error/bad_request.rb +7 -0
- data/lib/twitter/error/client_error.rb +7 -0
- data/lib/twitter/error/enhance_your_calm.rb +13 -0
- data/lib/twitter/error/forbidden.rb +7 -0
- data/lib/twitter/error/internal_server_error.rb +7 -0
- data/lib/twitter/error/not_acceptable.rb +7 -0
- data/lib/twitter/error/not_found.rb +7 -0
- data/lib/twitter/error/server_error.rb +7 -0
- data/lib/twitter/error/service_unavailable.rb +7 -0
- data/lib/twitter/error/unauthorized.rb +7 -0
- data/lib/twitter/favorite.rb +28 -0
- data/lib/twitter/follow.rb +27 -0
- data/lib/twitter/geo_factory.rb +22 -0
- data/lib/twitter/language.rb +7 -0
- data/lib/twitter/list.rb +22 -0
- data/lib/twitter/list_member_added.rb +36 -0
- data/lib/twitter/media_factory.rb +21 -0
- data/lib/twitter/mention.rb +43 -0
- data/lib/twitter/metadata.rb +7 -0
- data/lib/twitter/oembed.rb +8 -0
- data/lib/twitter/photo.rb +24 -0
- data/lib/twitter/place.rb +36 -0
- data/lib/twitter/point.rb +27 -0
- data/lib/twitter/polygon.rb +14 -0
- data/lib/twitter/rate_limit_status.rb +15 -0
- data/lib/twitter/relationship.rb +18 -0
- data/lib/twitter/reply.rb +36 -0
- data/lib/twitter/request.rb +38 -0
- data/lib/twitter/request/gateway.rb +20 -0
- data/lib/twitter/request/multipart_with_file.rb +37 -0
- data/lib/twitter/request/oauth.rb +26 -0
- data/lib/twitter/request/phoenix.rb +22 -0
- data/lib/twitter/response/parse_json.rb +28 -0
- data/lib/twitter/response/raise_client_error.rb +49 -0
- data/lib/twitter/response/raise_server_error.rb +23 -0
- data/lib/twitter/retweet.rb +36 -0
- data/lib/twitter/saved_search.rb +16 -0
- data/lib/twitter/settings.rb +17 -0
- data/lib/twitter/size.rb +16 -0
- data/lib/twitter/status.rb +80 -0
- data/lib/twitter/suggestion.rb +22 -0
- data/lib/twitter/trend.rb +14 -0
- data/lib/twitter/user.rb +65 -0
- data/lib/twitter/version.rb +30 -0
- data/spec/faraday/request_spec.rb +25 -0
- data/spec/faraday/response_spec.rb +68 -0
- data/spec/fixtures/about_me.json +1 -0
- data/spec/fixtures/all.json +1 -0
- data/spec/fixtures/bad_gateway.json +1 -0
- data/spec/fixtures/bad_request.json +1 -0
- data/spec/fixtures/by_friends.json +1 -0
- data/spec/fixtures/category.json +1 -0
- data/spec/fixtures/configuration.json +1 -0
- data/spec/fixtures/contributees.json +1 -0
- data/spec/fixtures/contributors.json +1 -0
- data/spec/fixtures/direct_message.json +1 -0
- data/spec/fixtures/direct_messages.json +1 -0
- data/spec/fixtures/end_session.json +1 -0
- data/spec/fixtures/enhance_your_calm.text +11 -0
- data/spec/fixtures/false.json +1 -0
- data/spec/fixtures/favorites.json +1 -0
- data/spec/fixtures/forbidden.json +1 -0
- data/spec/fixtures/friendships.json +1 -0
- data/spec/fixtures/id_list.json +1 -0
- data/spec/fixtures/ids.json +1 -0
- data/spec/fixtures/image_facets.json +1 -0
- data/spec/fixtures/internal_server_error.json +1 -0
- data/spec/fixtures/languages.json +1 -0
- data/spec/fixtures/list.json +1 -0
- data/spec/fixtures/lists.json +1 -0
- data/spec/fixtures/locations.json +1 -0
- data/spec/fixtures/matching_trends.json +1 -0
- data/spec/fixtures/me.jpeg +0 -0
- data/spec/fixtures/media_timeline.json +1 -0
- data/spec/fixtures/members.json +1 -0
- data/spec/fixtures/n605431196_2079896_558_normal.jpg +0 -0
- data/spec/fixtures/no_user_matches.json +1 -0
- data/spec/fixtures/not_acceptable.json +1 -0
- data/spec/fixtures/not_found.json +1 -0
- data/spec/fixtures/oembed.json +1 -0
- data/spec/fixtures/pengwynn.json +1 -0
- data/spec/fixtures/phoenix_search.phoenix +1 -0
- data/spec/fixtures/place.json +1 -0
- data/spec/fixtures/places.json +1 -0
- data/spec/fixtures/privacy.json +1 -0
- data/spec/fixtures/profile_image.text +24 -0
- data/spec/fixtures/rate_limit_status.json +1 -0
- data/spec/fixtures/recommendations.json +1 -0
- data/spec/fixtures/relationship.json +1 -0
- data/spec/fixtures/resolve.json +1 -0
- data/spec/fixtures/retweet.json +1 -0
- data/spec/fixtures/retweeters_of.json +1 -0
- data/spec/fixtures/retweets.json +1 -0
- data/spec/fixtures/saved_search.json +1 -0
- data/spec/fixtures/saved_searches.json +1 -0
- data/spec/fixtures/search.json +1 -0
- data/spec/fixtures/service_unavailable.json +1 -0
- data/spec/fixtures/settings.json +1 -0
- data/spec/fixtures/sferik.json +1 -0
- data/spec/fixtures/status.json +1 -0
- data/spec/fixtures/status_with_media.json +104 -0
- data/spec/fixtures/statuses.json +1 -0
- data/spec/fixtures/suggestions.json +1 -0
- data/spec/fixtures/tos.json +1 -0
- data/spec/fixtures/totals.json +1 -0
- data/spec/fixtures/trends.json +1 -0
- data/spec/fixtures/trends_current.json +1 -0
- data/spec/fixtures/trends_daily.json +1 -0
- data/spec/fixtures/trends_weekly.json +1 -0
- data/spec/fixtures/true.json +1 -0
- data/spec/fixtures/unauthorized.json +1 -0
- data/spec/fixtures/user_search.json +1 -0
- data/spec/fixtures/user_timeline.json +1 -0
- data/spec/fixtures/users.json +1 -0
- data/spec/fixtures/users_list.json +1 -0
- data/spec/fixtures/video_facets.json +1 -0
- data/spec/fixtures/we_concept_bg2.png +0 -0
- data/spec/helper.rb +49 -0
- data/spec/twitter/action_factory_spec.rb +37 -0
- data/spec/twitter/action_spec.rb +16 -0
- data/spec/twitter/base_spec.rb +29 -0
- data/spec/twitter/client/accounts_spec.rb +181 -0
- data/spec/twitter/client/activity_spec.rb +43 -0
- data/spec/twitter/client/block_spec.rb +106 -0
- data/spec/twitter/client/direct_messages_spec.rb +98 -0
- data/spec/twitter/client/favorites_spec.rb +80 -0
- data/spec/twitter/client/friends_and_followers_spec.rb +478 -0
- data/spec/twitter/client/help_spec.rb +44 -0
- data/spec/twitter/client/legal_spec.rb +41 -0
- data/spec/twitter/client/lists_spec.rb +1104 -0
- data/spec/twitter/client/local_trends_spec.rb +58 -0
- data/spec/twitter/client/notification_spec.rb +47 -0
- data/spec/twitter/client/places_and_geo_spec.rb +100 -0
- data/spec/twitter/client/saved_searches_spec.rb +80 -0
- data/spec/twitter/client/search_spec.rb +92 -0
- data/spec/twitter/client/spam_reporting_spec.rb +28 -0
- data/spec/twitter/client/suggested_users_spec.rb +65 -0
- data/spec/twitter/client/timelines_spec.rb +231 -0
- data/spec/twitter/client/trends_spec.rb +51 -0
- data/spec/twitter/client/tweets_spec.rb +189 -0
- data/spec/twitter/client/urls_spec.rb +31 -0
- data/spec/twitter/client/users_spec.rb +323 -0
- data/spec/twitter/client_spec.rb +94 -0
- data/spec/twitter/configuration_spec.rb +17 -0
- data/spec/twitter/cursor_spec.rb +43 -0
- data/spec/twitter/direct_message_spec.rb +56 -0
- data/spec/twitter/favorite_spec.rb +29 -0
- data/spec/twitter/follow_spec.rb +29 -0
- data/spec/twitter/geo_factory_spec.rb +21 -0
- data/spec/twitter/list_spec.rb +34 -0
- data/spec/twitter/media_factory_spec.rb +17 -0
- data/spec/twitter/mention_spec.rb +52 -0
- data/spec/twitter/oembed_spec.rb +145 -0
- data/spec/twitter/photo_spec.rb +35 -0
- data/spec/twitter/place_spec.rb +75 -0
- data/spec/twitter/point_spec.rb +32 -0
- data/spec/twitter/polygon_spec.rb +18 -0
- data/spec/twitter/rate_limit_status_spec.rb +16 -0
- data/spec/twitter/relationship_spec.rb +27 -0
- data/spec/twitter/reply_spec.rb +41 -0
- data/spec/twitter/retweet_spec.rb +41 -0
- data/spec/twitter/saved_search_spec.rb +34 -0
- data/spec/twitter/settings_spec.rb +16 -0
- data/spec/twitter/size_spec.rb +18 -0
- data/spec/twitter/status_spec.rb +148 -0
- data/spec/twitter/suggestion_spec.rb +20 -0
- data/spec/twitter/trend_spec.rb +20 -0
- data/spec/twitter/user_spec.rb +50 -0
- data/spec/twitter_spec.rb +91 -0
- data/twitter.gemspec +42 -0
- metadata +564 -0
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 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.
|
data/README.md
ADDED
@@ -0,0 +1,251 @@
|
|
1
|
+
# The Twitter Ruby Gem [![Build Status](https://secure.travis-ci.org/jnunemaker/twitter.png?branch=master)][travis] [![Dependency Status](https://gemnasium.com/jnunemaker/twitter.png?travis)][gemnasium]
|
2
|
+
A Ruby wrapper for the Twitter API.
|
3
|
+
|
4
|
+
[travis]: http://travis-ci.org/jnunemaker/twitter
|
5
|
+
[gemnasium]: https://gemnasium.com/jnunemaker/twitter
|
6
|
+
|
7
|
+
## <a name="installation"></a>Installation
|
8
|
+
gem install twitter
|
9
|
+
|
10
|
+
Looking for the Twitter command-line interface? It was [removed] from this gem
|
11
|
+
in version 0.5.0 and now is [maintained][] as a separate project called `t`.
|
12
|
+
|
13
|
+
gem install t
|
14
|
+
|
15
|
+
[removed]: https://github.com/jnunemaker/twitter/commit/dd2445e3e2c97f38b28a3f32ea902536b3897adf
|
16
|
+
[maintained]: https://github.com/sferik/t
|
17
|
+
|
18
|
+
## <a name="documentation"></a>Documentation
|
19
|
+
[http://rdoc.info/gems/twitter][documentation]
|
20
|
+
|
21
|
+
[documentation]: http://rdoc.info/gems/twitter
|
22
|
+
|
23
|
+
## <a name="follow"></a>Follow @gem on Twitter
|
24
|
+
You should [follow @gem][follow] on Twitter for announcements and updates about
|
25
|
+
the gem.
|
26
|
+
|
27
|
+
[follow]: https://twitter.com/gem
|
28
|
+
|
29
|
+
## <a name="mailing_list"></a>Mailing List
|
30
|
+
Please direct any questions about the library to the [mailing list].
|
31
|
+
|
32
|
+
[mailing list]: https://groups.google.com/group/ruby-twitter-gem
|
33
|
+
|
34
|
+
## <a name="apps"></a>Apps Wiki
|
35
|
+
Does your project or organization use this gem? Add it to the [apps
|
36
|
+
wiki][apps]!
|
37
|
+
|
38
|
+
[apps]: https://github.com/jnunemaker/twitter/wiki/apps
|
39
|
+
|
40
|
+
## <a name="2.0"></a>What's new in version 2?
|
41
|
+
This version introduces a number of new classes, notably:
|
42
|
+
|
43
|
+
Twitter::Configuration Twitter::List Twitter::Polygon Twitter::Settings
|
44
|
+
Twitter::Cursor Twitter::Metadata Twitter::RateLimitStatus Twitter::Size
|
45
|
+
Twitter::DirectMessage Twitter::Mention Twitter::Relationship Twitter::Status
|
46
|
+
Twitter::Favorite Twitter::Photo Twitter::Reply Twitter::Suggestion
|
47
|
+
Twitter::Follow Twitter::Place Twitter::Retweet Twitter::Trend
|
48
|
+
Twitter::Language Twitter::Point Twitter::SavedSearch Twitter::User
|
49
|
+
|
50
|
+
These classes (plus Ruby primitives) have replaced all instances of
|
51
|
+
`Hashie::Mash`. This allows us to remove the gem's dependency on [hashie][] and
|
52
|
+
eliminate a layer in the middleware stack.
|
53
|
+
|
54
|
+
[hashie]: https://github.com/intridea/hashie
|
55
|
+
|
56
|
+
This should have the effect of making object instantiation and method
|
57
|
+
invocation faster and less susceptible to typos. For example, if you typed
|
58
|
+
`Twitter.user("sferik").loctaion`, a `Hashie::Mash` would return `nil` instead
|
59
|
+
of raising a `NoMethodError`.
|
60
|
+
|
61
|
+
Another benefit of these new objects is instance methods like `created_at` now
|
62
|
+
return a `Time` instead of a `String`. This should make the objects easier to
|
63
|
+
work with and better fulfills the promise of this library as a Ruby wrapper for
|
64
|
+
the Twitter API.
|
65
|
+
|
66
|
+
Any instance method that returns a boolean can now be called with a trailing
|
67
|
+
question mark, for example:
|
68
|
+
|
69
|
+
Twitter.user("sferik").protected?
|
70
|
+
|
71
|
+
The `Twitter::Search` class has been replaced by the `Twitter::Client#search`
|
72
|
+
method. This unifies the library's interfaces and will make the code easier to
|
73
|
+
maintain over time. As a result, you can no longer build queries by chaining
|
74
|
+
methods (ARel-style). The new syntax is more consistent and concise.
|
75
|
+
|
76
|
+
This version also introduces object equivalence, so objects that are logically
|
77
|
+
equivalent are considered equal, even if they don't occupy the same address in
|
78
|
+
memory, for example:
|
79
|
+
|
80
|
+
Twitter.user("sferik") == Twitter.user("sferik") #=> true
|
81
|
+
Twitter.user("sferik") == Twitter.user(7505382) #=> true
|
82
|
+
|
83
|
+
In previous versions of this gem, both of the above statements would have
|
84
|
+
returned false. We've stopped short of implementing a true identity map, such
|
85
|
+
that:
|
86
|
+
|
87
|
+
Twitter.user("sferik").object_id == Twitter.user("sferik").object_id
|
88
|
+
|
89
|
+
A true identity map may be implemented in future versions of this library.
|
90
|
+
|
91
|
+
### Additional Notes
|
92
|
+
* All deprecated methods have been removed.
|
93
|
+
* `Twitter::Client#totals` has been removed. Use `Twitter::Client#user`
|
94
|
+
instead.
|
95
|
+
* `Twitter.faraday_options` has been renamed to `Twitter.connection_options`.
|
96
|
+
* `Twitter::Client#friendships` now takes up to 3 arguments instead of 1.
|
97
|
+
* Support for the XML response format has been removed. This decision was
|
98
|
+
guided largely by Twitter, which has started removing XML responses available
|
99
|
+
for [some resources][trends]. This allows us to remove the gem's dependency
|
100
|
+
on [multi_xml][]. Using JSON is faster than XML, both in terms of parsing
|
101
|
+
speed and time over the wire.
|
102
|
+
* All error classes have been moved inside the `Twitter::Error` namespace. If
|
103
|
+
you were previously rescuing `Twitter::NotFound` you'll need to change that
|
104
|
+
to `Twitter::Error::NotFound`.
|
105
|
+
|
106
|
+
[trends]: https://dev.twitter.com/blog/changing-trends-api
|
107
|
+
[multi_xml]: https://github.com/sferik/multi_xml
|
108
|
+
|
109
|
+
## <a href="performance"></a>Performance
|
110
|
+
You can improve performance by preloading a faster JSON parsing library. By
|
111
|
+
default, JSON will be parsed with [okjson][]. For faster JSON parsing, we
|
112
|
+
recommend [yajl][].
|
113
|
+
|
114
|
+
[okjson]: https://github.com/ddollar/okjson
|
115
|
+
[yajl]: https://github.com/brianmario/yajl-ruby
|
116
|
+
|
117
|
+
## <a name="examples"></a>Usage Examples
|
118
|
+
Return [@sferik][sferik]'s location
|
119
|
+
|
120
|
+
Twitter.user("sferik").location
|
121
|
+
Return [@sferik][sferik]'s most recent Tweet
|
122
|
+
|
123
|
+
Twitter.user_timeline("sferik").first.text
|
124
|
+
Return the text of the Tweet at https://twitter.com/sferik/statuses/27558893223
|
125
|
+
|
126
|
+
Twitter.status(27558893223).text
|
127
|
+
Find the 3 most recent marriage proposals to [@justinbieber][justinbieber]
|
128
|
+
|
129
|
+
Twitter.search("to:justinbieber marry me", :rpp => 3, :result_type => "recent").map do |status|
|
130
|
+
"#{status.from_user}: #{status.text}"
|
131
|
+
end
|
132
|
+
|
133
|
+
Let's find a Japanese-language Tweet tagged #ruby (no retweets)
|
134
|
+
|
135
|
+
Twitter.search("#ruby -rt", :lang => "ja", :rpp => 1).first.text
|
136
|
+
|
137
|
+
Certain methods require authentication. To get your Twitter OAuth credentials,
|
138
|
+
register an app at http://dev.twitter.com/apps
|
139
|
+
|
140
|
+
Twitter.configure do |config|
|
141
|
+
config.consumer_key = YOUR_CONSUMER_KEY
|
142
|
+
config.consumer_secret = YOUR_CONSUMER_SECRET
|
143
|
+
config.oauth_token = YOUR_OAUTH_TOKEN
|
144
|
+
config.oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET
|
145
|
+
end
|
146
|
+
Update your status
|
147
|
+
|
148
|
+
Twitter.update("I'm tweeting with @gem!")
|
149
|
+
Read the most recent Tweet in your timeline
|
150
|
+
|
151
|
+
Twitter.home_timeline.first.text
|
152
|
+
Get your rate limit status
|
153
|
+
|
154
|
+
Twitter.rate_limit_status.remaining_hits.to_s + " Twitter API request(s) remaining this hour"
|
155
|
+
|
156
|
+
[sferik]: https://twitter.com/sferik
|
157
|
+
[justinbieber]: https://twitter.com/justinbieber
|
158
|
+
|
159
|
+
## <a name="proxy"></a>Configuration for API Proxy Services
|
160
|
+
Use of API proxy services, like [Apigee](http://apigee.com), can be used to
|
161
|
+
attain higher rate limits to the Twitter API.
|
162
|
+
|
163
|
+
Twitter.gateway = YOUR_GATEWAY_HOSTNAME # e.g 'twitter.apigee.com'
|
164
|
+
|
165
|
+
## <a name="contributing"></a>Contributing
|
166
|
+
In the spirit of [free software][free-sw], **everyone** is encouraged to help improve
|
167
|
+
this project.
|
168
|
+
|
169
|
+
[free-sw]: http://www.fsf.org/licensing/essays/free-sw.html
|
170
|
+
|
171
|
+
Here are some ways *you* can contribute:
|
172
|
+
|
173
|
+
* by using alpha, beta, and prerelease versions
|
174
|
+
* by reporting bugs
|
175
|
+
* by suggesting new features
|
176
|
+
* by writing or editing documentation
|
177
|
+
* by writing specifications
|
178
|
+
* by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
|
179
|
+
* by refactoring code
|
180
|
+
* by closing [issues][]
|
181
|
+
* by reviewing patches
|
182
|
+
* [financially][]
|
183
|
+
|
184
|
+
[issues]: https://github.com/jnunemaker/twitter/issues
|
185
|
+
[financially]: http://pledgie.com/campaigns/1193
|
186
|
+
|
187
|
+
All contributors will be added to the [history][] and will receive the respect
|
188
|
+
and gratitude of the community.
|
189
|
+
|
190
|
+
[history]: https://github.com/jnunemaker/twitter/blob/master/HISTORY.md
|
191
|
+
|
192
|
+
## <a name="issues"></a>Submitting an Issue
|
193
|
+
We use the [GitHub issue tracker][issues] to track bugs and features. Before
|
194
|
+
submitting a bug report or feature request, check to make sure it hasn't
|
195
|
+
already been submitted. You can indicate support for an existing issue by
|
196
|
+
voting it up. When submitting a bug report, please include a [gist][] that
|
197
|
+
includes a stack trace and any details that may be necessary to reproduce the
|
198
|
+
bug, including your gem version, Ruby version, and operating system. Ideally, a
|
199
|
+
bug report should include a pull request with failing specs.
|
200
|
+
|
201
|
+
[gist]: https://gist.github.com/
|
202
|
+
|
203
|
+
## <a name="pulls"></a>Submitting a Pull Request
|
204
|
+
1. Fork the project.
|
205
|
+
2. Create a topic branch.
|
206
|
+
3. Implement your feature or bug fix.
|
207
|
+
4. Add documentation for your feature or bug fix.
|
208
|
+
5. Run `bundle exec rake yard`. If your changes are not 100% documented, go
|
209
|
+
back to step 4.
|
210
|
+
6. Add specs for your feature or bug fix.
|
211
|
+
7. Run `bundle exec rake spec`. If your changes are not 100% covered, go back
|
212
|
+
to step 6.
|
213
|
+
8. Commit and push your changes.
|
214
|
+
9. Submit a pull request. Please do not include changes to the gemspec,
|
215
|
+
version, or history file. (If you want to create your own version for some
|
216
|
+
reason, please do so in a separate commit.)
|
217
|
+
|
218
|
+
## <a name="versions"></a>Supported Ruby Versions
|
219
|
+
This library aims to support and is [tested against][travis] the following Ruby
|
220
|
+
implementations:
|
221
|
+
|
222
|
+
* Ruby 1.8.7
|
223
|
+
* Ruby 1.9.2
|
224
|
+
* Ruby 1.9.3
|
225
|
+
* [JRuby][]
|
226
|
+
* [Rubinius][]
|
227
|
+
* [Ruby Enterprise Edition][ree]
|
228
|
+
|
229
|
+
[jruby]: http://www.jruby.org/
|
230
|
+
[rubinius]: http://rubini.us/
|
231
|
+
[ree]: http://www.rubyenterpriseedition.com/
|
232
|
+
|
233
|
+
If something doesn't work on one of these interpreters, it should be considered
|
234
|
+
a bug.
|
235
|
+
|
236
|
+
This library may inadvertently work (or seem to work) on other Ruby
|
237
|
+
implementations, however support will only be provided for the versions listed
|
238
|
+
above.
|
239
|
+
|
240
|
+
If you would like this library to support another Ruby version, you may
|
241
|
+
volunteer to be a maintainer. Being a maintainer entails making sure all tests
|
242
|
+
run and pass on that implementation. When something breaks on your
|
243
|
+
implementation, you will be personally responsible for providing patches in a
|
244
|
+
timely fashion. If critical issues for a particular implementation exist at the
|
245
|
+
time of a major release, support for that Ruby version may be dropped.
|
246
|
+
|
247
|
+
## <a name="copyright"></a>Copyright
|
248
|
+
Copyright (c) 2011 John Nunemaker, Wynn Netherland, Erik Michaels-Ober, Steve Richert.
|
249
|
+
See [LICENSE][] for details.
|
250
|
+
|
251
|
+
[license]: https://github.com/jnunemaker/twitter/blob/master/LICENSE.md
|
data/Rakefile
ADDED
data/lib/twitter.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'twitter/client'
|
2
|
+
require 'twitter/config'
|
3
|
+
|
4
|
+
module Twitter
|
5
|
+
extend Config
|
6
|
+
class << self
|
7
|
+
# Alias for Twitter::Client.new
|
8
|
+
#
|
9
|
+
# @return [Twitter::Client]
|
10
|
+
def new(options={})
|
11
|
+
Twitter::Client.new(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Delegate to Twitter::Client
|
15
|
+
def method_missing(method, *args, &block)
|
16
|
+
return super unless new.respond_to?(method)
|
17
|
+
new.send(method, *args, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def respond_to?(method, include_private=false)
|
21
|
+
new.respond_to?(method, include_private) || super(method, include_private)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'twitter/favorite'
|
2
|
+
require 'twitter/follow'
|
3
|
+
require 'twitter/list_member_added'
|
4
|
+
require 'twitter/mention'
|
5
|
+
require 'twitter/reply'
|
6
|
+
require 'twitter/retweet'
|
7
|
+
|
8
|
+
require 'active_support/core_ext/string/inflections'
|
9
|
+
|
10
|
+
module Twitter
|
11
|
+
class ActionFactory
|
12
|
+
|
13
|
+
# Instantiates a new action object
|
14
|
+
#
|
15
|
+
# @param attrs [Hash]
|
16
|
+
# @raise [ArgumentError] Error raised when supplied argument is missing an 'action' key.
|
17
|
+
# @return [Twitter::Favorite, Twitter::Follow, Twitter::ListMemberAdded, Twitter::Mention, Twitter::Reply, Twitter::Retweet]
|
18
|
+
def self.new(action={})
|
19
|
+
type = action.delete('action')
|
20
|
+
if type
|
21
|
+
Twitter.const_get(type.camelize.to_sym).new(action)
|
22
|
+
else
|
23
|
+
raise ArgumentError, "argument must have an 'action' key"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Twitter
|
2
|
+
module Authenticatable
|
3
|
+
|
4
|
+
# Credentials hash
|
5
|
+
#
|
6
|
+
# @return [Hash]
|
7
|
+
def credentials
|
8
|
+
{
|
9
|
+
:consumer_key => consumer_key,
|
10
|
+
:consumer_secret => consumer_secret,
|
11
|
+
:token => oauth_token,
|
12
|
+
:token_secret => oauth_token_secret,
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
# Check whether credentials are present
|
17
|
+
#
|
18
|
+
# @return [Boolean]
|
19
|
+
def credentials?
|
20
|
+
credentials.values.all?
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/twitter/base.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Twitter
|
2
|
+
class Base
|
3
|
+
attr_accessor :attrs
|
4
|
+
alias :to_hash :attrs
|
5
|
+
|
6
|
+
# Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key
|
7
|
+
#
|
8
|
+
# @overload self.lazy_attr_reader(attr)
|
9
|
+
# @param attr [Symbol]
|
10
|
+
# @overload self.lazy_attr_reader(attrs)
|
11
|
+
# @param attrs [Array<Symbol>]
|
12
|
+
def self.lazy_attr_reader(*attrs)
|
13
|
+
attrs.each do |attribute|
|
14
|
+
class_eval do
|
15
|
+
define_method attribute do
|
16
|
+
@attrs[attribute.to_s]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Initializes a new Base object
|
23
|
+
#
|
24
|
+
# @param attrs [Hash]
|
25
|
+
# @return [Twitter::Base]
|
26
|
+
def initialize(attrs={})
|
27
|
+
@attrs = attrs.dup
|
28
|
+
end
|
29
|
+
|
30
|
+
# Initializes a new Base object
|
31
|
+
#
|
32
|
+
# @param method [String, Symbol] Message to send to the object
|
33
|
+
def [](method)
|
34
|
+
self.__send__(method.to_sym)
|
35
|
+
rescue NoMethodError
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'twitter/authenticatable'
|
2
|
+
require 'twitter/config'
|
3
|
+
require 'twitter/configuration'
|
4
|
+
require 'twitter/connection'
|
5
|
+
require 'twitter/cursor'
|
6
|
+
require 'twitter/direct_message'
|
7
|
+
require 'twitter/language'
|
8
|
+
require 'twitter/list'
|
9
|
+
require 'twitter/favorite'
|
10
|
+
require 'twitter/follow'
|
11
|
+
require 'twitter/mention'
|
12
|
+
require 'twitter/metadata'
|
13
|
+
require 'twitter/oembed'
|
14
|
+
require 'twitter/photo'
|
15
|
+
require 'twitter/place'
|
16
|
+
require 'twitter/point'
|
17
|
+
require 'twitter/polygon'
|
18
|
+
require 'twitter/rate_limit_status'
|
19
|
+
require 'twitter/relationship'
|
20
|
+
require 'twitter/reply'
|
21
|
+
require 'twitter/request'
|
22
|
+
require 'twitter/retweet'
|
23
|
+
require 'twitter/saved_search'
|
24
|
+
require 'twitter/settings'
|
25
|
+
require 'twitter/size'
|
26
|
+
require 'twitter/status'
|
27
|
+
require 'twitter/suggestion'
|
28
|
+
require 'twitter/trend'
|
29
|
+
require 'twitter/user'
|
30
|
+
|
31
|
+
module Twitter
|
32
|
+
# Wrapper for the Twitter REST API
|
33
|
+
#
|
34
|
+
# @note All methods have been separated into modules and follow the same grouping used in {http://dev.twitter.com/doc the Twitter API Documentation}.
|
35
|
+
# @see http://dev.twitter.com/pages/every_developer
|
36
|
+
class Client
|
37
|
+
|
38
|
+
include Twitter::Authenticatable
|
39
|
+
include Twitter::Connection
|
40
|
+
include Twitter::Request
|
41
|
+
|
42
|
+
require 'twitter/client/accounts'
|
43
|
+
include Twitter::Client::Accounts
|
44
|
+
|
45
|
+
require 'twitter/client/activity'
|
46
|
+
include Twitter::Client::Activity
|
47
|
+
|
48
|
+
require 'twitter/client/block'
|
49
|
+
include Twitter::Client::Block
|
50
|
+
|
51
|
+
require 'twitter/client/direct_messages'
|
52
|
+
include Twitter::Client::DirectMessages
|
53
|
+
|
54
|
+
require 'twitter/client/favorites'
|
55
|
+
include Twitter::Client::Favorites
|
56
|
+
|
57
|
+
require 'twitter/client/friends_and_followers'
|
58
|
+
include Twitter::Client::FriendsAndFollowers
|
59
|
+
|
60
|
+
require 'twitter/client/help'
|
61
|
+
include Twitter::Client::Help
|
62
|
+
|
63
|
+
require 'twitter/client/legal'
|
64
|
+
include Twitter::Client::Legal
|
65
|
+
|
66
|
+
require 'twitter/client/lists'
|
67
|
+
include Twitter::Client::Lists
|
68
|
+
|
69
|
+
require 'twitter/client/local_trends'
|
70
|
+
include Twitter::Client::LocalTrends
|
71
|
+
|
72
|
+
require 'twitter/client/notification'
|
73
|
+
include Twitter::Client::Notification
|
74
|
+
|
75
|
+
require 'twitter/client/places_and_geo'
|
76
|
+
include Twitter::Client::PlacesAndGeo
|
77
|
+
|
78
|
+
require 'twitter/client/saved_searches'
|
79
|
+
include Twitter::Client::SavedSearches
|
80
|
+
|
81
|
+
require 'twitter/client/search'
|
82
|
+
include Twitter::Client::Search
|
83
|
+
|
84
|
+
require 'twitter/client/spam_reporting'
|
85
|
+
include Twitter::Client::SpamReporting
|
86
|
+
|
87
|
+
require 'twitter/client/suggested_users'
|
88
|
+
include Twitter::Client::SuggestedUsers
|
89
|
+
|
90
|
+
require 'twitter/client/timelines'
|
91
|
+
include Twitter::Client::Timelines
|
92
|
+
|
93
|
+
require 'twitter/client/trends'
|
94
|
+
include Twitter::Client::Trends
|
95
|
+
|
96
|
+
require 'twitter/client/tweets'
|
97
|
+
include Twitter::Client::Tweets
|
98
|
+
|
99
|
+
require 'twitter/client/urls'
|
100
|
+
include Twitter::Client::Urls
|
101
|
+
|
102
|
+
require 'twitter/client/users'
|
103
|
+
include Twitter::Client::Users
|
104
|
+
|
105
|
+
attr_accessor *Config::VALID_OPTIONS_KEYS
|
106
|
+
|
107
|
+
# Initializes a new API object
|
108
|
+
#
|
109
|
+
# @param attrs [Hash]
|
110
|
+
# @return [Twitter::Client]
|
111
|
+
def initialize(attrs={})
|
112
|
+
attrs = Twitter.options.merge(attrs)
|
113
|
+
Config::VALID_OPTIONS_KEYS.each do |key|
|
114
|
+
instance_variable_set("@#{key}".to_sym, attrs[key])
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# Returns the configured screen name or the screen name of the authenticated user
|
119
|
+
#
|
120
|
+
# @return [Twitter::User]
|
121
|
+
def current_user
|
122
|
+
@current_user ||= Twitter::User.new(self.verify_credentials)
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|