Class: Cardflex::Configuration
- Inherits:
-
Object
- Object
- Cardflex::Configuration
- Defined in:
- lib/cardflex/configuration.rb
Constant Summary collapse
- API_VERSION =
2- SERVER =
"secure.cardflexonline.com"- PORT =
443
Class Attribute Summary collapse
-
.api_key ⇒ Object
writeonly
Sets the attribute api_key.
- .logger ⇒ Object
-
.password ⇒ Object
Returns the value of attribute password.
-
.username ⇒ Object
Returns the value of attribute username.
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
- ._default_logger ⇒ Object
- .environment=(env) ⇒ Object
- .expectant_reader(*attributes) ⇒ Object
- .gateway ⇒ Object
- .instantiate ⇒ Object
Instance Method Summary collapse
- #api_version ⇒ Object
- #ca_file ⇒ Object
- #http ⇒ Object
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #logger ⇒ Object
- #port ⇒ Object
- #protocol ⇒ Object
- #query_path ⇒ Object
- #server ⇒ Object
- #ssl? ⇒ Boolean
- #three_step_path ⇒ Object
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(={}) [:environment, :api_key, :username, :password, :logger].each do |attr| instance_variable_set("@#{attr}", [attr]) end end |
Class Attribute Details
.api_key=(value) ⇒ Object (writeonly)
Sets the attribute api_key
8 9 10 |
# File 'lib/cardflex/configuration.rb', line 8 def api_key=(value) @api_key = value end |
.logger ⇒ Object
93 94 95 |
# File 'lib/cardflex/configuration.rb', line 93 def self.logger @logger ||= _default_logger end |
.password ⇒ Object
Returns the value of attribute password.
9 10 11 |
# File 'lib/cardflex/configuration.rb', line 9 def password @password end |
.username ⇒ Object
Returns the value of attribute username.
9 10 11 |
# File 'lib/cardflex/configuration.rb', line 9 def username @username end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
12 13 14 |
# File 'lib/cardflex/configuration.rb', line 12 def api_key @api_key end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
12 13 14 |
# File 'lib/cardflex/configuration.rb', line 12 def password @password end |
#username ⇒ Object (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_logger ⇒ Object
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 |
.gateway ⇒ Object
39 40 41 |
# File 'lib/cardflex/configuration.rb', line 39 def self.gateway Cardflex::Gateway.new(instantiate) end |
.instantiate ⇒ Object
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_version ⇒ Object
85 86 87 |
# File 'lib/cardflex/configuration.rb', line 85 def api_version API_VERSION end |
#ca_file ⇒ Object
53 54 55 |
# File 'lib/cardflex/configuration.rb', line 53 def ca_file File.(File.join(File.dirname(__FILE__), "..", "ssl", "ca-certificates.ca.crt")) end |
#http ⇒ Object
57 58 59 |
# File 'lib/cardflex/configuration.rb', line 57 def http Http.new(self) end |
#logger ⇒ Object
89 90 91 |
# File 'lib/cardflex/configuration.rb', line 89 def logger @logger ||= self.class._default_logger end |
#port ⇒ Object
77 78 79 |
# File 'lib/cardflex/configuration.rb', line 77 def port PORT end |
#protocol ⇒ Object
73 74 75 |
# File 'lib/cardflex/configuration.rb', line 73 def protocol "https" end |
#query_path ⇒ Object
65 66 67 |
# File 'lib/cardflex/configuration.rb', line 65 def query_path "/api/query.php" end |
#server ⇒ Object
69 70 71 |
# File 'lib/cardflex/configuration.rb', line 69 def server SERVER end |
#ssl? ⇒ Boolean
81 82 83 |
# File 'lib/cardflex/configuration.rb', line 81 def ssl? true end |
#three_step_path ⇒ Object
61 62 63 |
# File 'lib/cardflex/configuration.rb', line 61 def three_step_path "/api/v2/three-step" end |