Class: Paymongo::Configuration
- Inherits:
-
Object
- Object
- Paymongo::Configuration
- Defined in:
- lib/paymongo/configuration.rb
Constant Summary collapse
- API_VERSION =
'1'
- READABLE_ATTRIBUTES =
%i[public_key secret_key]
- WRITABLE_ATTRIBUTES =
%i[logger public_key secret_key]
Class Method Summary collapse
- ._default_logger ⇒ Object
- .expectant_reader(*attributes) ⇒ Object
- .gateway ⇒ Object
- .instantiate ⇒ Object
- .logger ⇒ Object
Instance Method Summary collapse
- #api_version ⇒ Object
- #assert_has_keys ⇒ Object
- #base_url ⇒ Object
- #https ⇒ Object
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #inspect ⇒ Object
- #logger ⇒ Object
- #port ⇒ Object
- #protocol ⇒ Object
- #server ⇒ Object
- #ssl? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
47 48 49 50 51 52 |
# File 'lib/paymongo/configuration.rb', line 47 def initialize( = {}) WRITABLE_ATTRIBUTES.each do |attr| instance_variable_set "@#{attr}", [attr] || Paymongo.configuration.send(attr) end end |
Class Method Details
._default_logger ⇒ Object
86 87 88 89 90 |
# File 'lib/paymongo/configuration.rb', line 86 def self._default_logger logger = Logger.new(STDOUT) logger.level = Logger::INFO logger end |
.expectant_reader(*attributes) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/paymongo/configuration.rb', line 15 def self.expectant_reader(*attributes) attributes.each do |attribute| ( class << self self end ) .send(:define_method, attribute) do attribute_value = instance_variable_get("@#{attribute}") if attribute_value.nil? || attribute_value.to_s.empty? raise ConfigurationError.new( "Paymongo::Configuration.#{attribute.to_s} needs to be set" ) end attribute_value end end end |
.gateway ⇒ Object
35 36 37 |
# File 'lib/paymongo/configuration.rb', line 35 def self.gateway Paymongo::Gateway.new(instantiate) end |
.instantiate ⇒ Object
39 40 41 |
# File 'lib/paymongo/configuration.rb', line 39 def self.instantiate config = new end |
.logger ⇒ Object
43 44 45 |
# File 'lib/paymongo/configuration.rb', line 43 def self.logger @logger ||= _default_logger end |
Instance Method Details
#api_version ⇒ Object
54 55 56 |
# File 'lib/paymongo/configuration.rb', line 54 def api_version API_VERSION end |
#assert_has_keys ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/paymongo/configuration.rb', line 96 def assert_has_keys if public_key.nil? || secret_key.nil? raise ConfigurationError.new( 'Paymongo::Gateway public_key and secret_key are required.' ) end end |
#base_url ⇒ Object
58 59 60 |
# File 'lib/paymongo/configuration.rb', line 58 def base_url "#{protocol}://#{server}:#{port}/v#{API_VERSION}" end |
#https ⇒ Object
62 63 64 |
# File 'lib/paymongo/configuration.rb', line 62 def https Http.new(self) end |
#inspect ⇒ Object
92 93 94 |
# File 'lib/paymongo/configuration.rb', line 92 def inspect super.gsub(/@secret_key=\".*\"/, '@secret_key="[FILTERED]"') end |
#logger ⇒ Object
66 67 68 |
# File 'lib/paymongo/configuration.rb', line 66 def logger @logger ||= self.class._default_logger end |
#port ⇒ Object
70 71 72 |
# File 'lib/paymongo/configuration.rb', line 70 def port 443 end |
#protocol ⇒ Object
74 75 76 |
# File 'lib/paymongo/configuration.rb', line 74 def protocol 'https' end |
#server ⇒ Object
78 79 80 |
# File 'lib/paymongo/configuration.rb', line 78 def server 'api.paymongo.com' end |
#ssl? ⇒ Boolean
82 83 84 |
# File 'lib/paymongo/configuration.rb', line 82 def ssl? true end |