Class: DripDrop::HTTPServerHandler

Inherits:
BaseHandler show all
Defined in:
lib/dripdrop/handlers/http_server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseHandler

#handle_error, #on_error, #print_exception

Constructor Details

#initialize(uri, opts = {}) ⇒ HTTPServerHandler

Returns a new instance of HTTPServerHandler.



45
46
47
48
49
50
51
# File 'lib/dripdrop/handlers/http_server.rb', line 45

def initialize(uri,opts={})
  @uri      = uri
  @uri_path = @uri.path.empty? ? '/' : @uri.path
  @address  = uri.to_s
  @opts     = opts
  @message_class = @opts[:message_class] || DripDrop.default_message_class
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



43
44
45
# File 'lib/dripdrop/handlers/http_server.rb', line 43

def address
  @address
end

#message_classObject (readonly)

Returns the value of attribute message_class.



43
44
45
# File 'lib/dripdrop/handlers/http_server.rb', line 43

def message_class
  @message_class
end

#optsObject (readonly)

Returns the value of attribute opts.



43
44
45
# File 'lib/dripdrop/handlers/http_server.rb', line 43

def opts
  @opts
end

#recv_cbakObject (readonly)

Returns the value of attribute recv_cbak.



43
44
45
# File 'lib/dripdrop/handlers/http_server.rb', line 43

def recv_cbak
  @recv_cbak
end

#uriObject (readonly)

Returns the value of attribute uri.



43
44
45
# File 'lib/dripdrop/handlers/http_server.rb', line 43

def uri
  @uri
end

Instance Method Details

#on_receive(msg_format = :dripdrop_json, &block) ⇒ Object



53
54
55
56
57
# File 'lib/dripdrop/handlers/http_server.rb', line 53

def on_receive(msg_format=:dripdrop_json,&block)
  @recv_cbak = block
  @conn = EM.start_server(@uri.host, @uri.port, HTTPEMServer, self)
  self
end

#on_recv(*args, &block) ⇒ Object



59
60
61
62
# File 'lib/dripdrop/handlers/http_server.rb', line 59

def on_recv(*args,&block)
  $stderr.write "DripDrop Warning :on_recv is deprecated in favor of :on_receive"
  on_receive(*args,&block)
end