Skip to content

http_stream deprecation and examples #154

Open

Description

@simon3z

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

Activity

  1. summera commented on Feb 21, 2015

    @summera

    Wondering the same 👍

  2. myconode commented on Mar 24, 2015

    @myconode

    +1

  3. ACPK commented on Nov 25, 2015

    @ACPK

    Same. +1

  4. harleyg321 commented on Dec 20, 2015

    @harleyg321

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions