Class: CustomerScore::Client

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

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



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

def initialize()
  @default_url = "http://not_real.com/customer_scoring"
end

Instance Method Details

#get_score(income, zipcode, age) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/customer_score.rb', line 10

def get_score(income, zipcode, age)
  url = "#{@default_url}?income=#{income}&zipcode=#{zipcode}&age=#{age}"
  case status = Unirest.get(url).code
  when 200
    return Unirest.get(url).body
  when 404 
    raise ResourceNotFound, "Invalid URL"
  when 422
    raise InvalidInput, "Unprocessable Entity"
  when 500
    raise InternalError, "Internal Server Error"
  else
    raise "Error"
  end
end