class Playtypus::HttpSender
Public Class Methods
new(host)
click to toggle source
# File lib/playtypus/http_sender.rb, line 25 def initialize(host) @host = host end
Public Instance Methods
send(call)
click to toggle source
# File lib/playtypus/http_sender.rb, line 29 def send(call) $logger.debug("sending call #{call.inspect}") body = transform_payload(call.body) $logger.debug "transformed body to #{body}" begin URI.parse("#{@host}#{call.path}") @url = "#{@host}#{call.path}" rescue URI::InvalidURIError @url = URI::encode("#{@host}#{call.path}") end $logger.info("sending call to #{@url}") response = nil begin response = send_http(call.verb.downcase, @url, { :body => body, :headers => call.headers }) rescue => e $logger.warn "call failed with exception: #{e.inspect}" end unless(response == nil) $logger.debug "received response #{response.inspect}" end return response end
Private Instance Methods
send_http(verb, url, options)
click to toggle source
# File lib/playtypus/http_sender.rb, line 59 def send_http(verb, url, options) self.class.send(verb, url, options) end
transform_payload(input)
click to toggle source
# File lib/playtypus/http_sender.rb, line 63 def transform_payload(input) result = nil begin result = JSON.pretty_generate(input) rescue result = input end return result end