Class: Leapfrog::CustomerScoring::Client
- Inherits:
-
Object
- Object
- Leapfrog::CustomerScoring::Client
- Defined in:
- lib/leapfrog/customer_scoring/client.rb
Constant Summary collapse
- DEFAULT_URL =
"http://internal.leapfrogonline.com/customer_scoring"
Instance Method Summary collapse
-
#get_score(income, zipcode, age) ⇒ Object
Makes request to the initialized endpoint to retrieve customer scoring advice.
-
#initialize(url = DEFAULT_URL) ⇒ Client
constructor
You may initialize the Client with any url or just use the default url of “internal.leapfrogonline.com/customer_scoring”.
Constructor Details
#initialize(url = DEFAULT_URL) ⇒ Client
You may initialize the Client with any url or just use the default url of “internal.leapfrogonline.com/customer_scoring”.
client = Leapfrog::CustomerScoring::Client.new
– OR–
other_url = "http://example.com/customer_scoring"
client = Leapfrog::CustomerScoring::Client.new(other_url)
This is the url to which the client will make requests
17 18 19 |
# File 'lib/leapfrog/customer_scoring/client.rb', line 17 def initialize(url=DEFAULT_URL) @url = url end |
Instance Method Details
#get_score(income, zipcode, age) ⇒ Object
Makes request to the initialized endpoint to retrieve customer scoring advice. The income
, zipcode
and age
parameters are required. The return value is a Hash
with keys containing the :propensity
and :ranking
for customer with the passed parameters
advice = client.get_score("50000", "60621", "35")
advice.inspect
=> "{:propensity=>0.26532, :ranking=>\"C\"}"
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/leapfrog/customer_scoring/client.rb', line 31 def get_score(income, zipcode, age) params = {income: income, zipcode: zipcode, age: age} begin RestClient.get(url, params: params) do |response, request, result| case response.code when 200 return ::JSON.parse(response, symbolize_names: true) when 422 raise Leapfrog::CustomerScoring::InvalidInput when 404 raise Leapfrog::CustomerScoring::ResourceNotFound when 500 raise Leapfrog::CustomerScoring::ServerError else response.return!(request, result) end end rescue RestClient::RequestTimeout raise Leapfrog::CustomerScoring::ServerTimeout end end |