class VantivLite::Config

Constants

ENVS
InvalidEnvironment
OPTS

Attributes

proxy_uri[R]
sandbox[R]
sandbox?[R]
uri[R]

Public Class Methods

build(&blk) click to toggle source
# File lib/vantiv_lite/config.rb, line 36
def build(&blk)
  Config::Builder.(&blk)
end
new(**opts) click to toggle source
# File lib/vantiv_lite/config.rb, line 48
def initialize(**opts)
  @opts = opts.each_with_object({}) { |(k, v), h| OPTS.include?(k = k.to_sym) && h[k] = v.to_s }
  defaults!
  load_xml_lib
  env_valid?
  proxy_uri!
  @uri = ENVS[@opts[:env]]
end
with_obj(config) click to toggle source
# File lib/vantiv_lite/config.rb, line 40
def with_obj(config)
  config.is_a?(self) ? config : new(config)
end

Public Instance Methods

opts() click to toggle source
# File lib/vantiv_lite/config.rb, line 57
def opts
  @opts.dup
end
proxy_args() click to toggle source
# File lib/vantiv_lite/config.rb, line 61
def proxy_args
  @proxy_uri ? [@proxy_uri.host, @proxy_uri.port, @proxy_uri.user, @proxy_uri.password] : []
end
with(**opts) click to toggle source
# File lib/vantiv_lite/config.rb, line 65
def with(**opts)
  self.class.new(@opts.merge(opts))
end

Private Instance Methods

default_xml_lib() click to toggle source
# File lib/vantiv_lite/config.rb, line 73
def default_xml_lib
  return 'Ox' if defined?(::Ox)
  return 'Nokogiri' if defined?(::Nokogiri)
  'REXML'
end
defaults!() click to toggle source
# File lib/vantiv_lite/config.rb, line 79
def defaults!
  @opts[:env] ||= 'sandbox'
  @opts[:report_group] ||= 'Default Report Group'
  @opts[:version] ||= '8.22'
  @opts[:xml_lib] ||= default_xml_lib
  return unless (@sandbox = (opts[:env] == 'sandbox'))
  @opts[:merchant_id] ||= 'default'
  @opts[:password] ||= 'sandbox'
  @opts[:username] ||= 'sandbox'
end
env_valid?() click to toggle source
# File lib/vantiv_lite/config.rb, line 90
def env_valid?
  raise InvalidEnvironment, %(:env must be set to one of: "#{ENVS.keys.join('", "')}") unless
    ENVS.key?(@opts[:env])
end
load_xml_lib() click to toggle source
# File lib/vantiv_lite/config.rb, line 95
def load_xml_lib
  require "vantiv_lite/xml/#{@opts[:xml_lib].downcase}"
end
proxy_uri!() click to toggle source
# File lib/vantiv_lite/config.rb, line 99
def proxy_uri!
  return unless (url = @opts[:proxy_url] || ENV['HTTP_PROXY'] || ENV['http_proxy'])
  @proxy_uri = URI(url)
end