Class: AruxApp::API::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/arux_app/api/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



16
17
18
19
20
21
# File 'lib/arux_app/api/config.rb', line 16

def initialize(options = {})
  self.auth = options[:auth]

  raise API::InitializerError.new(:auth, "can't be blank") if self.auth.nil?
  raise API::InitializerError.new(:auth, "must be of class type AruxApp::API::Auth") if !self.auth.is_a?(AruxApp::API::Auth)
end

Instance Attribute Details

#authObject

Returns the value of attribute auth.



14
15
16
# File 'lib/arux_app/api/config.rb', line 14

def auth
  @auth
end

Class Method Details

.server_uriObject



4
5
6
7
8
9
10
11
12
# File 'lib/arux_app/api/config.rb', line 4

def self.server_uri
  if AruxApp::API.standardmode?
    "https://config.arux.app"
  elsif AruxApp::API.testmode?
    "https://config.arux.blue"
  elsif AruxApp::API.devmode?
    "http://config.#{HOSTNAME}"
  end
end

Instance Method Details

#get(subdomain_or_sn) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/arux_app/api/config.rb', line 23

def get(subdomain_or_sn)
  subdomain_or_sn = AruxApp::API.uri_escape(subdomain_or_sn.to_s)

  request = HTTPI::Request.new
  request.url = "#{self.class.server_uri}/v1/customers/#{subdomain_or_sn}"
  request.headers = self.generate_headers

  response = HTTPI.get(request)

  if !response.error?
    JSON.parse(response.body)
  else
    raise(API::Error.new(response.code, response.body))
  end
end

#get_by(key, value) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/arux_app/api/config.rb', line 39

def get_by(key, value)
  key = AruxApp::API.uri_escape(key.to_s)
  value = AruxApp::API.uri_escape(value.to_s)

  request = HTTPI::Request.new
  request.url = "#{self.class.server_uri}/v1/customers/by/#{key}/#{value}"
  request.headers = self.generate_headers

  response = HTTPI.get(request)

  if !response.error?
    JSON.parse(response.body)
  else
    raise(API::Error.new(response.code, response.body))
  end
end