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
Methods inherited from BaseHandler
#handle_error, #on_error, #print_exception
Constructor Details
#initialize(uri, opts = {}) ⇒ HTTPClientHandler
Returns a new instance of HTTPClientHandler.
65 66 67 68 69 70 |
# File 'lib/dripdrop/handlers/http.rb', line 65 def initialize(uri, opts={}) @uri = uri @address = @uri.to_s @opts = opts @message_class = @opts[:message_class] || DripDrop. end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
63 64 65 |
# File 'lib/dripdrop/handlers/http.rb', line 63 def address @address end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
63 64 65 |
# File 'lib/dripdrop/handlers/http.rb', line 63 def opts @opts end |
Instance Method Details
#send_message(message, &block) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/dripdrop/handlers/http.rb', line 72 def (,&block) = dd_messagify() if .is_a?(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| begin # Hack to fix evma http response[:content] =~ /(\{.*\})/ fixed_body = $1 block.call(@message_class.decode(fixed_body)) if block rescue StandardError => e handle_error(e) end end else raise "Unsupported message type '#{.class}'" end end |