Class: Youlend::Prequalification

Inherits:
Object
  • Object
show all
Defined in:
lib/youlend/prequalification.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Prequalification

Returns a new instance of Prequalification.



10
11
12
# File 'lib/youlend/prequalification.rb', line 10

def initialize(params)
  @params = params
end

Class Method Details

.verify(params) ⇒ Object



6
7
8
# File 'lib/youlend/prequalification.rb', line 6

def self.verify(params)
  new(params).verify
end

Instance Method Details

#verifyObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/youlend/prequalification.rb', line 14

def verify
  response = Youlend.connection.post('/prequalification/Requests', :prequalification, @params)

  # If there are errors in the data just return the response right away
  return response if response.status == 422

  # If we got back a response but all the funded amounts are 0.0 it means that the load was
  # actually rejected! We'll replace the response body with an error message instead and change
  # the success code.
  unless loan_accepted?(response.body)
    response.http_response.env.status = 422
    response.http_response.env.body = {
      error: 'Rejected',
      error_description: 'Loan was rejected'
    }
  end

  response
end