Sha256: 45ddc0e96a9a9b56c267b9a7fdbc527f9f25c9a74a914f062c7cccc349fd3727

Contents?: true

Size: 791 Bytes

Versions: 13

Compression:

Stored size: 791 Bytes

Contents

module Blather # :nodoc:
class Stream # :nodoc:

  class StreamHandler # :nodoc:
    def on_success(&block); @success = block; end
    def on_failure(&block); @failure = block; end

    def initialize(stream)
      @stream = stream
    end

    def handle(node)
      @node = node
      method = @node.element_name == 'iq' ? @node['type'] : @node.element_name
      if self.respond_to?(method, true)
        self.__send__ method
      else
        @failure.call UnknownResponse.new(@node)
      end
    end

  protected
    ##
    # Handle error response from the server
    def error
      failure
    end

    def success(message_back = nil)
      @success.call message_back
    end

    def failure(err = nil)
      @failure.call err
    end
  end #StreamHandler

end #Stream
end #Blather

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
sprsquish-blather-0.2.3 lib/blather/stream/stream_handler.rb
sprsquish-blather-0.3.0 lib/blather/stream/stream_handler.rb
sprsquish-blather-0.3.1 lib/blather/stream/stream_handler.rb
sprsquish-blather-0.3.2 lib/blather/stream/stream_handler.rb
sprsquish-blather-0.3.3 lib/blather/stream/stream_handler.rb
sprsquish-blather-0.3.4 lib/blather/stream/stream_handler.rb
blather-0.2.2 lib/blather/stream/stream_handler.rb
blather-0.3.1 lib/blather/stream/stream_handler.rb
blather-0.3.0 lib/blather/stream/stream_handler.rb
blather-0.2.3 lib/blather/stream/stream_handler.rb
blather-0.3.4 lib/blather/stream/stream_handler.rb
blather-0.3.3 lib/blather/stream/stream_handler.rb
blather-0.3.2 lib/blather/stream/stream_handler.rb