Module: RSqoot::Request

Included in:
Client
Defined in:
lib/rsqoot/request.rb

Instance Method Summary collapse

Instance Method Details

#get(path, opts = {}, parse = true) ⇒ Object



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

def get(path, opts = {}, parse = true)
  uri       = URI.parse base_api_url
  uri.path  = '/v2/' + path
  headers   = {read_timeout: read_timeout}
  query = options_parser opts
  endpoint  = path.split('/')[0]
  case authentication_method
  when :header
    headers.merge! h = {"Authorization" => "api_key #{api_key(endpoint)}"}
    query = query + "&api_key=#{api_key(endpoint)}" if !parse
  when :parameter
    query = query + "&api_key=#{api_key(endpoint)}"
  end
  uri.query = query
  if parse
    begin
      json = JSON.parse uri.open(headers).read
      ::Hashie::Mash.new json
    end
  else
    uri.to_s
  end
end