Class: AruxApp::API::Config
- Inherits:
-
Object
- Object
- AruxApp::API::Config
- Defined in:
- lib/arux_app/api/config.rb
Instance Attribute Summary collapse
-
#auth ⇒ Object
Returns the value of attribute auth.
Class Method Summary collapse
Instance Method Summary collapse
- #api_uri ⇒ Object
- #get(subdomain_or_sn) ⇒ Object
- #get_by(key, value) ⇒ Object
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #list(params = {}) ⇒ Object
- #public_uri ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
6 7 8 9 10 11 |
# File 'lib/arux_app/api/config.rb', line 6 def initialize( = {}) self.auth = [: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
#auth ⇒ Object
Returns the value of attribute auth.
4 5 6 |
# File 'lib/arux_app/api/config.rb', line 4 def auth @auth end |
Class Method Details
Instance Method Details
#api_uri ⇒ Object
25 26 27 |
# File 'lib/arux_app/api/config.rb', line 25 def api_uri self.class.api_uri end |
#get(subdomain_or_sn) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/arux_app/api/config.rb', line 29 def get(subdomain_or_sn) subdomain_or_sn = AruxApp::API.uri_escape(subdomain_or_sn.to_s) request = HTTPI::Request.new request.url = "#{api_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
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/arux_app/api/config.rb', line 45 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 = "#{api_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 |
#list(params = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/arux_app/api/config.rb', line 62 def list(params = {}) request = HTTPI::Request.new request.url = "#{api_uri}/v1/p/customers" request.query = URI.encode_www_form(params) request.headers = generate_headers response = HTTPI.get(request) if !response.error? JSON.parse(response.body) else raise(API::Error.new(response.code, response.body)) end end |
#public_uri ⇒ Object
17 18 19 |
# File 'lib/arux_app/api/config.rb', line 17 def public_uri self.class.public_uri end |