Class: Callcredit::Request
- Inherits:
-
Object
- Object
- Callcredit::Request
- Defined in:
- lib/callcredit/request.rb
Instance Method Summary collapse
-
#build_request_xml(checks, check_data = {}) ⇒ Object
Compile the complete XML request to send to Callcredit.
-
#initialize(connection, config) ⇒ Request
constructor
A new instance of Request.
-
#perform(checks, check_data = {}) ⇒ Object
Perform a credit check.
Constructor Details
#initialize(connection, config) ⇒ Request
Returns a new instance of Request.
3 4 5 6 |
# File 'lib/callcredit/request.rb', line 3 def initialize(connection, config) @connection = connection @config = config end |
Instance Method Details
#build_request_xml(checks, check_data = {}) ⇒ Object
Compile the complete XML request to send to Callcredit
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/callcredit/request.rb', line 25 def build_request_xml(checks, check_data = {}) builder = Nokogiri::XML::Builder.new do |xml| xml.callvalidate do authentication(xml) xml.sessions do xml.session("RID" => Time.now.to_f) do xml.data do personal_data(xml, check_data[:personal_data]) card_data(xml, check_data[:card_data]) bank_data(xml, check_data[:bank_data]) income_data(xml, check_data[:income_data]) required_checks(xml, checks) end end end xml.application @config[:application_name] end end builder.doc end |
#perform(checks, check_data = {}) ⇒ Object
Perform a credit check
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/callcredit/request.rb', line 9 def perform(checks, check_data = {}) # check_data = Callcredit::Validator.clean_check_data(check_data) response = @connection.get do |request| request.path = @config[:api_endpoint] request.body = build_request_xml(checks, check_data).to_s end @config[:raw] ? response : response.body rescue Faraday::Error::ClientError => e if e.response.nil? raise APIError.new else raise APIError.new(e.response[:body], e.response[:status], e.response) end end |