module MyApiClient::Request

Provides HTTP request method.

Private Instance Methods

_request_with_absolute_uri(http_method, uri, headers, body) click to toggle source

Executes HTTP request with absolute URI.

@param http_method [Symbol]

HTTP method. e.g. `:get`, `:post`, `:put`, `:patch` and `:delete`.

@param uri [URI]

Request target URI including query strings.

@param headers [Hash, nil]

Request headers.

@param body [Hash, nil]

Request body.

@return [Sawyer::Response]

Response instance.
# File lib/my_api_client/request.rb, line 44
def _request_with_absolute_uri(http_method, uri, headers, body)
  Executor.call(
    instance: self,
    request_params: Params::Request.new(http_method, uri, headers, body),
    request_logger: Logger.new(logger, http_method, uri),
    faraday_options: faraday_options
  )
end
_request_with_relative_uri(http_method, pathname, headers, query, body) click to toggle source

Executes HTTP request with relative URI.

@param http_method [Symbol]

HTTP method. e.g. `:get`, `:post`, `:put`, `:patch` and `:delete`.

@param pathname [String]

Pathname of the request target URL.
It's joined with the defined by `endpoint`.

@param headers [Hash, nil]

Request headers.

@param query [Hash, nil]

Query string.

@param body [Hash, nil]

Request body.

@return [Sawyer::Response]

Response instance.
# File lib/my_api_client/request.rb, line 26
def _request_with_relative_uri(http_method, pathname, headers, query, body)
  query_strings = query.present? ? "?#{query.to_query}" : ''
  uri = URI.join(File.join(endpoint, pathname), query_strings)
  _request_with_absolute_uri(http_method, uri, headers, body)
end
faraday_options() click to toggle source

Generates options for the faraday instance.

@return [Hash] Generated options.

# File lib/my_api_client/request.rb, line 56
def faraday_options
  {
    request: {
      timeout: (http_read_timeout if respond_to?(:http_read_timeout)),
      open_timeout: (http_open_timeout if respond_to?(:http_open_timeout)),
    }.compact,
  }
end