Class: DuffelAPI::APIService

Inherits:
Object
  • Object
show all
Defined in:
lib/duffel_api/api_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_url, access_token, options = {}) ⇒ APIService



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/duffel_api/api_service.rb', line 8

def initialize(base_url, access_token, options = {})
  @base_url = base_url
  root_url, @path_prefix = unpack_url(base_url)

  @connection = Faraday.new(root_url) do |faraday|
    faraday.response :raise_duffel_errors

    faraday.adapter(:net_http)
  end

  @headers = options[:default_headers] || {}
  @headers["Authorization"] = "Bearer #{access_token}"
end

Instance Method Details

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

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
# File 'lib/duffel_api/api_service.rb', line 22

def make_request(method, path, options = {})
  raise ArgumentError, "options must be a hash" unless options.is_a?(Hash)

  options[:headers] ||= {}
  options[:headers] = @headers.merge(options[:headers])
  Request.new(@connection, method, @path_prefix + path, options).request
end