Skip to content

Commit

Permalink
Add on_request callback
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Aug 18, 2013
1 parent 12cb5dd commit 36e9cfb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
17 changes: 15 additions & 2 deletions lib/twitter/streaming/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,23 @@ def track!(*keywords, &block)
end
end

# Set a Proc to be run when connection established.
def on_request(&block)
if block_given?
@on_request = block
self
elsif instance_variable_defined?(:@on_request)
@on_request
else
Proc.new {}
end
end

def request(options, &block)
on_request.call
# TODO: consider HTTP::Request
request = Twitter::Streaming::Request.new(@request_options.merge(options))
response = Twitter::Streaming::Response.new(block)
request = Twitter::Streaming::Request.new(@request_options.merge(options))
response = Twitter::Streaming::Response.new(block)
@connection.future.stream(request, response)
end

Expand Down
3 changes: 1 addition & 2 deletions lib/twitter/streaming/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ def initialize(block)
end

def on_headers_complete(headers)
puts headers
# handle response codes
# TODO: handle response codes
end

def on_body(data)
Expand Down

0 comments on commit 36e9cfb

Please sign in to comment.