minfraud 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +22 -0
  5. data/CHANGELOG.md +42 -0
  6. data/CODE_OF_CONDUCT.md +49 -0
  7. data/Gemfile +12 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.dev.md +4 -0
  10. data/README.md +178 -0
  11. data/Rakefile +6 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +8 -0
  14. data/lib/maxmind/geoip2/model/city.rb +99 -0
  15. data/lib/maxmind/geoip2/model/country.rb +94 -0
  16. data/lib/maxmind/geoip2/model/insights.rb +38 -0
  17. data/lib/maxmind/geoip2/record/abstract.rb +46 -0
  18. data/lib/maxmind/geoip2/record/city.rb +62 -0
  19. data/lib/maxmind/geoip2/record/continent.rb +61 -0
  20. data/lib/maxmind/geoip2/record/country.rb +78 -0
  21. data/lib/maxmind/geoip2/record/location.rb +97 -0
  22. data/lib/maxmind/geoip2/record/maxmind.rb +41 -0
  23. data/lib/maxmind/geoip2/record/place.rb +52 -0
  24. data/lib/maxmind/geoip2/record/postal.rb +54 -0
  25. data/lib/maxmind/geoip2/record/represented_country.rb +47 -0
  26. data/lib/maxmind/geoip2/record/subdivision.rb +72 -0
  27. data/lib/maxmind/geoip2/record/traits.rb +224 -0
  28. data/lib/minfraud.rb +51 -0
  29. data/lib/minfraud/assessments.rb +101 -0
  30. data/lib/minfraud/components/account.rb +23 -0
  31. data/lib/minfraud/components/addressable.rb +67 -0
  32. data/lib/minfraud/components/base.rb +35 -0
  33. data/lib/minfraud/components/billing.rb +5 -0
  34. data/lib/minfraud/components/credit_card.rb +52 -0
  35. data/lib/minfraud/components/custom_inputs.rb +14 -0
  36. data/lib/minfraud/components/device.rb +38 -0
  37. data/lib/minfraud/components/email.rb +21 -0
  38. data/lib/minfraud/components/event.rb +44 -0
  39. data/lib/minfraud/components/order.rb +52 -0
  40. data/lib/minfraud/components/payment.rb +152 -0
  41. data/lib/minfraud/components/report/transaction.rb +69 -0
  42. data/lib/minfraud/components/shipping.rb +18 -0
  43. data/lib/minfraud/components/shopping_cart.rb +30 -0
  44. data/lib/minfraud/components/shopping_cart_item.rb +33 -0
  45. data/lib/minfraud/enum.rb +34 -0
  46. data/lib/minfraud/error_handler.rb +65 -0
  47. data/lib/minfraud/errors.rb +10 -0
  48. data/lib/minfraud/http_service.rb +30 -0
  49. data/lib/minfraud/http_service/request.rb +37 -0
  50. data/lib/minfraud/http_service/response.rb +64 -0
  51. data/lib/minfraud/model/abstract.rb +20 -0
  52. data/lib/minfraud/model/address.rb +52 -0
  53. data/lib/minfraud/model/billing_address.rb +11 -0
  54. data/lib/minfraud/model/credit_card.rb +75 -0
  55. data/lib/minfraud/model/device.rb +54 -0
  56. data/lib/minfraud/model/disposition.rb +35 -0
  57. data/lib/minfraud/model/email.rb +54 -0
  58. data/lib/minfraud/model/email_domain.rb +24 -0
  59. data/lib/minfraud/model/error.rb +28 -0
  60. data/lib/minfraud/model/factors.rb +24 -0
  61. data/lib/minfraud/model/geoip2_location.rb +25 -0
  62. data/lib/minfraud/model/insights.rb +68 -0
  63. data/lib/minfraud/model/ip_address.rb +82 -0
  64. data/lib/minfraud/model/issuer.rb +49 -0
  65. data/lib/minfraud/model/score.rb +76 -0
  66. data/lib/minfraud/model/score_ip_address.rb +23 -0
  67. data/lib/minfraud/model/shipping_address.rb +30 -0
  68. data/lib/minfraud/model/subscores.rb +156 -0
  69. data/lib/minfraud/model/warning.rb +63 -0
  70. data/lib/minfraud/report.rb +38 -0
  71. data/lib/minfraud/resolver.rb +33 -0
  72. data/lib/minfraud/version.rb +3 -0
  73. data/minfraud.gemspec +29 -0
  74. metadata +198 -0
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'minfraud/model/abstract'
4
+
5
+ module Minfraud
6
+ module Model
7
+ # Warning about the minFraud request.
8
+ #
9
+ # Although more codes may be added in the future, the current warning codes
10
+ # are:
11
+ #
12
+ # * BILLING_CITY_NOT_FOUND - the billing city could not be found in our
13
+ # database.
14
+ # * BILLING_COUNTRY_MISSING - billing address information was provided
15
+ # without providing a billing country.
16
+ # * BILLING_COUNTRY_NOT_FOUND - the billing country could not be found in
17
+ # our database.
18
+ # * BILLING_POSTAL_NOT_FOUND - the billing postal could not be found in our
19
+ # database.
20
+ # * INPUT_INVALID - the value associated with the key does not meet the
21
+ # required constraints, e.g., "United States" in a field that requires a
22
+ # two-letter country code.
23
+ # * INPUT_UNKNOWN - an unknown key was encountered in the request body.
24
+ # * IP_ADDRESS_NOT_FOUND - the IP address could not be geolocated.
25
+ # * SHIPPING_COUNTRY_MISSING - shipping address information was provided
26
+ # without providing a shipping country.
27
+ # * SHIPPING_CITY_NOT_FOUND - the shipping city could not be found in our
28
+ # database.
29
+ # * SHIPPING_COUNTRY_NOT_FOUND - the shipping country could not be found in
30
+ # our database.
31
+ # * SHIPPING_POSTAL_NOT_FOUND - the shipping postal could not be found in
32
+ # our database.
33
+ class Warning < Abstract
34
+ # This value is a machine-readable code identifying the warning.
35
+ #
36
+ # @return [String]
37
+ attr_reader :code
38
+
39
+ # This property provides a human-readable explanation of the warning. The
40
+ # description may change at any time and should not be matched against.
41
+ #
42
+ # @return [String]
43
+ attr_reader :warning
44
+
45
+ # A JSON Pointer to the input field that the warning is associated with.
46
+ # For instance, if the warning was about the billing city, this would be
47
+ # '/billing/city'. If it was for the price in the second shopping cart
48
+ # item, it would be '/shopping_cart/1/price'.
49
+ #
50
+ # @return [String, nil]
51
+ attr_reader :input_pointer
52
+
53
+ # @!visibility private
54
+ def initialize(record)
55
+ super(record)
56
+
57
+ @code = get('code')
58
+ @warning = get('warning')
59
+ @input_pointer = get('input_pointer')
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,38 @@
1
+ module Minfraud
2
+ class Report
3
+ include ::Minfraud::HTTPService
4
+
5
+ # @!attribute transaction
6
+ # @return [Minfraud::Components::Report::Transaction] Report::Transaction component
7
+ attr_accessor :transaction
8
+
9
+ # @param [Hash] params hash of parameters
10
+ # @return [Minfraud::ReportTransaction] ReportTransaction instance
11
+ def initialize(params = {})
12
+ @transaction = params[:transaction]
13
+ end
14
+
15
+ # @method report_transaction
16
+ # Makes a request to the minFraud report transactions API.
17
+ # Raises an error in case of invalid response.
18
+ # @return [nil]
19
+ def report_transaction
20
+ raw = request.perform(verb: :post, endpoint: 'transactions/report', body: @transaction.to_json)
21
+
22
+ response = ::Minfraud::HTTPService::Response.new(
23
+ status: raw.status.to_i,
24
+ body: raw.body,
25
+ headers: raw.headers
26
+ )
27
+ ::Minfraud::ErrorHandler.examine(response)
28
+
29
+ return nil
30
+ end
31
+
32
+ # Creates memoized Minfraud::HTTPService::Request instance
33
+ # @return [Minfraud::HTTPService::Request] Request instance based on configuration params
34
+ def request
35
+ @request ||= Request.new(::Minfraud::HTTPService.configuration)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,33 @@
1
+ module Minfraud
2
+ module Resolver
3
+ class << self
4
+ # @param [Object] context an object for variable assignment
5
+ # @param [Hash] params a hash of parameters
6
+ # @return [Array] a list of supplied params
7
+ # @note Raises RequestFormatError once unpermitted key is met
8
+ def assign(context, params)
9
+ Array(params).each do |key, value|
10
+ raise RequestFormatError, "#{key} does not belong to request document format" unless MAPPING[key]
11
+
12
+ entity = MAPPING[key].new(value) unless value.is_a?(MAPPING[key])
13
+ context.send("#{key}=", entity || value)
14
+ end
15
+ end
16
+ end
17
+
18
+ # Mapping between components & minFraud request keys
19
+ MAPPING = {
20
+ account: ::Minfraud::Components::Account,
21
+ billing: ::Minfraud::Components::Billing,
22
+ credit_card: ::Minfraud::Components::CreditCard,
23
+ custom_inputs: ::Minfraud::Components::CustomInputs,
24
+ device: ::Minfraud::Components::Device,
25
+ email: ::Minfraud::Components::Email,
26
+ event: ::Minfraud::Components::Event,
27
+ order: ::Minfraud::Components::Order,
28
+ payment: ::Minfraud::Components::Payment,
29
+ shipping: ::Minfraud::Components::Shipping,
30
+ shopping_cart: ::Minfraud::Components::ShoppingCart,
31
+ }
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Minfraud
2
+ VERSION = '1.1.0'
3
+ end
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path('lib', File.dirname(File.realpath(__FILE__)))
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'minfraud/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'minfraud'
8
+ spec.version = Minfraud::VERSION
9
+ spec.authors = ['kushnir.yb']
10
+ spec.email = ['support@maxmind.com']
11
+
12
+ spec.summary = %q(Ruby interface to the MaxMind minFraud v2.0 API services)
13
+ spec.homepage = 'https://github.com/maxmind/minfraud-api-ruby'
14
+ spec.license = 'MIT'
15
+
16
+ spec.required_ruby_version = '>= 1.9'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_runtime_dependency 'faraday', '>= 0.9.1', '< 2.0'
24
+ spec.add_runtime_dependency 'faraday_middleware', '>= 0.9.1', '< 2.0'
25
+
26
+ spec.add_development_dependency 'bundler', '>= 1.16'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minfraud
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kushnir.yb
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.1
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.1
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: faraday_middleware
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.9.1
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.9.1
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '2.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '1.16'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '1.16'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '3.0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '3.0'
95
+ description:
96
+ email:
97
+ - support@maxmind.com
98
+ executables: []
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - ".gitignore"
103
+ - ".rspec"
104
+ - ".travis.yml"
105
+ - CHANGELOG.md
106
+ - CODE_OF_CONDUCT.md
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.dev.md
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/maxmind/geoip2/model/city.rb
115
+ - lib/maxmind/geoip2/model/country.rb
116
+ - lib/maxmind/geoip2/model/insights.rb
117
+ - lib/maxmind/geoip2/record/abstract.rb
118
+ - lib/maxmind/geoip2/record/city.rb
119
+ - lib/maxmind/geoip2/record/continent.rb
120
+ - lib/maxmind/geoip2/record/country.rb
121
+ - lib/maxmind/geoip2/record/location.rb
122
+ - lib/maxmind/geoip2/record/maxmind.rb
123
+ - lib/maxmind/geoip2/record/place.rb
124
+ - lib/maxmind/geoip2/record/postal.rb
125
+ - lib/maxmind/geoip2/record/represented_country.rb
126
+ - lib/maxmind/geoip2/record/subdivision.rb
127
+ - lib/maxmind/geoip2/record/traits.rb
128
+ - lib/minfraud.rb
129
+ - lib/minfraud/assessments.rb
130
+ - lib/minfraud/components/account.rb
131
+ - lib/minfraud/components/addressable.rb
132
+ - lib/minfraud/components/base.rb
133
+ - lib/minfraud/components/billing.rb
134
+ - lib/minfraud/components/credit_card.rb
135
+ - lib/minfraud/components/custom_inputs.rb
136
+ - lib/minfraud/components/device.rb
137
+ - lib/minfraud/components/email.rb
138
+ - lib/minfraud/components/event.rb
139
+ - lib/minfraud/components/order.rb
140
+ - lib/minfraud/components/payment.rb
141
+ - lib/minfraud/components/report/transaction.rb
142
+ - lib/minfraud/components/shipping.rb
143
+ - lib/minfraud/components/shopping_cart.rb
144
+ - lib/minfraud/components/shopping_cart_item.rb
145
+ - lib/minfraud/enum.rb
146
+ - lib/minfraud/error_handler.rb
147
+ - lib/minfraud/errors.rb
148
+ - lib/minfraud/http_service.rb
149
+ - lib/minfraud/http_service/request.rb
150
+ - lib/minfraud/http_service/response.rb
151
+ - lib/minfraud/model/abstract.rb
152
+ - lib/minfraud/model/address.rb
153
+ - lib/minfraud/model/billing_address.rb
154
+ - lib/minfraud/model/credit_card.rb
155
+ - lib/minfraud/model/device.rb
156
+ - lib/minfraud/model/disposition.rb
157
+ - lib/minfraud/model/email.rb
158
+ - lib/minfraud/model/email_domain.rb
159
+ - lib/minfraud/model/error.rb
160
+ - lib/minfraud/model/factors.rb
161
+ - lib/minfraud/model/geoip2_location.rb
162
+ - lib/minfraud/model/insights.rb
163
+ - lib/minfraud/model/ip_address.rb
164
+ - lib/minfraud/model/issuer.rb
165
+ - lib/minfraud/model/score.rb
166
+ - lib/minfraud/model/score_ip_address.rb
167
+ - lib/minfraud/model/shipping_address.rb
168
+ - lib/minfraud/model/subscores.rb
169
+ - lib/minfraud/model/warning.rb
170
+ - lib/minfraud/report.rb
171
+ - lib/minfraud/resolver.rb
172
+ - lib/minfraud/version.rb
173
+ - minfraud.gemspec
174
+ homepage: https://github.com/maxmind/minfraud-api-ruby
175
+ licenses:
176
+ - MIT
177
+ metadata: {}
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '1.9'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.7.6.2
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: Ruby interface to the MaxMind minFraud v2.0 API services
198
+ test_files: []