Sha256: dc4275323281fe0e6a252d19820e79e5342ef2459dd69d92aaf1a1e627fe35b7

Contents?: true

Size: 746 Bytes

Versions: 1

Compression:

Stored size: 746 Bytes

Contents

require 'em-http'

module Rsift

  class Socket

    def self.perform(stream_identifier)
      endpoint = "ws://websocket.datasift.net/"

      EventMachine.run {
        http = EventMachine::HttpRequest.new(
            "#{endpoint}#{stream_identifier}").get(:timeout => 0)

        http.callback do
          puts "Connected to datasift" 
        end
        
        http.errback do
          raise SocketError.new("Datasift threw an error")
        end
        
        http.disconnect do
           raise SocketDisconnect.new("Datasift disconnected me.")
        end

        http.stream { |msg|
          yield msg
        }
      }
    end
  end
  
  class SocketDisconnect < StandardError; end
  class SocketError < StandardError; end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rsift-0.3.6 lib/rsift/socket.rb