title: Using YAJL to pull a streaming API in Rails
body: <p>I'm trying to get YAJL working in my app - been testing it off the Twitter API and the Digg API and I can't seem to get it working.</p>
  
  <p>I'm not sure where I'm going wrong. Tapping into the Twitter streaming API using this code: (username/password removed)</p>
  
  <pre><code>max_allowed_errors = 1200
  consecutive_errors = 0
  while consecutive_errors &lt; 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
  </code></pre>
  
  <p>I get an error: </p>
  
  <pre><code>Yajl::HttpStream::HttpError in DashboardsController#streamit
  
  Code 200 expected got 0
  </code></pre>
  
  <p>The error refers to this line:</p>
  
  <pre><code>Yajl::HttpStream.get(url) do |status|
  </code></pre>
  
  <p>I'd like to avoid API-specific gems so I can reuse code and tap into other APIs down the road (i.e. TweetStream).</p>
  
  <p>Thanks in advance for the help! Let me know if you have any questions or if I can clarify this at all.</p>
  
  <p>Oh! I'll note I'm open to other gems to manage streaming if you have recommendations.</p>