Sha256: 531b3e59f789f91631ce43a6646f93e868e0081f3b347531510fed88d15c7b8d

Contents?: true

Size: 860 Bytes

Versions: 12

Compression:

Stored size: 860 Bytes

Contents

require 'rest_client'

module Airborne
  module RestClientRequester
    def make_request(method, url, options = {})
      headers = base_headers.merge(options[:headers] || {})
      res = if method == :post || method == :patch || method == :put
        begin
          request_body = options[:body].nil? ? '' : options[:body]
          request_body = request_body.to_json if options[:body].is_a?(Hash)
          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

    private

    def base_headers
      { content_type: :json }.merge(Airborne.configuration.headers || {})
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
airborne-0.3.0 lib/airborne/rest_client_requester.rb
airborne-0.2.13 lib/airborne/rest_client_requester.rb
airborne-0.2.12 lib/airborne/rest_client_requester.rb
airborne-0.2.11 lib/airborne/rest_client_requester.rb
airborne-0.2.10 lib/airborne/rest_client_requester.rb
airborne-0.2.9 lib/airborne/rest_client_requester.rb
airborne-0.2.8 lib/airborne/rest_client_requester.rb
airborne-0.2.7 lib/airborne/rest_client_requester.rb
airborne-0.2.6 lib/airborne/rest_client_requester.rb
airborne-0.2.5 lib/airborne/rest_client_requester.rb
airborne-0.2.4 lib/airborne/rest_client_requester.rb
airborne-0.2.3 lib/airborne/rest_client_requester.rb