tweetstream 0.1.8 → 0.1.9
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/VERSION +1 -1
- data/lib/tweetstream/client.rb +15 -6
- data/spec/tweetstream/client_spec.rb +16 -16
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.9
|
data/lib/tweetstream/client.rb
CHANGED
@@ -91,7 +91,7 @@ module TweetStream
|
|
91
91
|
query_params[param] = query_params[param].to_s
|
92
92
|
end
|
93
93
|
end
|
94
|
-
start('statuses/filter', query_params, &block)
|
94
|
+
start('statuses/filter', query_params.merge(:method => :post), &block)
|
95
95
|
end
|
96
96
|
|
97
97
|
# Set a Proc to be run when a deletion notice is received
|
@@ -137,12 +137,17 @@ module TweetStream
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def start(path, query_parameters = {}, &block) #:nodoc:
|
140
|
+
method = query_parameters.delete(:method) || :get
|
140
141
|
delete_proc = query_parameters.delete(:delete) || self.on_delete
|
141
142
|
limit_proc = query_parameters.delete(:limit) || self.on_limit
|
142
143
|
|
143
|
-
uri = build_uri(path, query_parameters)
|
144
|
-
|
145
|
-
|
144
|
+
uri = method == :get ? build_uri(path, query_parameters) : build_uri(path)
|
145
|
+
|
146
|
+
args = [uri]
|
147
|
+
args << build_post_body(query_parameters) if method == :post
|
148
|
+
args << {:symbolize_keys => true}
|
149
|
+
|
150
|
+
Yajl::HttpStream.send(method, *args) do |hash|
|
146
151
|
if hash[:delete] && hash[:delete][:status]
|
147
152
|
delete_proc.call(hash[:delete][:status][:id], hash[:delete][:status][:user_id]) if delete_proc.is_a?(Proc)
|
148
153
|
elsif hash[:limit] && hash[:limit][:track]
|
@@ -169,7 +174,11 @@ module TweetStream
|
|
169
174
|
URI.parse("http://#{URI.encode self.username}:#{URI.encode self.password}@stream.twitter.com/1/#{path}.json#{build_query_parameters(query_parameters)}")
|
170
175
|
end
|
171
176
|
|
172
|
-
def build_query_parameters(query)
|
177
|
+
def build_query_parameters(query)
|
178
|
+
query.size > 0 ? "?#{build_post_body(query)}" : ''
|
179
|
+
end
|
180
|
+
|
181
|
+
def build_post_body(query) #:nodoc:
|
173
182
|
return '' unless query && query.is_a?(::Hash) && query.size > 0
|
174
183
|
pairs = []
|
175
184
|
|
@@ -177,7 +186,7 @@ module TweetStream
|
|
177
186
|
pairs << "#{k.to_s}=#{CGI.escape(v.to_s)}"
|
178
187
|
end
|
179
188
|
|
180
|
-
|
189
|
+
pairs.join('&')
|
181
190
|
end
|
182
191
|
end
|
183
192
|
end
|
@@ -30,29 +30,29 @@ describe TweetStream::Client do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
describe '#
|
33
|
+
describe '#build_post_body' do
|
34
34
|
before do
|
35
35
|
@client = TweetStream::Client.new('abc','def')
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should return a blank string if passed a nil value' do
|
39
|
-
@client.send(:
|
39
|
+
@client.send(:build_post_body, nil).should == ''
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should return a blank string if passed an empty hash' do
|
43
|
-
@client.send(:
|
43
|
+
@client.send(:build_post_body, {}).should == ''
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should add a query parameter for a key' do
|
47
|
-
@client.send(:
|
47
|
+
@client.send(:build_post_body, {:query => 'abc'}).should == 'query=abc'
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'should escape characters in the value' do
|
51
|
-
@client.send(:
|
51
|
+
@client.send(:build_post_body, {:query => 'awesome guy'}).should == 'query=awesome+guy'
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'should join multiple pairs together' do
|
55
|
-
['
|
55
|
+
['a=b&c=d','c=d&a=b'].include?(@client.send(:build_post_body, {:a => 'b', :c => 'd'})).should be_true
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -67,7 +67,7 @@ describe TweetStream::Client do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'should yield a TwitterStream::Status for each update' do
|
70
|
-
Yajl::HttpStream.should_receive(:
|
70
|
+
Yajl::HttpStream.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
71
|
@client.track('musicmonday') do |status|
|
72
72
|
status.is_a?(TweetStream::Status).should be_true
|
73
73
|
@yielded = true
|
@@ -88,7 +88,7 @@ describe TweetStream::Client do
|
|
88
88
|
@called = false
|
89
89
|
@proc = Proc.new{|*args| @called = true }
|
90
90
|
@client.send("on_#{special_method}", &@proc)
|
91
|
-
Yajl::HttpStream.should_receive(:
|
91
|
+
Yajl::HttpStream.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
92
|
@client.track('musicmonday')
|
93
93
|
@called.should == true
|
94
94
|
end
|
@@ -96,7 +96,7 @@ describe TweetStream::Client do
|
|
96
96
|
it "should accept a proc on a :#{special_method} option if a #{special_method} object is given" do
|
97
97
|
@called = false
|
98
98
|
@proc = Proc.new{|*args| @called = true }
|
99
|
-
Yajl::HttpStream.should_receive(:
|
99
|
+
Yajl::HttpStream.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
100
|
@client.track('musicmonday', special_method => @proc)
|
101
101
|
@called.should == true
|
102
102
|
end
|
@@ -116,27 +116,27 @@ describe TweetStream::Client do
|
|
116
116
|
end
|
117
117
|
|
118
118
|
it '#track should make a call to start with "statuses/filter" and a track query parameter' do
|
119
|
-
@client.should_receive(:start).once.with('statuses/filter', :track => 'test')
|
119
|
+
@client.should_receive(:start).once.with('statuses/filter', :track => 'test', :method => :post)
|
120
120
|
@client.track('test')
|
121
121
|
end
|
122
122
|
|
123
123
|
it '#track should comma-join multiple arguments' do
|
124
|
-
@client.should_receive(:start).once.with('statuses/filter', :track => 'foo,bar,baz')
|
124
|
+
@client.should_receive(:start).once.with('statuses/filter', :track => 'foo,bar,baz', :method => :post)
|
125
125
|
@client.track('foo', 'bar', 'baz')
|
126
126
|
end
|
127
127
|
|
128
128
|
it '#follow should make a call to start with "statuses/filter" and a follow query parameter' do
|
129
|
-
@client.should_receive(:start).once.with('statuses/filter', :follow => '123')
|
129
|
+
@client.should_receive(:start).once.with('statuses/filter', :follow => '123', :method => :post)
|
130
130
|
@client.follow(123)
|
131
131
|
end
|
132
132
|
|
133
133
|
it '#follow should comma-join multiple arguments' do
|
134
|
-
@client.should_receive(:start).once.with('statuses/filter', :follow => '123,456')
|
134
|
+
@client.should_receive(:start).once.with('statuses/filter', :follow => '123,456', :method => :post)
|
135
135
|
@client.follow(123, 456)
|
136
136
|
end
|
137
137
|
|
138
138
|
it '#filter should make a call to "statuses/filter" with the query params provided' do
|
139
|
-
@client.should_receive(:start).once.with('statuses/filter', :follow => '123')
|
139
|
+
@client.should_receive(:start).once.with('statuses/filter', :follow => '123', :method => :post)
|
140
140
|
@client.filter(:follow => 123)
|
141
141
|
end
|
142
142
|
end
|
@@ -161,7 +161,7 @@ describe TweetStream::Client do
|
|
161
161
|
end
|
162
162
|
|
163
163
|
it 'should call #start with "statuses/filter" and the provided queries' do
|
164
|
-
@client.should_receive(:start).once.with('statuses/filter', :track => 'rock')
|
164
|
+
@client.should_receive(:start).once.with('statuses/filter', :track => 'rock', :method => :post)
|
165
165
|
@client.track('rock')
|
166
166
|
end
|
167
167
|
end
|
@@ -174,7 +174,7 @@ describe TweetStream::Client do
|
|
174
174
|
it 'should not cause a TweetStream to crash with a real exception' do
|
175
175
|
@client = TweetStream::Client.new('abc','def')
|
176
176
|
@statuses = []
|
177
|
-
Yajl::HttpStream.should_receive(:
|
177
|
+
Yajl::HttpStream.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
178
|
@client.track('musicmonday') do |status|
|
179
179
|
@statuses << status
|
180
180
|
TweetStream::Client.stop
|