Class: PayPal::SDK::Core::Config
- Inherits:
-
Object
- Object
- PayPal::SDK::Core::Config
- Includes:
- Exceptions, Logging
- Defined in:
- lib/paypal-sdk/core/config.rb
Overview
Config class is used to hold the configurations.
Examples
# To load configurations from file
Config.load('config/paypal.yml', 'development')
# Get configuration
Config.config # load default configuration
Config.config(:development) # load development configuration
Config.config(:development, :app_id => "XYZ") # Override configuration
# Read configuration attributes
config = Config.config
config.username
config.endpoint
Constant Summary collapse
- @@config_cache =
{}
Instance Attribute Summary collapse
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#cert_path ⇒ Object
Returns the value of attribute cert_path.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#device_ipaddress ⇒ Object
Returns the value of attribute device_ipaddress.
-
#endpoint ⇒ Object
(also: #end_point)
Returns the value of attribute endpoint.
-
#http_proxy ⇒ Object
Returns the value of attribute http_proxy.
-
#http_timeout ⇒ Object
Returns the value of attribute http_timeout.
-
#ipn_endpoint ⇒ Object
(also: #ipn_end_point)
Returns the value of attribute ipn_endpoint.
-
#merchant_endpoint ⇒ Object
(also: #merchant_end_point)
Returns the value of attribute merchant_endpoint.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#openid_client_id ⇒ Object
Returns the value of attribute openid_client_id.
-
#openid_client_secret ⇒ Object
Returns the value of attribute openid_client_secret.
-
#openid_endpoint ⇒ Object
Returns the value of attribute openid_endpoint.
-
#openid_redirect_uri ⇒ Object
Returns the value of attribute openid_redirect_uri.
-
#password ⇒ Object
Returns the value of attribute password.
-
#platform_endpoint ⇒ Object
(also: #platform_end_point)
Returns the value of attribute platform_endpoint.
-
#rest_endpoint ⇒ Object
(also: #rest_end_point)
Returns the value of attribute rest_endpoint.
-
#rest_token_endpoint ⇒ Object
(also: #rest_token_end_point)
Returns the value of attribute rest_token_endpoint.
-
#sandbox_email_address ⇒ Object
Returns the value of attribute sandbox_email_address.
-
#signature ⇒ Object
Returns the value of attribute signature.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#token ⇒ Object
Returns the value of attribute token.
-
#token_secret ⇒ Object
Returns the value of attribute token_secret.
-
#username ⇒ Object
Returns the value of attribute username.
-
#verbose_logging ⇒ Object
Returns the value of attribute verbose_logging.
Class Method Summary collapse
-
.config(env = default_environment, override_configuration = {}) ⇒ Object
Create or Load Config object based on given environment and configurations.
-
.configurations ⇒ Object
Get raw configurations in Hash format.
-
.configurations=(configs) ⇒ Object
Set configuration.
- .configure(options = {}, &block) ⇒ Object (also: set_config)
- .default_config(env = nil) ⇒ Object
-
.default_environment ⇒ Object
Get default environment name.
-
.default_environment=(env) ⇒ Object
Set default environment.
-
.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’). -
.logger ⇒ Object
Get logger.
-
.logger=(logger) ⇒ Object
Set logger.
Instance Method Summary collapse
- #ca_file=(ca_file) ⇒ Object
- #dev_central_url=(dev_central_url) ⇒ Object
- #http_verify_mode=(verify_mode) ⇒ Object
-
#initialize(options) ⇒ Config
constructor
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. - #logfile=(filename) ⇒ Object
-
#merge!(options) ⇒ Object
Override configurations.
- #redirect_url=(redirect_url) ⇒ Object
-
#required!(*names) ⇒ Object
Validate required configuration.
- #ssl_options ⇒ Object
- #ssl_options=(options) ⇒ Object
Methods included from Logging
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
100 101 102 |
# File 'lib/paypal-sdk/core/config.rb', line 100 def initialize() merge!() end |
Instance Attribute Details
#app_id ⇒ Object
Returns the value of attribute app_id.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def app_id @app_id end |
#cert_path ⇒ Object
Returns the value of attribute cert_path.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def cert_path @cert_path end |
#client_id ⇒ Object
Returns the value of attribute client_id.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def client_secret @client_secret end |
#device_ipaddress ⇒ Object
Returns the value of attribute device_ipaddress.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def device_ipaddress @device_ipaddress end |
#endpoint ⇒ Object Also known as: end_point
Returns the value of attribute endpoint.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def endpoint @endpoint end |
#http_proxy ⇒ Object
Returns the value of attribute http_proxy.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def http_proxy @http_proxy end |
#http_timeout ⇒ Object
Returns the value of attribute http_timeout.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def http_timeout @http_timeout end |
#ipn_endpoint ⇒ Object Also known as: ipn_end_point
Returns the value of attribute ipn_endpoint.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def ipn_endpoint @ipn_endpoint end |
#merchant_endpoint ⇒ Object Also known as: merchant_end_point
Returns the value of attribute merchant_endpoint.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def merchant_endpoint @merchant_endpoint end |
#mode ⇒ Object
Returns the value of attribute mode.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def mode @mode end |
#openid_client_id ⇒ Object
Returns the value of attribute openid_client_id.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def openid_client_id @openid_client_id end |
#openid_client_secret ⇒ Object
Returns the value of attribute openid_client_secret.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def openid_client_secret @openid_client_secret end |
#openid_endpoint ⇒ Object
Returns the value of attribute openid_endpoint.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def openid_endpoint @openid_endpoint end |
#openid_redirect_uri ⇒ Object
Returns the value of attribute openid_redirect_uri.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def openid_redirect_uri @openid_redirect_uri end |
#password ⇒ Object
Returns the value of attribute password.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def password @password end |
#platform_endpoint ⇒ Object Also known as: platform_end_point
Returns the value of attribute platform_endpoint.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def platform_endpoint @platform_endpoint end |
#rest_endpoint ⇒ Object Also known as: rest_end_point
Returns the value of attribute rest_endpoint.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def rest_endpoint @rest_endpoint end |
#rest_token_endpoint ⇒ Object Also known as: rest_token_end_point
Returns the value of attribute rest_token_endpoint.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def rest_token_endpoint @rest_token_endpoint end |
#sandbox_email_address ⇒ Object
Returns the value of attribute sandbox_email_address.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def sandbox_email_address @sandbox_email_address end |
#signature ⇒ Object
Returns the value of attribute signature.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def signature @signature end |
#subject ⇒ Object
Returns the value of attribute subject.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def subject @subject end |
#token ⇒ Object
Returns the value of attribute token.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def token @token end |
#token_secret ⇒ Object
Returns the value of attribute token_secret.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def token_secret @token_secret end |
#username ⇒ Object
Returns the value of attribute username.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def username @username end |
#verbose_logging ⇒ Object
Returns the value of attribute verbose_logging.
71 72 73 |
# File 'lib/paypal-sdk/core/config.rb', line 71 def verbose_logging @verbose_logging end |
Class Method Details
.config(env = default_environment, override_configuration = {}) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/paypal-sdk/core/config.rb', line 195 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 |
.configurations ⇒ Object
Get raw configurations in Hash format.
231 232 233 |
# File 'lib/paypal-sdk/core/config.rb', line 231 def configurations @@configurations ||= read_configurations end |
.configurations=(configs) ⇒ Object
Set configuration
236 237 238 239 |
# File 'lib/paypal-sdk/core/config.rb', line 236 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
176 177 178 179 180 181 182 183 184 |
# File 'lib/paypal-sdk/core/config.rb', line 176 def configure( = {}, &block) begin self.config.merge!() rescue Errno::ENOENT self.configurations = { default_environment => } end block.call(self.config) if block self.config end |
.default_config(env = nil) ⇒ Object
207 208 209 210 211 212 213 214 |
# File 'lib/paypal-sdk/core/config.rb', line 207 def default_config(env = nil) env = (env || default_environment).to_s if configurations[env] @@config_cache[env] ||= new(configurations[env]) else raise Exceptions::MissingConfig.new("Configuration[#{env}] NotFound") end end |
.default_environment ⇒ Object
Get default environment name
167 168 169 |
# File 'lib/paypal-sdk/core/config.rb', line 167 def default_environment @@default_environment ||= ENV['PAYPAL_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV'] || "development" end |
.default_environment=(env) ⇒ Object
Set default environment
172 173 174 |
# File 'lib/paypal-sdk/core/config.rb', line 172 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')
159 160 161 162 163 164 |
# File 'lib/paypal-sdk/core/config.rb', line 159 def load(file_name, default_env = default_environment) @@config_cache = {} @@configurations = read_configurations(file_name) @@default_environment = default_env config end |
.logger ⇒ Object
Get logger
222 223 224 225 226 227 228 |
# File 'lib/paypal-sdk/core/config.rb', line 222 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 |
Instance Method Details
#ca_file=(ca_file) ⇒ Object
125 126 127 128 |
# File 'lib/paypal-sdk/core/config.rb', line 125 def ca_file=(ca_file) logger.warn '`ca_file=` is deprecated, Please configure `ca_file=` under `ssl_options`' self. = { :ca_file => ca_file } end |
#dev_central_url=(dev_central_url) ⇒ Object
112 113 114 |
# File 'lib/paypal-sdk/core/config.rb', line 112 def dev_central_url=(dev_central_url) logger.warn '`dev_central_url=` is deprecated.' end |
#http_verify_mode=(verify_mode) ⇒ Object
130 131 132 133 |
# File 'lib/paypal-sdk/core/config.rb', line 130 def http_verify_mode=(verify_mode) logger.warn '`http_verify_mode=` is deprecated, Please configure `verify_mode=` under `ssl_options`' self. = { :verify_mode => verify_mode } end |
#logfile=(filename) ⇒ Object
104 105 106 |
# File 'lib/paypal-sdk/core/config.rb', line 104 def logfile=(filename) logger.warn '`logfile=` is deprecated, Please use `PayPal::SDK::Core::Config.logger = Logger.new(STDERR)`' end |
#merge!(options) ⇒ Object
Override configurations
136 137 138 139 140 141 |
# File 'lib/paypal-sdk/core/config.rb', line 136 def merge!() .each do |key, value| send("#{key}=", value) end self end |
#redirect_url=(redirect_url) ⇒ Object
108 109 110 |
# File 'lib/paypal-sdk/core/config.rb', line 108 def redirect_url=(redirect_url) logger.warn '`redirect_url=` is deprecated.' end |
#required!(*names) ⇒ Object
Validate required configuration
144 145 146 147 |
# File 'lib/paypal-sdk/core/config.rb', line 144 def required!(*names) names = names.select{|name| send(name).nil? } raise MissingConfig.new("Required configuration(#{names.join(", ")})") if names.any? end |
#ssl_options ⇒ Object
116 117 118 |
# File 'lib/paypal-sdk/core/config.rb', line 116 def @ssl_options ||= {}.freeze end |
#ssl_options=(options) ⇒ Object
120 121 122 123 |
# File 'lib/paypal-sdk/core/config.rb', line 120 def () = Hash[.map{|key, value| [key.to_sym, value] }] @ssl_options = .merge().freeze end |