Class: MastercardCoreSdk::Core::MasterCardApiConfiguration
- Inherits:
-
Object
- Object
- MastercardCoreSdk::Core::MasterCardApiConfiguration
- Extended by:
- Exceptions
- Defined in:
- lib/mastercard_core_sdk/core/mastercard_api_configuration.rb
Overview
Setting MasterCard API configuration parameters for API calls
Constant Summary collapse
- PROD_KEY =
"__PROD__"- SANDBOX_KEY =
"__SANDBOX__"- SANDBOX_URL =
"https://sandbox.api.mastercard.com"- PROD_URL =
"https://api.mastercard.com"- @@logger =
Logging.logger[self]
- @@builders =
Initialize builders hash with sandbox/production environment configurations.
{}
- @@sandbox =
ApiConfigBuilder.new.name(SANDBOX_KEY).host_url(SANDBOX_URL)
- @@production =
ApiConfigBuilder.new.name(PROD_KEY).host_url(PROD_URL)
Class Attribute Summary collapse
-
.additional_properties ⇒ Object
Defines additional_properties for plugin.
-
.configs ⇒ Object
Defines Hash having environment name as key and api_config object as value.
-
.consumer_key ⇒ Object
Defines consumer key from developer site.
-
.private_key ⇒ Object
Defines private key from p12 file from developer site.
-
.sandbox ⇒ Object
Determines if environment is Sandbox.
Class Method Summary collapse
-
.api_config(name = nil) ⇒ ApiConfig
Determine api_config object.
-
.register_config(api_config) ⇒ Object
Registers the API configuration.
-
.sandbox? ⇒ Boolean
Check if environment is Sandbox.
-
.validate_config(config) ⇒ Object
Validates private key, consumer key and host_url for api_config.
Class Attribute Details
.additional_properties ⇒ Object
Defines additional_properties for plugin.
26 27 28 |
# File 'lib/mastercard_core_sdk/core/mastercard_api_configuration.rb', line 26 def additional_properties @additional_properties end |
.configs ⇒ Object
Defines Hash having environment name as key and api_config object as value.
29 30 31 |
# File 'lib/mastercard_core_sdk/core/mastercard_api_configuration.rb', line 29 def configs @configs end |
.consumer_key ⇒ Object
Defines consumer key from developer site.
20 21 22 |
# File 'lib/mastercard_core_sdk/core/mastercard_api_configuration.rb', line 20 def consumer_key @consumer_key end |
.private_key ⇒ Object
Defines private key from p12 file from developer site.
23 24 25 |
# File 'lib/mastercard_core_sdk/core/mastercard_api_configuration.rb', line 23 def private_key @private_key end |
.sandbox ⇒ Object
Determines if environment is Sandbox.
32 33 34 |
# File 'lib/mastercard_core_sdk/core/mastercard_api_configuration.rb', line 32 def sandbox @sandbox end |
Class Method Details
.api_config(name = nil) ⇒ ApiConfig
Determine api_config object.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/mastercard_core_sdk/core/mastercard_api_configuration.rb', line 70 def api_config(name = nil) if name return self.configs[name] else if sandbox? @@sandbox.private_key(self.private_key) @@sandbox.consumer_key(self.consumer_key) return @@sandbox.build else @@production.private_key(self.private_key) @@production.consumer_key(self.consumer_key) return @@production.build end end end |
.register_config(api_config) ⇒ Object
Registers the API configuration.
57 58 59 |
# File 'lib/mastercard_core_sdk/core/mastercard_api_configuration.rb', line 57 def register_config(api_config) self.configs.merge!({ api_config.name => api_config }) end |
.sandbox? ⇒ Boolean
Check if environment is Sandbox.
63 64 65 |
# File 'lib/mastercard_core_sdk/core/mastercard_api_configuration.rb', line 63 def sandbox? self.sandbox end |
.validate_config(config) ⇒ Object
Validates private key, consumer key and host_url for api_config.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mastercard_core_sdk/core/mastercard_api_configuration.rb', line 36 def validate_config(config) if config.nil? @@logger.error ERR_MSG_API_CONFIG raise SDKValidationError.new(ERR_MSG_API_CONFIG) end if config.consumer_key.to_s.empty? @@logger.error ERR_MSG_CONSUMER_KEY raise SDKValidationError.new(ERR_MSG_CONSUMER_KEY) end if config.private_key.nil? @@logger.error ERR_MSG_PRIVATE_KEY raise SDKValidationError.new(ERR_MSG_PRIVATE_KEY) end if config.host_url.to_s.empty? @@logger.error ERR_MSG_HOST_URL raise SDKValidationError.new(ERR_MSG_HOST_URL) end end |