incognia_api 1.2.0 → 2.0.0

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
  SHA256:
3
- metadata.gz: f17e031979fde13ac3ac30d9cc3ebf9369da407eef0aec67e0313dcfa9c1ecd3
4
- data.tar.gz: ecbd6959f1546fa24d5d85d5f7e95e8980539ab2fddca46838e46076571bc8b4
3
+ metadata.gz: 3fb783b99b2bfd7a392bc8208308f946ad62aaf2aa538bdfa291e86ac5b86d5a
4
+ data.tar.gz: 0aa4f32696dfffe2f15deecd250d4faf4118ccd647b293d10b8fe88b3cb0ed07
5
5
  SHA512:
6
- metadata.gz: 0f9945bb733db1fb2015636f85b3342684635a027ff70d8bd493887365085b893877ca4ea77d3f8c4e937cccfd2c4cf580bcf8223505bbfdebf5b61ada4684fe
7
- data.tar.gz: 4f85f0ab80d4f9ca47509a6ff9edf78514990de7d0d25a3cd6c8e2a90fdbc904516d554189ad29651aae120b20ee5afe61e7ecfa80bb3f0b511c0882664d0cdb
6
+ metadata.gz: '074959772f96adda32ab81e8b21ae024d1cd820c90e2e81997e2abd878c86b50967ce6131ff44bc55764c9d1140de4ecb5b4889a0de6f862bb7f156e91b7f1e8'
7
+ data.tar.gz: 34638c23171aa08dc79b8141f036275b843286225871c2d8f138fd2abcca821594d31d9f76c03c030e9d420a30f071c96b01b03a846b0b7ad0c1a44a7856c639
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [2.0.0] - 2024-11-12
4
+
5
+ - Remove support for instance usage of Incognia::Api
6
+ - Remove invalid feedback types
7
+ - Remove support for sending feedback timestamp
8
+
9
+ ## [1.3.0] - 2024-11-12
10
+
11
+ - Add support for general configuration and use Incognia::Api as a static class
12
+
3
13
  ## [1.2.0] - 2024-08-26
4
14
 
5
15
  - Removes the requirement to send installation id to register signup, login and payment
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- incognia_api (1.2.0)
4
+ incognia_api (2.0.0)
5
5
  faraday (~> 1.10)
6
6
  faraday_middleware (~> 1.2)
7
7
 
data/README.md CHANGED
@@ -35,16 +35,18 @@ Or install it yourself as:
35
35
 
36
36
  ### Configuration
37
37
 
38
- Before using the API client, you must initialize it using credentials obtained
39
- from the [Incognia dashboard]():
38
+ Before using the API client, you must configure it using credentials obtained
39
+ from the [Incognia dashboard](https://dash.incognia.com/):
40
40
 
41
41
  ```ruby
42
- api = Incognia::Api.new(client_id: "your-client-id", client_secret:
43
- "your-client-secret")
42
+ Incognia.configure(client_id: ENV['INCOGNIA_CLIENT_ID'], client_secret: ENV['INCOGNIA_CLIENT_SECRET'])
44
43
 
44
+ # Incognia.configure(client_id: "your-client-id", client_secret: "your-client-secret")
45
45
  ```
46
46
 
47
- For sandbox credentials, refer to the [API testing guide]().
47
+ For sandbox credentials, refer to the [API testing guide](https://developer.incognia.com/).
48
+
49
+ :bulb: For Rails applications it's recommended to create an initializer file, for example `config/initializers/incognia.rb`.
48
50
 
49
51
 
50
52
  ### Registering a Signup
@@ -55,7 +57,7 @@ This method registers a new signup for the given request token and address, retu
55
57
  address = Incognia::Address.new(line: "West 34th Street, New York City, NY 10001")
56
58
  request_token = "WlMksW+jh5GPhqWBorsV8yDihoSHHpmt+DpjJ7eYxpHhuO/5tuHTuA..."
57
59
 
58
- assessment = api.register_signup(
60
+ assessment = Incognia::Api.register_signup(
59
61
  request_token: request_token,
60
62
  address: address
61
63
  )
@@ -71,7 +73,7 @@ address = Incognia::Address.new(line: "West 34th Street, New York City, NY 10001
71
73
  request_token = "WlMksW+jh5GPhqWBorsV8yDihoSHHpmt+DpjJ7eYxpHhuO/5tuHTuA..."
72
74
  external_id = "7b02736a-7718-4b83-8982-f68fb6f501fa"
73
75
 
74
- assessment = api.register_signup(
76
+ assessment = Incognia::Api.register_signup(
75
77
  request_token: request_token,
76
78
  address: address,
77
79
  external_id: external_id
@@ -88,7 +90,7 @@ This method registers a new login for the given request token and account, retur
88
90
  request_token = "WlMksW+jh5GPhqWBorsV8yDihoSHHpmt+DpjJ7eYxpHhuO/5tuHTuA..."
89
91
  account_id = 'account-identifier-123'
90
92
 
91
- assessment = api.register_login(
93
+ assessment = Incognia::Api.register_login(
92
94
  request_token: request_token,
93
95
  account_id: account_id,
94
96
  )
@@ -104,7 +106,7 @@ request_token = "WlMksW+jh5GPhqWBorsV8yDihoSHHpmt+DpjJ7eYxpHhuO/5tuHTuA..."
104
106
  account_id = 'account-identifier-123'
105
107
  external_id = 'some-external-identifier'
106
108
 
107
- assessment = api.register_login(
109
+ assessment = Incognia::Api.register_login(
108
110
  request_token: request_token,
109
111
  account_id: account_id,
110
112
  external_id: external_id,
@@ -120,7 +122,7 @@ This method registers a new payment for the given request token and account, ret
120
122
  containing the risk assessment and supporting evidence.
121
123
 
122
124
  ```ruby
123
- assessment = api.register_payment(
125
+ assessment = Incognia::Api.register_payment(
124
126
  request_token: 'request-token',
125
127
  account_id: 'account-id'
126
128
  )
@@ -180,7 +182,7 @@ payment_methods = [
180
182
  }
181
183
  ]
182
184
 
183
- assessment = api.register_payment(
185
+ assessment = Incognia::Api.register_payment(
184
186
  request_token: 'request-token',
185
187
  account_id: 'account-id',
186
188
  external_id: 'external-id',
@@ -196,7 +198,7 @@ assessment = api.register_payment(
196
198
 
197
199
  This method registers a feedback event for the given identifiers (optional arguments), returning true when success.
198
200
 
199
- The `timestamp` argument should be a _Time_, _DateTime_ or an _Integer_ being the timestamp in milliseconds.
201
+ The `occurred_at` argument should be a _Time_, _DateTime_ or an date in **RFC 3339** format.
200
202
 
201
203
  The `expires_at` argument should be a _Time_, _DateTime_ or an date in **RFC 3339** format.
202
204
 
@@ -206,7 +208,7 @@ request_token = 'request-token'
206
208
  account_id = 'account-id'
207
209
  occurred_at = DateTime.parse('2024-07-22T15:20:00Z')
208
210
 
209
- success = api.register_feedback(
211
+ success = Incognia::Api.register_feedback(
210
212
  event: Incognia::Constants::FeedbackEvent::ACCOUNT_TAKEOVER,
211
213
  occurred_at: occurred_at,
212
214
  request_token: request_token,
@@ -219,7 +221,7 @@ success = api.register_feedback(
219
221
  For custom fraud, set the value of `event` with the corresponding code:
220
222
 
221
223
  ```ruby
222
- success = api.register_feedback(
224
+ success = Incognia::Api.register_feedback(
223
225
  event: 'custom_fraud_name',
224
226
  occurred_at: occurred_at,
225
227
  request_token: request_token,
@@ -5,83 +5,77 @@ require 'faraday_middleware'
5
5
 
6
6
  module Incognia
7
7
  class Api
8
- # business layer: uses the Client to build domain objects
9
- # raises missing parameters errors
10
- attr_accessor :connection
11
-
12
- def initialize(client_id:, client_secret:)
13
- @connection = Client.new(client_id: client_id,
14
- client_secret: client_secret,
15
- host: "https://api.incognia.com/api")
16
- end
17
-
18
- def register_signup(request_token: nil, address: nil, **opts)
19
- params = { request_token: request_token }.compact
20
- params.merge!(opts)
21
- params.merge!(address&.to_hash) if address
22
-
23
- response = connection.request(
24
- :post,
25
- 'v2/onboarding/signups',
26
- params
27
- )
28
-
29
- SignupAssessment.from_hash(response.body) if response.success?
30
- end
31
-
32
- def register_login(account_id:, request_token: nil, **opts)
33
- params = {
34
- type: :login,
35
- account_id: account_id,
36
- request_token: request_token
37
- }.compact
38
- params.merge!(opts)
39
-
40
- response = connection.request(
41
- :post,
42
- 'v2/authentication/transactions',
43
- params
44
- )
45
-
46
- LoginAssessment.from_hash(response.body) if response.success?
47
- end
48
-
49
- def register_feedback(event:, occurred_at: nil, expires_at: nil, timestamp: nil, **ids)
50
- if !timestamp.nil?
51
- warn("Deprecation warning: use occurred_at instead of timestamp")
8
+ class << self
9
+ # business layer: uses the Client.instance to build domain objects
10
+ # raises missing parameters errors
11
+
12
+ def register_signup(request_token: nil, address: nil, **opts)
13
+ params = { request_token: request_token }.compact
14
+ params.merge!(opts)
15
+ params.merge!(address&.to_hash) if address
16
+
17
+ response = connection.request(
18
+ :post,
19
+ 'v2/onboarding/signups',
20
+ params
21
+ )
22
+
23
+ SignupAssessment.from_hash(response.body) if response.success?
52
24
  end
53
25
 
54
- timestamp = timestamp.strftime('%s%L') if timestamp.respond_to? :strftime
55
- occurred_at = occurred_at.to_datetime.rfc3339 if occurred_at.respond_to? :to_datetime
56
- expires_at = expires_at.to_datetime.rfc3339 if expires_at.respond_to? :to_datetime
26
+ def register_login(account_id:, request_token: nil, **opts)
27
+ params = {
28
+ type: :login,
29
+ account_id: account_id,
30
+ request_token: request_token
31
+ }.compact
32
+ params.merge!(opts)
33
+
34
+ response = connection.request(
35
+ :post,
36
+ 'v2/authentication/transactions',
37
+ params
38
+ )
39
+
40
+ LoginAssessment.from_hash(response.body) if response.success?
41
+ end
57
42
 
58
- params = { event: event, timestamp: timestamp&.to_i, occurred_at: occurred_at, expires_at: expires_at }.compact
59
- params.merge!(ids)
43
+ def register_feedback(event:, occurred_at: nil, expires_at: nil, **ids)
44
+ occurred_at = occurred_at.to_datetime.rfc3339 if occurred_at.respond_to? :to_datetime
45
+ expires_at = expires_at.to_datetime.rfc3339 if expires_at.respond_to? :to_datetime
60
46
 
61
- response = connection.request(
62
- :post,
63
- '/api/v2/feedbacks',
64
- params
65
- )
47
+ params = { event: event, occurred_at: occurred_at, expires_at: expires_at }.compact
48
+ params.merge!(ids)
66
49
 
67
- response.success?
68
- end
50
+ response = connection.request(
51
+ :post,
52
+ '/api/v2/feedbacks',
53
+ params
54
+ )
69
55
 
70
- def register_payment(account_id:, request_token: nil, **opts)
71
- params = {
72
- type: :payment,
73
- account_id: account_id,
74
- request_token: request_token
75
- }.compact
76
- params.merge!(opts)
56
+ response.success?
57
+ end
77
58
 
78
- response = connection.request(
79
- :post,
80
- 'v2/authentication/transactions',
81
- params
82
- )
59
+ def register_payment(account_id:, request_token: nil, **opts)
60
+ params = {
61
+ type: :payment,
62
+ account_id: account_id,
63
+ request_token: request_token
64
+ }.compact
65
+ params.merge!(opts)
66
+
67
+ response = connection.request(
68
+ :post,
69
+ 'v2/authentication/transactions',
70
+ params
71
+ )
72
+
73
+ PaymentAssessment.from_hash(response.body) if response.success?
74
+ end
83
75
 
84
- PaymentAssessment.from_hash(response.body) if response.success?
76
+ def connection
77
+ Client.instance
78
+ end
85
79
  end
86
80
  end
87
81
  end
@@ -1,32 +1,14 @@
1
1
  require "time"
2
+ require "singleton"
2
3
 
3
4
  module Incognia
4
5
  class Client
6
+ include Singleton
5
7
  # TODO:
6
8
  # (ok) http/adapter specific code
7
9
  # (ok) raises network/authentication errors
8
10
  # (ok) handles token refreshing ok
9
11
  # future: handles retrying
10
- attr_reader :connection
11
-
12
- def initialize(client_id:, client_secret:, host:)
13
- @client_id = client_id
14
- @client_secret = client_secret
15
- @host = host
16
-
17
- headers = { 'User-Agent' => "incognia-ruby/#{Incognia::VERSION} " \
18
- "({#{RbConfig::CONFIG['host']}}) " \
19
- "{#{RbConfig::CONFIG['arch']}} " \
20
- "Ruby/#{RbConfig::CONFIG['ruby_version']}" }
21
-
22
- @connection = Faraday.new(host, headers: headers) do |faraday|
23
- faraday.request :json
24
- faraday.response :json, content_type: /\bjson$/
25
- faraday.response :raise_error
26
-
27
- faraday.adapter Faraday.default_adapter
28
- end
29
- end
30
12
 
31
13
  def request(method, endpoint = nil, data = nil, headers = {})
32
14
  json_data = JSON.generate(data) if data
@@ -48,12 +30,29 @@ module Incognia
48
30
  @credentials
49
31
  end
50
32
 
33
+ def connection
34
+ return @connection if @connection
35
+
36
+ headers = { 'User-Agent' => "incognia-ruby/#{Incognia::VERSION} " \
37
+ "({#{RbConfig::CONFIG['host']}}) " \
38
+ "{#{RbConfig::CONFIG['arch']}} " \
39
+ "Ruby/#{RbConfig::CONFIG['ruby_version']}" }
40
+
41
+ @connection = Faraday.new(Incognia.config.host, headers: headers) do |faraday|
42
+ faraday.request :json
43
+ faraday.response :json, content_type: /\bjson$/
44
+ faraday.response :raise_error
45
+
46
+ faraday.adapter Faraday.default_adapter
47
+ end
48
+ end
49
+
51
50
  protected
52
51
 
53
52
  def request_credentials
54
53
  basic_auth = Faraday::Request
55
54
  .lookup_middleware(:basic_auth)
56
- .header(@client_id, @client_secret)
55
+ .header(Incognia.config.client_id, Incognia.config.client_secret)
57
56
 
58
57
  response = connection.send(:post, 'v2/token') do |r|
59
58
  r.headers[Faraday::Request::Authorization::KEY] = basic_auth
@@ -0,0 +1,17 @@
1
+ require 'singleton'
2
+
3
+ module Incognia
4
+ class Configuration
5
+ include Singleton
6
+
7
+ attr_accessor :client_id, :client_secret, :host
8
+
9
+ def configure(client_id:, client_secret:, host: nil)
10
+ @client_id = client_id
11
+ @client_secret = client_secret
12
+ @host = host || 'https://api.incognia.com/api'
13
+
14
+ self
15
+ end
16
+ end
17
+ end
@@ -1,16 +1,13 @@
1
1
  module Incognia
2
2
  module Constants
3
3
  module FeedbackEvent
4
+ ACCOUNT_ALLOWED = 'account_allowed'.freeze
4
5
  ACCOUNT_TAKEOVER = 'account_takeover'.freeze
5
- CHALLENGE_FAILED = 'challenge_failed'.freeze
6
- CHALLENGE_PASSED = 'challenge_passed'.freeze
7
6
  CHARGEBACK = 'chargeback'.freeze
8
7
  CHARGEBACK_NOTIFICATION = 'chargeback_notification'.freeze
9
- IDENTITY_FRAUD = 'identity_fraud'.freeze
10
- MPOS_FRAUD = 'mpos_fraud'.freeze
11
- PASSWORD_CHANGE_FAILED = 'password_change_failed'.freeze
12
- PASSWORD_CHANGED_SUCCESSFULLY = 'password_changed_successfully'.freeze
13
8
  PROMOTION_ABUSE = 'promotion_abuse'.freeze
9
+ DEVICE_ALLOWED = 'device_allowed'.freeze
10
+ IDENTITY_FRAUD = 'identity_fraud'.freeze
14
11
  RESET = 'reset'.freeze
15
12
  VERIFIED = 'verified'.freeze
16
13
 
@@ -18,7 +15,12 @@ module Incognia
18
15
  SIGNUP_DECLINED = 'signup_declined'.freeze
19
16
 
20
17
  LOGIN_ACCEPTED = 'login_accepted'.freeze
18
+ LOGIN_ACCEPTED_BY_DEVICE_VERIFICATION = 'login_accepted_by_device_verification'.freeze
19
+ LOGIN_ACCEPTED_BY_FACIAL_BIOMETRICS = 'login_accepted_by_facial_biometrics'.freeze
20
+ LOGIN_ACCEPTED_BY_MANUAL_REVIEW = 'login_accepted_by_manual_review'.freeze
21
21
  LOGIN_DECLINED = 'login_declined'.freeze
22
+ LOGIN_DECLINED_BY_FACIAL_BIOMETRICS = 'login_declined_by_facial_biometrics'.freeze
23
+ LOGIN_DECLINED_BY_MANUAL_REVIEW = 'login_declined_by_manual_review'.freeze
22
24
 
23
25
  PAYMENT_ACCEPTED = 'payment_accepted'.freeze
24
26
  PAYMENT_ACCEPTED_BY_CONTROL_GROUP = 'payment_accepted_by_control_group'.freeze
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Incognia
4
- VERSION = "1.2.0"
4
+ VERSION = "2.0.0"
5
5
  end
data/lib/incognia_api.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "incognia_api/configuration"
3
4
  require_relative "incognia_api/version"
4
5
  require_relative "incognia_api/client"
5
6
  require_relative "incognia_api/util"
@@ -15,6 +16,14 @@ require_relative "incognia_api/resources/credentials"
15
16
  require_relative "incognia_api/constants/feedback_event"
16
17
 
17
18
  module Incognia
19
+ def self.configure(**args)
20
+ config.configure(**args)
21
+ end
22
+
23
+ def self.config
24
+ Configuration.instance
25
+ end
26
+
18
27
  class APIError < StandardError
19
28
  attr_reader :message, :errors, :status
20
29
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: incognia_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Cavalcanti
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-26 00:00:00.000000000 Z
11
+ date: 2024-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -63,6 +63,7 @@ files:
63
63
  - lib/incognia_api/address.rb
64
64
  - lib/incognia_api/api.rb
65
65
  - lib/incognia_api/client.rb
66
+ - lib/incognia_api/configuration.rb
66
67
  - lib/incognia_api/constants/feedback_event.rb
67
68
  - lib/incognia_api/resources/api_resource.rb
68
69
  - lib/incognia_api/resources/credentials.rb
@@ -77,7 +78,7 @@ metadata:
77
78
  homepage_uri: https://github.com/inloco/incognia-ruby
78
79
  source_code_uri: https://github.com/inloco/incognia-ruby
79
80
  changelog_uri: https://github.com/inloco/incognia-ruby/blob/master/
80
- post_install_message:
81
+ post_install_message:
81
82
  rdoc_options: []
82
83
  require_paths:
83
84
  - lib
@@ -92,8 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
93
  - !ruby/object:Gem::Version
93
94
  version: '0'
94
95
  requirements: []
95
- rubygems_version: 3.1.6
96
- signing_key:
96
+ rubygems_version: 3.4.19
97
+ signing_key:
97
98
  specification_version: 4
98
99
  summary: Official Ruby lib for communicating with Incognia API
99
100
  test_files: []