sift 4.1.0 → 4.5.1
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/.github/pull_request_template.md +12 -0
- data/.github/workflows/ci.yml +49 -0
- data/.github/workflows/publishing_sift_ruby.yml +38 -0
- data/.gitignore +1 -0
- data/HISTORY +16 -0
- data/README.md +99 -2
- data/examples/psp_merchant_management_apis.rb +105 -0
- data/examples/validation_apis.rb +47 -0
- data/lib/sift/client.rb +199 -0
- data/lib/sift/version.rb +2 -1
- data/lib/sift.rb +27 -0
- data/spec/unit/client_205_spec.rb +117 -0
- data/spec/unit/client_psp_merchant_spec.rb +133 -0
- data/spec/unit/client_spec.rb +165 -0
- data/spec/unit/client_validationapi_spec.rb +91 -0
- data/test_integration_app/decisions_api/test_decisions_api.rb +31 -0
- data/test_integration_app/events_api/test_events_api.rb +843 -0
- data/test_integration_app/globals.rb +2 -0
- data/test_integration_app/main.rb +67 -0
- data/test_integration_app/psp_merchants_api/test_psp_merchant_api.rb +44 -0
- data/test_integration_app/score_api/test_score_api.rb +11 -0
- data/test_integration_app/verification_api/test_verification_api.rb +32 -0
- metadata +19 -16
- data/.circleci/config.yml +0 -43
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0be867318fbb8cb5cb85b614e48de3748def9c8d9a6122c066c785d65c6b3b48
|
|
4
|
+
data.tar.gz: abf0fe3da0bbf939f29cdb1071e9acb7db62473bc9fdc37dcde52631db930abc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cc2d9d80295f6f4605413d001bb29b4745e28ecc58e9595a526bd8a7d8529d2b63dc14fce063e1ee347bde3b9d9370ad160917a795e59377a54d5eeb50f876b7
|
|
7
|
+
data.tar.gz: f5f75423865db471ed649a4146a8e3e388203977ec6607c20966c9622f9b074f8e149574f9bbe28db22f44b21203e9ae082b52386bea6f8c2096afd869955a65
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
## Purpose
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
## Testing
|
|
6
|
+
|
|
7
|
+
## Checklist
|
|
8
|
+
- [ ] The change was thoroughly tested manually
|
|
9
|
+
- [ ] The change was covered with unit tests
|
|
10
|
+
- [ ] The change was tested with real API calls (if applicable)
|
|
11
|
+
- [ ] Necessary changes were made in the integration tests (if applicable)
|
|
12
|
+
- [ ] New functionality is reflected in README
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
name: Ruby-ci
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- master
|
|
10
|
+
|
|
11
|
+
env:
|
|
12
|
+
ACCOUNT_ID: ${{ secrets.ACCOUNT_ID }}
|
|
13
|
+
API_KEY: ${{ secrets.API_KEY }}
|
|
14
|
+
|
|
15
|
+
permissions:
|
|
16
|
+
contents: read
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
build:
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
strategy:
|
|
22
|
+
matrix:
|
|
23
|
+
ruby-version: ['2.4.2']
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v4
|
|
26
|
+
- name: Set up Ruby
|
|
27
|
+
uses: ruby/setup-ruby@v1
|
|
28
|
+
with:
|
|
29
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
30
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
31
|
+
- name: Run tests
|
|
32
|
+
run: bundle exec rspec --format RspecJunitFormatter --out test_results/rspec.xml --format progress
|
|
33
|
+
|
|
34
|
+
run_integration_tests:
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
if: ${{ github.ref == 'refs/heads/master' }}
|
|
37
|
+
strategy:
|
|
38
|
+
matrix:
|
|
39
|
+
ruby-version: [ '2.4.2' ]
|
|
40
|
+
steps:
|
|
41
|
+
- uses: actions/checkout@v4
|
|
42
|
+
- name: Set up Ruby
|
|
43
|
+
uses: ruby/setup-ruby@v1
|
|
44
|
+
with:
|
|
45
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
46
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
47
|
+
- name: Run tests
|
|
48
|
+
run: |
|
|
49
|
+
bundle exec ruby test_integration_app/main.rb
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: Build and Publish Gem
|
|
2
|
+
on:
|
|
3
|
+
release:
|
|
4
|
+
types: [published]
|
|
5
|
+
|
|
6
|
+
env:
|
|
7
|
+
GH_TOKEN: ${{ github.token }}
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build_and_publish:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout code
|
|
14
|
+
uses: actions/checkout@v3
|
|
15
|
+
- name: Set up Ruby
|
|
16
|
+
uses: ruby/setup-ruby@v1
|
|
17
|
+
with:
|
|
18
|
+
ruby-version: 2.7
|
|
19
|
+
- name: Install Bundler
|
|
20
|
+
run: |
|
|
21
|
+
sudo gem install bundler
|
|
22
|
+
bundle install
|
|
23
|
+
- name: Build and push gem
|
|
24
|
+
run: |
|
|
25
|
+
mkdir -p $HOME/.gem
|
|
26
|
+
touch $HOME/.gem/credentials
|
|
27
|
+
chmod 0600 $HOME/.gem/credentials
|
|
28
|
+
printf -- "---\n:rubygems_api_key: ${{ secrets.GH_RGEMS_KEY }}\n" > $HOME/.gem/credentials
|
|
29
|
+
version=$(awk -F'"' '/ VERSION = / {print $2}' < lib/sift/version.rb)
|
|
30
|
+
all_versions=$(gem list -r -e --all sift --no-verbose)
|
|
31
|
+
if [[ $all_versions != *"$version"* ]]; then
|
|
32
|
+
echo "Gem version does not exist on RubyGems. Building and pushing!"
|
|
33
|
+
gem build sift.gemspec
|
|
34
|
+
gem push sift-$version.gem
|
|
35
|
+
rm -rf $HOME/.gem
|
|
36
|
+
else
|
|
37
|
+
echo "Gem version $version exists on RubyGems"
|
|
38
|
+
fi
|
data/.gitignore
CHANGED
data/HISTORY
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
=== 4.5.1 2025-04-07
|
|
2
|
+
- Fix Verification URLs
|
|
3
|
+
|
|
4
|
+
=== 4.5.0 2024-05-16
|
|
5
|
+
- Support for warnings in Events API
|
|
6
|
+
|
|
7
|
+
=== 4.4.0 2023-10-05
|
|
8
|
+
- Score percentiles in Score API
|
|
9
|
+
|
|
10
|
+
=== 4.3.0 2023-08-21
|
|
11
|
+
- PSP Merchant Management API
|
|
12
|
+
|
|
13
|
+
=== 4.2.0 2023-06-20
|
|
14
|
+
- Verification API support [Verification API](https://sift.com/developers/docs/curl/verification-api/overview)
|
|
15
|
+
- Support for score percentiles (only applicable for the accounts with the feature enabled)
|
|
16
|
+
|
|
1
17
|
=== 4.1.0 2022-06-22
|
|
2
18
|
- Add return_route_info query param
|
|
3
19
|
|
data/README.md
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
# sift-ruby
|
|
2
|
-
[](https://circleci.com/gh/SiftScience/sift-ruby)
|
|
3
2
|
|
|
4
3
|
The official Ruby bindings for the latest version (v205) of the [Sift API](https://sift.com/developers/docs/java/apis-overview).
|
|
5
4
|
|
|
@@ -39,8 +38,22 @@ client = Sift::Client.new(api_key: '<your_api_key_here>', account_id: '<your_acc
|
|
|
39
38
|
|
|
40
39
|
```
|
|
41
40
|
|
|
42
|
-
### Sending
|
|
41
|
+
### Sending an event
|
|
42
|
+
Send event to Sift.
|
|
43
|
+
To learn more about the Events API visit our [developer docs](https://developers.sift.com/docs/ruby/events-api/overview).
|
|
43
44
|
|
|
45
|
+
|
|
46
|
+
**Optional Params**
|
|
47
|
+
- `return_score`: `:true` or `:false`
|
|
48
|
+
- `return_action`: `:true` or `:false`
|
|
49
|
+
- `return_workflow_status`: `:true` or `:false`
|
|
50
|
+
- `return_route_info`: `:true` or `:false`
|
|
51
|
+
- `force_workflow_run`: `:true` or `:false`
|
|
52
|
+
- `include_score_percentiles`: `:true` or `:false`
|
|
53
|
+
- `warnings`: `:true` or `:false`
|
|
54
|
+
- `abuse_types`: `["payment_abuse", "content_abuse", "content_abuse", "account_abuse", "legacy", "account_takeover"]`
|
|
55
|
+
|
|
56
|
+
**Example:**
|
|
44
57
|
```ruby
|
|
45
58
|
event = "$transaction"
|
|
46
59
|
|
|
@@ -217,6 +230,72 @@ response = client.get_session_decisions('example_user_id', 'example_session_id')
|
|
|
217
230
|
response = client.get_content_decisions('example_user_id', 'example_order_id')
|
|
218
231
|
```
|
|
219
232
|
|
|
233
|
+
## PSP Merchant Management API
|
|
234
|
+
|
|
235
|
+
To learn more about the decisions endpoint visit our [developer docs](https://sift.com/developers/docs/ruby/psp-merchant-management-api).
|
|
236
|
+
|
|
237
|
+
```ruby
|
|
238
|
+
# On-board a PSP merchant summary to Sift Platform.
|
|
239
|
+
# Sample psp_merchant_profile
|
|
240
|
+
properties = {
|
|
241
|
+
"id": "merchant_id_01000",
|
|
242
|
+
"name": "Wonderful Payments Inc.",
|
|
243
|
+
"description": "Wonderful Payments payment provider.",
|
|
244
|
+
"address": {
|
|
245
|
+
"name": "Alany",
|
|
246
|
+
"address_1": "Big Payment blvd, 22",
|
|
247
|
+
"address_2": "apt, 8",
|
|
248
|
+
"city": "New Orleans",
|
|
249
|
+
"region": "NA",
|
|
250
|
+
"country": "US",
|
|
251
|
+
"zipcode": "76830",
|
|
252
|
+
"phone": "0394888320"
|
|
253
|
+
},
|
|
254
|
+
"category": "1002",
|
|
255
|
+
"service_level": "Platinum",
|
|
256
|
+
"status": "active",
|
|
257
|
+
"risk_profile": {
|
|
258
|
+
"level": "low",
|
|
259
|
+
"score": 10
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
response = client.create_psp_merchant_profile(properties)
|
|
263
|
+
|
|
264
|
+
# Update a merchant summary to reflect changes in the status or service level or address etc.
|
|
265
|
+
properties = {
|
|
266
|
+
"id": "merchant_id_01000",
|
|
267
|
+
"name": "Wonderful Payments Inc.",
|
|
268
|
+
"description": "Wonderful Payments payment provider.",
|
|
269
|
+
"address": {
|
|
270
|
+
"name": "Alany",
|
|
271
|
+
"address_1": "Big Payment blvd, 22",
|
|
272
|
+
"address_2": "apt, 8",
|
|
273
|
+
"city": "New Orleans",
|
|
274
|
+
"region": "NA",
|
|
275
|
+
"country": "US",
|
|
276
|
+
"zipcode": "76830",
|
|
277
|
+
"phone": "0394888320"
|
|
278
|
+
},
|
|
279
|
+
"category": "1002",
|
|
280
|
+
"service_level": "Platinum",
|
|
281
|
+
"status": "active",
|
|
282
|
+
"risk_profile": {
|
|
283
|
+
"level": "low",
|
|
284
|
+
"score": 10
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
response = client.update_psp_merchant_profile('merchant_id', properties)
|
|
288
|
+
|
|
289
|
+
# Get the existing PSP merchant summaries.
|
|
290
|
+
response = client.get_a_psp_merchant_profile('merchant_id')
|
|
291
|
+
|
|
292
|
+
# Get all PSP merchant summaries
|
|
293
|
+
response = client.get_psp_merchant_profiles()
|
|
294
|
+
|
|
295
|
+
# Get PSP merchant summaries paginated
|
|
296
|
+
response = client.get_psp_merchant_profiles('batch_size', 'batch_token')
|
|
297
|
+
```
|
|
298
|
+
|
|
220
299
|
## Response Object
|
|
221
300
|
|
|
222
301
|
All requests to our apis will return a `Response` instance.
|
|
@@ -252,3 +331,21 @@ To run the various tests use the rake command as follows:
|
|
|
252
331
|
```ruby
|
|
253
332
|
$ rake spec
|
|
254
333
|
```
|
|
334
|
+
|
|
335
|
+
## Integration testing app
|
|
336
|
+
|
|
337
|
+
For testing the app with real calls it is possible to run the integration testing app,
|
|
338
|
+
it makes calls to almost all our public endpoints to make sure the library integrates
|
|
339
|
+
well. At the moment, the app is run on every merge to master
|
|
340
|
+
|
|
341
|
+
#### How to run it locally
|
|
342
|
+
|
|
343
|
+
1. Add env variable `ACCOUNT_ID` with the valid account id
|
|
344
|
+
2. Add env variable `API_KEY` with the valid Api Key associated from the account
|
|
345
|
+
3. Run the following under the project root folder
|
|
346
|
+
```
|
|
347
|
+
# Install the budle locally
|
|
348
|
+
bundle check || bundle install
|
|
349
|
+
# Run the app
|
|
350
|
+
bundle exec ruby test_integration_app/main.rb
|
|
351
|
+
```
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'sift'
|
|
3
|
+
require 'multi_json'
|
|
4
|
+
|
|
5
|
+
class MyLogger
|
|
6
|
+
def warn(e)
|
|
7
|
+
puts "[WARN] " + e.to_s
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def error(e)
|
|
11
|
+
puts "[ERROR] " + e.to_s
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def fatal(e)
|
|
15
|
+
puts "[FATAL] " + e.to_s
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def info(e)
|
|
19
|
+
puts "[INFO] " + e.to_s
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def handle_response(response)
|
|
24
|
+
if response.nil?
|
|
25
|
+
puts 'Error: there was an HTTP error calling through the API'
|
|
26
|
+
else
|
|
27
|
+
puts 'Successfully sent request; was ok? : ' + response.ok?.to_s
|
|
28
|
+
puts 'API error message : ' + response.api_error_message.to_s
|
|
29
|
+
puts 'API status code : ' + response.api_status.to_s
|
|
30
|
+
puts 'HTTP status code : ' + response.http_status_code.to_s
|
|
31
|
+
puts 'original request : ' + response.original_request.to_s
|
|
32
|
+
puts 'response body : ' + response.body.to_s
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
Sift.logger = MyLogger.new
|
|
37
|
+
|
|
38
|
+
$api_key = 'put-valid-api-key'
|
|
39
|
+
$account_id = 'put-valid-account-id'
|
|
40
|
+
|
|
41
|
+
def post_merchant_properties
|
|
42
|
+
# Sample psp_merchant_profile
|
|
43
|
+
{
|
|
44
|
+
"id": "merchant_id_01004",
|
|
45
|
+
"name": "Wonderful Payments Inc.",
|
|
46
|
+
"description": "Wonderful Payments payment provider.",
|
|
47
|
+
"address": {
|
|
48
|
+
"name": "Alany",
|
|
49
|
+
"address_1": "Big Payment blvd, 22",
|
|
50
|
+
"address_2": "apt, 8",
|
|
51
|
+
"city": "New Orleans",
|
|
52
|
+
"region": "NA",
|
|
53
|
+
"country": "US",
|
|
54
|
+
"zipcode": "76830",
|
|
55
|
+
"phone": "0394888320"
|
|
56
|
+
},
|
|
57
|
+
"category": "1002",
|
|
58
|
+
"service_level": "Platinum",
|
|
59
|
+
"status": "active",
|
|
60
|
+
"risk_profile": {
|
|
61
|
+
"level": "low",
|
|
62
|
+
"score": 10
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def put_merchant_properties
|
|
68
|
+
# Sample update psp_merchant_profile
|
|
69
|
+
{
|
|
70
|
+
"id": "merchant_id_01004",
|
|
71
|
+
"name": "Wonderful Payments Inc. update",
|
|
72
|
+
"description": "Wonderful Payments payment provider. update",
|
|
73
|
+
"address": {
|
|
74
|
+
"name": "Alany",
|
|
75
|
+
"address_1": "Big Payment blvd, 22",
|
|
76
|
+
"address_2": "apt, 8",
|
|
77
|
+
"city": "New Orleans",
|
|
78
|
+
"region": "NA",
|
|
79
|
+
"country": "US",
|
|
80
|
+
"zipcode": "76830",
|
|
81
|
+
"phone": "0394888320"
|
|
82
|
+
},
|
|
83
|
+
"category": "1002",
|
|
84
|
+
"service_level": "Platinum",
|
|
85
|
+
"status": "active",
|
|
86
|
+
"risk_profile": {
|
|
87
|
+
"level": "low",
|
|
88
|
+
"score": 10
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# handle_response Sift::Client.new(:api_key => $api_key, :account_id => $account_id).create_psp_merchant_profile(post_merchant_properties)
|
|
94
|
+
|
|
95
|
+
# handle_response Sift::Client.new(:api_key => $api_key, :account_id => $account_id).update_psp_merchant_profile("merchant_id_01004", put_merchant_properties)
|
|
96
|
+
|
|
97
|
+
# handle_response Sift::Client.new(:api_key => $api_key, :account_id => $account_id).get_a_psp_merchant_profile("merchant_id_01004")
|
|
98
|
+
|
|
99
|
+
# handle_response Sift::Client.new(:api_key => $api_key, :account_id => $account_id).get_psp_merchant_profiles()
|
|
100
|
+
|
|
101
|
+
# handle_response Sift::Client.new(:api_key => $api_key, :account_id => $account_id).get_psp_merchant_profiles(2)
|
|
102
|
+
|
|
103
|
+
handle_response Sift::Client.new(:api_key => $api_key, :account_id => $account_id).get_psp_merchant_profiles(5, "next_ref")
|
|
104
|
+
|
|
105
|
+
puts "request completed"
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require "sift"
|
|
2
|
+
require 'multi_json'
|
|
3
|
+
|
|
4
|
+
#$api_key = "put-a-valid-apikey"
|
|
5
|
+
#$user_id = "put-a-valid-userid"
|
|
6
|
+
|
|
7
|
+
def valid_send_properties
|
|
8
|
+
{
|
|
9
|
+
:$user_id => $user_id,
|
|
10
|
+
:$send_to => $user_id,
|
|
11
|
+
:$verification_type => '$email',
|
|
12
|
+
:$brand_name => 'all',
|
|
13
|
+
:$language => 'en',
|
|
14
|
+
:$event => {
|
|
15
|
+
:$session_id => 'gigtleqddo84l8cm15qe4il',
|
|
16
|
+
:$verified_event => '$login',
|
|
17
|
+
:$reason => '$automated_rule',
|
|
18
|
+
:$ip => '192.168.1.1',
|
|
19
|
+
:$browser => {
|
|
20
|
+
:$user_agent => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def valid_resend_properties
|
|
27
|
+
{
|
|
28
|
+
:$user_id => $user_id,
|
|
29
|
+
:$verified_event => '$login'
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def valid_check_properties
|
|
34
|
+
{
|
|
35
|
+
:$user_id => $user_id,
|
|
36
|
+
:$code => '668316'
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
#response = Sift::Client.new(:api_key => $api_key,:user_id => $user_id,:version=>1.1).verification_send(valid_send_properties)
|
|
41
|
+
|
|
42
|
+
#response = Sift::Client.new(:api_key => $api_key,:user_id => $user_id,:version=>1.1).verification_resend(valid_resend_properties)
|
|
43
|
+
response = Sift::Client.new(:api_key => $api_key,:user_id => $user_id,:version=>1.1).verification_check(valid_check_properties)
|
|
44
|
+
|
|
45
|
+
p response
|
|
46
|
+
|
|
47
|
+
puts "completed"
|
data/lib/sift/client.rb
CHANGED
|
@@ -139,6 +139,7 @@ module Sift
|
|
|
139
139
|
@api_key = opts[:api_key] || Sift.api_key
|
|
140
140
|
@account_id = opts[:account_id] || Sift.account_id
|
|
141
141
|
@version = opts[:version] || API_VERSION
|
|
142
|
+
@verification_version = opts[:verification_version] || VERIFICATION_API_VERSION
|
|
142
143
|
@timeout = opts[:timeout] || 2 # 2-second timeout by default
|
|
143
144
|
@path = opts[:path] || Sift.rest_api_path(@version)
|
|
144
145
|
|
|
@@ -202,6 +203,12 @@ module Sift
|
|
|
202
203
|
# :path::
|
|
203
204
|
# Overrides the URI path for this API call.
|
|
204
205
|
#
|
|
206
|
+
# :include_score_percentiles::
|
|
207
|
+
# include_score_percentiles(optional) : Whether to add new parameter in the query parameter.
|
|
208
|
+
#
|
|
209
|
+
# :warnings::
|
|
210
|
+
# warnings(optional) : Whether to add list of warnings (if any) to response.
|
|
211
|
+
#
|
|
205
212
|
# ==== Returns:
|
|
206
213
|
#
|
|
207
214
|
# In the case of a network error (timeout, broken connection, etc.),
|
|
@@ -219,6 +226,8 @@ module Sift
|
|
|
219
226
|
return_route_info = opts[:return_route_info]
|
|
220
227
|
force_workflow_run = opts[:force_workflow_run]
|
|
221
228
|
abuse_types = opts[:abuse_types]
|
|
229
|
+
include_score_percentiles = opts[:include_score_percentiles]
|
|
230
|
+
warnings = opts[:warnings]
|
|
222
231
|
|
|
223
232
|
raise("event must be a non-empty string") if (!event.is_a? String) || event.empty?
|
|
224
233
|
raise("properties cannot be empty") if properties.empty?
|
|
@@ -232,6 +241,13 @@ module Sift
|
|
|
232
241
|
query["force_workflow_run"] = "true" if force_workflow_run
|
|
233
242
|
query["abuse_types"] = abuse_types.join(",") if abuse_types
|
|
234
243
|
|
|
244
|
+
if include_score_percentiles == "true" || warnings == "true"
|
|
245
|
+
fields = []
|
|
246
|
+
fields << "SCORE_PERCENTILES" if include_score_percentiles == "true"
|
|
247
|
+
fields << "WARNINGS" if warnings == "true"
|
|
248
|
+
query["fields"] = fields.join(",")
|
|
249
|
+
end
|
|
250
|
+
|
|
235
251
|
options = {
|
|
236
252
|
:body => MultiJson.dump(delete_nils(properties).merge({"$type" => event,
|
|
237
253
|
"$api_key" => api_key})),
|
|
@@ -272,6 +288,9 @@ module Sift
|
|
|
272
288
|
# :version::
|
|
273
289
|
# Overrides the version of the Events API to call.
|
|
274
290
|
#
|
|
291
|
+
# :include_score_percentiles::
|
|
292
|
+
# include_score_percentiles(optional) : Whether to add new parameter in the query parameter.
|
|
293
|
+
#
|
|
275
294
|
# ==== Returns:
|
|
276
295
|
#
|
|
277
296
|
# A Response object containing a status code, status message, and,
|
|
@@ -282,6 +301,7 @@ module Sift
|
|
|
282
301
|
api_key = opts[:api_key] || @api_key
|
|
283
302
|
timeout = opts[:timeout] || @timeout
|
|
284
303
|
version = opts[:version] || @version
|
|
304
|
+
include_score_percentiles = opts[:include_score_percentiles]
|
|
285
305
|
|
|
286
306
|
raise("user_id must be a non-empty string") if (!user_id.is_a? String) || user_id.to_s.empty?
|
|
287
307
|
raise("Bad api_key parameter") if api_key.empty?
|
|
@@ -289,6 +309,9 @@ module Sift
|
|
|
289
309
|
query = {}
|
|
290
310
|
query["api_key"] = api_key
|
|
291
311
|
query["abuse_types"] = abuse_types.join(",") if abuse_types
|
|
312
|
+
if include_score_percentiles == "true"
|
|
313
|
+
query["fields"] = "SCORE_PERCENTILES"
|
|
314
|
+
end
|
|
292
315
|
|
|
293
316
|
options = {
|
|
294
317
|
:headers => {"User-Agent" => user_agent},
|
|
@@ -329,6 +352,9 @@ module Sift
|
|
|
329
352
|
# :timeout::
|
|
330
353
|
# Overrides the timeout (in seconds) for this call.
|
|
331
354
|
#
|
|
355
|
+
# :include_score_percentiles::
|
|
356
|
+
# include_score_percentiles(optional) : Whether to add new parameter in the query parameter.
|
|
357
|
+
#
|
|
332
358
|
# ==== Returns:
|
|
333
359
|
#
|
|
334
360
|
# A Response object containing a status code, status message, and,
|
|
@@ -338,6 +364,7 @@ module Sift
|
|
|
338
364
|
abuse_types = opts[:abuse_types]
|
|
339
365
|
api_key = opts[:api_key] || @api_key
|
|
340
366
|
timeout = opts[:timeout] || @timeout
|
|
367
|
+
include_score_percentiles = opts[:include_score_percentiles]
|
|
341
368
|
|
|
342
369
|
raise("user_id must be a non-empty string") if (!user_id.is_a? String) || user_id.to_s.empty?
|
|
343
370
|
raise("Bad api_key parameter") if api_key.empty?
|
|
@@ -345,6 +372,9 @@ module Sift
|
|
|
345
372
|
query = {}
|
|
346
373
|
query["api_key"] = api_key
|
|
347
374
|
query["abuse_types"] = abuse_types.join(",") if abuse_types
|
|
375
|
+
if include_score_percentiles == "true"
|
|
376
|
+
query["fields"] = "SCORE_PERCENTILES"
|
|
377
|
+
end
|
|
348
378
|
|
|
349
379
|
options = {
|
|
350
380
|
:headers => {"User-Agent" => user_agent},
|
|
@@ -716,6 +746,175 @@ module Sift
|
|
|
716
746
|
handle_response(apply_decision(configs))
|
|
717
747
|
end
|
|
718
748
|
|
|
749
|
+
def build_default_headers_post(api_key)
|
|
750
|
+
{
|
|
751
|
+
"Authorization" => "Basic #{Base64.encode64(api_key+":")}",
|
|
752
|
+
"User-Agent" => "SiftScience/v#{@version} sift-ruby/#{VERSION}",
|
|
753
|
+
"Content-Type" => "application/json"
|
|
754
|
+
}
|
|
755
|
+
end
|
|
756
|
+
|
|
757
|
+
def verification_send(properties = {}, opts = {})
|
|
758
|
+
api_key = opts[:api_key] || @api_key
|
|
759
|
+
version = opts[:verification_version] || @verification_version
|
|
760
|
+
timeout = opts[:timeout] || @timeout
|
|
761
|
+
|
|
762
|
+
raise("properties cannot be empty") if properties.empty?
|
|
763
|
+
raise("api_key cannot be empty") if api_key.empty?
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
options = {
|
|
767
|
+
:body => MultiJson.dump(delete_nils(properties)),
|
|
768
|
+
:headers => build_default_headers_post(api_key)
|
|
769
|
+
}
|
|
770
|
+
options.merge!(:timeout => timeout) unless timeout.nil?
|
|
771
|
+
response = self.class.post(Sift.verification_api_send_path(@version), options)
|
|
772
|
+
Response.new(response.body, response.code, response.response)
|
|
773
|
+
end
|
|
774
|
+
|
|
775
|
+
def verification_resend(properties = {}, opts = {})
|
|
776
|
+
api_key = opts[:api_key] || @api_key
|
|
777
|
+
version = opts[:verification_version] || @verification_version
|
|
778
|
+
timeout = opts[:timeout] || @timeout
|
|
779
|
+
|
|
780
|
+
raise("properties cannot be empty") if properties.empty?
|
|
781
|
+
raise("api_key cannot be empty") if api_key.empty?
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
options = {
|
|
785
|
+
:body => MultiJson.dump(delete_nils(properties)),
|
|
786
|
+
:headers => build_default_headers_post(api_key)
|
|
787
|
+
}
|
|
788
|
+
options.merge!(:timeout => timeout) unless timeout.nil?
|
|
789
|
+
|
|
790
|
+
response = self.class.post(Sift.verification_api_resend_path(@version), options)
|
|
791
|
+
Response.new(response.body, response.code, response.response)
|
|
792
|
+
end
|
|
793
|
+
|
|
794
|
+
def verification_check(properties = {}, opts = {})
|
|
795
|
+
api_key = opts[:api_key] || @api_key
|
|
796
|
+
version = opts[:verification_version] || @verification_version
|
|
797
|
+
timeout = opts[:timeout] || @timeout
|
|
798
|
+
|
|
799
|
+
raise("properties cannot be empty") if properties.empty?
|
|
800
|
+
raise("api_key cannot be empty") if api_key.empty?
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
options = {
|
|
804
|
+
:body => MultiJson.dump(delete_nils(properties)),
|
|
805
|
+
:headers => build_default_headers_post(api_key)
|
|
806
|
+
}
|
|
807
|
+
options.merge!(:timeout => timeout) unless timeout.nil?
|
|
808
|
+
|
|
809
|
+
response = self.class.post(Sift.verification_api_check_path(@version), options)
|
|
810
|
+
Response.new(response.body, response.code, response.response)
|
|
811
|
+
end
|
|
812
|
+
|
|
813
|
+
def create_psp_merchant_profile(properties = {}, opts = {})
|
|
814
|
+
# Create a new PSP Merchant profile
|
|
815
|
+
# Args:
|
|
816
|
+
# properties: A dict of merchant profile data.
|
|
817
|
+
# Returns
|
|
818
|
+
# A sift.client.Response object if the call succeeded, else raises an ApiException
|
|
819
|
+
|
|
820
|
+
account_id = opts[:account_id] || @account_id
|
|
821
|
+
api_key = opts[:api_key] || @api_key
|
|
822
|
+
timeout = opts[:timeout] || @timeout
|
|
823
|
+
|
|
824
|
+
raise("api_key cannot be empty") if api_key.empty?
|
|
825
|
+
raise("account_id cannot be empty") if account_id.empty?
|
|
826
|
+
raise("properties cannot be empty") if properties.empty?
|
|
827
|
+
|
|
828
|
+
options = {
|
|
829
|
+
:body => MultiJson.dump(delete_nils(properties)),
|
|
830
|
+
:headers => { "User-Agent" => user_agent, "Content-Type" => "application/json" },
|
|
831
|
+
:basic_auth => { :username => api_key, :password => "" }
|
|
832
|
+
}
|
|
833
|
+
options.merge!(:timeout => timeout) unless timeout.nil?
|
|
834
|
+
response = self.class.post(API_ENDPOINT + Sift.psp_merchant_api_path(account_id), options)
|
|
835
|
+
Response.new(response.body, response.code, response.response)
|
|
836
|
+
end
|
|
837
|
+
|
|
838
|
+
def update_psp_merchant_profile(merchant_id, properties = {}, opts = {})
|
|
839
|
+
# Update an existing PSP Merchant profile
|
|
840
|
+
# Args:
|
|
841
|
+
# merchant_id: id of merchant
|
|
842
|
+
# properties: A dict of merchant profile data.
|
|
843
|
+
# Returns
|
|
844
|
+
# A sift.client.Response object if the call succeeded, else raises an ApiException
|
|
845
|
+
|
|
846
|
+
account_id = opts[:account_id] || @account_id
|
|
847
|
+
api_key = opts[:api_key] || @api_key
|
|
848
|
+
timeout = opts[:timeout] || @timeout
|
|
849
|
+
|
|
850
|
+
raise("api_key cannot be empty") if api_key.empty?
|
|
851
|
+
raise("account_id cannot be empty") if account_id.empty?
|
|
852
|
+
raise("merchant_id cannot be empty") if merchant_id.empty?
|
|
853
|
+
raise("properties cannot be empty") if properties.empty?
|
|
854
|
+
|
|
855
|
+
options = {
|
|
856
|
+
:body => MultiJson.dump(delete_nils(properties)),
|
|
857
|
+
:headers => { "User-Agent" => user_agent, "Content-Type" => "application/json" },
|
|
858
|
+
:basic_auth => { :username => api_key, :password => "" }
|
|
859
|
+
}
|
|
860
|
+
options.merge!(:timeout => timeout) unless timeout.nil?
|
|
861
|
+
response = self.class.put(API_ENDPOINT + Sift.psp_merchant_id_api_path(account_id, merchant_id), options)
|
|
862
|
+
Response.new(response.body, response.code, response.response)
|
|
863
|
+
end
|
|
864
|
+
|
|
865
|
+
def get_a_psp_merchant_profile(merchant_id, opts = {})
|
|
866
|
+
# Gets a PSP merchant profile using merchant id.
|
|
867
|
+
# Args:
|
|
868
|
+
# merchant_id: id of merchant
|
|
869
|
+
# Returns
|
|
870
|
+
# A sift.client.Response object if the call succeeded, else raises an ApiException
|
|
871
|
+
|
|
872
|
+
account_id = opts[:account_id] || @account_id
|
|
873
|
+
api_key = opts[:api_key] || @api_key
|
|
874
|
+
timeout = opts[:timeout] || @timeout
|
|
875
|
+
|
|
876
|
+
raise("api_key cannot be empty") if api_key.empty?
|
|
877
|
+
raise("account_id cannot be empty") if account_id.empty?
|
|
878
|
+
raise("merchant_id cannot be empty") if merchant_id.empty?
|
|
879
|
+
|
|
880
|
+
options = {
|
|
881
|
+
:headers => { "User-Agent" => user_agent, "Content-Type" => "application/json" },
|
|
882
|
+
:basic_auth => { :username => api_key, :password => "" }
|
|
883
|
+
}
|
|
884
|
+
options.merge!(:timeout => timeout) unless timeout.nil?
|
|
885
|
+
response = self.class.get(API_ENDPOINT + Sift.psp_merchant_id_api_path(account_id, merchant_id), options)
|
|
886
|
+
Response.new(response.body, response.code, response.response)
|
|
887
|
+
end
|
|
888
|
+
|
|
889
|
+
def get_psp_merchant_profiles(batch_size = nil, batch_token = nil, opts = {})
|
|
890
|
+
# Get all PSP merchant profiles.
|
|
891
|
+
# Args:
|
|
892
|
+
# batch_size : Batch or page size of the paginated sequence.
|
|
893
|
+
# batch_token : Batch or page position of the paginated sequence.
|
|
894
|
+
# Returns
|
|
895
|
+
# A sift.client.Response object if the call succeeded, else raises an ApiException
|
|
896
|
+
|
|
897
|
+
account_id = opts[:account_id] || @account_id
|
|
898
|
+
api_key = opts[:api_key] || @api_key
|
|
899
|
+
timeout = opts[:timeout] || @timeout
|
|
900
|
+
|
|
901
|
+
raise("api_key cannot be empty") if api_key.empty?
|
|
902
|
+
raise("account_id cannot be empty") if account_id.empty?
|
|
903
|
+
|
|
904
|
+
query = {}
|
|
905
|
+
query["batch_size"] = batch_size if batch_size
|
|
906
|
+
query["batch_token"] = batch_token if batch_token
|
|
907
|
+
|
|
908
|
+
options = {
|
|
909
|
+
:headers => { "User-Agent" => user_agent, "Content-Type" => "application/json" },
|
|
910
|
+
:basic_auth => { :username => api_key, :password => "" },
|
|
911
|
+
:query => query
|
|
912
|
+
}
|
|
913
|
+
options.merge!(:timeout => timeout) unless timeout.nil?
|
|
914
|
+
response = self.class.get(API_ENDPOINT + Sift.psp_merchant_api_path(account_id), options)
|
|
915
|
+
Response.new(response.body, response.code, response.response)
|
|
916
|
+
end
|
|
917
|
+
|
|
719
918
|
private
|
|
720
919
|
|
|
721
920
|
def handle_response(response)
|