Sha256: 5dd85184442b336ebdc12696fa37fdc886c1904f8af4857ede9345abbb3dc11a
Contents?: true
Size: 1.12 KB
Versions: 7
Compression:
Stored size: 1.12 KB
Contents
class DripDrop class HTTPClientHandler < BaseHandler attr_reader :address, :opts def initialize(uri, opts={}) @uri = uri @address = @uri.to_s @opts = opts @message_class = @opts[:message_class] || DripDrop.default_message_class end def send_message(message,&block) dd_message = dd_messagify(message) if dd_message.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 => dd_message.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 '#{dd_message.class}'" end end end end
Version data entries
7 entries across 7 versions & 1 rubygems