From 24c05ff0f5a3568461c7703e3426dd9c6d1bab8e Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Sun, 11 Oct 2009 17:04:10 +0400 Subject: [PATCH] readme update, call on_error if @code != 200 --- README.markdown | 18 +++++++++++++++--- lib/twitter/json_stream.rb | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.markdown b/README.markdown index d7f2287..7dc9992 100644 --- a/README.markdown +++ b/README.markdown @@ -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 } diff --git a/lib/twitter/json_stream.rb b/lib/twitter/json_stream.rb index 3827aa0..4426001 100644 --- a/lib/twitter/json_stream.rb +++ b/lib/twitter/json_stream.rb @@ -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