Class: Halo::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/halo-api/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/halo-api/client.rb', line 13

def initialize(options = {})
  @api_key = options[:api_key]
  @region = options[:region]
  @endpoint = options[:endpoint]

  options = Halo.options.merge(options)

  Halo::Configuration::OPTIONS.each do |key|
    send("#{key}=", options[key])
  end

  self.class.base_uri "https://www.haloapi.com#{@endpoint}"
end

Instance Method Details

#get(path, params = {}) ⇒ Object



27
28
29
# File 'lib/halo-api/client.rb', line 27

def get(path, params = {})
  make_request :get, path, params
end

#make_request(verb, path, params = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/halo-api/client.rb', line 31

def make_request(verb, path, params = {})
  options = {}
  headers = {
    'Ocp-Apim-Subscription-Key' => @api_key,
    'Accept-Language' => @region
  }

  options[:headers] = headers unless headers.empty?
  options[:query]   = params unless params.empty?

  self.class.send(verb, Addressable::URI.encode(path), options)
end