Module: Mirakl::ApiOperations::Request::ClassMethods

Defined in:
lib/mirakl/api_operations/request.rb

Instance Method Summary collapse

Instance Method Details

#request(method, url, params = {}, opts = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mirakl/api_operations/request.rb', line 7

def request(method, url, params = {}, opts = {})
  warn_on_opts_in_params(params)

  opts = Util.normalize_opts(opts)
  opts[:client] ||= MiraklClient.active_client

  headers = opts.clone
  api_key = headers.delete(:api_key)
  api_base = headers.delete(:api_base)
  client = headers.delete(:client)
  # Assume all remaining opts must be headers

  resp, opts[:api_key] = client.execute_request(
    method, url,
    api_base: api_base, api_key: api_key,
    headers: headers, params: params
  )

  # Hash#select returns an array before 1.9
  opts_to_persist = {}
  opts.each do |k, v|
    opts_to_persist[k] = v if Util::OPTS_PERSISTABLE.include?(k)
  end

  [resp, opts_to_persist]
end