Class: Cardflex::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/cardflex/configuration.rb

Constant Summary collapse

API_VERSION =
3
SERVER =
"secure.cardflexonline.com"
PORT =
443

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration

Returns a new instance of Configuration.



24
25
26
27
28
# File 'lib/cardflex/configuration.rb', line 24

def initialize(options={})
  [:environment, :api_key, :logger].each do |attr|
    instance_variable_set("@#{attr}", options[attr])
  end
end

Class Attribute Details

.api_key=(value) ⇒ Object (writeonly)

Sets the attribute api_key

Parameters:

  • value

    the value to set the attribute api_key to.



8
9
10
# File 'lib/cardflex/configuration.rb', line 8

def api_key=(value)
  @api_key = value
end

.loggerObject



86
87
88
# File 'lib/cardflex/configuration.rb', line 86

def self.logger
  @logger ||= _default_logger
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



11
12
13
# File 'lib/cardflex/configuration.rb', line 11

def api_key
  @api_key
end

Class Method Details

._default_loggerObject



90
91
92
93
94
# File 'lib/cardflex/configuration.rb', line 90

def self._default_logger
  logger = Logger.new(STDOUT)
  logger.level = Logger::INFO
  logger
end

.environment=(env) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/cardflex/configuration.rb', line 30

def self.environment=(env)
  unless [:development, :test, :production].include?(env)
    raise ArgumentError, "#{env} is not a valid environment"
  end

  @environment = env
end

.expectant_reader(*attributes) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/cardflex/configuration.rb', line 13

def self.expectant_reader(*attributes)
  attributes.each do |attribute|
    (class << self; self; end).send(:define_method, attribute) do
      value = instance_variable_get("@#{attribute}")
      raise ConfigurationError.new(attribute.to_s, "needs to be set") unless value
      value
    end
  end
end

.gatewayObject



38
39
40
# File 'lib/cardflex/configuration.rb', line 38

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

.instantiateObject



42
43
44
45
46
47
48
# File 'lib/cardflex/configuration.rb', line 42

def self.instantiate
  config = new(
    :environment => @environment,
    :logger => logger,
    :api_key => api_key
  )
end

Instance Method Details

#api_versionObject



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

def api_version
  API_VERSION
end

#ca_fileObject



50
51
52
# File 'lib/cardflex/configuration.rb', line 50

def ca_file
  File.expand_path(File.join(File.dirname(__FILE__), "..", "ssl", "ca-certificates.ca.crt"))
end

#httpObject



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

def http
  Http.new(self)
end

#loggerObject



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

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

#portObject



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

def port
  PORT
end

#protocolObject



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

def protocol
  "https"
end

#serverObject



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

def server
  SERVER
end

#ssl?Boolean

Returns:

  • (Boolean)


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

def ssl?
  true
end

#three_step_pathObject



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

def three_step_path
  "/api/v2/three-step"
end