Class: Playtypus::HttpSender

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/playtypus/http_sender.rb

Defined Under Namespace

Classes: HttpSendError

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ HttpSender

Returns a new instance of HttpSender.



25
26
27
# File 'lib/playtypus/http_sender.rb', line 25

def initialize(host)
  @host = host
end

Instance Method Details

#send(call) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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