Method: PulpContainerClient::ApiClient#build_request

Defined in:
lib/pulp_container_client/api_client.rb

#build_request(http_method, path, request, opts = {}) ⇒ Faraday::Request

Builds the HTTP request

Parameters:

  • http_method (String)

    HTTP method/verb (e.g. POST)

  • path (String)

    URL path (e.g. /account/new)

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

    a customizable set of options

Options Hash (opts):

  • :header_params (Hash)

    Header parameters

  • :query_params (Hash)

    Query parameters

  • :form_params (Hash)

    Query parameters

  • :body (Object)

    HTTP body (JSON/XML)

Returns:

  • (Faraday::Request)

    A Faraday Request


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/pulp_container_client/api_client.rb', line 102

def build_request(http_method, path, request, opts = {})
  url = build_request_url(path, opts)
  http_method = http_method.to_sym.downcase

  header_params = @default_headers.merge(opts[:header_params] || {})
  query_params = opts[:query_params] || {}
  form_params = opts[:form_params] || {}

  update_params_for_auth! header_params, query_params, opts[:auth_names]

  if [:post, :patch, :put, :delete].include?(http_method)
    req_body = build_request_body(header_params, form_params, opts[:body])
    if config.debugging
      config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
    end
  end
  request.headers = header_params
  request.body = req_body

  # Overload default options only if provided
  request.options.params_encoder = config.params_encoder if config.params_encoder
  request.options.timeout        = config.timeout        if config.timeout

  request.url url
  request.params = query_params
  request
end