Class: Paymongo::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(options = {})
  WRITABLE_ATTRIBUTES.each do |attr|
    instance_variable_set "@#{attr}",
                          options[attr] || Paymongo.configuration.send(attr)
  end
end

Class Method Details

._default_loggerObject



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

.gatewayObject



35
36
37
# File 'lib/paymongo/configuration.rb', line 35

def self.gateway
  Paymongo::Gateway.new(instantiate)
end

.instantiateObject



39
40
41
# File 'lib/paymongo/configuration.rb', line 39

def self.instantiate
  config = new
end

.loggerObject



43
44
45
# File 'lib/paymongo/configuration.rb', line 43

def self.logger
  @logger ||= _default_logger
end

Instance Method Details

#api_versionObject



54
55
56
# File 'lib/paymongo/configuration.rb', line 54

def api_version
  API_VERSION
end

#assert_has_keysObject



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_urlObject



58
59
60
# File 'lib/paymongo/configuration.rb', line 58

def base_url
  "#{protocol}://#{server}:#{port}/v#{API_VERSION}"
end

#httpsObject



62
63
64
# File 'lib/paymongo/configuration.rb', line 62

def https
  Http.new(self)
end

#inspectObject



92
93
94
# File 'lib/paymongo/configuration.rb', line 92

def inspect
  super.gsub(/@secret_key=\".*\"/, '@secret_key="[FILTERED]"')
end

#loggerObject



66
67
68
# File 'lib/paymongo/configuration.rb', line 66

def logger
  @logger ||= self.class._default_logger
end

#portObject



70
71
72
# File 'lib/paymongo/configuration.rb', line 70

def port
  443
end

#protocolObject



74
75
76
# File 'lib/paymongo/configuration.rb', line 74

def protocol
  'https'
end

#serverObject



78
79
80
# File 'lib/paymongo/configuration.rb', line 78

def server
  'api.paymongo.com'
end

#ssl?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/paymongo/configuration.rb', line 82

def ssl?
  true
end