Class: DripDrop::HTTPClientHandler
- Inherits:
-
BaseHandler
- Object
- BaseHandler
- DripDrop::HTTPClientHandler
- Defined in:
- lib/dripdrop/handlers/http.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#initialize(uri, opts = {}) ⇒ HTTPClientHandler
constructor
A new instance of HTTPClientHandler.
- #send_message(message, &block) ⇒ Object
Constructor Details
#initialize(uri, opts = {}) ⇒ HTTPClientHandler
Returns a new instance of HTTPClientHandler.
89 90 91 92 93 |
# File 'lib/dripdrop/handlers/http.rb', line 89 def initialize(uri, opts={}) @uri = uri @address = @uri.to_s @opts = opts end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
87 88 89 |
# File 'lib/dripdrop/handlers/http.rb', line 87 def address @address end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
87 88 89 |
# File 'lib/dripdrop/handlers/http.rb', line 87 def opts @opts end |
Instance Method Details
#send_message(message, &block) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/dripdrop/handlers/http.rb', line 95 def (,&block) = dd_messagify() if .class == DripDrop::Message uri_path = @uri.path.empty? ? '/' : @uri.path req = EM::Protocols::HttpClient.request( :host => @uri.host, :port => @uri.port, :request => uri_path, :verb => 'POST', :contenttype => 'application/json', :content => .encode_json ) req.callback do |response| block.call(DripDrop::Message.decode_json(response[:content])) end else raise "Unsupported message type '#{.class}'" end end |