Skip to content

Commit

Permalink
readme update, call on_error if @code != 200
Browse files Browse the repository at this point in the history
  • Loading branch information
voloko committed Oct 11, 2009
1 parent ab588a3 commit 24c05ff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
18 changes: 15 additions & 3 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,32 @@ Uses [EventMachine](http://rubyeventmachine.com/) for connection handling. Adher

JSON format only.

## Install

sudo gem install twitter-stream -s http://gemcutter.org

## Usage

require 'rubygems'
require 'twitter/json_stream'

EventMachine::run {
stream = Twitter::JSONStream.connect(
:path => '/1/statuses/filter.json?track=football',
:auth => 'LOGIN:PASSWORD',
:auth => 'LOGIN:PASSWORD'
)

stream.each_item do |item|
# do someting with unparsed JSON item
# Do someting with unparsed JSON item.
end

stream.on_error do |message|
# log or something
# No need to worry here. It might be an issue with Twitter.
# Log message for future reference. JSONStream will try to reconnect after a timeout.
end
stream.on_max_reconnects do |timeout, retries|
# Something is wrong on your side. Send yourself an email.
end
}

Expand Down
1 change: 1 addition & 0 deletions lib/twitter/json_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def parse_response_line ln
if ln =~ /\AHTTP\/1\.[01] ([\d]{3})/
@code = $1.to_i
@state = :headers
receive_error("invalid status code: #{@code}. #{ln}") unless @code == 200
else
receive_error('invalid response')
close_connection
Expand Down

0 comments on commit 24c05ff

Please sign in to comment.