incognia_api 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +15 -13
- data/lib/incognia_api/api.rb +78 -62
- 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 +7 -6
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
data/Gemfile.lock
CHANGED
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
|
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
|
@@ -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 =
|
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 =
|
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 =
|
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 =
|
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 =
|
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 =
|
185
|
+
assessment = Incognia::Api.register_payment(
|
184
186
|
request_token: 'request-token',
|
185
187
|
account_id: 'account-id',
|
186
188
|
external_id: 'external-id',
|
@@ -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 =
|
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 =
|
224
|
+
success = Incognia::Api.register_feedback(
|
223
225
|
event: 'custom_fraud_name',
|
224
226
|
occurred_at: occurred_at,
|
225
227
|
request_token: request_token,
|
data/lib/incognia_api/api.rb
CHANGED
@@ -5,83 +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
|
-
}.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
|
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
|
48
33
|
|
49
|
-
|
50
|
-
|
51
|
-
|
34
|
+
response = connection.request(
|
35
|
+
:post,
|
36
|
+
'v2/onboarding/signups',
|
37
|
+
params
|
38
|
+
)
|
39
|
+
|
40
|
+
SignupAssessment.from_hash(response.body) if response.success?
|
52
41
|
end
|
53
42
|
|
54
|
-
|
55
|
-
|
56
|
-
|
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?
|
58
|
+
end
|
57
59
|
|
58
|
-
|
59
|
-
|
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
|
60
64
|
|
61
|
-
|
62
|
-
:
|
63
|
-
|
64
|
-
params
|
65
|
-
)
|
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
|
66
68
|
|
67
|
-
|
68
|
-
|
69
|
+
params = { event: event, timestamp: timestamp&.to_i, occurred_at: occurred_at, expires_at: expires_at }.compact
|
70
|
+
params.merge!(ids)
|
69
71
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
72
|
+
response = connection.request(
|
73
|
+
:post,
|
74
|
+
'/api/v2/feedbacks',
|
75
|
+
params
|
76
|
+
)
|
77
|
+
|
78
|
+
response.success?
|
79
|
+
end
|
80
|
+
|
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
|
97
|
+
|
98
|
+
def connection
|
99
|
+
Client.instance
|
100
|
+
end
|
85
101
|
end
|
86
102
|
end
|
87
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
|
@@ -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.
|
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: []
|