tweetstream 0.1.9 → 0.3.0
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/README.rdoc +2 -2
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/lib/tweetstream/client.rb +9 -2
- data/spec/tweetstream/client_spec.rb +24 -6
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -82,7 +82,7 @@ options when you make your method call:
|
|
82
82
|
TweetStream::Client.new('user','pass').track('intridea',
|
83
83
|
:delete => Proc.new{ |status_id, user_id| # do something },
|
84
84
|
:limit => Proc.new{ |skip_count| # do something }
|
85
|
-
) do |status
|
85
|
+
) do |status|
|
86
86
|
# do something with the status like normal
|
87
87
|
end
|
88
88
|
|
@@ -114,7 +114,7 @@ It is also possible to create a daemonized script quite easily
|
|
114
114
|
using the TweetStream library:
|
115
115
|
|
116
116
|
# The third argument is an optional process name
|
117
|
-
TweetStream::
|
117
|
+
TweetStream::Daemon.new('username','password', 'tracker').track('term1', 'term2') do |status|
|
118
118
|
# do something in the background
|
119
119
|
end
|
120
120
|
|
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ begin
|
|
12
12
|
gem.authors = ["Michael Bleigh"]
|
13
13
|
gem.files = FileList["[A-Z]*", "{lib,spec}/**/*"] - FileList["**/*.log"]
|
14
14
|
gem.add_development_dependency "rspec"
|
15
|
-
gem.add_dependency 'yajl-ruby', '>= 0.6.
|
15
|
+
gem.add_dependency 'yajl-ruby', '>= 0.6.6'
|
16
16
|
gem.add_dependency 'daemons'
|
17
17
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
18
|
end
|
@@ -38,6 +38,7 @@ Spec::Rake::SpecTask.new(:rcov) do |spec|
|
|
38
38
|
spec.libs << 'lib' << 'spec'
|
39
39
|
spec.pattern = 'spec/**/*_spec.rb'
|
40
40
|
spec.rcov = true
|
41
|
+
spec.rcov_opts = %w{--exclude "spec\/*,gems\/*"}
|
41
42
|
end
|
42
43
|
|
43
44
|
task :spec => :check_dependencies
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/tweetstream/client.rb
CHANGED
@@ -146,8 +146,10 @@ module TweetStream
|
|
146
146
|
args = [uri]
|
147
147
|
args << build_post_body(query_parameters) if method == :post
|
148
148
|
args << {:symbolize_keys => true}
|
149
|
-
|
150
|
-
Yajl::HttpStream.
|
149
|
+
|
150
|
+
@stream = Yajl::HttpStream.new
|
151
|
+
|
152
|
+
@stream.send(method, *args) do |hash|
|
151
153
|
if hash[:delete] && hash[:delete][:status]
|
152
154
|
delete_proc.call(hash[:delete][:status][:id], hash[:delete][:status][:user_id]) if delete_proc.is_a?(Proc)
|
153
155
|
elsif hash[:limit] && hash[:limit][:track]
|
@@ -167,6 +169,11 @@ module TweetStream
|
|
167
169
|
def self.stop
|
168
170
|
raise TweetStream::Terminated
|
169
171
|
end
|
172
|
+
|
173
|
+
# Terminate the currently running TweetStream.
|
174
|
+
def stop
|
175
|
+
@stream.terminate unless @stream.nil?
|
176
|
+
end
|
170
177
|
|
171
178
|
protected
|
172
179
|
|
@@ -62,12 +62,14 @@ describe TweetStream::Client do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'should make a call to Yajl::HttpStream' do
|
65
|
-
Yajl::HttpStream.should_receive(:
|
65
|
+
Yajl::HttpStream.should_receive(:new).and_return(y = mock("Yajl::HttpStream"))
|
66
|
+
y.should_receive(:get).once.with(URI.parse('http://abc:def@stream.twitter.com/1/cool.json'), :symbolize_keys => true).and_return({})
|
66
67
|
@client.start('cool')
|
67
68
|
end
|
68
69
|
|
69
70
|
it 'should yield a TwitterStream::Status for each update' do
|
70
|
-
Yajl::HttpStream.should_receive(:
|
71
|
+
Yajl::HttpStream.should_receive(:new).and_return(y = mock("Yajl::HttpStream"))
|
72
|
+
y.should_receive(:post).once.with(URI.parse('http://abc:def@stream.twitter.com/1/statuses/filter.json'), 'track=musicmonday', :symbolize_keys => true).and_yield(sample_tweets[0])
|
71
73
|
@client.track('musicmonday') do |status|
|
72
74
|
status.is_a?(TweetStream::Status).should be_true
|
73
75
|
@yielded = true
|
@@ -76,7 +78,8 @@ describe TweetStream::Client do
|
|
76
78
|
end
|
77
79
|
|
78
80
|
it 'should wrap Yajl errors in TweetStream errors' do
|
79
|
-
Yajl::HttpStream.should_receive(:
|
81
|
+
Yajl::HttpStream.should_receive(:new).and_return(y = mock("Yajl::HttpStream"))
|
82
|
+
y.should_receive(:get).once.with(URI.parse('http://abc:def@stream.twitter.com/1/cool.json'), :symbolize_keys => true).and_raise(Yajl::HttpStream::InvalidContentType)
|
80
83
|
lambda{@client.start('cool')}.should raise_error(TweetStream::ConnectionError)
|
81
84
|
end
|
82
85
|
|
@@ -88,7 +91,8 @@ describe TweetStream::Client do
|
|
88
91
|
@called = false
|
89
92
|
@proc = Proc.new{|*args| @called = true }
|
90
93
|
@client.send("on_#{special_method}", &@proc)
|
91
|
-
Yajl::HttpStream.should_receive(:
|
94
|
+
Yajl::HttpStream.should_receive(:new).and_return(y = mock("Yajl::HttpStream"))
|
95
|
+
y.should_receive(:post).once.with(URI.parse('http://abc:def@stream.twitter.com/1/statuses/filter.json'), "track=musicmonday", :symbolize_keys => true).and_yield(special_object)
|
92
96
|
@client.track('musicmonday')
|
93
97
|
@called.should == true
|
94
98
|
end
|
@@ -96,7 +100,8 @@ describe TweetStream::Client do
|
|
96
100
|
it "should accept a proc on a :#{special_method} option if a #{special_method} object is given" do
|
97
101
|
@called = false
|
98
102
|
@proc = Proc.new{|*args| @called = true }
|
99
|
-
Yajl::HttpStream.should_receive(:
|
103
|
+
Yajl::HttpStream.should_receive(:new).and_return(y = mock("Yajl::HttpStream"))
|
104
|
+
y.should_receive(:post).once.with(URI.parse('http://abc:def@stream.twitter.com/1/statuses/filter.json'), "track=musicmonday", :symbolize_keys => true).and_yield(special_object)
|
100
105
|
@client.track('musicmonday', special_method => @proc)
|
101
106
|
@called.should == true
|
102
107
|
end
|
@@ -174,7 +179,8 @@ describe TweetStream::Client do
|
|
174
179
|
it 'should not cause a TweetStream to crash with a real exception' do
|
175
180
|
@client = TweetStream::Client.new('abc','def')
|
176
181
|
@statuses = []
|
177
|
-
Yajl::HttpStream.should_receive(:
|
182
|
+
Yajl::HttpStream.should_receive(:new).and_return(y = mock("Yajl::HttpStream"))
|
183
|
+
y.should_receive(:post).once.with(URI.parse('http://abc:def@stream.twitter.com/1/statuses/filter.json'), 'track=musicmonday', :symbolize_keys => true).and_yield(sample_tweets[0])
|
178
184
|
@client.track('musicmonday') do |status|
|
179
185
|
@statuses << status
|
180
186
|
TweetStream::Client.stop
|
@@ -182,4 +188,16 @@ describe TweetStream::Client do
|
|
182
188
|
@statuses.size.should == 1
|
183
189
|
end
|
184
190
|
end
|
191
|
+
|
192
|
+
describe 'instance .stop' do
|
193
|
+
it 'should stop to receive the stream' do
|
194
|
+
@client = TweetStream::Client.new('abc','def')
|
195
|
+
Yajl::HttpStream.should_receive(:new).and_return(y = mock('Yajl::HttpStream'))
|
196
|
+
y.should_receive(:post)
|
197
|
+
y.should_receive(:terminate).once
|
198
|
+
|
199
|
+
@client.follow('10')
|
200
|
+
@client.stop
|
201
|
+
end
|
202
|
+
end
|
185
203
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tweetstream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-03 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.6.
|
33
|
+
version: 0.6.6
|
34
34
|
version:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: daemons
|