Class: Experian::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/experian/client.rb

Direct Known Subclasses

Experian::ConnectCheck::Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



4
5
6
# File 'lib/experian/client.rb', line 4

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



4
5
6
# File 'lib/experian/client.rb', line 4

def response
  @response
end

Instance Method Details

#invalid_login?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/experian/client.rb', line 24

def invalid_login?
  !!(@raw_response.headers["Location"] =~ /sso_logon/)
end

#request_bodyObject



16
17
18
# File 'lib/experian/client.rb', line 16

def request_body
  URI.encode_www_form('NETCONNECT_TRANSACTION' => request.xml)
end

#request_headersObject



20
21
22
# File 'lib/experian/client.rb', line 20

def request_headers
  { "Content-Type" => "application/x-www-form-urlencoded" }
end

#submit_requestObject



6
7
8
9
10
11
12
13
14
# File 'lib/experian/client.rb', line 6

def submit_request
  connection = Excon.new(Experian.net_connect_uri.to_s, idempotent: true)
  @raw_response = connection.post(body: request_body, headers: request_headers)
  raise Experian::Forbidden, "Invalid Experian login credentials" if invalid_login?
  @raw_response.body

rescue Excon::Errors::SocketError => e
  raise Experian::ClientError, "Could not connect to Experian: #{e.message}"
end