Module: Airborne::RestClientRequester

Defined in:
lib/airborne/rest_client_requester.rb

Instance Method Summary collapse

Instance Method Details

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



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/airborne/rest_client_requester.rb', line 5

def make_request(method, url, options = {})
  headers = base_headers.merge(options[:headers] || {})
  verify_ssl = options.fetch(:verify_ssl, true)
  res = if method == :post || method == :patch || method == :put || method == :delete
    begin
      request_body = options[:body].nil? || options[:body].empty? ? '' : options[:body]
      request_body = request_body.to_json if is_json_request(headers) && !request_body.empty?
      RestClient::Request.execute(
        method: method,
        url: get_url(url),
        payload: request_body,
        headers: headers,
        verify_ssl: verify_ssl
      ) { |response, request, result| response }
    rescue RestClient::Exception => e
      e.response
    end
  else
    begin
      RestClient::Request.execute(
        method: method,
        url: get_url(url),
        headers: headers,
        verify_ssl: verify_ssl
      ) { |response, request, result| response }
    rescue RestClient::Exception => e
      e.response
    end
  end
  res
end