Class: DuffelAPI::Request

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

Overview

An internal class used within the library that represents a request to be made to the Duffel API, and which is able to dispatch that request

Instance Method Summary collapse

Constructor Details

#initialize(connection, method, path, headers: {}, params: {}, query_params: {}) ⇒ Request

Initialize a request class, which makes calls to the API

Parameters:

  • connection (Faraday)

    a Faraday connection

  • method (Symbol)

    the HTTP method to make the request with

  • path (String)

    the path to make the request to

  • headers (Hash) (defaults to: {})

    the HTTP request headers to send with the request

  • params (Hash) (defaults to: {})

    Any paramters to include in the HTTP body

  • query_params (Hash) (defaults to: {})

    Any parameters to include in the HTTP querystring



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/duffel_api/request.rb', line 17

def initialize(connection, method, path, headers: {}, params: {}, query_params: {})
  @connection = connection
  @method = method
  @path = path
  @headers = headers.transform_keys(&:to_s)
  @option = params
  @query_params = query_params

  @request_body = request_body

  if @request_body.is_a?(Hash)
    @request_body = @request_body.to_json
    @headers["Content-Type"] ||= "application/json"
  end
end

Instance Method Details

#callResponse

Dispatches the request and returns the response

Returns:

  • (Response)

    the response from the request



36
37
38
# File 'lib/duffel_api/request.rb', line 36

def call
  Response.new(make_request)
end