Class: Eleyo::API::Config
- Inherits:
-
Object
- Object
- Eleyo::API::Config
- Defined in:
- lib/eleyo/api/config.rb
Instance Attribute Summary collapse
-
#auth ⇒ Object
Returns the value of attribute auth.
Class Method Summary collapse
Instance Method Summary collapse
- #get(subdomain_or_sn) ⇒ Object
- #get_by(key, value) ⇒ Object
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
16 17 18 19 20 21 |
# File 'lib/eleyo/api/config.rb', line 16 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 Eleyo::API::Auth") if !self.auth.is_a?(Eleyo::API::Auth) end |
Instance Attribute Details
#auth ⇒ Object
Returns the value of attribute auth.
14 15 16 |
# File 'lib/eleyo/api/config.rb', line 14 def auth @auth end |
Class Method Details
.server_uri ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/eleyo/api/config.rb', line 4 def self.server_uri if Eleyo::API.standardmode? "https://config.reg.eleyo.com" elsif Eleyo::API.testmode? "https://config.reg.eleyo.green" elsif Eleyo::API.devmode? "https://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/eleyo/api/config.rb', line 23 def get(subdomain_or_sn) subdomain_or_sn = 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/eleyo/api/config.rb', line 39 def get_by(key, value) key = URI.escape(key.to_s) value = 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 |