Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http_stream deprecation and examples #154

Open
simon3z opened this issue Feb 8, 2015 · 4 comments
Open

http_stream deprecation and examples #154

simon3z opened this issue Feb 8, 2015 · 4 comments

Comments

@simon3z
Copy link

simon3z commented Feb 8, 2015

If http_stream is going to be deprecated in 2.0 (generating a warning) what's the preferred implementation of the current:

require 'uri'
require 'yajl/http_stream'

uri = URI.parse("http://#{username}:#{password}@stream.twitter.com/spritzer.json")
Yajl::HttpStream.get(uri, :symbolize_keys => true) do |hash|
  puts hash.inspect
end

Would it be possible to update the README with the new code? Thanks

@summera
Copy link

summera commented Feb 21, 2015

Wondering the same 👍

@myconode
Copy link

+1

@ACPK
Copy link

ACPK commented Nov 25, 2015

Same. +1

@harleyg321
Copy link

The following would be a way to do streaming with Net::HTTP, although twitter now requires oauth for authentication so the twitter example wouldn't work as it currently stands anyway.

require 'yajl'
require 'net/http'

def object_parsed(obj)
    puts obj.inspect
end

uri = URI("http://#{username}:#{password}@stream.twitter.com/spritzer.json")
request = Net::HTTP::Get.new(uri.request_uri)

Net::HTTP.start(uri.host, uri.port) do |http|
    http.request request do |response|
        parser = Yajl::Parser.new()
        parser.on_parse_complete = method(:object_parsed)
        response.read_body do |chunk|
            parser << chunk
        end
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants