Module: Helio::APIOperations::Request::ClassMethods

Defined in:
lib/helio/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/helio/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] ||= HelioClient.active_client

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

  resp, opts[:api_token] = client.execute_request(
    method, url,
    api_base: api_base, api_token: api_token,
    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