tweetstream 1.0.5 → 1.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of tweetstream might be problematic. Click here for more details.
- data/.document +5 -0
- data/.gemtest +0 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.yardopts +4 -0
- data/Gemfile +2 -0
- data/Guardfile +10 -0
- data/{LICENSE → LICENSE.md} +1 -1
- data/README.md +223 -0
- data/{RELEASE_NOTES.rdoc → RELEASE_NOTES.md} +2 -1
- data/Rakefile +13 -54
- data/examples/oauth.rb +17 -0
- data/lib/tweetstream.rb +21 -0
- data/lib/tweetstream/client.rb +137 -79
- data/lib/tweetstream/configuration.rb +82 -0
- data/lib/tweetstream/daemon.rb +6 -2
- data/lib/tweetstream/version.rb +3 -0
- data/spec/spec_helper.rb +8 -7
- data/spec/tweetstream/client_spec.rb +124 -64
- data/spec/tweetstream/parser_spec.rb +25 -22
- data/spec/tweetstream_spec.rb +106 -0
- data/tweetstream.gemspec +35 -0
- metadata +131 -36
- data/Gemfile.lock +0 -56
- data/README.rdoc +0 -162
- data/VERSION +0 -1
- data/lib/tweetstream/parsers/active_support.rb +0 -11
- data/lib/tweetstream/parsers/json_gem.rb +0 -11
- data/lib/tweetstream/parsers/json_pure.rb +0 -11
- data/lib/tweetstream/parsers/yajl.rb +0 -11
- data/spec/spec.opts +0 -2
data/README.rdoc
DELETED
@@ -1,162 +0,0 @@
|
|
1
|
-
= TweetStream
|
2
|
-
|
3
|
-
TweetStream provides simple Ruby access to Twitter's Streaming API
|
4
|
-
(http://apiwiki.twitter.com/Streaming-API-Documentation).
|
5
|
-
|
6
|
-
== Installation
|
7
|
-
|
8
|
-
To install from Gemcutter:
|
9
|
-
|
10
|
-
gem install tweetstream
|
11
|
-
|
12
|
-
== Usage
|
13
|
-
|
14
|
-
Using TweetStream is quite simple:
|
15
|
-
|
16
|
-
require 'rubygems'
|
17
|
-
require 'tweetstream'
|
18
|
-
|
19
|
-
# This will pull a sample of all tweets based on
|
20
|
-
# your Twitter account's Streaming API role.
|
21
|
-
TweetStream::Client.new('username','password').sample do |status|
|
22
|
-
# The status object is a special Hash with
|
23
|
-
# method access to its keys.
|
24
|
-
puts "#{status.text}"
|
25
|
-
end
|
26
|
-
|
27
|
-
You can also use it to track keywords or follow a given set of
|
28
|
-
user ids:
|
29
|
-
|
30
|
-
# Use 'track' to track a list of single-word keywords
|
31
|
-
TweetStream::Client.new('username','password').track('term1', 'term2') do |status|
|
32
|
-
puts "#{status.text}"
|
33
|
-
end
|
34
|
-
|
35
|
-
# Use 'follow' to follow a group of user ids (integers, not screen names)
|
36
|
-
TweetStream::Client.new('username','password').follow(14252, 53235) do |status|
|
37
|
-
puts "#{status.text}"
|
38
|
-
end
|
39
|
-
|
40
|
-
The methods available to TweetStream::Client will be kept in parity
|
41
|
-
with the methods available on the Streaming API wiki page.
|
42
|
-
|
43
|
-
== Swappable JSON Parsing
|
44
|
-
|
45
|
-
As of version 1.0, TweetStream supports swappable JSON backends for
|
46
|
-
parsing the Tweets. These are specified when you initialize the
|
47
|
-
client or daemon by passing it in as the last argument:
|
48
|
-
|
49
|
-
# Parse tweets using Yajl-Ruby
|
50
|
-
TweetStream::Client.new('abc','def',:yajl) # ...
|
51
|
-
|
52
|
-
Available options are <tt>:yajl</tt>, <tt>:json_gem</tt> (default),
|
53
|
-
<tt>:json_pure</tt>, and <tt>:active_support</tt>.
|
54
|
-
|
55
|
-
== Handling Deletes and Rate Limitations
|
56
|
-
|
57
|
-
Sometimes the Streaming API will send messages other than statuses.
|
58
|
-
Specifically, it does so when a status is deleted or rate limitations
|
59
|
-
have caused some tweets not to appear in the stream. To handle these,
|
60
|
-
you can use the on_delete and on_limit methods. Example:
|
61
|
-
|
62
|
-
@client = TweetStream::Client.new('user','pass')
|
63
|
-
|
64
|
-
@client.on_delete do |status_id, user_id|
|
65
|
-
Tweet.delete(status_id)
|
66
|
-
end
|
67
|
-
|
68
|
-
@client.on_limit do |skip_count|
|
69
|
-
# do something
|
70
|
-
end
|
71
|
-
|
72
|
-
@client.track('intridea')
|
73
|
-
|
74
|
-
The on_delete and on_limit methods can also be chained, like so:
|
75
|
-
|
76
|
-
TweetStream::Client.new('user','pass').on_delete{ |status_id, user_id|
|
77
|
-
Tweet.delete(status_id)
|
78
|
-
}.on_limit { |skip_count|
|
79
|
-
# do something
|
80
|
-
}.track('intridea') do |status|
|
81
|
-
# do something with the status like normal
|
82
|
-
end
|
83
|
-
|
84
|
-
You can also provide <tt>:delete</tt> and/or <tt>:limit</tt>
|
85
|
-
options when you make your method call:
|
86
|
-
|
87
|
-
TweetStream::Client.new('user','pass').track('intridea',
|
88
|
-
:delete => Proc.new{ |status_id, user_id| # do something },
|
89
|
-
:limit => Proc.new{ |skip_count| # do something }
|
90
|
-
) do |status|
|
91
|
-
# do something with the status like normal
|
92
|
-
end
|
93
|
-
|
94
|
-
Twitter recommends honoring deletions as quickly as possible, and
|
95
|
-
you would likely be wise to integrate this functionality into your
|
96
|
-
application.
|
97
|
-
|
98
|
-
== Errors and Reconnecting
|
99
|
-
|
100
|
-
TweetStream uses EventMachine to connect to the Twitter Streaming
|
101
|
-
API, and attempts to honor Twitter's guidelines in terms of automatic
|
102
|
-
reconnection. When Twitter becomes unavailable, the block specified
|
103
|
-
by you in <tt>on_error</tt> will be called. Note that this does not
|
104
|
-
indicate something is actually wrong, just that Twitter is momentarily
|
105
|
-
down. It could be for routine maintenance, etc.
|
106
|
-
|
107
|
-
TweetStream::Client.new('abc','def').on_error do |message|
|
108
|
-
# Log your error message somewhere
|
109
|
-
end.track('term') do |status|
|
110
|
-
# Do things when nothing's wrong
|
111
|
-
end
|
112
|
-
|
113
|
-
However, if the maximum number of reconnect attempts has been reached,
|
114
|
-
TweetStream will raise a <tt>TweetStream::ReconnectError</tt> with
|
115
|
-
information about the timeout and number of retries attempted.
|
116
|
-
|
117
|
-
== Terminating a TweetStream
|
118
|
-
|
119
|
-
It is often the case that you will need to change the parameters of your
|
120
|
-
track or follow tweet streams. In the case that you need to terminate
|
121
|
-
a stream, you may add a second argument to your block that will yield
|
122
|
-
the client itself:
|
123
|
-
|
124
|
-
# Stop after collecting 10 statuses
|
125
|
-
@statuses = []
|
126
|
-
TweetStream::Client.new('username','password').sample do |status, client|
|
127
|
-
@statuses << status
|
128
|
-
client.stop if @statuses.size >= 10
|
129
|
-
end
|
130
|
-
|
131
|
-
When <tt>stop</tt> is called, TweetStream will return from the block
|
132
|
-
the last successfully yielded status, allowing you to make note of
|
133
|
-
it in your application as necessary.
|
134
|
-
|
135
|
-
== Daemonizing
|
136
|
-
|
137
|
-
It is also possible to create a daemonized script quite easily
|
138
|
-
using the TweetStream library:
|
139
|
-
|
140
|
-
# The third argument is an optional process name
|
141
|
-
TweetStream::Daemon.new('username','password', 'tracker').track('term1', 'term2') do |status|
|
142
|
-
# do something in the background
|
143
|
-
end
|
144
|
-
|
145
|
-
If you put the above into a script and run the script with <tt>ruby scriptname.rb</tt>, you will see a list of daemonization commands such
|
146
|
-
as start, stop, and run.
|
147
|
-
|
148
|
-
== Note on Patches/Pull Requests
|
149
|
-
|
150
|
-
* Fork the project.
|
151
|
-
* Make your feature addition or bug fix.
|
152
|
-
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
153
|
-
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
154
|
-
* Send me a pull request. Bonus points for topic branches.
|
155
|
-
|
156
|
-
== Contributors
|
157
|
-
|
158
|
-
* Michael Bleigh (initial gem)
|
159
|
-
|
160
|
-
== Copyright
|
161
|
-
|
162
|
-
Copyright (c) 2009 Intridea, Inc. (http://www.intridea.com/). See LICENSE for details.
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.0.5
|
data/spec/spec.opts
DELETED