module Cardflex class Configuration API_VERSION = 2 SERVER = "secure.cardflexonline.com" PORT = 443 class << self attr_writer :logger, :api_key attr_accessor :username, :password end attr_reader :api_key, :username, :password 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 expectant_reader :api_key, :environment def initialize(options={}) [:environment, :api_key, :username, :password, :logger].each do |attr| instance_variable_set("@#{attr}", options[attr]) end end def self.environment=(env) unless [:development, :test, :production].include?(env) raise ArgumentError, "#{env} is not a valid environment" end @environment = env end def self.gateway Cardflex::Gateway.new(instantiate) end def self.instantiate config = new( :environment => @environment, :logger => logger, :username => username, :password => password, :api_key => api_key ) end def ca_file File.expand_path(File.join(File.dirname(__FILE__), "..", "ssl", "ca-certificates.ca.crt")) end def http Http.new(self) end def three_step_path "/api/v2/three-step" end def query_path "/api/query.php" end def server SERVER end def protocol "https" end def port PORT end def ssl? true end def api_version API_VERSION end def logger @logger ||= self.class._default_logger end def self.logger @logger ||= _default_logger end def self._default_logger logger = Logger.new(STDOUT) logger.level = Logger::INFO logger end end end