minfraud 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6a55c03cbdb1487ae09c4e1e8b0286b53f49ae98
4
- data.tar.gz: 436b76d31314d1971fd511cce43e05d1cf80f1f4
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YThlNDg5YmIwNzY5NjIyZjEyMWE4ODQwNjY0NWQxMTZhOGI3ZTdiNQ==
5
+ data.tar.gz: !binary |-
6
+ ZGZlMWUwYTI3ZGExNTk0MWVlMWUyNTI5Mzc0OTgwNGFkZWNmMTgyZQ==
5
7
  SHA512:
6
- metadata.gz: febcdcdfc8828f99424d485f041f621ef9763b2eca5f2b7a401b5ad54b2f1b312711d47c782cd8f986848fdac46a749e17621e88f86bb98e9e6693cde3d8980a
7
- data.tar.gz: 28279d249f2cc2495e4223337900f90c875eb48e6a667a75c994a8dc8ff19a9d0512b1914eac748e60a8a16a0d0973ee179f77c77657b4dad1185fdd2199cb3b
8
+ metadata.gz: !binary |-
9
+ YmY2ZWE4MTZkOTBkYTc3MjkyZjZjNTNiZjFlNmU0YWQ3YWY5Y2IwOGFlZDYx
10
+ ZDVjMzMwMjRkZjY5YjJjNmNmZTBmZjdmMTEwMjYzNWU4ZGI0ZjMyOGFlMjhk
11
+ NWI2NjFhMTRjMjdhMjQ5OWQxMzU5ZWMzMzU0M2FhMzg2ZTNhODI=
12
+ data.tar.gz: !binary |-
13
+ NGMzZGE3YTBlNjRhN2Y3ZTM1NGEzYmI0ZjI5YTU4ZGM4MjRhZDBjYjZkMmVj
14
+ MWVjMTQ1YmM0YzAzMjRjYThlYzgwYmIyYmI1MTRmMzg2YjQ2MTEwNzg0MDA4
15
+ YTg4N2U2NzYyYmIzMDQ5MWJkZGRlMWFiOGUxNjQ3Y2Q3ZGJiOWE=
@@ -0,0 +1,5 @@
1
+ # Minfraud Changelog
2
+
3
+ ## v1.0.2
4
+
5
+ * Adds support for Ruby >= 1.9
@@ -45,11 +45,10 @@ 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
+ # @note In case when params is a Hash of components it just assigns them to the corresponding instance variables
50
49
  # @return [Minfraud::Assessments] Assessments instance
51
50
  def initialize(params = {}, resolver = ::Minfraud::Resolver)
52
- resolver.assign(context: self, params: params)
51
+ resolver.assign(self, params)
53
52
  end
54
53
 
55
54
  # @!macro [attach] define
@@ -59,7 +58,7 @@ module Minfraud
59
58
  # @return [Minfraud::HTTPService::Response] Wrapped minFraud response
60
59
  def self.define(endpoint)
61
60
  define_method(endpoint) do
62
- raw = request.perform(verb: :post, endpoint: endpoint, body: request_body)
61
+ raw = request.perform(verb: :post, endpoint: endpoint.to_s, body: request_body)
63
62
  response = ::Minfraud::HTTPService::Response.new(
64
63
  status: raw.status.to_i,
65
64
  body: raw.body,
@@ -78,7 +77,10 @@ module Minfraud
78
77
  # Creates a unified request body from components converted to JSON
79
78
  # @return [Hash] Request body
80
79
  def request_body
81
- MAPPING.keys.inject({}) { |mem, e| mem.merge!(e.to_s => send(e)&.to_json) }
80
+ MAPPING.keys.inject({}) do |mem, e|
81
+ next mem unless value = send(e)
82
+ mem.merge!(e.to_s => value.to_json)
83
+ end
82
84
  end
83
85
 
84
86
  # Creates memoized Minfraud::HTTPService::Request instance
@@ -46,7 +46,7 @@ module Minfraud
46
46
  attr_accessor :phone_country_code
47
47
 
48
48
  # Creates Minfraud::Components::Addressable instance
49
- # This class is used as a parent class for Billing and Shipping components
49
+ # @note This class is used as a parent class for Billing and Shipping components
50
50
  # @param [Hash] params hash of parameters
51
51
  # @return [Minfraud::Components::Addressable] an Addressable instance
52
52
  def initialize(params = {})
@@ -1,12 +1,22 @@
1
1
  module Minfraud
2
2
  module Components
3
- # Note: This class is used as a parent class for all other components
4
- # It defines a method which is used for basic JSON representation of PORO objects
3
+ # @note This class is used as a parent class for all other components
4
+ # @note It defines a method which is used for basic JSON representation of PORO objects
5
5
  class Base
6
6
  # @return [Hash] a JSON representation of component attributes
7
7
  def to_json
8
- instance_variables.inject({}) { |mem, e| mem.merge!(e.to_s.gsub(/@/, '') => instance_variable_get(e).to_s) }
9
- .delete_if { |_, v| v.empty? }
8
+ instance_variables.inject({}) { |mem, e| populate!(mem, e) }
9
+ end
10
+
11
+ private
12
+
13
+ # @note This method may modify passed hash. Non-existing instance variables are ignored
14
+ # @param [Hash] hash an accumulator
15
+ # @param [Symbol] v_sym an instance variable symbol
16
+ # @return [Hash] a hash containing a JSON representation of instance variable name and it's value
17
+ def populate!(hash, v_sym)
18
+ return hash unless value = instance_variable_get(v_sym)
19
+ hash.merge!(v_sym.to_s.gsub(/@/, '') => value.to_s)
10
20
  end
11
21
  end
12
22
  end
@@ -16,13 +16,7 @@ module Minfraud
16
16
  attr_accessor :time
17
17
 
18
18
  # @attribute type
19
- # @return [String] The type of event being scored. The valid types are:
20
- # => account_creation
21
- # => account_login
22
- # => purchase
23
- # => recurring_purchase
24
- # => referral
25
- # => survey
19
+ # @return [String] The type of event being scored
26
20
  enum_accessor :type, [:account_creation, :account_login, :purchase, :recurring_purchase, :referral, :survey]
27
21
 
28
22
  # Creates Minfraud::Components::Event instance
@@ -4,10 +4,6 @@ module Minfraud
4
4
  include ::Minfraud::Enum
5
5
  # @attribute delivery_speed
6
6
  # @return [String] The shipping delivery speed for the order. The valid values are:
7
- # => same_day
8
- # => overnight
9
- # => expedited
10
- # => standard
11
7
  enum_accessor :delivery_speed, [:same_day, :overnight, :expedited, :standard]
12
8
 
13
9
  # Creates Minfraud::Components::Shipping instance
@@ -25,7 +25,7 @@ module Minfraud
25
25
  define_method("#{attribute}") { instance_variable_get("@#{attribute}") }
26
26
  define_method "#{attribute}=" do |value|
27
27
  raise NotEnumValueError, 'Value is not permitted' if value && !self.class.mapping[attribute].include?(value.intern)
28
- instance_variable_set("@#{attribute}", value&.intern)
28
+ instance_variable_set("@#{attribute}", value ? value.intern : nil)
29
29
  end
30
30
  end
31
31
  end
@@ -7,7 +7,7 @@ module Minfraud
7
7
  def inspect(response)
8
8
  return response if response.status == 200
9
9
 
10
- raise *STATUS_CODES.fetch(response.code&.intern, [ServerError, 'Service not available'])
10
+ raise *STATUS_CODES.fetch(response.code, [ServerError, 'Server error'])
11
11
  end
12
12
 
13
13
  # A hash that maps status codes returned by minFraud with errors & messages
@@ -14,7 +14,7 @@ module Minfraud
14
14
  # Creates Minfraud::HTTPService::Request instance
15
15
  # @param [Hash] params hash of parameters
16
16
  # @return [Minfraud::HTTPService::Request] Request instance
17
- def initialize(params)
17
+ def initialize(params = {})
18
18
  @middleware = params[:middleware]
19
19
  @server = params[:server]
20
20
  end
@@ -16,16 +16,16 @@ module Minfraud
16
16
  # Creates Minfraud::HTTPService::Response instance
17
17
  # @param [Hash] params hash of parameters
18
18
  # @return [Minfraud::HTTPService::Response] Response instance
19
- def initialize(params)
19
+ def initialize(params = {})
20
20
  @status = params[:status]
21
21
  @body = params[:body]
22
22
  @headers = params[:headers]
23
23
  end
24
24
 
25
25
  # Returns minFraud specific response code
26
- # @return [String] minFraud specific request code
26
+ # @return [Symbol] minFraud specific request code
27
27
  def code
28
- body.code if body.respond_to?(:code)
28
+ body.code.intern if body.respond_to?(:code) && body.code
29
29
  end
30
30
  end
31
31
  end
@@ -4,8 +4,8 @@ module Minfraud
4
4
  # @param [Object] context an object for variable assignment
5
5
  # @param [Hash] params a hash of parameters
6
6
  # @return [Array] a list of supplied params
7
- # Note: Raises RequestFormatError once unpermitted key is met
8
- def assign(context:, params:)
7
+ # @note Raises RequestFormatError once unpermitted key is met
8
+ def assign(context, params)
9
9
  Array(params).each do |key, value|
10
10
  raise RequestFormatError, "#{key} does not belong to request document format" unless MAPPING[key]
11
11
 
@@ -1,3 +1,3 @@
1
1
  module Minfraud
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -13,13 +13,16 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/kushniryb/minfraud-api-v2"
14
14
  spec.license = "MIT"
15
15
 
16
+ spec.required_ruby_version = '>= 1.9'
17
+
16
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
19
  spec.bindir = "exe"
18
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
21
  spec.require_paths = ["lib"]
20
22
 
21
- spec.add_runtime_dependency 'faraday'
22
- spec.add_runtime_dependency 'faraday_middleware'
23
+ spec.add_runtime_dependency 'faraday', '~> 0.9', '>= 0.9.1'
24
+ spec.add_runtime_dependency 'faraday_middleware', '~> 0.9', '>= 0.9.1'
25
+ spec.add_runtime_dependency 'hashie', '~> 3.0'
23
26
  spec.add_development_dependency "bundler", "~> 1.12"
24
27
  spec.add_development_dependency "rake", "~> 10.0"
25
28
  spec.add_development_dependency "rspec", "~> 3.0"
metadata CHANGED
@@ -1,83 +1,109 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minfraud
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
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-05 00:00:00.000000000 Z
11
+ date: 2016-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.9'
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.1
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - ">="
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
30
+ - - ! '>='
25
31
  - !ruby/object:Gem::Version
26
- version: '0'
32
+ version: 0.9.1
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: faraday_middleware
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - ">="
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '0.9'
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: 0.9.1
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'
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: 0.9.1
53
+ - !ruby/object:Gem::Dependency
54
+ name: hashie
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ~>
32
58
  - !ruby/object:Gem::Version
33
- version: '0'
59
+ version: '3.0'
34
60
  type: :runtime
35
61
  prerelease: false
36
62
  version_requirements: !ruby/object:Gem::Requirement
37
63
  requirements:
38
- - - ">="
64
+ - - ~>
39
65
  - !ruby/object:Gem::Version
40
- version: '0'
66
+ version: '3.0'
41
67
  - !ruby/object:Gem::Dependency
42
68
  name: bundler
43
69
  requirement: !ruby/object:Gem::Requirement
44
70
  requirements:
45
- - - "~>"
71
+ - - ~>
46
72
  - !ruby/object:Gem::Version
47
73
  version: '1.12'
48
74
  type: :development
49
75
  prerelease: false
50
76
  version_requirements: !ruby/object:Gem::Requirement
51
77
  requirements:
52
- - - "~>"
78
+ - - ~>
53
79
  - !ruby/object:Gem::Version
54
80
  version: '1.12'
55
81
  - !ruby/object:Gem::Dependency
56
82
  name: rake
57
83
  requirement: !ruby/object:Gem::Requirement
58
84
  requirements:
59
- - - "~>"
85
+ - - ~>
60
86
  - !ruby/object:Gem::Version
61
87
  version: '10.0'
62
88
  type: :development
63
89
  prerelease: false
64
90
  version_requirements: !ruby/object:Gem::Requirement
65
91
  requirements:
66
- - - "~>"
92
+ - - ~>
67
93
  - !ruby/object:Gem::Version
68
94
  version: '10.0'
69
95
  - !ruby/object:Gem::Dependency
70
96
  name: rspec
71
97
  requirement: !ruby/object:Gem::Requirement
72
98
  requirements:
73
- - - "~>"
99
+ - - ~>
74
100
  - !ruby/object:Gem::Version
75
101
  version: '3.0'
76
102
  type: :development
77
103
  prerelease: false
78
104
  version_requirements: !ruby/object:Gem::Requirement
79
105
  requirements:
80
- - - "~>"
106
+ - - ~>
81
107
  - !ruby/object:Gem::Version
82
108
  version: '3.0'
83
109
  description:
@@ -87,9 +113,10 @@ executables: []
87
113
  extensions: []
88
114
  extra_rdoc_files: []
89
115
  files:
90
- - ".gitignore"
91
- - ".rspec"
92
- - ".travis.yml"
116
+ - .gitignore
117
+ - .rspec
118
+ - .travis.yml
119
+ - CHANGELOG.md
93
120
  - CODE_OF_CONDUCT.md
94
121
  - Gemfile
95
122
  - LICENSE.txt
@@ -131,19 +158,18 @@ require_paths:
131
158
  - lib
132
159
  required_ruby_version: !ruby/object:Gem::Requirement
133
160
  requirements:
134
- - - ">="
161
+ - - ! '>='
135
162
  - !ruby/object:Gem::Version
136
- version: '0'
163
+ version: '1.9'
137
164
  required_rubygems_version: !ruby/object:Gem::Requirement
138
165
  requirements:
139
- - - ">="
166
+ - - ! '>='
140
167
  - !ruby/object:Gem::Version
141
168
  version: '0'
142
169
  requirements: []
143
170
  rubyforge_project:
144
- rubygems_version: 2.6.6
171
+ rubygems_version: 2.4.3
145
172
  signing_key:
146
173
  specification_version: 4
147
174
  summary: Ruby interface to the MaxMind minFraud v2.0 API services
148
175
  test_files: []
149
- has_rdoc: