Class: Cardflex::Configuration

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

Constant Summary collapse

API_VERSION =
2
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.



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

def initialize(options={})
  [:environment, :api_key, :username, :password, :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



93
94
95
# File 'lib/cardflex/configuration.rb', line 93

def self.logger
  @logger ||= _default_logger
end

.passwordObject

Returns the value of attribute password.



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

def password
  @password
end

.usernameObject

Returns the value of attribute username.



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

def username
  @username
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#passwordObject (readonly)

Returns the value of attribute password.



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

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

Class Method Details

._default_loggerObject



97
98
99
100
101
# File 'lib/cardflex/configuration.rb', line 97

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

.environment=(env) ⇒ Object



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

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



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

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



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

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

.instantiateObject



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

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

Instance Method Details

#api_versionObject



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

def api_version
  API_VERSION
end

#ca_fileObject



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

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

#httpObject



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

def http
  Http.new(self)
end

#loggerObject



89
90
91
# File 'lib/cardflex/configuration.rb', line 89

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

#portObject



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

def port
  PORT
end

#protocolObject



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

def protocol
  "https"
end

#query_pathObject



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

def query_path
  "/api/query.php"
end

#serverObject



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

def server
  SERVER
end

#ssl?Boolean

Returns:

  • (Boolean)


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

def ssl?
  true
end

#three_step_pathObject



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

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