Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #91 from chatgris/enhance_your_calm

Added enhance_your_calm callback.
  • Loading branch information...
commit 2bcb82886e52b79cdd3f1c8bb5926f194b1c3e69 2 parents 5ee6cc6 + 90caf78
@sferik sferik authored
View
6 README.md
@@ -213,7 +213,7 @@ JSON parser and it will be used to parse responses.
Sometimes the Streaming API will send messages other than statuses.
Specifically, it does so when a status is deleted or rate limitations
have caused some tweets not to appear in the stream. To handle these,
-you can use the on_delete and on_limit methods. Example:
+you can use the on_delete, on_limit and on_enhance_your_calm methods. Example:
```ruby
@client = TweetStream::Client.new
@@ -226,6 +226,10 @@ end
# do something
end
+@client.on_enhance_your_calm do
+ # do something
+end
+
@client.track('intridea')
```
View
20 lib/tweetstream/client.rb
@@ -348,6 +348,21 @@ def on_no_data_received(&block)
end
end
+ # Set a Proc to be run when enhance_your_calm signal is received.
+ #
+ # @client = TweetStream::Client.new
+ # @client.on_enhance_your_calm do
+ # # do something, your account has been blocked
+ # end
+ def on_enhance_your_calm(&block)
+ if block_given?
+ @on_enhance_your_calm = block
+ self
+ else
+ @on_enhance_your_calm
+ end
+ end
+
# connect to twitter while starting a new EventMachine run loop
def start(path, query_parameters = {}, &block)
if EventMachine.reactor_running?
@@ -369,6 +384,7 @@ def connect(path, query_parameters = {}, &block)
scrub_geo_proc = query_parameters.delete(:scrub_geo) || self.on_scrub_geo
limit_proc = query_parameters.delete(:limit) || self.on_limit
error_proc = query_parameters.delete(:error) || self.on_error
+ enhance_your_calm_proc = query_parameters.delete(:enhance_your_calm) || self.on_error
unauthorized_proc = query_parameters.delete(:unauthorized) || self.on_unauthorized
reconnect_proc = query_parameters.delete(:reconnect) || self.on_reconnect
inited_proc = query_parameters.delete(:inited) || self.on_inited
@@ -460,6 +476,10 @@ def connect(path, query_parameters = {}, &block)
unauthorized_proc.call if unauthorized_proc.is_a?(Proc)
end
+ @stream.on_enhance_your_calm do
+ enhance_your_calm_proc.call if enhance_your_calm_proc.is_a?(Proc)
+ end
+
@stream.on_reconnect do |timeout, retries|
reconnect_proc.call(timeout, retries) if reconnect_proc.is_a?(Proc)
end
View
12 spec/tweetstream/client_spec.rb
@@ -58,7 +58,8 @@
:on_reconnect => true,
:connection_completed => true,
:on_no_data_received => true,
- :on_unauthorized => true
+ :on_unauthorized => true,
+ :on_enhance_your_calm => true
)
EM.stub!(:run).and_yield
EM::Twitter::Client.stub!(:connect).and_return(@stream)
@@ -326,7 +327,7 @@
end
end
- %w(on_delete on_limit on_inited on_reconnect on_no_data_received on_unauthorized).each do |proc_setter|
+ %w(on_delete on_limit on_inited on_reconnect on_no_data_received on_unauthorized on_enhance_your_calm).each do |proc_setter|
describe "##{proc_setter}" do
it 'should set when a block is given' do
proc = Proc.new{|a,b| puts a }
@@ -373,6 +374,7 @@
:connection_completed => true,
:on_no_data_received => true,
:on_unauthorized => true,
+ :on_enhance_your_calm => true,
:stop => true
)
EM::Twitter::Client.stub!(:connect).and_return(@stream)
@@ -409,7 +411,8 @@
:on_reconnect => true,
:connection_completed => true,
:on_no_data_received => true,
- :on_unauthorized => true
+ :on_unauthorized => true,
+ :on_enhance_your_calm => true
)
EM.stub!(:run).and_yield
EM::Twitter::Client.stub!(:connect).and_return(@stream)
@@ -453,7 +456,8 @@
:on_reconnect => true,
:connection_completed => true,
:on_no_data_received => true,
- :on_unauthorized => true
+ :on_unauthorized => true,
+ :on_enhance_your_calm => true
)
EM.stub!(:run).and_yield
EM::Twitter::Client.stub!(:connect).and_return(@stream)
View
3  spec/tweetstream/site_stream_client_spec.rb
@@ -101,6 +101,7 @@
end
called.should be_true
end
+
end
end
@@ -229,4 +230,4 @@
end
end
-end
+end
View
3  spec/tweetstream_spec.rb
@@ -16,7 +16,8 @@
:on_reconnect => true,
:connection_completed => true,
:on_no_data_received => true,
- :on_unauthorized => true
+ :on_unauthorized => true,
+ :on_enhance_your_calm => true
)
EM.stub!(:run).and_yield
EM::Twitter::Client.stub!(:connect).and_return(@stream)
Please sign in to comment.
Something went wrong with that request. Please try again.