maxmind 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.markdown +93 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/examples/example.rb +39 -0
- data/lib/maxmind.rb +6 -0
- data/lib/maxmind/request.rb +89 -0
- data/lib/maxmind/response.rb +70 -0
- data/maxmind.gemspec +55 -0
- data/test/fixtures/response.txt +1 -0
- data/test/maxmind_test.rb +129 -0
- data/test/test_helper.rb +14 -0
- metadata +78 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Adam
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,93 @@
|
|
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/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "maxmind"
|
8
|
+
gem.summary = %Q{TODO}
|
9
|
+
gem.email = "adam@mediadrive.ca"
|
10
|
+
gem.homepage = "http://github.com/adam12/maxmind"
|
11
|
+
gem.authors = ["Adam Daniels"]
|
12
|
+
gem.add_dependency 'httparty'
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/*_test.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rake/rdoctask'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
if File.exist?('VERSION.yml')
|
46
|
+
config = YAML.load(File.read('VERSION.yml'))
|
47
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
48
|
+
else
|
49
|
+
version = ""
|
50
|
+
end
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "maxmind #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
57
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.2
|
data/examples/example.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'pp'
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'lib/maxmind')
|
3
|
+
|
4
|
+
required_fields = {
|
5
|
+
:client_ip => '24.24.24.24',
|
6
|
+
:city => 'New York',
|
7
|
+
:region => 'NY',
|
8
|
+
:postal => '11434',
|
9
|
+
:country => 'US'
|
10
|
+
}
|
11
|
+
|
12
|
+
recommended_fields = {
|
13
|
+
:domain => 'yahoo.com',
|
14
|
+
:bin => '549099',
|
15
|
+
:forwarded_ip => '24.24.24.25',
|
16
|
+
:email => 'test@test.com',
|
17
|
+
:username => 'test_carder_username',
|
18
|
+
:password => 'test_carder_password'
|
19
|
+
}
|
20
|
+
|
21
|
+
optional_fields = {
|
22
|
+
:bin_name => 'MBNA America Bank',
|
23
|
+
:bin_phone => '800-421-2110',
|
24
|
+
:cust_phone => '212-242',
|
25
|
+
:requested_type => 'premium',
|
26
|
+
:shipping_address => '145-50 157th Street',
|
27
|
+
:shipping_city => 'Jamaica',
|
28
|
+
:shipping_region => 'NY',
|
29
|
+
:shipping_postal => '11434',
|
30
|
+
:shipping_country => 'US',
|
31
|
+
:transaction_id => '1234',
|
32
|
+
:session_id => 'abcd9876',
|
33
|
+
: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',
|
34
|
+
:accept_language => 'en-us'
|
35
|
+
}
|
36
|
+
|
37
|
+
request = Maxmind::Request.new('LICENSE_KEY', required_fields.merge(recommended_fields).merge(optional_fields))
|
38
|
+
response = Maxmind::Response.new(request.query)
|
39
|
+
pp response
|
data/lib/maxmind.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
module Maxmind
|
2
|
+
class Request
|
3
|
+
# Required Fields
|
4
|
+
attr_accessor :client_ip, :city, :region, :postal, :country, :license_key
|
5
|
+
|
6
|
+
# Optional Fields
|
7
|
+
attr_accessor :domain, :bin, :bin_name, :bin_phone, :cust_phone, :requested_type,
|
8
|
+
:forwarded_ip, :email, :username, :password, :transaction_id, :session_id,
|
9
|
+
:shipping_address, :shipping_city, :shipping_region, :shipping_postal,
|
10
|
+
:shipping_country, :user_agent, :accept_language
|
11
|
+
|
12
|
+
def initialize(license_key, options = {})
|
13
|
+
@license_key = license_key
|
14
|
+
|
15
|
+
options.each do |k, v|
|
16
|
+
self.instance_variable_set("@#{k}", v)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def query(string = false)
|
21
|
+
validate
|
22
|
+
|
23
|
+
required_fields = {
|
24
|
+
:i => @client_ip,
|
25
|
+
:city => @city,
|
26
|
+
:region => @region,
|
27
|
+
:postal => @postal,
|
28
|
+
:country => @country,
|
29
|
+
:license_key => @license_key
|
30
|
+
}
|
31
|
+
|
32
|
+
optional_fields = {
|
33
|
+
:domain => @domain,
|
34
|
+
:bin => @bin,
|
35
|
+
:binName => @bin_name,
|
36
|
+
:binPhone => @bin_phone,
|
37
|
+
:custPhone => @cust_phone,
|
38
|
+
:requested_type => @requested_type,
|
39
|
+
:forwardedIP => @forwarded_ip,
|
40
|
+
:emailMD5 => @email,
|
41
|
+
:usernameMD5 => @username,
|
42
|
+
:passwordMD5 => @password,
|
43
|
+
:shipAddr => @shipping_address,
|
44
|
+
:shipCity => @shipping_city,
|
45
|
+
:shipRegion => @shipping_region,
|
46
|
+
:shipPostal => @shipping_postal,
|
47
|
+
:shipCountry => @shipping_country,
|
48
|
+
:txnID => @transaction_id,
|
49
|
+
:sessionID => @session_id,
|
50
|
+
:user_agent => @user_agent,
|
51
|
+
:accept_language => @accept_langage
|
52
|
+
}
|
53
|
+
|
54
|
+
query = required_fields.merge(optional_fields)
|
55
|
+
if string == false
|
56
|
+
return get(query.reject {|k, v| v.nil? })
|
57
|
+
else
|
58
|
+
return query.reject {|k, v| v.nil? }.to_params
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def get(query)
|
63
|
+
response = HTTParty.get('http://minfraud3.maxmind.com/app/ccv2r', :query => query)
|
64
|
+
return response.body
|
65
|
+
end
|
66
|
+
|
67
|
+
def email=(email)
|
68
|
+
@email = Digest::MD5.hexdigest(email.downcase)
|
69
|
+
end
|
70
|
+
|
71
|
+
def username=(username)
|
72
|
+
@username = Digest::MD5.hexdigest(username.downcase)
|
73
|
+
end
|
74
|
+
|
75
|
+
def password=(password)
|
76
|
+
@password = Digest::MD5.hexdigest(password.downcase)
|
77
|
+
end
|
78
|
+
|
79
|
+
protected
|
80
|
+
def validate
|
81
|
+
raise ArgumentError, 'license key required' if @license_key.nil?
|
82
|
+
raise ArgumentError, 'IP address required' if @client_ip.nil?
|
83
|
+
raise ArgumentError, 'city required' if @city.nil?
|
84
|
+
raise ArgumentError, 'region required' if @region.nil?
|
85
|
+
raise ArgumentError, 'postal code required' if @postal.nil?
|
86
|
+
raise ArgumentError, 'country required' if @country.nil?
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Maxmind
|
2
|
+
class Response
|
3
|
+
attr_accessor :country_match, :country_code, :high_risk_country, :distance,
|
4
|
+
:ip_region, :ip_city, :ip_latitude, :ip_longitude, :ip_isp, :ip_org,
|
5
|
+
:anonymous_proxy, :proxy_score, :is_transparent_proxy,
|
6
|
+
:free_mail, :carder_email, :high_risk_username, :high_risk_password,
|
7
|
+
:bin_match, :bin_country, :bin_name_match, :bin_name, :bin_phone_match,
|
8
|
+
:bin_phone, :phone_in_billing_location, :ship_forward, :city_postal_match,
|
9
|
+
:ship_city_postal_match, :score, :explanation, :risk_score, :queries_remaining,
|
10
|
+
:maxmind_id, :error, :response
|
11
|
+
|
12
|
+
def initialize(response = nil)
|
13
|
+
raise ArgumentError, 'need a valid response string' if response.nil?
|
14
|
+
|
15
|
+
parse(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse(response)
|
19
|
+
response.split(';').each do |parameter|
|
20
|
+
k, v = parameter.split('=')
|
21
|
+
|
22
|
+
case k
|
23
|
+
when 'err'
|
24
|
+
set_attribute('error', v)
|
25
|
+
when 'custPhoneInBillingLoc'
|
26
|
+
set_attribute('phone_in_billing_location', v)
|
27
|
+
when 'maxmindID'
|
28
|
+
set_attribute('maxmind_id', v)
|
29
|
+
when 'isTransProxy'
|
30
|
+
set_attribute('is_transparent_proxy', v)
|
31
|
+
when 'explanation'
|
32
|
+
@explanation = v
|
33
|
+
else
|
34
|
+
set_attribute(k.gsub(/([A-Z])/, '_\1').downcase, v)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
alias_method :country_match?, :country_match
|
40
|
+
alias_method :high_risk_country?, :high_risk_country
|
41
|
+
alias_method :anonymous_proxy?, :anonymous_proxy
|
42
|
+
alias_method :is_transparent_proxy?, :is_transparent_proxy
|
43
|
+
alias_method :free_mail?, :free_mail
|
44
|
+
alias_method :carder_email?, :carder_email
|
45
|
+
alias_method :high_risk_username?, :high_risk_username
|
46
|
+
alias_method :high_risk_password?, :high_risk_password
|
47
|
+
alias_method :city_postal_match?, :city_postal_match
|
48
|
+
alias_method :ship_city_postal_match?, :ship_city_postal_match
|
49
|
+
alias_method :bin_match?, :bin_match
|
50
|
+
|
51
|
+
protected
|
52
|
+
def set_attribute(k, v)
|
53
|
+
if v.nil?
|
54
|
+
self.instance_variable_set("@#{k}", nil)
|
55
|
+
return
|
56
|
+
end
|
57
|
+
|
58
|
+
v = Integer(v) rescue Float(v) rescue v;
|
59
|
+
|
60
|
+
case v
|
61
|
+
when /[Yy]es/
|
62
|
+
self.instance_variable_set("@#{k}", true)
|
63
|
+
when /[Nn]o/
|
64
|
+
self.instance_variable_set("@#{k}", false)
|
65
|
+
else
|
66
|
+
self.instance_variable_set("@#{k}", v)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/maxmind.gemspec
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{maxmind}
|
5
|
+
s.version = "0.1.2"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Adam Daniels"]
|
9
|
+
s.date = %q{2009-05-16}
|
10
|
+
s.email = %q{adam@mediadrive.ca}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.markdown"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".document",
|
17
|
+
".gitignore",
|
18
|
+
"LICENSE",
|
19
|
+
"README.markdown",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"examples/example.rb",
|
23
|
+
"lib/maxmind.rb",
|
24
|
+
"lib/maxmind/request.rb",
|
25
|
+
"lib/maxmind/response.rb",
|
26
|
+
"maxmind.gemspec",
|
27
|
+
"test/fixtures/response.txt",
|
28
|
+
"test/maxmind_test.rb",
|
29
|
+
"test/test_helper.rb"
|
30
|
+
]
|
31
|
+
s.has_rdoc = true
|
32
|
+
s.homepage = %q{http://github.com/adam12/maxmind}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.1}
|
36
|
+
s.summary = %q{TODO}
|
37
|
+
s.test_files = [
|
38
|
+
"test/maxmind_test.rb",
|
39
|
+
"test/test_helper.rb",
|
40
|
+
"examples/example.rb"
|
41
|
+
]
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 2
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
distance=329;countryMatch=Yes;countryCode=US;freeMail=Yes;anonymousProxy=No;score=7.66;binMatch=Yes;binCountry=US;err=;proxyScore=0.00;ip_region=NY;ip_city=Syracuse;ip_latitude=43.0514;ip_longitude=-76.1495;binName=;ip_isp=Road Runner;ip_org=Road Runner;binNameMatch=Yes;binPhoneMatch=Yes;binPhone=;custPhoneInBillingLoc=No;highRiskCountry=No;queriesRemaining=955;cityPostalMatch=No;shipCityPostalMatch=Yes;maxmindID=9VSOSDE2;isTransProxy=No;carderEmail=No;shipForward=Yes;highRiskUsername=No;highRiskPassword=No;riskScore=2.00;explanation=This order is very high risk, and we suggest you not accept it. This order is considered to be very slightly higher risk because the distance between the billing address and the user's actual location is larger than expected. The order is slightly riskier because the e-mail domain, yahoo.com, is a free e-mail provider. The order is slightly riskier because the phone number supplied by the user is not located within the zip code of the billing address for the credit card. The order is riskier because the shipping address given is a mail forwarding address, so there is no way to know where the products are actually going
|
@@ -0,0 +1,129 @@
|
|
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
ADDED
@@ -0,0 +1,14 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: maxmind
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Daniels
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-16 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: httparty
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: adam@mediadrive.ca
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.markdown
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.markdown
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- examples/example.rb
|
42
|
+
- lib/maxmind.rb
|
43
|
+
- lib/maxmind/request.rb
|
44
|
+
- lib/maxmind/response.rb
|
45
|
+
- maxmind.gemspec
|
46
|
+
- test/fixtures/response.txt
|
47
|
+
- test/maxmind_test.rb
|
48
|
+
- test/test_helper.rb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://github.com/adam12/maxmind
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --charset=UTF-8
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.3.1
|
72
|
+
signing_key:
|
73
|
+
specification_version: 2
|
74
|
+
summary: TODO
|
75
|
+
test_files:
|
76
|
+
- test/maxmind_test.rb
|
77
|
+
- test/test_helper.rb
|
78
|
+
- examples/example.rb
|