Class: ScoringClient

Inherits:
Object
  • Object
show all
Defined in:
lib/leapfrog/scoring_client.rb

Constant Summary collapse

@@API_URL =
"http://internal.leapfrogonline.com/customer_scoring"

Instance Method Summary collapse

Instance Method Details

#score(customer) ⇒ Object

Raises:

  • (ArgumentError)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/leapfrog/scoring_client.rb', line 4

def score(customer)
  raise ArgumentError, "income cannot be nil" if customer.income.nil?
  raise ArgumentError, "zipcode cannot be nil" if customer.zipcode.nil?
  raise ArgumentError, "age cannot be nil" if customer.age.nil?

  begin
    response = RestClient.get(@@API_URL, {params: customer_to_query_params(customer), accept: :json})
  rescue RestClient::InternalServerError => error
    raise "Scoring Advice Internal Error"
  rescue RestClient::Forbidden => error
    if error.response.code == 403
      raise ArgumentError, "request parameters invalid"
    end
  end
  
  response_to_advice(response)
end