consumer_score 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/consumer_score.rb +27 -20
- metadata +2 -2
data/lib/consumer_score.rb
CHANGED
@@ -1,28 +1,35 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'json'
|
3
|
+
require 'fakeweb'
|
3
4
|
|
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"])
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
request = build_request(income,zip_code,age)
|
12
|
-
response = Net::HTTP.get_response(request)
|
9
|
+
class RequestError < StandardError
|
10
|
+
def initialize(code, message)
|
11
|
+
super(code + ': ' + message)
|
12
|
+
end
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
15
|
+
class ConsumerScore
|
16
|
+
def self.get_score(income, zip_code, age)
|
17
|
+
raise ArgumentError.new("Income must be a number") if income.is_a?(Fixnum) == false
|
18
|
+
raise ArgumentError.new("Zip Code must be be the correct format (60201 or 60201-1111)") if !zip_code.match(/\d{5}[- ]\d{4}|\d{5}/)
|
19
|
+
raise ArgumentError.new("Age must be a number") if age.is_a?(Fixnum) == false
|
20
20
|
|
21
|
-
|
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
|
21
|
+
request = build_request(income, zip_code, age)
|
22
|
+
response = Net::HTTP.get_response(request)
|
26
23
|
|
27
|
-
|
24
|
+
if response.kind_of?(Net::HTTPSuccess)
|
25
|
+
score = JSON.parse(response.body)
|
26
|
+
else
|
27
|
+
RequestError.new(response.code, response.message)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.build_request(income, zip_code, age)
|
32
|
+
URI("http://internal.leapfrogonline.com/customer_scoring?income=#{income}&zipcode=#{zip_code}&age=#{age}")
|
33
|
+
end
|
28
34
|
|
35
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consumer_score
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-18 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: API integration with LeapFrog service to obtain consumer score based
|
15
15
|
on income, zip code, and age
|