YAJL in Rails to pull from streaming APIs

I’m trying to get an app running to pull data from a variety of
streaming APIs. I’m staring with the Twitter API and will be moving to
others following. I’d prefer not to use an API-specific gem like
TweetStream so I can reuse code and make things more efficient.

I’m using YAJL (open to suggestions on other gems) to pull from the
stream, but am getting an error when connecting. My code for the
connection is: (username/password removed):

max_allowed_errors = 1200
consecutive_errors = 0
while consecutive_errors < max_allowed_errors do
url =
URI.parse(“https://[username]:[password]!@stream.twitter.com/1/statuses/sample.json”)
begin
Yajl::HttpStream.get(url) do |status|
consecutive_errors = 0
# puts status.inspect
end
rescue Yajl::HttpStream::InvalidContentType
consecutive_errors += 1
end
sleep(0.25*consecutive_errors)
end

The error is:

Yajl::HttpStream::HttpError in DashboardsController#streamit

Code 200 expected got 0

The error refers to this line:

Yajl::HttpStream.get(url) do |status|

Appreciate any support on getting this running.

Thanks,
-matthew