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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3dd67d789e955bf5a4d4bb1b1900439ae8a3b386
4
- data.tar.gz: a6b08f07d7adf54d3df09823bb17b5d53644c354
3
+ metadata.gz: 6a55c03cbdb1487ae09c4e1e8b0286b53f49ae98
4
+ data.tar.gz: 436b76d31314d1971fd511cce43e05d1cf80f1f4
5
5
  SHA512:
6
- metadata.gz: f55e059b7e4d96be4d6b92247c3580bb4b5be5299a4f59264e2eaaf9c913e2b0c4ee1ac2b8786282c8bd255ffb343772e4311115343eff106c4e6c6dc91695aa
7
- data.tar.gz: 85f7b208c1d116987a4754355d7ee4ec2295ea6a151a741eaf29d3280ba4ad8dcf04397817d454cced3cf712abbca6a687da19356cba66445bfb31af8d54d315
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 # => Response status code
70
- result.code # => minFraud specific response code
71
- result.body # => Mashified 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 assigned value does not belong to enum list
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 at [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.
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
@@ -38,7 +38,7 @@ module Minfraud
38
38
  yield self
39
39
  end
40
40
 
41
- # @return [Hash] with the current configuration
41
+ # @return [Hash] current Minfraud configuration
42
42
  def configuration
43
43
  {
44
44
  user_id: @user_id,
@@ -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
- # These methods correspond to the minFraud API endpoints and require the same set of params
54
- # Raises an error in case of invalid response
55
- # @return [Minfraud::HTTPService::Response] Wrapped minFraud response
56
- %w(score insights factors).each do |endpoint|
57
- define_method endpoint do
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] a Account instance
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]
@@ -32,7 +32,7 @@ module Minfraud
32
32
  @transaction_id = params[:transaction_id]
33
33
  @shop_id = params[:shop_id]
34
34
  @time = params[:time]
35
- @type = params[:type]
35
+ self.type = params[:type]
36
36
  end
37
37
  end
38
38
  end
@@ -33,7 +33,7 @@ module Minfraud
33
33
  def initialize(params = {})
34
34
  @was_authorized = params[:was_authorized]
35
35
  @decline_code = params[:decline_code]
36
- @processor = params[:processor]
36
+ self.processor = params[:processor]
37
37
  end
38
38
  end
39
39
  end
@@ -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
- @delivery_speed = params[:delivery_speed]
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
@@ -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(&:to_s)
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' unless self.class.mapping[attribute].include?(value.to_s)
24
- instance_variable_set("@#{attribute}", value.to_s)
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
@@ -1,3 +1,3 @@
1
1
  module Minfraud
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
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.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-03 00:00:00.000000000 Z
11
+ date: 2016-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday