Sha256: 84fa464034262ad208750eb9b34514c542d7996a01bb74b5f99106749b100015

Contents?: true

Size: 752 Bytes

Versions: 1

Compression:

Stored size: 752 Bytes

Contents

require 'em-http'

module Rsift

  class Socket

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

      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.5 lib/rsift/socket.rb