consumer_score 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/consumer_score.rb +17 -30
- metadata +1 -1
data/lib/consumer_score.rb
CHANGED
@@ -1,41 +1,28 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'json'
|
3
|
-
require 'fakeweb'
|
4
|
-
|
5
|
-
FakeWeb.register_uri(:get, "http://internal.leapfrogonline.com/customer_scoring?income=50000&zipcode=60201&age=35",
|
6
|
-
:body => {'propensity' => 0.26532, 'ranking' => 'C' }.to_json,
|
7
|
-
:status => ["200", "OK"])
|
8
3
|
|
9
4
|
class ConsumerScore
|
10
|
-
attr_accessor :propensity, :ranking
|
11
|
-
attr_reader :income, :zip_code, :age, :request_uri
|
12
|
-
|
13
|
-
def initialize(income, zip_code, age)
|
14
|
-
@income = income
|
15
|
-
@zip_code = zip_code
|
16
|
-
@age = age
|
17
|
-
@propensity = nil
|
18
|
-
@ranking = nil
|
19
|
-
end
|
20
|
-
|
21
|
-
def build_request
|
22
|
-
URI("http://internal.leapfrogonline.com/customer_scoring?income=#{income}&zipcode=#{zip_code}&age=#{age}")
|
23
|
-
end
|
24
5
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
|
6
|
+
def self.get_score(income, zip_code, age)
|
7
|
+
raise StandardError.new("Income must be a number") if income.is_a?(Fixnum) == false
|
8
|
+
raise StandardError.new("Zip Code must be a number") if zip_code.is_a?(Fixnum) == false
|
9
|
+
raise StandardError.new("Age must be a number") if age.is_a?(Fixnum) == false
|
10
|
+
|
11
|
+
request = build_request(income,zip_code,age)
|
12
|
+
response = Net::HTTP.get_response(request)
|
29
13
|
|
30
|
-
def get_score
|
31
|
-
response = Net::HTTP.get_response(build_request)
|
32
|
-
p response
|
33
14
|
case response.code
|
34
15
|
when "200" then
|
35
16
|
score = JSON.parse(response.body)
|
36
|
-
|
37
|
-
score
|
38
|
-
else response.code + ": " + response.message
|
17
|
+
else StandardError.new(response.code + ": " + response.message)
|
39
18
|
end
|
40
19
|
end
|
41
|
-
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def self.build_request(income, zip_code, age)
|
24
|
+
URI("http://internal.leapfrogonline.com/customer_scoring?income=#{income}&zipcode=#{zip_code}&age=#{age}")
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|