twitter 5.17.0 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +37 -10
- data/LICENSE.md +1 -1
- data/README.md +78 -407
- data/lib/twitter/base.rb +5 -19
- data/lib/twitter/basic_user.rb +0 -3
- data/lib/twitter/client.rb +9 -23
- data/lib/twitter/configuration.rb +4 -4
- data/lib/twitter/creatable.rb +5 -1
- data/lib/twitter/cursor.rb +13 -4
- data/lib/twitter/direct_message.rb +2 -0
- data/lib/twitter/direct_message_event.rb +44 -0
- data/lib/twitter/direct_messages/welcome_message.rb +17 -0
- data/lib/twitter/direct_messages/welcome_message_rule.rb +12 -0
- data/lib/twitter/direct_messages/welcome_message_rule_wrapper.rb +36 -0
- data/lib/twitter/direct_messages/welcome_message_wrapper.rb +42 -0
- data/lib/twitter/entity/uri.rb +0 -4
- data/lib/twitter/enumerable.rb +14 -3
- data/lib/twitter/error.rb +122 -95
- data/lib/twitter/geo_results.rb +0 -1
- data/lib/twitter/headers.rb +11 -15
- data/lib/twitter/media/photo.rb +5 -2
- data/lib/twitter/media/video.rb +5 -2
- data/lib/twitter/media/video_info.rb +1 -1
- data/lib/twitter/null_object.rb +20 -7
- data/lib/twitter/premium_search_results.rb +67 -0
- data/lib/twitter/profile.rb +5 -4
- data/lib/twitter/profile_banner.rb +1 -2
- data/lib/twitter/rate_limit.rb +3 -3
- data/lib/twitter/rest/account_activity.rb +99 -0
- data/lib/twitter/rest/api.rb +6 -2
- data/lib/twitter/rest/client.rb +0 -78
- data/lib/twitter/rest/direct_messages/welcome_messages.rb +90 -0
- data/lib/twitter/rest/direct_messages.rb +133 -44
- data/lib/twitter/rest/favorites.rb +29 -8
- data/lib/twitter/rest/friends_and_followers.rb +1 -3
- data/lib/twitter/rest/lists.rb +20 -30
- data/lib/twitter/rest/oauth.rb +15 -15
- data/lib/twitter/rest/premium_search.rb +34 -0
- data/lib/twitter/rest/request.rb +133 -18
- data/lib/twitter/rest/saved_searches.rb +1 -3
- data/lib/twitter/rest/search.rb +6 -3
- data/lib/twitter/rest/timelines.rb +1 -0
- data/lib/twitter/rest/trends.rb +1 -0
- data/lib/twitter/rest/tweets.rb +54 -18
- data/lib/twitter/rest/undocumented.rb +3 -4
- data/lib/twitter/rest/upload_utils.rb +68 -0
- data/lib/twitter/rest/users.rb +23 -37
- data/lib/twitter/rest/utils.rb +38 -28
- data/lib/twitter/search_results.rb +4 -4
- data/lib/twitter/streaming/client.rb +23 -25
- data/lib/twitter/streaming/connection.rb +37 -11
- data/lib/twitter/streaming/deleted_tweet.rb +0 -1
- data/lib/twitter/streaming/event.rb +6 -6
- data/lib/twitter/streaming/message_parser.rb +1 -1
- data/lib/twitter/streaming/response.rb +7 -3
- data/lib/twitter/trend_results.rb +1 -2
- data/lib/twitter/tweet.rb +11 -6
- data/lib/twitter/user.rb +2 -4
- data/lib/twitter/utils.rb +5 -18
- data/lib/twitter/version.rb +6 -6
- data/lib/twitter.rb +5 -0
- data/twitter.gemspec +10 -11
- metadata +31 -42
- data/lib/twitter/rest/media.rb +0 -30
- data/lib/twitter/rest/request/multipart_with_file.rb +0 -47
- data/lib/twitter/rest/response/parse_error_json.rb +0 -13
- data/lib/twitter/rest/response/parse_json.rb +0 -31
- data/lib/twitter/rest/response/raise_error.rb +0 -32
- data/lib/twitter/token.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 578178613b24f694731c9b87c940488762c35a0f4027b57bbd518bd9f914469c
|
4
|
+
data.tar.gz: 4ad56cc9e3c49d60cdc9f60777f37070cd6d933cd53bb2b2a9e82fe6f6f5f193
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9e85b61e8f806fda08720a1b3290370bf1824bd5afba0f2afce2e3d29956dafaa60ae500299349863e320074d4c8944046dd98b065d7f9900c7eb4e896fa05f
|
7
|
+
data.tar.gz: a10adbd38f44ba009ca21230a3a439f3b246bc84779aa9f80161643efb36e6abebeeb0d648257d1a29ccb1a65b06de445eac523aff36137e045cb40beae0246c
|
data/CHANGELOG.md
CHANGED
@@ -1,16 +1,43 @@
|
|
1
|
-
|
1
|
+
7.0.0
|
2
2
|
------
|
3
|
-
* [Add `
|
4
|
-
* [
|
5
|
-
* [
|
6
|
-
* [
|
3
|
+
* [Add `Twitter::DirectMessageEvent`](https://github.com/sferik/twitter/commit/38f6aaa482dcd5f4982abd811dbe6e21e36c2ae8) ([@FabienChaynes](https://twitter.com/FabienChaynes))
|
4
|
+
* [Create `Twitter::DirectMessageEvent` with media](https://github.com/sferik/twitter/commit/21478530ec6f8a798717a5ab8b197b895db3bc28) ([@FabienChaynes](https://twitter.com/FabienChaynes))
|
5
|
+
* [Support for DM welcome messages](https://github.com/sferik/twitter/pull/950) ([@FabienChaynes](https://twitter.com/FabienChaynes))
|
6
|
+
* [Support for closing `Twitter::Streaming::Connection`](https://github.com/sferik/twitter/commit/89e3543aa06e00eeab7eaf5bdd3a33a6112356b1) ([@okkez](https://twitter.com/okkez))
|
7
|
+
* [Add `Twitter::REST::Client#create_direct_message_event`](https://github.com/sferik/twitter/commit/b45d545c7ebfd28e4d908037dd3fde04e3c307cf) ([@cyu](https://twitter.com/cyu))
|
8
|
+
* [Add `Twitter::REST::Client#premium_search`](https://github.com/sferik/twitter/pull/953)
|
9
|
+
* [Add `Twitter::REST::AccountActivity`](https://github.com/sferik/twitter/pull/939)
|
10
|
+
* [Update all direct message methods to return `Twitter::DirectMessageEvent`](https://github.com/sferik/twitter/commit/0833471366a33657cd2920850e3928db010eecab) ([@flikglick](https://twitter.com/flikglick))
|
11
|
+
* [Correctly handle different `Twitter::Error::AlreadyRetweeted` error messages](https://github.com/sferik/twitter/commit/c9bf100eedc89aee43689c17f160025e0f40cfb4) ([@knu](https://twitter.com/knu))
|
12
|
+
* [Fix proxy setting sample](https://github.com/sferik/twitter/commit/91c037cfb26ac0c9d3099cdeec42d65fe8716b78) ([@nicklegr](https://twitter.com/nicklegr))
|
13
|
+
* [Add Active Support `presence` methods on `Twitter::NullObject`](https://github.com/sferik/twitter/commit/07a5d7b60f335aefd583dae85ba959235bc9f55f) ([@davebrace](https://twitter.com/davebrace))
|
14
|
+
* [Upload GIFs over 5MB in chunks](https://github.com/sferik/twitter/commit/ba6a3062782b37cf83b9813c5128c87d4971ab9c) ([@wild_dmitry](https://twitter.com/wild_dmitry))
|
15
|
+
* [Track rate limit when searching tweets](https://github.com/sferik/twitter/commit/067e751d58b7bb0bfbe8a5531a4288f4c966b301) ([@dsalahutdinov1](https://twitter.com/dsalahutdinov1))
|
16
|
+
* [Add `quote_count` and `reply_count` attributes to `Twitter::Tweet`](https://github.com/sferik/twitter/commit/844818cad07ce490ccb9d8542ebb6b4fc7a61cb4)
|
17
|
+
* [Drop support for Ruby 2.0, 2.1, and 2.2](https://github.com/sferik/twitter/commit/95861ec83e582c2a88499b97d9d5388a96d0abf0)
|
18
|
+
|
19
|
+
6.2.0
|
20
|
+
------
|
21
|
+
Not yet documented, sorry. For now, please use git to compare tags:
|
22
|
+
https://github.com/sferik/twitter/compare/v6.1.0...v6.2.0
|
23
|
+
|
24
|
+
6.1.0
|
25
|
+
------
|
26
|
+
Not yet documented, sorry. For now, please use git to compare tags:
|
27
|
+
https://github.com/sferik/twitter/compare/v6.0.0...v6.1.0
|
28
|
+
|
29
|
+
6.0.0
|
30
|
+
------
|
31
|
+
* [Drop support for Ruby 1.8.7 and Ruby 1.9.3](https://github.com/sferik/twitter/commit/27980f45fb357e34b86e46cb9134d86ed29b3ce3)
|
7
32
|
|
8
33
|
5.16.0
|
9
34
|
------
|
10
|
-
* [Add
|
11
|
-
* [Add
|
12
|
-
* [
|
13
|
-
* [
|
35
|
+
* [Add Twitter::Trend#tweet_volume](https://github.com/sferik/twitter/commit/e797b62e5e6a768e8aeafde6186e1f5310e6bfc6)
|
36
|
+
* [Add new settings to Twitter::Settings](https://github.com/sferik/twitter/commit/d047ce00034d26a99927076c28679ce08fd69308)
|
37
|
+
* [Fix `Version.to_a`](https://github.com/sferik/twitter/commit/0cd119abf64e6c2b7fd861b0df65b7cb41d892b4)
|
38
|
+
* [Remove the encoding of profile urls](https://github.com/sferik/twitter/commit/6d46bd689ab4a4f119d1d692488aab37e4e99893)
|
39
|
+
* [Update http dependency to ~> 1.0](https://github.com/sferik/twitter/commit/8d379a45be6948a9d9264aa2e91ef5f7bdbe1db8)
|
40
|
+
* [Fetch host and port directly from the request object](https://github.com/sferik/twitter/commit/f9f1bbdabde2ec96dcdd8900fe7bca072f9bea6b)
|
14
41
|
|
15
42
|
5.15.0
|
16
43
|
------
|
@@ -59,7 +86,7 @@
|
|
59
86
|
5.9.0
|
60
87
|
-----
|
61
88
|
* [Use expanded URIs when available](https://github.com/sferik/twitter/commit/f1d5d1f4c0ea75ebeaf9e7eb760b9efd245a5df2)
|
62
|
-
* [Deprecate `Twitter::REST::Client#middleware=` and `#connection_options`](https://github.com/sferik/twitter/commit/
|
89
|
+
* [Deprecate `Twitter::REST::Client#middleware=` and `#connection_options`](https://github.com/sferik/twitter/commit/2ec17d8d43a87766dd4b89fcc6d5a2433530bf7c)
|
63
90
|
* [Ensure predicate methods return `false` for `Twitter::NullObject`](https://github.com/sferik/twitter/commit/f1b42bf82440f2dc0ba61761fc8f12460e20aadf)
|
64
91
|
* [Make `Twitter::Place#id` attribute accessible](https://github.com/sferik/twitter/commit/a4fa4739283a325886d44f97b2648e3b00f933b1)
|
65
92
|
* [Enable injection of custom TCP/SSL socket classes](https://github.com/sferik/twitter/commit/3629a1edfbc6b35099d4b0fc165b938a67c02d86) ([@neektza](https://twitter.com/neektza))
|
data/LICENSE.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2006-
|
1
|
+
Copyright (c) 2006-2020 Erik Berlin, John Nunemaker, Wynn Netherland, Steve Richert, Steve Agalloco
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
# The Twitter Ruby Gem
|
2
2
|
|
3
|
-
[![Gem Version](
|
4
|
-
[![Build Status](
|
5
|
-
[![
|
6
|
-
[![
|
7
|
-
[![Coverage Status](http://img.shields.io/coveralls/sferik/twitter.svg)][coveralls]
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/twitter.svg)][gem]
|
4
|
+
[![Build Status](https://travis-ci.org/sferik/twitter.svg?branch=master)][travis]
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/09362621ad91e8f599b3/maintainability)][maintainability]
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/github/sferik/twitter/badge.svg?branch=master)][coveralls]
|
8
7
|
[![Inline docs](http://inch-ci.org/github/sferik/twitter.svg?style=shields)][inchpages]
|
9
8
|
|
10
9
|
[gem]: https://rubygems.org/gems/twitter
|
11
10
|
[travis]: https://travis-ci.org/sferik/twitter
|
12
|
-
[
|
13
|
-
[codeclimate]: https://codeclimate.com/github/sferik/twitter
|
11
|
+
[maintainability]: https://codeclimate.com/github/sferik/twitter/maintainability
|
14
12
|
[coveralls]: https://coveralls.io/r/sferik/twitter
|
15
13
|
[inchpages]: http://inch-ci.org/github/sferik/twitter
|
16
14
|
|
@@ -20,7 +18,6 @@ A Ruby interface to the Twitter API.
|
|
20
18
|
gem install twitter
|
21
19
|
|
22
20
|
## CLI
|
23
|
-
|
24
21
|
Looking for the Twitter command-line interface? It was [removed][] from this
|
25
22
|
gem in version 0.5.0 and now exists as a [separate project][t].
|
26
23
|
|
@@ -54,376 +51,6 @@ wiki][apps]!
|
|
54
51
|
|
55
52
|
[apps]: https://github.com/sferik/twitter/wiki/apps
|
56
53
|
|
57
|
-
## What's New in Version 5?
|
58
|
-
### Configuration
|
59
|
-
Global configuration has been removed, as it was not threadsafe. Instead, you
|
60
|
-
can configure a `Twitter::REST::Client` by passing it a block when it's
|
61
|
-
initialized.
|
62
|
-
|
63
|
-
```ruby
|
64
|
-
client = Twitter::REST::Client.new do |config|
|
65
|
-
config.consumer_key = "YOUR_CONSUMER_KEY"
|
66
|
-
config.consumer_secret = "YOUR_CONSUMER_SECRET"
|
67
|
-
config.access_token = "YOUR_ACCESS_TOKEN"
|
68
|
-
config.access_token_secret = "YOUR_ACCESS_SECRET"
|
69
|
-
end
|
70
|
-
```
|
71
|
-
|
72
|
-
Note: `oauth_token` has been renamed to `access_token` and `oauth_token_secret`
|
73
|
-
is now `access_token_secret` to conform to the terminology used in Twitter's
|
74
|
-
developer documentation.
|
75
|
-
|
76
|
-
### Streaming (Experimental)
|
77
|
-
This library now offers support for the [Twitter Streaming API][streaming].
|
78
|
-
|
79
|
-
[streaming]: https://dev.twitter.com/streaming/overview
|
80
|
-
[tweetstream]: http://rubygems.org/gems/tweetstream
|
81
|
-
|
82
|
-
Site Streams are restricted to whitelisted accounts. To apply for access,
|
83
|
-
[follow the steps in the Site Streams documentation][site-streams]. [User
|
84
|
-
Streams][user-streams] do not require prior approval.
|
85
|
-
|
86
|
-
[site-streams]: https://dev.twitter.com/streaming/sitestreams#applyingforaccess
|
87
|
-
[user-streams]: https://dev.twitter.com/streaming/userstreams
|
88
|
-
|
89
|
-
Unlike the rest of this library, this feature is not well tested and not
|
90
|
-
recommended for production applications. I've decided to ship it as an
|
91
|
-
experimental feature and make it more robust over time. Patches in this area are
|
92
|
-
particularly welcome.
|
93
|
-
|
94
|
-
Hopefully, by the time version 6 is released, this gem can fully replace
|
95
|
-
[TweetStream][], [em-twitter][], [twitterstream][], and [twitter-stream].
|
96
|
-
Special thanks to [Steve Agalloco][spagalloco], [Tim Carey-Smith][halorgium],
|
97
|
-
and [Tony Arcieri][tarcieri] for helping to develop this feature.
|
98
|
-
|
99
|
-
[em-twitter]: http://rubygems.org/gems/em-twitter
|
100
|
-
[twitterstream]: http://rubygems.org/gems/twitterstream
|
101
|
-
[twitter-stream]: http://rubygems.org/gems/twitter-stream
|
102
|
-
[spagalloco]: https://github.com/spagalloco
|
103
|
-
[halorgium]: https://github.com/halorgium
|
104
|
-
[tarcieri]: https://github.com/tarcieri
|
105
|
-
|
106
|
-
**Configuration works just like `Twitter::REST::Client`**
|
107
|
-
|
108
|
-
```ruby
|
109
|
-
client = Twitter::Streaming::Client.new do |config|
|
110
|
-
config.consumer_key = "YOUR_CONSUMER_KEY"
|
111
|
-
config.consumer_secret = "YOUR_CONSUMER_SECRET"
|
112
|
-
config.access_token = "YOUR_ACCESS_TOKEN"
|
113
|
-
config.access_token_secret = "YOUR_ACCESS_SECRET"
|
114
|
-
end
|
115
|
-
```
|
116
|
-
|
117
|
-
**Stream mentions of coffee or tea**
|
118
|
-
|
119
|
-
```ruby
|
120
|
-
topics = ["coffee", "tea"]
|
121
|
-
client.filter(:track => topics.join(",")) do |object|
|
122
|
-
puts object.text if object.is_a?(Twitter::Tweet)
|
123
|
-
end
|
124
|
-
```
|
125
|
-
|
126
|
-
**Stream a random sample of all tweets**
|
127
|
-
|
128
|
-
```ruby
|
129
|
-
client.sample do |object|
|
130
|
-
puts object.text if object.is_a?(Twitter::Tweet)
|
131
|
-
end
|
132
|
-
```
|
133
|
-
|
134
|
-
**Stream tweets, events, and direct messages for the authenticated user**
|
135
|
-
|
136
|
-
```ruby
|
137
|
-
client.user do |object|
|
138
|
-
case object
|
139
|
-
when Twitter::Tweet
|
140
|
-
puts "It's a tweet!"
|
141
|
-
when Twitter::DirectMessage
|
142
|
-
puts "It's a direct message!"
|
143
|
-
when Twitter::Streaming::StallWarning
|
144
|
-
warn "Falling behind!"
|
145
|
-
end
|
146
|
-
end
|
147
|
-
```
|
148
|
-
|
149
|
-
An `object` may be one of the following:
|
150
|
-
* `Twitter::DirectMessage`
|
151
|
-
* `Twitter::Streaming::DeletedTweet`
|
152
|
-
* `Twitter::Streaming::Event`
|
153
|
-
* `Twitter::Streaming::FriendList`
|
154
|
-
* `Twitter::Streaming::StallWarning`
|
155
|
-
* `Twitter::Tweet`
|
156
|
-
|
157
|
-
### Cursors
|
158
|
-
The `Twitter::Cursor` class has been completely redesigned with a focus on
|
159
|
-
simplicity and performance.
|
160
|
-
|
161
|
-
<table>
|
162
|
-
<thead>
|
163
|
-
<tr>
|
164
|
-
<th>Notes</th>
|
165
|
-
<th colspan="2">Version 4</th>
|
166
|
-
<th colspan="2">Version 5</th>
|
167
|
-
</tr>
|
168
|
-
<tr>
|
169
|
-
<th></th>
|
170
|
-
<th>Code</th>
|
171
|
-
<th>HTTP GETs</th>
|
172
|
-
<th>Code</th>
|
173
|
-
<th>HTTP GETs</th>
|
174
|
-
</tr>
|
175
|
-
</thead>
|
176
|
-
<tbody>
|
177
|
-
<tr>
|
178
|
-
<td>
|
179
|
-
Are you at the start of the cursor?
|
180
|
-
</td>
|
181
|
-
<td>
|
182
|
-
<pre><code>client.friends.first</code></pre>
|
183
|
-
</td>
|
184
|
-
<td>
|
185
|
-
<em>Θ(1)</em>
|
186
|
-
</td>
|
187
|
-
<td>
|
188
|
-
<pre><code>client.friends.first?</code></pre>
|
189
|
-
</td>
|
190
|
-
<td>
|
191
|
-
<em>Θ(1)</em>
|
192
|
-
</td>
|
193
|
-
</tr>
|
194
|
-
<tr>
|
195
|
-
<td>
|
196
|
-
Return your most recent friend.
|
197
|
-
</td>
|
198
|
-
<td>
|
199
|
-
<pre><code>client.friends.users.first</code></pre>
|
200
|
-
</td>
|
201
|
-
<td>
|
202
|
-
<em>Θ(1)</em>
|
203
|
-
</td>
|
204
|
-
<td>
|
205
|
-
<pre><code>client.friends.first</code></pre>
|
206
|
-
</td>
|
207
|
-
<td>
|
208
|
-
<em>Θ(1)</em>
|
209
|
-
</td>
|
210
|
-
</tr>
|
211
|
-
<tr>
|
212
|
-
<td>
|
213
|
-
Return an array of all your friends.
|
214
|
-
</td>
|
215
|
-
<td>
|
216
|
-
<pre><code>client.friends.all</code></pre>
|
217
|
-
</td>
|
218
|
-
<td>
|
219
|
-
<em>Θ(n+1)</em>
|
220
|
-
</td>
|
221
|
-
<td>
|
222
|
-
<pre><code>client.friends.to_a</code></pre>
|
223
|
-
</td>
|
224
|
-
<td>
|
225
|
-
<em>Θ(n)</em>
|
226
|
-
</td>
|
227
|
-
</tr>
|
228
|
-
<tr>
|
229
|
-
<td>
|
230
|
-
Collect your 20 most recent friends.
|
231
|
-
</td>
|
232
|
-
<td>
|
233
|
-
<pre><code>client.friends.take(20)</code></pre>
|
234
|
-
</td>
|
235
|
-
<td>
|
236
|
-
<em>Θ(n+1)</em>
|
237
|
-
</td>
|
238
|
-
<td>
|
239
|
-
<pre><code>client.friends.take(20)</code></pre>
|
240
|
-
</td>
|
241
|
-
<td>
|
242
|
-
<em>Θ(1)</em>
|
243
|
-
</td>
|
244
|
-
</tr>
|
245
|
-
<tr>
|
246
|
-
<td>
|
247
|
-
Collect your 20 most recent friends twice.
|
248
|
-
</td>
|
249
|
-
<td>
|
250
|
-
<pre><code>friends = client.friends
|
251
|
-
2.times.collect do
|
252
|
-
friends.take(20)
|
253
|
-
end</code></pre>
|
254
|
-
</td>
|
255
|
-
<td>
|
256
|
-
<em>Θ(2n+2)</em>
|
257
|
-
</td>
|
258
|
-
<td>
|
259
|
-
<pre><code>friends = client.friends
|
260
|
-
2.times.collect do
|
261
|
-
friends.take(20)
|
262
|
-
end</code></pre>
|
263
|
-
</td>
|
264
|
-
<td>
|
265
|
-
<em>Θ(1)</em>
|
266
|
-
</td>
|
267
|
-
</tr>
|
268
|
-
</tbody>
|
269
|
-
</table>
|
270
|
-
|
271
|
-
In the examples above, *n* varies with the number of people the authenticated
|
272
|
-
user follows on Twitter. This resource returns up to 20 friends per HTTP GET,
|
273
|
-
so if the authenticated user follows 200 people, calling
|
274
|
-
`client.friends.take(20)` would make 11 HTTP requests in version 4. In version
|
275
|
-
5, it makes just 1 HTTP request. Keep in mind, eliminating a single HTTP
|
276
|
-
request to the Twitter API will reduce the latency of your application by
|
277
|
-
[about 500 ms][status].
|
278
|
-
|
279
|
-
[status]: https://dev.twitter.com/overview/status
|
280
|
-
|
281
|
-
The last example might seem contrived ("Why would I call
|
282
|
-
`client.friends.take(20)` twice?") but it applies to any
|
283
|
-
[`Enumerable`][enumerable] method you might call on a cursor, including:
|
284
|
-
`#all?`, `#collect`, `#count`, `#each`, `#inject`, `#max`, `#min`, `#reject`,
|
285
|
-
`#reverse_each`, `#select`, `#sort`, `#sort_by`, and `#to_a`. In version 4,
|
286
|
-
each time you called one of those methods, it would perform *n+1* HTTP
|
287
|
-
requests. In version 5, it only performs those HTTP requests the first time any
|
288
|
-
one of those methods is called. Each subsequent call fetches data from a
|
289
|
-
[cache][].
|
290
|
-
|
291
|
-
[enumerable]: http://ruby-doc.org/core-2.0/Enumerable.html
|
292
|
-
[cache]: https://github.com/sferik/twitter/commit/7d8b2727af9400643ac397207185fd54e3f6387b
|
293
|
-
|
294
|
-
The performance improvements are actually even **better** than the table above
|
295
|
-
indicates. In version 5, calling `Twitter::Cursor#each` (or any
|
296
|
-
[`Enumerable`][enumerable] method) starts yielding results immediately and
|
297
|
-
continues yielding as each response comes back from the server. In version 4,
|
298
|
-
`#each` made a series of requests and waited for the last one to complete
|
299
|
-
before yielding any data.
|
300
|
-
|
301
|
-
Here is a list of the interface changes to `Twitter::Cursor`:
|
302
|
-
|
303
|
-
* `#all` has been replaced by `#to_a`.
|
304
|
-
* `#last` has been replaced by `#last?`.
|
305
|
-
* `#first` has been replaced by `#first?`.
|
306
|
-
* `#first` now returns the first element in the collection, as prescribed by `Enumerable`.
|
307
|
-
* `#collection` and its aliases have been removed.
|
308
|
-
|
309
|
-
### Search Results
|
310
|
-
The `Twitter::SearchResults` class has also been redesigned to have an
|
311
|
-
[`Enumerable`][enumerable] interface. The `#statuses` method and its aliases
|
312
|
-
(`#collection` and `#results`) have been replaced by `#to_a`. Additionally,
|
313
|
-
this class no longer inherits from `Twitter::Base`. As a result, the `#[]`
|
314
|
-
method has been removed.
|
315
|
-
|
316
|
-
### Trend Results
|
317
|
-
The `#trends` method now returns an [`Enumerable`][enumerable]
|
318
|
-
`Twitter::TrendResults` object instead of an array. This object provides
|
319
|
-
methods to determine the recency of the trend (`#as_of`), when the trend
|
320
|
-
started (`#created_at`), and the location of the trend (`#location`). This data
|
321
|
-
was previously unavailable.
|
322
|
-
|
323
|
-
### Geo Results
|
324
|
-
Similarly, the `#reverse_geocode`, `#geo_search`, and `#similar_places` methods
|
325
|
-
now return an [`Enumerable`][enumerable] `Twitter::GeoResults` object instead
|
326
|
-
of an array. This object provides access to the token to create a new place
|
327
|
-
(`#token`), which was previously unavailable.
|
328
|
-
|
329
|
-
### Tweets
|
330
|
-
The `Twitter::Tweet` object has been cleaned up. The following methods have been
|
331
|
-
removed:
|
332
|
-
|
333
|
-
* `#from_user`
|
334
|
-
* `#from_user_id`
|
335
|
-
* `#from_user_name`
|
336
|
-
* `#to_user`
|
337
|
-
* `#to_user_id`
|
338
|
-
* `#to_user_name`
|
339
|
-
* `#profile_image_url`
|
340
|
-
* `#profile_image_url_https`
|
341
|
-
|
342
|
-
These attributes can be accessed via the `Twitter::User` object, returned
|
343
|
-
through the `#user` method.
|
344
|
-
|
345
|
-
### Users
|
346
|
-
The `Twitter::User` object has also been cleaned up. The following aliases have
|
347
|
-
been removed:
|
348
|
-
|
349
|
-
* `#favorite_count` (use `#favorites_count`)
|
350
|
-
* `#favoriters_count` (use `#favorites_count`)
|
351
|
-
* `#favourite_count` (use `#favorites_count`)
|
352
|
-
* `#favouriters_count` (use `#favorites_count`)
|
353
|
-
* `#follower_count` (use `#followers_count`)
|
354
|
-
* `#friend_count` (use `#friends_count`)
|
355
|
-
* `#status_count` (use `#statuses_count`)
|
356
|
-
* `#tweet_count` (use `#tweets_count`)
|
357
|
-
* `#update_count` (use `#tweets_count`)
|
358
|
-
* `#updates_count` (use `#tweets_count`)
|
359
|
-
* `#translator` (use `#translator?`)
|
360
|
-
|
361
|
-
### Remove British English aliases
|
362
|
-
Earlier versions of this library aliased `favourites` to `favorites`. These
|
363
|
-
aliases have been removed. Ruby is implemented in American English. The
|
364
|
-
`initialize` method is spelled with a "z", not an "s", and Ruby provides no
|
365
|
-
alias. Likewise, this library does not provide aliases for Commonwealthers.
|
366
|
-
Merica. :us:
|
367
|
-
|
368
|
-
### More natural method names
|
369
|
-
All create, destroy, add, and remove methods have been renamed to put the verb
|
370
|
-
at the beginning:
|
371
|
-
|
372
|
-
* `#direct_message_create` is now `#create_direct_message`
|
373
|
-
* `#direct_message_destroy` is now `#destroy_direct_message`
|
374
|
-
* `#list_create` is now `#create_list`
|
375
|
-
* `#list_destroy` is now `#destroy_list`
|
376
|
-
* `#list_remove_member` is now `#remove_list_member`
|
377
|
-
* `#list_remove_members` is now `#remove_list_members`
|
378
|
-
* `#list_add_member` is now `#add_list_member`
|
379
|
-
* `#list_add_members` is now `#add_list_members`
|
380
|
-
* `#lists_owned` is now `#owned_lists`
|
381
|
-
* `#saved_search_create` is now `#create_saved_search`
|
382
|
-
* `#saved_search_destroy` is now `#destroy_saved_search`
|
383
|
-
* `#status_destroy` is now `#destroy_status`
|
384
|
-
|
385
|
-
### Null Objects
|
386
|
-
In version 4, methods you would expect to return a `Twitter` object would
|
387
|
-
return `nil` if that object was missing. This may have resulted in a
|
388
|
-
`NoMethodError`. To prevent such errors, you may have introduced checks for the
|
389
|
-
truthiness of the response, for example:
|
390
|
-
|
391
|
-
```ruby
|
392
|
-
status = client.status(55709764298092545)
|
393
|
-
if status.place
|
394
|
-
# Do something with the Twitter::Place object
|
395
|
-
elsif status.geo
|
396
|
-
# Do something with the Twitter::Geo object
|
397
|
-
end
|
398
|
-
```
|
399
|
-
In version 5, all such methods will return a `Twitter::NullObject` instead of
|
400
|
-
`nil`. This should prevent `NoMethodError` but may result in unexpected
|
401
|
-
behavior if you have truthiness checks in place, since everything is truthy in
|
402
|
-
Ruby except `false` and `nil`. For these cases, there are now predicate
|
403
|
-
methods:
|
404
|
-
|
405
|
-
```ruby
|
406
|
-
status = client.status(55709764298092545)
|
407
|
-
if status.place?
|
408
|
-
# Do something with the Twitter::Place object
|
409
|
-
elsif status.geo?
|
410
|
-
# Do something with the Twitter::Geo object
|
411
|
-
end
|
412
|
-
```
|
413
|
-
|
414
|
-
### URI Methods
|
415
|
-
The `Twitter::List`, `Twitter::Tweet`, and `Twitter::User` objects all have a
|
416
|
-
`#uri` method, which returns an HTTPS URI to twitter.com. This clobbers the
|
417
|
-
`Twitter::List#uri` method, which previously returned the list URI's path (not
|
418
|
-
a URI).
|
419
|
-
|
420
|
-
These methods are aliased to `#url` for users who prefer that nomenclature.
|
421
|
-
`Twitter::User` previously had a `#url` method, which returned the user's
|
422
|
-
website. This URI is now available via the `#website` method.
|
423
|
-
|
424
|
-
All `#uri` methods now return `Addressable::URI` objects instead of strings. To convert an
|
425
|
-
`Addressable::URI` object to a string, call `#to_s` on it.
|
426
|
-
|
427
54
|
## Configuration
|
428
55
|
Twitter API v1.1 requires you to authenticate via OAuth, so you'll need to
|
429
56
|
[register your application with Twitter][register]. Once you've registered an
|
@@ -452,19 +79,8 @@ client = Twitter::REST::Client.new do |config|
|
|
452
79
|
end
|
453
80
|
```
|
454
81
|
|
455
|
-
After configuration, requests can be made like so:
|
456
|
-
|
457
|
-
```ruby
|
458
|
-
client.update("I'm tweeting with @gem!")
|
459
|
-
```
|
460
|
-
|
461
|
-
**Performance/DNS settings issue**
|
462
|
-
|
463
|
-
When you are using the gem in production (running for example in a DigitalOcean VPS) be aware that DNS settings on the server can affect outbound traffic performance with `Twitter::Error::RequestTimeout` as a result. Don't use the public Google DNS services (4.4.4.4 / 8.8.8.8) they are rate-limited and have very bad response times. Use a DNS service close to your data-center.
|
464
|
-
|
465
82
|
## Usage Examples
|
466
|
-
|
467
|
-
href="#configuration">configuration</a>.
|
83
|
+
After configuring a `client`, you can do the following things.
|
468
84
|
|
469
85
|
**Tweet (as the authenticated user)**
|
470
86
|
|
@@ -498,12 +114,6 @@ client.friends(213747670)
|
|
498
114
|
client.friends
|
499
115
|
```
|
500
116
|
|
501
|
-
**Fetch a collection of user_ids that the currently authenticated user does not want to receive retweets from**
|
502
|
-
|
503
|
-
```ruby
|
504
|
-
client.no_retweet_ids
|
505
|
-
````
|
506
|
-
|
507
117
|
**Fetch the timeline of Tweets by a user**
|
508
118
|
|
509
119
|
```ruby
|
@@ -528,19 +138,83 @@ client.status(27558893223)
|
|
528
138
|
**Collect the three most recent marriage proposals to @justinbieber**
|
529
139
|
|
530
140
|
```ruby
|
531
|
-
client.search("to:justinbieber marry me", :
|
141
|
+
client.search("to:justinbieber marry me", result_type: "recent").take(3).collect do |tweet|
|
532
142
|
"#{tweet.user.screen_name}: #{tweet.text}"
|
533
143
|
end
|
534
144
|
```
|
535
145
|
**Find a Japanese-language Tweet tagged #ruby (excluding retweets)**
|
536
146
|
|
537
147
|
```ruby
|
538
|
-
client.search("#ruby -rt", :
|
148
|
+
client.search("#ruby -rt", lang: "ja").first.text
|
539
149
|
```
|
540
150
|
For more usage examples, please see the full [documentation][].
|
541
151
|
|
542
|
-
##
|
152
|
+
## Streaming
|
153
|
+
Site Streams are restricted to whitelisted accounts. To apply for access,
|
154
|
+
[follow the steps in the Site Streams documentation][site-streams]. [User
|
155
|
+
Streams][user-streams] do not require prior approval.
|
156
|
+
|
157
|
+
[site-streams]: https://dev.twitter.com/streaming/sitestreams#applyingforaccess
|
158
|
+
[user-streams]: https://dev.twitter.com/streaming/userstreams
|
159
|
+
|
160
|
+
**Configuration works just like `Twitter::REST::Client`**
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
client = Twitter::Streaming::Client.new do |config|
|
164
|
+
config.consumer_key = "YOUR_CONSUMER_KEY"
|
165
|
+
config.consumer_secret = "YOUR_CONSUMER_SECRET"
|
166
|
+
config.access_token = "YOUR_ACCESS_TOKEN"
|
167
|
+
config.access_token_secret = "YOUR_ACCESS_SECRET"
|
168
|
+
end
|
169
|
+
```
|
543
170
|
|
171
|
+
**Stream a random sample of all tweets**
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
client.sample do |object|
|
175
|
+
puts object.text if object.is_a?(Twitter::Tweet)
|
176
|
+
end
|
177
|
+
```
|
178
|
+
|
179
|
+
**Stream mentions of coffee or tea**
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
topics = ["coffee", "tea"]
|
183
|
+
client.filter(track: topics.join(",")) do |object|
|
184
|
+
puts object.text if object.is_a?(Twitter::Tweet)
|
185
|
+
end
|
186
|
+
```
|
187
|
+
|
188
|
+
**Stream tweets, events, and direct messages for the authenticated user**
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
client.user do |object|
|
192
|
+
case object
|
193
|
+
when Twitter::Tweet
|
194
|
+
puts "It's a tweet!"
|
195
|
+
when Twitter::DirectMessage
|
196
|
+
puts "It's a direct message!"
|
197
|
+
when Twitter::Streaming::StallWarning
|
198
|
+
warn "Falling behind!"
|
199
|
+
end
|
200
|
+
end
|
201
|
+
```
|
202
|
+
|
203
|
+
An `object` may be one of the following:
|
204
|
+
* `Twitter::Tweet`
|
205
|
+
* `Twitter::DirectMessage`
|
206
|
+
* `Twitter::Streaming::DeletedTweet`
|
207
|
+
* `Twitter::Streaming::Event`
|
208
|
+
* `Twitter::Streaming::FriendList`
|
209
|
+
* `Twitter::Streaming::StallWarning`
|
210
|
+
|
211
|
+
## Ads
|
212
|
+
|
213
|
+
We recommend using the [Twitter Ads SDK for Ruby][ads] to interact with the Twitter Ads API.
|
214
|
+
|
215
|
+
[ads]: http://twitterdev.github.io/twitter-ruby-ads-sdk/
|
216
|
+
|
217
|
+
## Object Graph
|
544
218
|
![Entity-relationship diagram][erd]
|
545
219
|
|
546
220
|
[erd]: https://cdn.rawgit.com/sferik/twitter/master/etc/erd.svg "Entity-relationship diagram"
|
@@ -552,16 +226,13 @@ command:
|
|
552
226
|
bundle exec rake erd
|
553
227
|
|
554
228
|
## Supported Ruby Versions
|
555
|
-
|
556
229
|
This library aims to support and is [tested against][travis] the following Ruby
|
557
230
|
versions:
|
558
231
|
|
559
|
-
* Ruby
|
560
|
-
* Ruby
|
561
|
-
* Ruby 2.
|
562
|
-
* Ruby 2.
|
563
|
-
* Ruby 2.2
|
564
|
-
* JRuby 1.7 (Both 1.9 mode and 1.8 mode)
|
232
|
+
* Ruby 2.4
|
233
|
+
* Ruby 2.5
|
234
|
+
* Ruby 2.6
|
235
|
+
* Ruby 2.7
|
565
236
|
|
566
237
|
If something doesn't work on one of these versions, it's a bug.
|
567
238
|
|
@@ -586,7 +257,7 @@ introduced with new major versions. As a result of this policy, you can (and
|
|
586
257
|
should) specify a dependency on this gem using the [Pessimistic Version
|
587
258
|
Constraint][pvc] with two digits of precision. For example:
|
588
259
|
|
589
|
-
spec.add_dependency 'twitter', '~>
|
260
|
+
spec.add_dependency 'twitter', '~> 6.0'
|
590
261
|
|
591
262
|
[semver]: http://semver.org/
|
592
263
|
[pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
|