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.
@@ -1,70 +1,76 @@
1
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
-
2
+ class Response
3
+ attr_accessor :attributes
4
+
5
+ ATTRIBUTE_MAP = {
6
+ 'custPhoneInBillingLoc' => 'phone_in_billing_location',
7
+ 'maxmindID' => 'maxmind_id',
8
+ 'isTransProxy' => 'is_transparent_proxy',
9
+ 'err' => 'error'
10
+ }
11
+
12
12
  def initialize(response = nil)
13
- raise ArgumentError, 'need a valid response string' if response.nil?
14
-
13
+ raise ArgumentError, 'Missing response string' unless response
14
+ @attributes = {}
15
15
  parse(response)
16
16
  end
17
-
17
+
18
18
  def parse(response)
19
19
  response.split(';').each do |parameter|
20
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
21
+
22
+ if ATTRIBUTE_MAP.has_key?(k)
23
+ set_attribute(ATTRIBUTE_MAP[k], v)
33
24
  else
34
25
  set_attribute(k.gsub(/([A-Z])/, '_\1').downcase, v)
35
26
  end
36
27
  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
-
28
+ end
29
+
30
+ # Returns an array of names for the attributes available
31
+ # on this object sorted alphabetically.
32
+ def attribute_names
33
+ attributes.keys.sort
34
+ end
35
+
36
+ def method_missing(meth, *args)
37
+ if meth.to_s[-1] == '?'
38
+ send(meth[0..-2])
39
+ elsif attributes.has_key?(meth)
40
+ attributes[meth]
41
+ else
42
+ super
43
+ end
44
+ end
45
+
46
+ def respond_to?(meth)
47
+ if meth.to_s[-1] == '?'
48
+ respond_to? meth[0..-2]
49
+ else
50
+ super
51
+ end
52
+ end
53
+
51
54
  protected
52
- def set_attribute(k, v)
55
+
56
+ def set_attribute(k, v)
57
+ k = k.to_sym
58
+
53
59
  if v.nil?
54
- self.instance_variable_set("@#{k}", nil)
60
+ attributes[k] = nil
55
61
  return
56
62
  end
57
-
63
+
58
64
  v = Integer(v) rescue Float(v) rescue v;
59
-
65
+
60
66
  case v
61
67
  when /[Yy]es/
62
- self.instance_variable_set("@#{k}", true)
68
+ attributes[k] = true
63
69
  when /[Nn]o/
64
- self.instance_variable_set("@#{k}", false)
70
+ attributes[k] = false
65
71
  else
66
- self.instance_variable_set("@#{k}", v)
72
+ attributes[k] = v
67
73
  end
68
- end
74
+ end
69
75
  end
70
76
  end
@@ -0,0 +1,3 @@
1
+ module Maxmind
2
+ VERSION = '0.4.2'
3
+ end
data/maxmind.gemspec CHANGED
@@ -1,55 +1,30 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'maxmind/version'
2
4
 
3
5
  Gem::Specification.new do |s|
4
- s.name = %q{maxmind}
5
- s.version = "0.1.2"
6
+ s.name = "maxmind"
7
+ s.version = Maxmind::VERSION
6
8
 
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}
9
+ s.authors = ["Adam Daniels", "Tinu Cleatus", "t.e.morgan", "Sam Oliver"]
10
+ s.date = "2012-01-06"
11
+ s.description = "A wrapper around MaxMind's minFraud anti-fraud service. \n\nhttp://www.maxmind.com/app/ccv_overview\n"
12
+ s.email = "adam@mediadrive.ca"
11
13
  s.extra_rdoc_files = [
12
14
  "LICENSE",
13
- "README.markdown"
15
+ "README.md"
14
16
  ]
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"]
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.homepage = "http://github.com/adam12/maxmind"
34
21
  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
- ]
22
+ s.summary = "Wrapper for MaxMind's minFraud service"
42
23
 
43
- if s.respond_to? :specification_version then
44
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
- s.specification_version = 2
24
+ s.add_development_dependency 'rspec'
25
+ s.add_development_dependency 'mocha'
26
+ s.add_development_dependency 'webmock'
46
27
 
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
28
+ s.add_runtime_dependency 'active_support', '>= 3.0.0'
55
29
  end
30
+
@@ -0,0 +1,17 @@
1
+ {
2
+ "bin_name": "MBNA America Bank",
3
+ "bin_phone": "800-421-2110",
4
+ "cust_phone": "212-242",
5
+ "request_type": "premium",
6
+ "shipping_address": "145-50 157th Street",
7
+ "shipping_city": "Jamaica",
8
+ "shipping_region": "NY",
9
+ "shipping_postal": "11434",
10
+ "shipping_country": "US",
11
+ "transaction_id": "1234",
12
+ "order_amount": 9.99,
13
+ "order_currency": "GBP",
14
+ "session_id": "abcd9876",
15
+ "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",
16
+ "accept_language": "en-us"
17
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "domain": "yahoo.com",
3
+ "bin": "549099",
4
+ "forwarded_ip": "24.24.24.25",
5
+ "email": "test@test.com",
6
+ "username": "test_carder_username",
7
+ "password": "test_carder_password"
8
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "client_ip": "24.24.24.24",
3
+ "city": "New York",
4
+ "region": "NY",
5
+ "postal": "11434",
6
+ "country": "US"
7
+ }
File without changes
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Maxmind::Request do
4
+ before do
5
+ Maxmind.license_key = 'key'
6
+ required_fields = JSON.parse(load_fixture("required_fields.json"))
7
+ @request = Maxmind::Request.new(required_fields)
8
+ end
9
+
10
+ it "requires a key" do
11
+ Maxmind.license_key = nil
12
+ expect { @request.send(:validate) }.to raise_error(ArgumentError)
13
+ Maxmind.license_key = 'key'
14
+ end
15
+
16
+ it "requires client IP" do
17
+ expect { @request.client_ip = nil; @request.send(:validate) }.to raise_exception(ArgumentError)
18
+ end
19
+
20
+ it "requires city" do
21
+ expect { @request.city = nil; @request.send(:validate) }.to raise_exception(ArgumentError)
22
+ end
23
+
24
+ it "requires region" do
25
+ expect { @request.region = nil; @request.send(:validate) }.to raise_exception(ArgumentError)
26
+ end
27
+
28
+ it "requires postal" do
29
+ expect { @request.postal = nil; @request.send(:validate) }.to raise_exception(ArgumentError)
30
+ end
31
+
32
+ it "requires country" do
33
+ expect { @request.country = nil; @request.send(:validate) }.to raise_exception(ArgumentError)
34
+ end
35
+
36
+ it "converts username to MD5" do
37
+ @request.username = 'testuser'
38
+ @request.username.should == '5d9c68c6c50ed3d02a2fcf54f63993b6'
39
+ end
40
+
41
+ it "converts password to MD5" do
42
+ @request.password = 'testpassword'
43
+ @request.password.should == 'e16b2ab8d12314bf4efbd6203906ea6c'
44
+ end
45
+
46
+ it "converts email to MD5" do
47
+ @request.email = 'test@test.com'
48
+ @request.email.should == 'b642b4217b34b1e8d3bd915fc65c4452'
49
+ end
50
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ REQUIRED_FIELDS =
4
+
5
+ RECOMMENDED_FIELDS =
6
+
7
+ OPTIONAL_FIELDS =
8
+
9
+ describe Maxmind::Response do
10
+ before do
11
+ Maxmind.license_key = 'LICENSE_KEY'
12
+
13
+ required_fields = JSON.parse(load_fixture("required_fields.json"))
14
+ recommended_fields = JSON.parse(load_fixture("recommended_fields.json"))
15
+ optional_fields = JSON.parse(load_fixture("optional_fields.json"))
16
+ all_fields = required_fields.merge(recommended_fields).merge(optional_fields)
17
+
18
+ request = Maxmind::Request.new(all_fields)
19
+ stub_request(:post, "https://minfraud.maxmind.com/app/ccv2r").
20
+ to_return(:body => load_fixture("response.txt"), :status => 200)
21
+ @response = request.process!
22
+ end
23
+
24
+ it "requires a response" do
25
+ expect { Maxmind::Response.new }.to raise_exception(ArgumentError)
26
+ end
27
+
28
+ it "exposes its attributes" do
29
+ @response.attributes.should be_a Hash
30
+ end
31
+
32
+ it "has a distance" do
33
+ @response.distance.should == 329
34
+ end
35
+
36
+ it "has a maxmind ID" do
37
+ @response.maxmind_id.should == '9VSOSDE2'
38
+ end
39
+
40
+ it "has a risk score" do
41
+ @response.risk_score.should == 2.0
42
+ end
43
+
44
+ it "has a score" do
45
+ @response.score.should == 7.66
46
+ end
47
+
48
+ it "has queries remaining" do
49
+ @response.queries_remaining.should == 955
50
+ end
51
+
52
+ it "has an explanation" do
53
+ @response.explanation.should_not == nil
54
+ end
55
+
56
+ it "has a country match" do
57
+ @response.country_match.should_not == nil
58
+ end
59
+
60
+ it "has a boolean country match" do
61
+ @response.country_match.should_not == "Yes"
62
+ @response.country_match.should == true
63
+ end
64
+
65
+ it "has a phone in billing location" do
66
+ @response.phone_in_billing_location.should == false
67
+ end
68
+
69
+ it "has a phone in billing location ? method" do
70
+ @response.phone_in_billing_location?.should == false
71
+ end
72
+ end
@@ -0,0 +1,30 @@
1
+ require 'mocha_standalone'
2
+ require 'maxmind'
3
+ require 'json'
4
+ require 'webmock/rspec'
5
+
6
+ RSpec.configure do |config|
7
+
8
+ config.before(:suite) do
9
+ # Disable all live HTTP requests
10
+ WebMock.disable_net_connect!(allow_localhost: true)
11
+ end
12
+
13
+ config.mock_with :mocha
14
+ end
15
+
16
+ # Constants (classes, etc) defined within a block passed to this method
17
+ # will be removed from the global namespace after the block as run.
18
+ def isolate_constants
19
+ existing_constants = Object.constants
20
+ yield
21
+ ensure
22
+ (Object.constants - existing_constants).each do |constant|
23
+ Object.send(:remove_const, constant)
24
+ end
25
+ end
26
+
27
+
28
+ def load_fixture(*filename)
29
+ File.open(File.join('spec', 'data', *filename)).read
30
+ end
metadata CHANGED
@@ -1,78 +1,145 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: maxmind
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.2
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Adam Daniels
9
+ - Tinu Cleatus
10
+ - t.e.morgan
11
+ - Sam Oliver
8
12
  autorequire:
9
13
  bindir: bin
10
14
  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
15
+ date: 2012-01-06 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: rspec
19
+ requirement: !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ type: :development
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: mocha
35
+ requirement: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ - !ruby/object:Gem::Dependency
50
+ name: webmock
51
+ requirement: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ - !ruby/object:Gem::Dependency
66
+ name: active_support
67
+ requirement: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: 3.0.0
17
73
  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:
74
+ prerelease: false
75
+ version_requirements: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: 3.0.0
81
+ description: ! "A wrapper around MaxMind's minFraud anti-fraud service. \n\nhttp://www.maxmind.com/app/ccv_overview\n"
26
82
  email: adam@mediadrive.ca
27
83
  executables: []
28
-
29
84
  extensions: []
30
-
31
- extra_rdoc_files:
85
+ extra_rdoc_files:
32
86
  - LICENSE
33
- - README.markdown
34
- files:
35
- - .document
87
+ - README.md
88
+ files:
36
89
  - .gitignore
90
+ - Gemfile
91
+ - Guardfile
37
92
  - LICENSE
38
- - README.markdown
93
+ - README.md
39
94
  - Rakefile
40
- - VERSION
41
95
  - examples/example.rb
42
96
  - lib/maxmind.rb
43
97
  - lib/maxmind/request.rb
44
98
  - lib/maxmind/response.rb
99
+ - lib/maxmind/version.rb
45
100
  - maxmind.gemspec
46
- - test/fixtures/response.txt
47
- - test/maxmind_test.rb
48
- - test/test_helper.rb
49
- has_rdoc: true
101
+ - spec/data/optional_fields.json
102
+ - spec/data/recommended_fields.json
103
+ - spec/data/required_fields.json
104
+ - spec/data/response.txt
105
+ - spec/maxmind/request_spec.rb
106
+ - spec/maxmind/response_spec.rb
107
+ - spec/spec_helper.rb
50
108
  homepage: http://github.com/adam12/maxmind
109
+ licenses: []
51
110
  post_install_message:
52
- rdoc_options:
53
- - --charset=UTF-8
54
- require_paths:
111
+ rdoc_options: []
112
+ require_paths:
55
113
  - 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:
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ segments:
121
+ - 0
122
+ hash: -1867686245011996081
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ segments:
130
+ - 0
131
+ hash: -1867686245011996081
68
132
  requirements: []
69
-
70
133
  rubyforge_project:
71
- rubygems_version: 1.3.1
134
+ rubygems_version: 1.8.21
72
135
  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
136
+ specification_version: 3
137
+ summary: Wrapper for MaxMind's minFraud service
138
+ test_files:
139
+ - spec/data/optional_fields.json
140
+ - spec/data/recommended_fields.json
141
+ - spec/data/required_fields.json
142
+ - spec/data/response.txt
143
+ - spec/maxmind/request_spec.rb
144
+ - spec/maxmind/response_spec.rb
145
+ - spec/spec_helper.rb