incognia_api 1.1.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +31 -29
- data/lib/incognia_api/api.rb +76 -56
- data/lib/incognia_api/client.rb +20 -21
- data/lib/incognia_api/configuration.rb +17 -0
- data/lib/incognia_api/version.rb +1 -1
- data/lib/incognia_api.rb +9 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a57edb1d744307af54b8b03d93f7b607f919cf41a66f71d92e3df45db1569b13
|
4
|
+
data.tar.gz: e572c70ff386ddb53c47a7921ff4b9ad1439a27188322c23d2098af1d2f77e03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 942653d86e52ced892b20eaf9684fc0ed43535742f6d265c5b886caa5491bfdaedc56521d38c5ae8ed142d4f8196a13ee117d632c3dd7906977e8bdc3ff2687a
|
7
|
+
data.tar.gz: 15f3d172105df2645d60f94850abee3e280eb5ae425431e9409fb782eb49de21f1003c8d8fe6f8b7ae19e870c9738da97e980631adf8133c12f29ff021578a59
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [1.3.0] - 2024-10-30
|
4
|
+
|
5
|
+
- Add support for general configuration and use Incognia::Api as a static class
|
6
|
+
|
7
|
+
## [1.2.0] - 2024-08-26
|
8
|
+
|
9
|
+
- Removes the requirement to send installation id to register signup, login and payment
|
10
|
+
|
3
11
|
## [1.1.0] - 2024-07-24
|
4
12
|
|
5
13
|
- Add support to passing request_token and occurred_at to #register_feedback
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -35,28 +35,30 @@ Or install it yourself as:
|
|
35
35
|
|
36
36
|
### Configuration
|
37
37
|
|
38
|
-
Before using the API client, you must
|
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
|
-
|
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
|
51
53
|
|
52
|
-
This method registers a new signup for the given
|
54
|
+
This method registers a new signup for the given request token and address, returning a signup assessment, containing the risk assessment and supporting evidence:
|
53
55
|
|
54
56
|
```ruby
|
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 =
|
59
|
-
|
60
|
+
assessment = Incognia::Api.register_signup(
|
61
|
+
request_token: request_token,
|
60
62
|
address: address
|
61
63
|
)
|
62
64
|
|
@@ -68,11 +70,11 @@ It also supports optional parameters, for example:
|
|
68
70
|
|
69
71
|
```ruby
|
70
72
|
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 =
|
75
|
-
|
76
|
+
assessment = Incognia::Api.register_signup(
|
77
|
+
request_token: request_token,
|
76
78
|
address: address,
|
77
79
|
external_id: external_id
|
78
80
|
)
|
@@ -82,14 +84,14 @@ assessment = api.register_signup(
|
|
82
84
|
|
83
85
|
### Registering a Login
|
84
86
|
|
85
|
-
This method registers a new login for the given
|
87
|
+
This method registers a new login for the given request token and account, returning a login assessment, containing the risk assessment and supporting evidence:
|
86
88
|
|
87
89
|
```ruby
|
88
|
-
|
90
|
+
request_token = "WlMksW+jh5GPhqWBorsV8yDihoSHHpmt+DpjJ7eYxpHhuO/5tuHTuA..."
|
89
91
|
account_id = 'account-identifier-123'
|
90
92
|
|
91
|
-
assessment =
|
92
|
-
|
93
|
+
assessment = Incognia::Api.register_login(
|
94
|
+
request_token: request_token,
|
93
95
|
account_id: account_id,
|
94
96
|
)
|
95
97
|
|
@@ -100,12 +102,12 @@ assessment = api.register_login(
|
|
100
102
|
It also supports optional parameters, for example:
|
101
103
|
|
102
104
|
```ruby
|
103
|
-
|
105
|
+
request_token = "WlMksW+jh5GPhqWBorsV8yDihoSHHpmt+DpjJ7eYxpHhuO/5tuHTuA..."
|
104
106
|
account_id = 'account-identifier-123'
|
105
107
|
external_id = 'some-external-identifier'
|
106
108
|
|
107
|
-
assessment =
|
108
|
-
|
109
|
+
assessment = Incognia::Api.register_login(
|
110
|
+
request_token: request_token,
|
109
111
|
account_id: account_id,
|
110
112
|
external_id: external_id,
|
111
113
|
eval: false # can be used to register a new login without evaluating it
|
@@ -116,12 +118,12 @@ assessment = api.register_login(
|
|
116
118
|
|
117
119
|
### Registering Payment
|
118
120
|
|
119
|
-
This method registers a new payment for the given
|
121
|
+
This method registers a new payment for the given request token and account, returning a `hash`,
|
120
122
|
containing the risk assessment and supporting evidence.
|
121
123
|
|
122
124
|
```ruby
|
123
|
-
assessment =
|
124
|
-
|
125
|
+
assessment = Incognia::Api.register_payment(
|
126
|
+
request_token: 'request-token',
|
125
127
|
account_id: 'account-id'
|
126
128
|
)
|
127
129
|
|
@@ -180,8 +182,8 @@ payment_methods = [
|
|
180
182
|
}
|
181
183
|
]
|
182
184
|
|
183
|
-
assessment =
|
184
|
-
|
185
|
+
assessment = Incognia::Api.register_payment(
|
186
|
+
request_token: 'request-token',
|
185
187
|
account_id: 'account-id',
|
186
188
|
external_id: 'external-id',
|
187
189
|
addresses: addresses,
|
@@ -202,14 +204,14 @@ The `expires_at` argument should be a _Time_, _DateTime_ or an date in **RFC 333
|
|
202
204
|
|
203
205
|
|
204
206
|
```ruby
|
205
|
-
|
207
|
+
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 =
|
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,
|
213
215
|
account_id: account_id
|
214
216
|
)
|
215
217
|
|
@@ -219,10 +221,10 @@ 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 =
|
224
|
+
success = Incognia::Api.register_feedback(
|
223
225
|
event: 'custom_fraud_name',
|
224
226
|
occurred_at: occurred_at,
|
225
|
-
|
227
|
+
request_token: request_token,
|
226
228
|
account_id: account_id
|
227
229
|
)
|
228
230
|
|
data/lib/incognia_api/api.rb
CHANGED
@@ -5,79 +5,99 @@ require 'faraday_middleware'
|
|
5
5
|
|
6
6
|
module Incognia
|
7
7
|
class Api
|
8
|
-
# business layer: uses the Client to build domain objects
|
8
|
+
# business layer: uses the Client.instance to build domain objects
|
9
9
|
# raises missing parameters errors
|
10
|
-
attr_accessor :connection
|
11
10
|
|
12
11
|
def initialize(client_id:, client_secret:)
|
13
|
-
|
14
|
-
client_secret: client_secret,
|
15
|
-
host: "https://api.incognia.com/api")
|
16
|
-
end
|
12
|
+
Incognia.configure(client_id: client_id, client_secret: client_secret)
|
17
13
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
params.merge!(address&.to_hash) if address
|
14
|
+
warn("Deprecation warning: The Incognia::Api instance will be removed. " +
|
15
|
+
"Please set up with `Incognia.configure` and use class methods instead.")
|
16
|
+
end
|
22
17
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
def register_signup(**args); self.class.register_signup(**args) end
|
19
|
+
def register_login(**args); self.class.register_login(**args) end
|
20
|
+
def register_feedback(**args); self.class.register_feedback(**args) end
|
21
|
+
def register_payment(**args); self.class.register_payment(**args) end
|
22
|
+
def connection
|
23
|
+
warn("Deprecation warning: #connection and .connection are deprecated and will be private.")
|
28
24
|
|
29
|
-
|
25
|
+
self.class.connection
|
30
26
|
end
|
31
27
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
LoginAssessment.from_hash(response.body) if response.success?
|
47
|
-
end
|
28
|
+
class << self
|
29
|
+
def register_signup(request_token: nil, address: nil, **opts)
|
30
|
+
params = { request_token: request_token }.compact
|
31
|
+
params.merge!(opts)
|
32
|
+
params.merge!(address&.to_hash) if address
|
33
|
+
|
34
|
+
response = connection.request(
|
35
|
+
:post,
|
36
|
+
'v2/onboarding/signups',
|
37
|
+
params
|
38
|
+
)
|
39
|
+
|
40
|
+
SignupAssessment.from_hash(response.body) if response.success?
|
41
|
+
end
|
48
42
|
|
49
|
-
|
50
|
-
|
51
|
-
|
43
|
+
def register_login(account_id:, request_token: nil, **opts)
|
44
|
+
params = {
|
45
|
+
type: :login,
|
46
|
+
account_id: account_id,
|
47
|
+
request_token: request_token
|
48
|
+
}.compact
|
49
|
+
params.merge!(opts)
|
50
|
+
|
51
|
+
response = connection.request(
|
52
|
+
:post,
|
53
|
+
'v2/authentication/transactions',
|
54
|
+
params
|
55
|
+
)
|
56
|
+
|
57
|
+
LoginAssessment.from_hash(response.body) if response.success?
|
52
58
|
end
|
53
59
|
|
54
|
-
|
55
|
-
|
56
|
-
|
60
|
+
def register_feedback(event:, occurred_at: nil, expires_at: nil, timestamp: nil, **ids)
|
61
|
+
if !timestamp.nil?
|
62
|
+
warn("Deprecation warning: use occurred_at instead of timestamp")
|
63
|
+
end
|
57
64
|
|
58
|
-
|
59
|
-
|
65
|
+
timestamp = timestamp.strftime('%s%L') if timestamp.respond_to? :strftime
|
66
|
+
occurred_at = occurred_at.to_datetime.rfc3339 if occurred_at.respond_to? :to_datetime
|
67
|
+
expires_at = expires_at.to_datetime.rfc3339 if expires_at.respond_to? :to_datetime
|
60
68
|
|
61
|
-
|
62
|
-
|
63
|
-
'/api/v2/feedbacks',
|
64
|
-
params
|
65
|
-
)
|
69
|
+
params = { event: event, timestamp: timestamp&.to_i, occurred_at: occurred_at, expires_at: expires_at }.compact
|
70
|
+
params.merge!(ids)
|
66
71
|
|
67
|
-
|
68
|
-
|
72
|
+
response = connection.request(
|
73
|
+
:post,
|
74
|
+
'/api/v2/feedbacks',
|
75
|
+
params
|
76
|
+
)
|
69
77
|
|
70
|
-
|
71
|
-
|
72
|
-
params.merge!(opts)
|
78
|
+
response.success?
|
79
|
+
end
|
73
80
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
81
|
+
def register_payment(account_id:, request_token: nil, **opts)
|
82
|
+
params = {
|
83
|
+
type: :payment,
|
84
|
+
account_id: account_id,
|
85
|
+
request_token: request_token
|
86
|
+
}.compact
|
87
|
+
params.merge!(opts)
|
88
|
+
|
89
|
+
response = connection.request(
|
90
|
+
:post,
|
91
|
+
'v2/authentication/transactions',
|
92
|
+
params
|
93
|
+
)
|
94
|
+
|
95
|
+
PaymentAssessment.from_hash(response.body) if response.success?
|
96
|
+
end
|
79
97
|
|
80
|
-
|
98
|
+
def connection
|
99
|
+
Client.instance
|
100
|
+
end
|
81
101
|
end
|
82
102
|
end
|
83
103
|
end
|
data/lib/incognia_api/client.rb
CHANGED
@@ -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(
|
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
|
data/lib/incognia_api/version.rb
CHANGED
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.
|
4
|
+
version: 1.3.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-
|
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
|
@@ -93,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
94
|
version: '0'
|
94
95
|
requirements: []
|
95
96
|
rubygems_version: 3.4.19
|
96
|
-
signing_key:
|
97
|
+
signing_key:
|
97
98
|
specification_version: 4
|
98
99
|
summary: Official Ruby lib for communicating with Incognia API
|
99
100
|
test_files: []
|