Sha256: f442ea1c1d81a9bde90421de27ada4fb46141dd7b776c93edf52921b5ec8b2ec

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

module Exact
  class Credentials

    attr_accessor :config
    
    def initialize
      load_configuration(ENV['LOCATION'])
    end
    
    # obtain the credentials for the processor specified by
    # ENV['PROCESSOR'], defaulting to 'emergis'
    def current_gateway
      processor = ENV['PROCESSOR'] || 'emergis'
      self.config[processor]
    end
    
    def chase
      self.config['chase']
    end
    def chase_batch
      self.config['chase_batch']
    end
    def chase?
      [self.chase[:gateway_id], self.chase_batch[:gateway_id]].include?(current_gateway[:gateway_id])
    end
    
    def tsys
      self.config['tsys']
    end
    def tsys?
      current_gateway[:gateway_id] == self.tsys[:gateway_id]
    end
    
    def emergis
      self.config['emergis']
    end
    def emergis?
      current_gateway[:gateway_id] == self.emergis[:gateway_id]
    end
    
    def moneris
      self.config['moneris']
    end
    def moneris?
      current_gateway[:gateway_id] == self.moneris[:gateway_id]
    end
    
    def load_configuration(environment)
      config_file = File.dirname(__FILE__) + '/credentials.yml'
      yaml = YAML::load(IO.read(config_file))
      environment ||= 'DEV'

      self.config = yaml[environment]
    
      if self.config.nil?
        abort "No credentials configured. Please create a properly-formatted credentials.yml file in #{File.dirname(__FILE__)}."
      end
    end
    private :load_configuration
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
exact4r-1.0 ./test/credentials.rb