samoli-maxmind 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
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.
@@ -0,0 +1,95 @@
1
+ maxmind
2
+ =======
3
+
4
+ Interfaces with Maxmind's minFraud anti-fraud service.
5
+
6
+ Installation
7
+ ------------
8
+ sudo gem install hackedunit-maxmind --source=http://gemcutter.org
9
+
10
+
11
+ Dependencies
12
+ ------------
13
+ * [shoulda](http://github.com/thoughtbot/shoulda/) (used in tests only)
14
+ * [matchy](http://github.com/jeremymcanally/matchy/) (used in tests only)
15
+
16
+
17
+ Usage
18
+ -----
19
+
20
+ ### Minimum Required ###
21
+ These are the only required fields to acquire a response from Maxmind.
22
+
23
+ require 'maxmind'
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
+ require 'maxmind'
39
+ request = Maxmind::Request.new('LICENSE_KEY',
40
+ :client_ip => '24.24.24.24',
41
+ :city => 'New York',
42
+ :region => 'NY',
43
+ :postal => '11434',
44
+ :country => 'US',
45
+ :domain => 'yahoo.com',
46
+ :bin => '549099',
47
+ :forwarded_ip => '24.24.24.25',
48
+ :email => 'test@test.com',
49
+ :username => 'test_carder_username',
50
+ :password => 'test_carder_password')
51
+
52
+ response = Maxmind::Response.new(request.query)
53
+
54
+ ### Thorough ###
55
+
56
+ require 'maxmind'
57
+ request = Maxmind::Request.new('LICENSE_KEY',
58
+ :client_ip => '24.24.24.24',
59
+ :city => 'New York',
60
+ :region => 'NY',
61
+ :postal => '11434',
62
+ :country => 'US',
63
+ :domain => 'yahoo.com',
64
+ :bin => '549099',
65
+ :forwarded_ip => '24.24.24.25',
66
+ :email => 'test@test.com',
67
+ :username => 'test_carder_username',
68
+ :password => 'test_carder_password'
69
+ :bin_name => 'MBNA America Bank',
70
+ :bin_phone => '800-421-2110',
71
+ :cust_phone => '212-242',
72
+ :requested_type => 'premium',
73
+ :shipping_address => '145-50 157th Street',
74
+ :shipping_city => 'Jamaica',
75
+ :shipping_region => 'NY',
76
+ :shipping_postal => '11434',
77
+ :shipping_country => 'US',
78
+ :transaction_id => '1234',
79
+ :session_id => 'abcd9876',
80
+ :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',
81
+ :accept_language => 'en-us')
82
+
83
+ response = Maxmind::Response.new(request.query)
84
+
85
+ Also see examples/example.rb
86
+
87
+
88
+ Reference
89
+ ---------
90
+ [minFraud API Reference](http://www.maxmind.com/app/ccv)
91
+
92
+
93
+ Copyright
94
+ ---------
95
+ Copyright (c) 2009 Adam. See LICENSE for details.
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "hackedunit-maxmind"
8
+ gem.summary = "MaxMind Minfraud using Net::HTTP"
9
+ gem.email = "tinu@tinucleatus.com"
10
+ gem.homepage = "http://github.com/hackedunit/maxmind"
11
+ gem.authors = ["Adam Daniels", "Tinu Cleatus"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION.yml')
45
+ config = YAML.load(File.read('VERSION.yml'))
46
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "maxmind #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
56
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
@@ -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
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'net/http'
4
+ require 'net/https'
5
+ require 'uri'
6
+ require 'digest/md5'
7
+ require File.join(File.dirname(__FILE__), 'maxmind/request')
8
+ require File.join(File.dirname(__FILE__), 'maxmind/response')
@@ -0,0 +1,93 @@
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? }.to_query)
57
+ else
58
+ return query.reject {|k, v| v.nil? }.to_query
59
+ end
60
+ end
61
+
62
+ def get(query)
63
+ url = URI.parse("https://minfraud1.maxmind.com/app/ccv2r")
64
+ req = Net::HTTP::Get.new("#{url.path}?#{query}")
65
+ h = Net::HTTP.new(url.host, url.port)
66
+ h.use_ssl = true
67
+ response = h.start { |http| http.request(req) }
68
+ return response.body
69
+ end
70
+
71
+ def email=(email)
72
+ @email = Digest::MD5.hexdigest(email.downcase)
73
+ end
74
+
75
+ def username=(username)
76
+ @username = Digest::MD5.hexdigest(username.downcase)
77
+ end
78
+
79
+ def password=(password)
80
+ @password = Digest::MD5.hexdigest(password.downcase)
81
+ end
82
+
83
+ protected
84
+ def validate
85
+ raise ArgumentError, 'license key required' if @license_key.nil?
86
+ raise ArgumentError, 'IP address required' if @client_ip.nil?
87
+ raise ArgumentError, 'city required' if @city.nil?
88
+ raise ArgumentError, 'region required' if @region.nil?
89
+ raise ArgumentError, 'postal code required' if @postal.nil?
90
+ raise ArgumentError, 'country required' if @country.nil?
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,102 @@
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
+ @attributes = attributes_from_response
17
+ end
18
+
19
+ def attributes_from_response
20
+ hash_to_return = {}
21
+ self.instance_variables.each do |var|
22
+ hash_to_return[var.to_s.gsub("@","")] = self.instance_variable_get(var)
23
+ end
24
+ return hash_to_return
25
+ end
26
+
27
+ def parse(response)
28
+ response.split(';').each do |parameter|
29
+ k, v = parameter.split('=')
30
+
31
+ case k
32
+ when 'err'
33
+ set_attribute('error', v)
34
+ when 'custPhoneInBillingLoc'
35
+ set_attribute('phone_in_billing_location', v)
36
+ when 'maxmindID'
37
+ set_attribute('maxmind_id', v)
38
+ when 'isTransProxy'
39
+ set_attribute('is_transparent_proxy', v)
40
+ when 'explanation'
41
+ @explanation = v
42
+ else
43
+ set_attribute(k.gsub(/([A-Z])/, '_\1').downcase, v)
44
+ end
45
+ end
46
+ end
47
+
48
+ alias_method :country_match?, :country_match
49
+ alias_method :high_risk_country?, :high_risk_country
50
+ alias_method :anonymous_proxy?, :anonymous_proxy
51
+ alias_method :is_transparent_proxy?, :is_transparent_proxy
52
+ alias_method :free_mail?, :free_mail
53
+ alias_method :carder_email?, :carder_email
54
+ alias_method :high_risk_username?, :high_risk_username
55
+ alias_method :high_risk_password?, :high_risk_password
56
+ alias_method :city_postal_match?, :city_postal_match
57
+ alias_method :ship_city_postal_match?, :ship_city_postal_match
58
+ alias_method :bin_match?, :bin_match
59
+
60
+ # Returns an array of names for the attributes available on this object sorted alphabetically.
61
+ def attribute_names
62
+ @attributes.keys.sort
63
+ end
64
+
65
+ # Returns a hash of all the attributes with their names as keys and the values of the attributes as values.
66
+ def attributes
67
+ attrs = self.attribute_names.inject({}) do |attrs, name|
68
+ attrs[name] = read_attribute(name)
69
+ attrs
70
+ end
71
+ attrs.symbolize_keys
72
+ end
73
+
74
+ def read_attribute(attr_name)
75
+ attr_name = attr_name.to_s
76
+ if !(value = @attributes[attr_name]).nil?
77
+ value
78
+ else
79
+ nil
80
+ end
81
+ end
82
+
83
+ protected
84
+ def set_attribute(k, v)
85
+ if v.nil?
86
+ self.instance_variable_set("@#{k}", nil)
87
+ return
88
+ end
89
+
90
+ v = Integer(v) rescue Float(v) rescue v;
91
+
92
+ case v
93
+ when /[Yy]es/
94
+ self.instance_variable_set("@#{k}", true)
95
+ when /[Nn]o/
96
+ self.instance_variable_set("@#{k}", false)
97
+ else
98
+ self.instance_variable_set("@#{k}", v)
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{samoli-maxmind}
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Adam Daniels", "Tinu Cleatus"]
12
+ s.date = %q{2010-02-22}
13
+ s.email = %q{tinu@tinucleatus.com}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.markdown"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "README.markdown",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "examples/example.rb",
26
+ "maxmind.gemspec",
27
+ "lib/maxmind.rb",
28
+ "lib/maxmind/request.rb",
29
+ "lib/maxmind/response.rb",
30
+ "test/fixtures/response.txt",
31
+ "test/maxmind_test.rb",
32
+ "test/test_helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/hackedunit/maxmind}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.5}
38
+ s.summary = %q{MaxMind Minfraud using Net::HTTP}
39
+ s.test_files = [
40
+ "test/maxmind_test.rb",
41
+ "test/test_helper.rb",
42
+ "examples/example.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ else
51
+ end
52
+ else
53
+ end
54
+ end
55
+
@@ -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, "https://minfraud1.maxmind.com/app/ccv2r?" + request.query(true), :body => 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 == nil
127
+ end
128
+ end
129
+ end
@@ -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,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: samoli-maxmind
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Daniels
9
+ - Tinu Cleatus
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2010-02-22 00:00:00.000000000 +00:00
14
+ default_executable:
15
+ dependencies: []
16
+ description:
17
+ email: tinu@tinucleatus.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files:
21
+ - LICENSE
22
+ - README.markdown
23
+ files:
24
+ - .document
25
+ - .gitignore
26
+ - LICENSE
27
+ - README.markdown
28
+ - Rakefile
29
+ - VERSION
30
+ - examples/example.rb
31
+ - maxmind.gemspec
32
+ - lib/maxmind.rb
33
+ - lib/maxmind/request.rb
34
+ - lib/maxmind/response.rb
35
+ - test/fixtures/response.txt
36
+ - test/maxmind_test.rb
37
+ - test/test_helper.rb
38
+ has_rdoc: true
39
+ homepage: http://github.com/hackedunit/maxmind
40
+ licenses: []
41
+ post_install_message:
42
+ rdoc_options:
43
+ - --charset=UTF-8
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.6.2
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: MaxMind Minfraud using Net::HTTP
64
+ test_files:
65
+ - test/maxmind_test.rb
66
+ - test/test_helper.rb
67
+ - examples/example.rb