Sha256: f0481544996a437c8b64732c8e5f92961bd770e2b59bc8c352941215814927df

Contents?: true

Size: 993 Bytes

Versions: 1

Compression:

Stored size: 993 Bytes

Contents

module RUPNP

  # Event subscriber to an event's service
  # @author Sylvain Daubert
  class CP::EventSubscriber < EM::Connection
    include LogMixin

    # Response from device
    # @return [EM::Channel]
    attr_reader :response


    # @param [String] msg message to send for subscribing
    def initialize(msg)
      @msg = msg
      @response = EM::Channel.new
    end

    # @return [void]
    def post_init
      log :debug, "send event subscribe request:\n#@msg"
      send_data @msg
    end

    # Receive response from device and send it through {#response}
    # @param [String] data
    # @return [void]
    def receive_data(data)
      log :debug, "receive data from subscribe event action:\n#{data}"
      resp = {}
      io = StringIO.new(data)

      status = io.readline

      if status =~ /HTTP\/1\.1 (\d+) (.+)/
        resp[:status] = $2
        resp[:status_code] = $1

        resp.merge!(get_http_headers(io))

        @response << resp
      end
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rupnp-0.2.2 lib/rupnp/cp/event_subscriber.rb