maxmind 0.1.2 → 0.4.2
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/.gitignore +3 -0
- data/Gemfile +2 -0
- data/Guardfile +6 -0
- data/README.md +134 -0
- data/Rakefile +9 -46
- data/examples/example.rb +6 -4
- data/lib/maxmind.rb +8 -3
- data/lib/maxmind/request.rb +117 -46
- data/lib/maxmind/response.rb +53 -47
- data/lib/maxmind/version.rb +3 -0
- data/maxmind.gemspec +19 -44
- data/spec/data/optional_fields.json +17 -0
- data/spec/data/recommended_fields.json +8 -0
- data/spec/data/required_fields.json +7 -0
- data/{test/fixtures → spec/data}/response.txt +0 -0
- data/spec/maxmind/request_spec.rb +50 -0
- data/spec/maxmind/response_spec.rb +72 -0
- data/spec/spec_helper.rb +30 -0
- metadata +120 -53
- data/.document +0 -5
- data/README.markdown +0 -93
- data/VERSION +0 -1
- data/test/maxmind_test.rb +0 -129
- data/test/test_helper.rb +0 -14
data/.document
DELETED
data/README.markdown
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
maxmind
|
2
|
-
=======
|
3
|
-
|
4
|
-
Interfaces with Maxmind's minFraud anti-fraud service.
|
5
|
-
|
6
|
-
Installation
|
7
|
-
------------
|
8
|
-
gem install adam12-maxmind --source=http://gems.github.com
|
9
|
-
|
10
|
-
|
11
|
-
Dependencies
|
12
|
-
------------
|
13
|
-
* [httparty](http://github.com/jnunemaker/httparty/)
|
14
|
-
* [shoulda](http://github.com/thoughtbot/shoulda/) (used in tests only)
|
15
|
-
* [matchy](http://github.com/jeremymcanally/matchy/) (used in tests only)
|
16
|
-
|
17
|
-
|
18
|
-
Usage
|
19
|
-
-----
|
20
|
-
|
21
|
-
### Minimum Required ###
|
22
|
-
These are the only required fields to acquire a response from Maxmind.
|
23
|
-
|
24
|
-
request = Maxmind::Request.new('LICENSE_KEY',
|
25
|
-
:client_ip => '24.24.24.24',
|
26
|
-
:city => 'New York',
|
27
|
-
:region => 'NY',
|
28
|
-
:postal => '11434',
|
29
|
-
:country => 'US')
|
30
|
-
|
31
|
-
response = Maxmind::Response.new(request.query)
|
32
|
-
|
33
|
-
|
34
|
-
### Recommended ###
|
35
|
-
For increased accuracy, these are the recommended fields to submit to Maxmind. The additional
|
36
|
-
fields here are optional and can be all or none.
|
37
|
-
|
38
|
-
request = Maxmind::Request.new('LICENSE_KEY',
|
39
|
-
:client_ip => '24.24.24.24',
|
40
|
-
:city => 'New York',
|
41
|
-
:region => 'NY',
|
42
|
-
:postal => '11434',
|
43
|
-
:country => 'US',
|
44
|
-
:domain => 'yahoo.com',
|
45
|
-
:bin => '549099',
|
46
|
-
:forwarded_ip => '24.24.24.25',
|
47
|
-
:email => 'test@test.com',
|
48
|
-
:username => 'test_carder_username',
|
49
|
-
:password => 'test_carder_password')
|
50
|
-
|
51
|
-
response = Maxmind::Response.new(request.query)
|
52
|
-
|
53
|
-
### Thorough ###
|
54
|
-
|
55
|
-
request = Maxmind::Request.new('LICENSE_KEY',
|
56
|
-
:client_ip => '24.24.24.24',
|
57
|
-
:city => 'New York',
|
58
|
-
:region => 'NY',
|
59
|
-
:postal => '11434',
|
60
|
-
:country => 'US',
|
61
|
-
:domain => 'yahoo.com',
|
62
|
-
:bin => '549099',
|
63
|
-
:forwarded_ip => '24.24.24.25',
|
64
|
-
:email => 'test@test.com',
|
65
|
-
:username => 'test_carder_username',
|
66
|
-
:password => 'test_carder_password'
|
67
|
-
:bin_name => 'MBNA America Bank',
|
68
|
-
:bin_phone => '800-421-2110',
|
69
|
-
:cust_phone => '212-242',
|
70
|
-
:requested_type => 'premium',
|
71
|
-
:shipping_address => '145-50 157th Street',
|
72
|
-
:shipping_city => 'Jamaica',
|
73
|
-
:shipping_region => 'NY',
|
74
|
-
:shipping_postal => '11434',
|
75
|
-
:shipping_country => 'US',
|
76
|
-
:transaction_id => '1234',
|
77
|
-
:session_id => 'abcd9876',
|
78
|
-
:user_agent => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_5; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1',
|
79
|
-
:accept_language => 'en-us')
|
80
|
-
|
81
|
-
response = Maxmind::Response.new(request.query)
|
82
|
-
|
83
|
-
Also see examples/example.rb
|
84
|
-
|
85
|
-
|
86
|
-
Reference
|
87
|
-
---------
|
88
|
-
[minFraud API Reference](http://www.maxmind.com/app/ccv)
|
89
|
-
|
90
|
-
|
91
|
-
Copyright
|
92
|
-
---------
|
93
|
-
Copyright (c) 2009 Adam. See LICENSE for details.
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.2
|
data/test/maxmind_test.rb
DELETED
@@ -1,129 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
REQUIRED_FIELDS = {
|
4
|
-
:client_ip => '24.24.24.24',
|
5
|
-
:city => 'New York',
|
6
|
-
:region => 'NY',
|
7
|
-
:postal => '11434',
|
8
|
-
:country => 'US'
|
9
|
-
}
|
10
|
-
|
11
|
-
RECOMMENDED_FIELDS = {
|
12
|
-
:domain => 'yahoo.com',
|
13
|
-
:bin => '549099',
|
14
|
-
:forwarded_ip => '24.24.24.25',
|
15
|
-
:email => 'test@test.com',
|
16
|
-
:username => 'test_carder_username',
|
17
|
-
:password => 'test_carder_password'
|
18
|
-
}
|
19
|
-
|
20
|
-
OPTIONAL_FIELDS = {
|
21
|
-
:bin_name => 'MBNA America Bank',
|
22
|
-
:bin_phone => '800-421-2110',
|
23
|
-
:cust_phone => '212-242',
|
24
|
-
:requested_type => 'premium',
|
25
|
-
:shipping_address => '145-50 157th Street',
|
26
|
-
:shipping_city => 'Jamaica',
|
27
|
-
:shipping_region => 'NY',
|
28
|
-
:shipping_postal => '11434',
|
29
|
-
:shipping_country => 'US',
|
30
|
-
:transaction_id => '1234',
|
31
|
-
:session_id => 'abcd9876',
|
32
|
-
:user_agent => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_5; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1',
|
33
|
-
:accept_language => 'en-us'
|
34
|
-
}
|
35
|
-
|
36
|
-
class MaxmindTest < Test::Unit::TestCase
|
37
|
-
context "New Request object" do
|
38
|
-
setup do
|
39
|
-
@request = Maxmind::Request.new('key', REQUIRED_FIELDS)
|
40
|
-
end
|
41
|
-
|
42
|
-
should "require a key" do
|
43
|
-
lambda { Maxmind::Request.new }.should raise_error(ArgumentError)
|
44
|
-
|
45
|
-
Maxmind::Request.new('key').license_key.should == 'key'
|
46
|
-
end
|
47
|
-
|
48
|
-
should "require client IP" do
|
49
|
-
lambda { @request.client_ip = nil; @request.query }.should raise_error(ArgumentError)
|
50
|
-
end
|
51
|
-
|
52
|
-
should "require city" do
|
53
|
-
lambda { @request.city = nil; @request.query }.should raise_error(ArgumentError)
|
54
|
-
end
|
55
|
-
|
56
|
-
should "require region" do
|
57
|
-
lambda { @request.region = nil; @request.query }.should raise_error(ArgumentError)
|
58
|
-
end
|
59
|
-
|
60
|
-
should "require postal" do
|
61
|
-
lambda { @request.postal = nil; @request.query }.should raise_error(ArgumentError)
|
62
|
-
end
|
63
|
-
|
64
|
-
should "require country" do
|
65
|
-
lambda { @request.country = nil; @request.query }.should raise_error(ArgumentError)
|
66
|
-
end
|
67
|
-
|
68
|
-
should "convert username to MD5" do
|
69
|
-
@request.username = 'testuser'
|
70
|
-
@request.username.should == '5d9c68c6c50ed3d02a2fcf54f63993b6'
|
71
|
-
end
|
72
|
-
|
73
|
-
should "convert password to MD5" do
|
74
|
-
@request.password = 'testpassword'
|
75
|
-
@request.password.should == 'e16b2ab8d12314bf4efbd6203906ea6c'
|
76
|
-
end
|
77
|
-
|
78
|
-
should "convert email to MD5" do
|
79
|
-
@request.email = 'test@test.com'
|
80
|
-
@request.email.should == 'b642b4217b34b1e8d3bd915fc65c4452'
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
#context "Requesting" do
|
85
|
-
# setup do
|
86
|
-
# request = Maxmind::Request.new('LICENSE_KEY', REQUIRED_FIELDS.merge(RECOMMENDED_FIELDS).merge(OPTIONAL_FIELDS))
|
87
|
-
# FakeWeb.register_uri(:get, "http://minfraud3.maxmind.com/app/ccv2r?" + request.query(true), :string => File.read(File.join(File.dirname(__FILE__), "fixtures/basic.txt")))
|
88
|
-
#
|
89
|
-
# @response = Maxmind::Response.new(request)
|
90
|
-
# end
|
91
|
-
#end
|
92
|
-
|
93
|
-
context "Response" do
|
94
|
-
setup do
|
95
|
-
request = Maxmind::Request.new('LICENSE_KEY', REQUIRED_FIELDS.merge(RECOMMENDED_FIELDS).merge(OPTIONAL_FIELDS))
|
96
|
-
FakeWeb.register_uri(:get, "http://minfraud3.maxmind.com/app/ccv2r?" + request.query(true), :string => File.read(File.join(File.dirname(__FILE__), "fixtures/response.txt")))
|
97
|
-
|
98
|
-
@response = Maxmind::Response.new(request.query)
|
99
|
-
end
|
100
|
-
|
101
|
-
should "require a response" do
|
102
|
-
lambda { Maxmind::Response.new }.should raise_error(ArgumentError)
|
103
|
-
end
|
104
|
-
|
105
|
-
should "have a distance" do
|
106
|
-
@response.distance.should == 329
|
107
|
-
end
|
108
|
-
|
109
|
-
should "have a maxmind ID" do
|
110
|
-
@response.maxmind_id.should == '9VSOSDE2'
|
111
|
-
end
|
112
|
-
|
113
|
-
should "have a risk score" do
|
114
|
-
@response.risk_score.should == 2.0
|
115
|
-
end
|
116
|
-
|
117
|
-
should "have a score" do
|
118
|
-
@response.score.should == 7.66
|
119
|
-
end
|
120
|
-
|
121
|
-
should "have queries remaining" do
|
122
|
-
@response.queries_remaining.should == 955
|
123
|
-
end
|
124
|
-
|
125
|
-
should "have an explanation" do
|
126
|
-
@response.explanation.should_not be_nil
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'shoulda'
|
4
|
-
require 'matchy'
|
5
|
-
require 'fakeweb'
|
6
|
-
|
7
|
-
FakeWeb.allow_net_connect = false
|
8
|
-
|
9
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
10
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
11
|
-
require 'maxmind'
|
12
|
-
|
13
|
-
class Test::Unit::TestCase
|
14
|
-
end
|