Class: GatorjuiceCreditRating::Assessment

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_hash) ⇒ Assessment

Returns a new instance of Assessment.



8
9
10
11
# File 'lib/gatorjuice_credit_rating.rb', line 8

def initialize(input_hash)
  @propensity = input_hash["propensity"].to_f
  @ranking = input_hash["ranking"]
end

Instance Attribute Details

#propensityObject (readonly)

Returns the value of attribute propensity.



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

def propensity
  @propensity
end

#rankingObject (readonly)

Returns the value of attribute ranking.



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

def ranking
  @ranking
end

Class Method Details

.inquiry(input_options) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gatorjuice_credit_rating.rb', line 13

def self.inquiry(input_options)
  if 
    input_options[:age] && 
    input_options[:age].to_i >= 18 && 
    !!Integer(input_options[:age]) && 
    input_options[:income] && 
    input_options[:income].to_i > 0 && 
    !!Integer(input_options[:income]) &&
    input_options[:zipcode] && 
    input_options[:zipcode].to_s.length == 5 && 
    !!Integer(input_options[:zipcode]) && 
    input_options.class == Hash
    response = Unirest.get(
      "https://pacific-stream-61271.herokuapp.com/api/v1/inquiries",
      headers: {
        "Accept" => "application/json"
      },
      parameters: {
        age: input_options[:age].to_s,
        income: input_options[:income].to_s,
        zipcode: input_options[:zipcode],
        api_token: "ABCDEFG1234567" # ENV[API_TOKEN]
      }
    ).body 
    response["response"] ? response["response"] : Assessment.new(response)
  else
    raise ArgumentError, "#inquiry takes one hash as an argument and must have keys and numeric values for: age, income, zipcode"
  end
end