minfraud 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -11
- data/lib/minfraud.rb +1 -1
- data/lib/minfraud/assessments.rb +13 -5
- data/lib/minfraud/components/account.rb +1 -1
- data/lib/minfraud/components/event.rb +1 -1
- data/lib/minfraud/components/payment.rb +1 -1
- data/lib/minfraud/components/shipping.rb +1 -1
- data/lib/minfraud/components/shopping_cart.rb +2 -1
- data/lib/minfraud/enum.rb +8 -4
- data/lib/minfraud/http_service/response.rb +0 -4
- data/lib/minfraud/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a55c03cbdb1487ae09c4e1e8b0286b53f49ae98
|
4
|
+
data.tar.gz: 436b76d31314d1971fd511cce43e05d1cf80f1f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: febcdcdfc8828f99424d485f041f621ef9763b2eca5f2b7a401b5ad54b2f1b312711d47c782cd8f986848fdac46a749e17621e88f86bb98e9e6693cde3d8980a
|
7
|
+
data.tar.gz: 28279d249f2cc2495e4223337900f90c875eb48e6a667a75c994a8dc8ff19a9d0512b1914eac748e60a8a16a0d0973ee179f77c77657b4dad1185fdd2199cb3b
|
data/README.md
CHANGED
@@ -40,11 +40,6 @@ end
|
|
40
40
|
|
41
41
|
## Usage
|
42
42
|
```ruby
|
43
|
-
Minfraud.configure do |c|
|
44
|
-
c.user_id = 'user_id' # your minFraud user id
|
45
|
-
c.license_key = 'license_key' # your minFraud license key
|
46
|
-
end
|
47
|
-
|
48
43
|
# You can either provide a hash of params to initializer
|
49
44
|
assessment = Minfraud::Assessments.new(
|
50
45
|
device: {
|
@@ -57,18 +52,22 @@ assessment = Minfraud::Assessments.new(device: device)
|
|
57
52
|
# or
|
58
53
|
assessment = Minfraud::Assessments.new
|
59
54
|
assessment.device = device
|
55
|
+
# There are multiple components that reflect minFraud request top level keys
|
60
56
|
|
57
|
+
# Some components will raise an error if provided with the wrong values for attributes, e.g
|
58
|
+
event = Minfraud::Components::Event.new(type: 'foobar') # => Minfraud::NotEnumValueError
|
59
|
+
# You can check the list of permitted values for the attribute by calling a class method
|
60
|
+
Minfraud::Components::Event.type_values # => ["account_creation", "account_login", ....]
|
61
61
|
|
62
|
-
# There are multiple components that reflect minFraud request top level keys
|
63
62
|
# You can now call 3 different minFraud endpoints: score, insights, factors
|
64
63
|
assessment.insights
|
65
64
|
assessment.factors
|
66
65
|
|
67
66
|
result = assessment.score # => Minfraud::Response instance
|
68
67
|
|
69
|
-
result.status
|
70
|
-
result.code
|
71
|
-
result.body
|
68
|
+
result.status # => Response status code
|
69
|
+
result.code # => minFraud specific response code
|
70
|
+
result.body # => Mashified body
|
72
71
|
result.headers # => Response headers
|
73
72
|
|
74
73
|
# You can also change data inbetween requests
|
@@ -93,13 +92,13 @@ class AuthorizationError < BaseError; end
|
|
93
92
|
# Raised if minFraud returns an error, or if there is an HTTP error
|
94
93
|
class ServerError < BaseError; end
|
95
94
|
|
96
|
-
# Raised if
|
95
|
+
# Raised if an attribute value doesn't belong to the predefined set of values
|
97
96
|
class NotEnumValueError < BaseError; end
|
98
97
|
```
|
99
98
|
|
100
99
|
## Contributing
|
101
100
|
|
102
|
-
Bug reports and pull requests are welcome on GitHub
|
101
|
+
Bug reports and pull requests are welcome on GitHub [here](https://github.com/kushniryb/minfraud-api-v2). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
103
102
|
|
104
103
|
|
105
104
|
## License
|
data/lib/minfraud.rb
CHANGED
data/lib/minfraud/assessments.rb
CHANGED
@@ -45,16 +45,20 @@ module Minfraud
|
|
45
45
|
|
46
46
|
# @param [Hash] params hash of parameters
|
47
47
|
# @param [Minfraud::Resolver] resolver resolver that maps params to components
|
48
|
+
# In case if params is a Hash of components it just assignes them to corresponding
|
49
|
+
# instance variables
|
48
50
|
# @return [Minfraud::Assessments] Assessments instance
|
49
51
|
def initialize(params = {}, resolver = ::Minfraud::Resolver)
|
50
52
|
resolver.assign(context: self, params: params)
|
51
53
|
end
|
52
54
|
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
|
57
|
-
|
55
|
+
# @!macro [attach] define
|
56
|
+
# @method $1
|
57
|
+
# Makes a request to minFraud $1 endpoint.
|
58
|
+
# Raises an error in case of invalid response
|
59
|
+
# @return [Minfraud::HTTPService::Response] Wrapped minFraud response
|
60
|
+
def self.define(endpoint)
|
61
|
+
define_method(endpoint) do
|
58
62
|
raw = request.perform(verb: :post, endpoint: endpoint, body: request_body)
|
59
63
|
response = ::Minfraud::HTTPService::Response.new(
|
60
64
|
status: raw.status.to_i,
|
@@ -66,6 +70,10 @@ module Minfraud
|
|
66
70
|
end
|
67
71
|
end
|
68
72
|
|
73
|
+
define :score
|
74
|
+
define :insights
|
75
|
+
define :factors
|
76
|
+
|
69
77
|
private
|
70
78
|
# Creates a unified request body from components converted to JSON
|
71
79
|
# @return [Hash] Request body
|
@@ -13,7 +13,7 @@ module Minfraud
|
|
13
13
|
|
14
14
|
# Creates Minfraud::Components::Account instance
|
15
15
|
# @param [Hash] params hash of parameters
|
16
|
-
# @return [Minfraud::Components::Account]
|
16
|
+
# @return [Minfraud::Components::Account] an Account instance
|
17
17
|
def initialize(params = {})
|
18
18
|
@user_id = params[:user_id]
|
19
19
|
@username_md5 = params[:username_md5]
|
@@ -14,7 +14,7 @@ module Minfraud
|
|
14
14
|
# @param [Hash] params hash of parameters
|
15
15
|
# @return [Minfraud::Components::Shipping] Shipping instance
|
16
16
|
def initialize(params = {})
|
17
|
-
|
17
|
+
self.delivery_speed = params[:delivery_speed]
|
18
18
|
super
|
19
19
|
end
|
20
20
|
end
|
@@ -20,9 +20,10 @@ module Minfraud
|
|
20
20
|
private
|
21
21
|
|
22
22
|
# @param [Hash] params hash of parameters for Minfraud::Components::ShoppingCartItem
|
23
|
+
# or Minfraud::Components::ShoppingCartItem instance
|
23
24
|
# @return [Minfraud::Components::ShoppingCart] ShoppingCart instance
|
24
25
|
def resolve(params)
|
25
|
-
ShoppingCartItem.new(params)
|
26
|
+
params.is_a?(ShoppingCartItem) ? params : ShoppingCartItem.new(params)
|
26
27
|
end
|
27
28
|
end
|
28
29
|
end
|
data/lib/minfraud/enum.rb
CHANGED
@@ -5,12 +5,17 @@ module Minfraud
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module ClassMethods
|
8
|
+
# Returns a hash with in the following format: attribute_name => permitted_values
|
9
|
+
# @return [Hash] mapping
|
8
10
|
def mapping
|
9
11
|
@mapping ||= {}
|
10
12
|
end
|
11
13
|
|
14
|
+
# Creates a set of methods for enum-like behaviour of the attribute
|
15
|
+
# @param [Symbol] attribute attribute name
|
16
|
+
# @param [Array] assignable_values a set of values which are permitted
|
12
17
|
def enum_accessor(attribute, assignable_values)
|
13
|
-
mapping[attribute] = assignable_values.map(&:
|
18
|
+
mapping[attribute] = assignable_values.map(&:intern)
|
14
19
|
|
15
20
|
self.class.instance_eval do
|
16
21
|
define_method("#{attribute}_values") { mapping[attribute] }
|
@@ -18,10 +23,9 @@ module Minfraud
|
|
18
23
|
|
19
24
|
self.class_eval do
|
20
25
|
define_method("#{attribute}") { instance_variable_get("@#{attribute}") }
|
21
|
-
|
22
26
|
define_method "#{attribute}=" do |value|
|
23
|
-
raise NotEnumValueError, 'Value is not permitted'
|
24
|
-
instance_variable_set("@#{attribute}", value
|
27
|
+
raise NotEnumValueError, 'Value is not permitted' if value && !self.class.mapping[attribute].include?(value.intern)
|
28
|
+
instance_variable_set("@#{attribute}", value&.intern)
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
@@ -13,10 +13,6 @@ module Minfraud
|
|
13
13
|
# @return [Hash] HTTP response headers
|
14
14
|
attr_reader :headers
|
15
15
|
|
16
|
-
# @attribute code
|
17
|
-
# @return [String] minFraud specific HTTP response code
|
18
|
-
attr_reader :code
|
19
|
-
|
20
16
|
# Creates Minfraud::HTTPService::Response instance
|
21
17
|
# @param [Hash] params hash of parameters
|
22
18
|
# @return [Minfraud::HTTPService::Response] Response instance
|
data/lib/minfraud/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minfraud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kushnir.yb
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|