Class: SgtnCldr::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/sgtn-cldr/core/config.rb

Constant Summary collapse

@@config_cache =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Config

Create Config object

Options(Hash)

  • username – Username

  • password – Password

  • signature (Optional if certificate present) – Signature

  • app_id – Application ID

  • cert_path (Optional if signature present) – Certificate file path



53
54
55
# File 'lib/sgtn-cldr/core/config.rb', line 53

def initialize(options)
  merge!(options)
end

Instance Attribute Details

#app_idObject

Returns the value of attribute app_id.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def app_id
  @app_id
end

#bundle_modeObject

Returns the value of attribute bundle_mode.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def bundle_mode
  @bundle_mode
end

#cache_expiry_periodObject

Returns the value of attribute cache_expiry_period.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def cache_expiry_period
  @cache_expiry_period
end

#cert_pathObject

Returns the value of attribute cert_path.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def cert_path
  @cert_path
end

#client_idObject

Returns the value of attribute client_id.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def client_secret
  @client_secret
end

#device_ipaddressObject

Returns the value of attribute device_ipaddress.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def device_ipaddress
  @device_ipaddress
end

#disable_cacheObject

Returns the value of attribute disable_cache.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def disable_cache
  @disable_cache
end

#endpointObject

Returns the value of attribute endpoint.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def endpoint
  @endpoint
end

#http_proxyObject

Returns the value of attribute http_proxy.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def http_proxy
  @http_proxy
end

#http_timeoutObject

Returns the value of attribute http_timeout.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def http_timeout
  @http_timeout
end

#ipn_endpointObject

Returns the value of attribute ipn_endpoint.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def ipn_endpoint
  @ipn_endpoint
end

#merchant_endpointObject

Returns the value of attribute merchant_endpoint.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def merchant_endpoint
  @merchant_endpoint
end

#modeObject

Returns the value of attribute mode.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def mode
  @mode
end

#openid_client_idObject

Returns the value of attribute openid_client_id.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def openid_client_id
  @openid_client_id
end

#openid_client_secretObject

Returns the value of attribute openid_client_secret.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def openid_client_secret
  @openid_client_secret
end

#openid_endpointObject

Returns the value of attribute openid_endpoint.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def openid_endpoint
  @openid_endpoint
end

#openid_redirect_uriObject

Returns the value of attribute openid_redirect_uri.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def openid_redirect_uri
  @openid_redirect_uri
end

#passwordObject

Returns the value of attribute password.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def password
  @password
end

#platform_endpointObject

Returns the value of attribute platform_endpoint.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def platform_endpoint
  @platform_endpoint
end

#product_nameObject

Returns the value of attribute product_name.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def product_name
  @product_name
end

#rest_endpointObject

Returns the value of attribute rest_endpoint.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def rest_endpoint
  @rest_endpoint
end

#rest_token_endpointObject

Returns the value of attribute rest_token_endpoint.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def rest_token_endpoint
  @rest_token_endpoint
end

#sandbox_email_addressObject

Returns the value of attribute sandbox_email_address.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def sandbox_email_address
  @sandbox_email_address
end

#signatureObject

Returns the value of attribute signature.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def signature
  @signature
end

#source_bundleObject

Returns the value of attribute source_bundle.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def source_bundle
  @source_bundle
end

#subjectObject

Returns the value of attribute subject.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def subject
  @subject
end

#tokenObject

Returns the value of attribute token.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def token
  @token
end

#token_secretObject

Returns the value of attribute token_secret.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def token_secret
  @token_secret
end

#translation_bundleObject

Returns the value of attribute translation_bundle.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def translation_bundle
  @translation_bundle
end

#usernameObject

Returns the value of attribute username.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def username
  @username
end

#verbose_loggingObject

Returns the value of attribute verbose_logging.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def verbose_logging
  @verbose_logging
end

#versionObject

Returns the value of attribute version.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def version
  @version
end

#vip_serverObject

Returns the value of attribute vip_server.



35
36
37
# File 'lib/sgtn-cldr/core/config.rb', line 35

def vip_server
  @vip_server
end

Class Method Details

.config(env = default_environment, override_configuration = {}) ⇒ Object

Create or Load Config object based on given environment and configurations.

Attributes

  • env (Optional) – Environment name

  • override_configuration (Optional) – Override the configuration given in file.

Example

Config.config
Config.config(:development)
Config.config(:development, { :app_id => "XYZ" })


113
114
115
116
117
118
119
120
121
122
123
# File 'lib/sgtn-cldr/core/config.rb', line 113

def config(env = default_environment, override_configuration = {})
  if env.is_a? Hash
    override_configuration = env
    env = default_environment
  end
  if override_configuration.nil? or override_configuration.empty?
    default_config(env)
  else
    default_config(env).dup.merge!(override_configuration)
  end
end

.configurationsObject

Get raw configurations in Hash format.



135
136
137
# File 'lib/sgtn-cldr/core/config.rb', line 135

def configurations
  @@configurations ||= read_configurations
end

.configurations=(configs) ⇒ Object

Set configuration



140
141
142
143
# File 'lib/sgtn-cldr/core/config.rb', line 140

def configurations=(configs)
  @@config_cache   = {}
  @@configurations = configs && Hash[configs.map{|k,v| [k.to_s, v] }]
end

.configure(options = {}, &block) ⇒ Object Also known as: set_config



94
95
96
97
98
99
100
101
102
# File 'lib/sgtn-cldr/core/config.rb', line 94

def configure(options = {}, &block)
  begin
    self.config.merge!(options)
  rescue Errno::ENOENT
    self.configurations = { default_environment => options }
  end
  block.call(self.config) if block
  self.config
end

.default_config(env = nil) ⇒ Object



125
126
127
128
129
130
131
132
# File 'lib/sgtn-cldr/core/config.rb', line 125

def default_config(env = nil)
  env = (env || default_environment).to_s
  if configurations[env]
    @@config_cache[env] ||= new(configurations[env])
  else
    raise SgtnClient::Exceptions::MissingConfig.new("Configuration[#{env}] NotFound")
  end
end

.default_environmentObject

Get default environment name



84
85
86
# File 'lib/sgtn-cldr/core/config.rb', line 84

def default_environment
  @@default_environment ||= ENV['SGTN_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV'] || "development"
end

.default_environment=(env) ⇒ Object

Set default environment



90
91
92
# File 'lib/sgtn-cldr/core/config.rb', line 90

def default_environment=(env)
  @@default_environment = env.to_s
end

.load(file_name, default_env = default_environment) ⇒ Object

Load configurations from file

Arguments

  • file_name – Configuration file path

  • default_environment (Optional) – default environment configuration to load

Example

Config.load('config/paypal.yml', 'development')


75
76
77
78
79
80
# File 'lib/sgtn-cldr/core/config.rb', line 75

def load(file_name, default_env = default_environment)
  @@config_cache        = {}
  @@configurations      = read_configurations(file_name)
  @@default_environment = default_env
  config
end

.loggerObject

Get logger



151
152
153
154
155
156
157
# File 'lib/sgtn-cldr/core/config.rb', line 151

def logger
  if @@configurations[:mode] == 'live' and Logging.logger.level == Logger::DEBUG
    Logging.logger.warn "DEBUG log level not allowed in live mode for security of confidential information. Changing log level to INFO..."
    Logging.logger.level = Logger::INFO
  end
  Logging.logger
end

.logger=(logger) ⇒ Object

Set logger



146
147
148
# File 'lib/sgtn-cldr/core/config.rb', line 146

def logger=(logger)
  Logging.logger = logger
end

Instance Method Details

#merge!(options) ⇒ Object

Override configurations



58
59
60
61
62
63
# File 'lib/sgtn-cldr/core/config.rb', line 58

def merge!(options)
  options.each do |key, value|
    send("#{key}=", value)
  end
  self
end