lib/creditsafe/client.rb in creditsafe-0.3.1 vs lib/creditsafe/client.rb in creditsafe-0.3.2
- old
+ new
@@ -12,14 +12,23 @@
require 'active_support/notifications'
module Creditsafe
class Client
- def initialize(username: nil, password: nil, savon_opts: {})
+ ENVIRONMENTS = %i(live test).freeze
+
+ def initialize(username: nil, password: nil, savon_opts: {},
+ environment: :live, log_level: :warn)
raise ArgumentError, "Username must be provided" if username.nil?
raise ArgumentError, "Password must be provided" if password.nil?
+ unless ENVIRONMENTS.include?(environment.to_sym)
+ raise ArgumentError, "Environment needs to be one of #{ENVIRONMENTS.join('/')}"
+ end
+
+ @environment = environment.to_s
+ @log_level = log_level
@username = username
@password = password
@savon_opts = savon_opts
end
@@ -120,16 +129,19 @@
namespace_identifier: Creditsafe::Namespace::OPER,
namespaces: Creditsafe::Namespace::ALL,
wsdl: wsdl_path,
headers: auth_header,
convert_request_keys_to: :none,
- adapter: :excon
+ adapter: :excon,
+ log: true,
+ log_level: @log_level,
+ pretty_print_xml: true
}
Savon.client(options.merge(@savon_opts))
end
def wsdl_path
root_dir = File.join(File.dirname(__FILE__), '..', '..')
- File.join(root_dir, 'data', "creditsafe-live.xml")
+ File.join(root_dir, 'data', "creditsafe-#{@environment}.xml")
end
end
end