lib/rents.rb in rents-1.0.0 vs lib/rents.rb in rents-1.0.1

- old
+ new

@@ -5,23 +5,38 @@ require 'bigdecimal' require 'bigdecimal/util' # Overrides require 'rents/hash' +require 'rents/array' # Gem files [:version, :connection, :status, :transaction, :currency, :string].each { |lib| require "rents/#{lib}" } module Rents + # Module attr + @@enum = nil + # Production settings @@app_id = nil @@secret_key = nil # Tests settings + @@proxy_yml = nil @@test_env = nil - @@debugger = nil + @@debug = nil + def self.proxy_yml + @@proxy_yml = Rents.get_proxy_from_yml if @@proxy_yml.nil? + @@proxy_yml + end + + def self.proxy + return nil if Rents.proxy_yml.nil? || Rents.proxy_yml.empty? + "http://#{Rents.proxy_yml[:login]}:#{Rents.proxy_yml[:password]}@#{Rents.proxy_yml[:host]}:#{Rents.proxy_yml[:port]}/" + end + def self.app_id=(app_id) @@app_id = app_id end def self.app_id @@ -42,13 +57,36 @@ def self.test_env=(test_env) @@test_env = test_env end - def self.debugger - @@test_env + def self.debug + @@debug end - def self.debugger=(debugger) - @@debugger = debugger + def self.debug=(debug) + @@debug = debug + end + + def self.get_proxy_from_yml + yml = YAML::load_file(File.join(File.dirname(File.expand_path(__FILE__)), 'rents/config/proxy.yml')) + !yml.nil? || yml.is_a?(Hash) ? yml.it_keys_to_sym : {} if yml + end + + def self.enum + return @@enum unless @@enum.nil? + enum = {} + + enum = enum.merge load_yml('brands.yml') + enum = enum.merge load_yml('currencies.yml') + enum = enum.merge load_yml('payment_methods.yml') + enum = enum.merge load_yml('recurrence_periods.yml') + enum = enum.merge load_yml('transaction_codes.yml') + + enum = enum.it_keys_to_sym + @@enum = enum + end + + def self.load_yml file_name + YAML::load_file(File.join(File.dirname(File.expand_path(__FILE__)), 'rents/config/enums/' + file_name)) end end