Module: Airborne::RestClientRequester

Defined in:
lib/spaceborne.rb

Instance Method Summary collapse

Instance Method Details

#make_request(method, url, options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/spaceborne.rb', line 38

def make_request(method, url, options = {})
  @json_body = nil
  @request_body = nil
  if options[:headers] && options[:headers].has_key?(:use_proxy)
    proxy_option = options[:headers][:use_proxy]
    RestClient.proxy = proxy_option
  end
  headers = base_headers.merge(options[:headers] || {})
  res = if method == :post || method == :patch || method == :put
    begin
      @request_body = options[:body].nil? ? '' : options[:body]
      if options[:body].is_a?(Hash)
        if headers.delete(:nonjson_data)
          headers.delete('Content-Type')
        else
          headers.merge!(no_restclient_headers: true)
          @request_body = @request_body.to_json
        end
      end
      RestClient.send(method, get_url(url), @request_body, headers)
    rescue RestClient::Exception => e
      e.response
    end
  else
    begin
      RestClient.send(method, get_url(url), headers)
    rescue RestClient::Exception => e
      e.response
    end
  end
  res
end