sift 4.2.0 → 4.5.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/.circleci/config.yml +17 -0
- data/.github/workflows/publishing_sift_ruby.yml +38 -0
- data/.gitignore +1 -0
- data/.jenkins/Jenkinsfile +103 -0
- data/HISTORY +9 -0
- data/README.md +99 -2
- data/examples/psp_merchant_management_apis.rb +105 -0
- data/lib/sift/client.rb +132 -2
- data/lib/sift/version.rb +1 -1
- data/lib/sift.rb +12 -0
- data/spec/unit/client_psp_merchant_spec.rb +133 -0
- data/spec/unit/client_spec.rb +165 -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 +15 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71be696ff04ffb1503d22a724241e5087809d2ffa2ab29f08666939ecd6bb98b
|
4
|
+
data.tar.gz: e2e841d8259fbea8c247b1b2bd3cdf208bd53ded613a765a75f595714a2e1e8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b578f6bccf6323d4ef53947cea5a517678920d882439da1d1df262cf5eb39e45064aab3a1dee702da01f41f29a522df0c5e7b850c68e1ac302fa0f7d9830e29
|
7
|
+
data.tar.gz: 3c4565ffc5f98626ac67a07b378adfd80aaef787e47ffc50d84780da4b62788bdfb43e1b2e4ed90ca59cb4ee0fe23ec727dad8d1c0dd9413c137d7ec1de95510
|
data/.circleci/config.yml
CHANGED
@@ -81,8 +81,25 @@ jobs:
|
|
81
81
|
- slack/notify:
|
82
82
|
<<: *slack_notify
|
83
83
|
|
84
|
+
run_integration_tests:
|
85
|
+
docker:
|
86
|
+
- image: circleci/ruby:2.4.2-jessie-node
|
87
|
+
steps:
|
88
|
+
- checkout
|
89
|
+
- run:
|
90
|
+
name: Install bundle and run the tests
|
91
|
+
command: |
|
92
|
+
bundle check || bundle install
|
93
|
+
bundle exec ruby test_integration_app/main.rb
|
94
|
+
|
84
95
|
workflows:
|
85
96
|
ruby-test:
|
86
97
|
jobs:
|
87
98
|
- build:
|
88
99
|
context: *context
|
100
|
+
ruby-integration-tests:
|
101
|
+
jobs:
|
102
|
+
- run_integration_tests:
|
103
|
+
filters:
|
104
|
+
branches:
|
105
|
+
only: master
|
@@ -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
@@ -0,0 +1,103 @@
|
|
1
|
+
// Load Jenkins shared library
|
2
|
+
jenkinsBranch = 'v0.37.0'
|
3
|
+
sharedLib = library("shared-lib@${jenkinsBranch}")
|
4
|
+
|
5
|
+
def siftRubyWorkflow = sharedLib.com.sift.ci.SiftRubyWorkflow.new()
|
6
|
+
def ciUtil = sharedLib.com.sift.ci.CIUtil.new()
|
7
|
+
def stackdriver = sharedLib.com.sift.ci.StackDriverMetrics.new()
|
8
|
+
|
9
|
+
// Default GitHub status context for automatically triggered builds
|
10
|
+
def defaultStatusContext = 'Jenkins:auto'
|
11
|
+
|
12
|
+
// Pod template file for Jenkins agent pod
|
13
|
+
// Pod template yaml file is defined in https://github.com/SiftScience/jenkins/tree/master/resources/jenkins-k8s-pod-templates
|
14
|
+
def ruby2PodTemplateFile = 'ruby-2-4-2-pod-template.yaml'
|
15
|
+
def ruby2PodLabel = "ruby2-${BUILD_TAG}"
|
16
|
+
|
17
|
+
|
18
|
+
// GitHub repo name
|
19
|
+
def repoName = 'sift-ruby'
|
20
|
+
|
21
|
+
pipeline {
|
22
|
+
agent none
|
23
|
+
options {
|
24
|
+
timestamps()
|
25
|
+
skipDefaultCheckout()
|
26
|
+
disableConcurrentBuilds()
|
27
|
+
disableRestartFromStage()
|
28
|
+
parallelsAlwaysFailFast()
|
29
|
+
buildDiscarder logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '30', numToKeepStr: '')
|
30
|
+
timeout(time: 1, unit: 'HOURS')
|
31
|
+
}
|
32
|
+
environment {
|
33
|
+
GIT_BRANCH = "${env.CHANGE_BRANCH != null? env.CHANGE_BRANCH : env.BRANCH_NAME}"
|
34
|
+
}
|
35
|
+
stages {
|
36
|
+
stage('Initialize') {
|
37
|
+
steps {
|
38
|
+
script {
|
39
|
+
statusContext = defaultStatusContext
|
40
|
+
// Get the commit sha for the build
|
41
|
+
commitSha = ciUtil.commitHashForBuild()
|
42
|
+
ciUtil.updateGithubCommitStatus(repoName, statusContext, 'Started', 'pending', commitSha)
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
stage ('Build and Test Workflows') {
|
47
|
+
steps {
|
48
|
+
script {
|
49
|
+
def workflows = [:]
|
50
|
+
def stage1 = 'Run Integration Tests - ruby'
|
51
|
+
workflows[stage1] = {
|
52
|
+
stage(stage1) {
|
53
|
+
if (env.GIT_BRANCH.equals('master')) {
|
54
|
+
ciUtil.updateGithubCommitStatus(repoName, stage1, 'Started', 'pending', commitSha)
|
55
|
+
try {
|
56
|
+
siftRubyWorkflow.runSiftRubyIntegration(ruby2PodTemplateFile, ruby2PodLabel)
|
57
|
+
ciUtil.updateGithubCommitStatus(repoName, stage1, 'SUCCESS', 'success', commitSha)
|
58
|
+
} catch (Exception e) {
|
59
|
+
ciUtil.updateGithubCommitStatus(repoName, stage1, 'FAILURE', 'failure', commitSha)
|
60
|
+
print("${stage1} failed")
|
61
|
+
throw e
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
def stage2 = 'Test - ruby'
|
67
|
+
workflows[stage2] = {
|
68
|
+
stage(stage2) {
|
69
|
+
ciUtil.updateGithubCommitStatus(repoName, stage2, 'Started', 'pending', commitSha)
|
70
|
+
try {
|
71
|
+
siftRubyWorkflow.runSiftRubyTest(ruby2PodTemplateFile, ruby2PodLabel)
|
72
|
+
ciUtil.updateGithubCommitStatus(repoName, stage2, 'SUCCESS', 'success', commitSha)
|
73
|
+
} catch (Exception e) {
|
74
|
+
ciUtil.updateGithubCommitStatus(repoName, stage2, 'FAILURE', 'failure', commitSha)
|
75
|
+
print("${stage2} failed")
|
76
|
+
throw e
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
parallel workflows
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
post {
|
86
|
+
success {
|
87
|
+
script {
|
88
|
+
ciUtil.updateGithubCommitStatus(repoName, statusContext, currentBuild.currentResult, 'success', commitSha)
|
89
|
+
}
|
90
|
+
}
|
91
|
+
unsuccessful {
|
92
|
+
script {
|
93
|
+
ciUtil.updateGithubCommitStatus(repoName, statusContext, currentBuild.currentResult, 'failure', commitSha)
|
94
|
+
ciUtil.notifySlack(repoName, commitSha)
|
95
|
+
}
|
96
|
+
}
|
97
|
+
always {
|
98
|
+
script {
|
99
|
+
stackdriver.updatePipelineStatistics(this)
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
data/HISTORY
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
=== 4.5.0 2024-05-16
|
2
|
+
- Support for warnings in Events API
|
3
|
+
|
4
|
+
=== 4.4.0 2023-10-05
|
5
|
+
- Score percentiles in Score API
|
6
|
+
|
7
|
+
=== 4.3.0 2023-08-21
|
8
|
+
- PSP Merchant Management API
|
9
|
+
|
1
10
|
=== 4.2.0 2023-06-20
|
2
11
|
- Verification API support [Verification API](https://sift.com/developers/docs/curl/verification-api/overview)
|
3
12
|
- Support for score percentiles (only applicable for the accounts with the feature enabled)
|
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"
|
data/lib/sift/client.rb
CHANGED
@@ -201,6 +201,12 @@ module Sift
|
|
201
201
|
#
|
202
202
|
# :path::
|
203
203
|
# Overrides the URI path for this API call.
|
204
|
+
#
|
205
|
+
# :include_score_percentiles::
|
206
|
+
# include_score_percentiles(optional) : Whether to add new parameter in the query parameter.
|
207
|
+
#
|
208
|
+
# :warnings::
|
209
|
+
# warnings(optional) : Whether to add list of warnings (if any) to response.
|
204
210
|
#
|
205
211
|
# ==== Returns:
|
206
212
|
#
|
@@ -220,6 +226,7 @@ module Sift
|
|
220
226
|
force_workflow_run = opts[:force_workflow_run]
|
221
227
|
abuse_types = opts[:abuse_types]
|
222
228
|
include_score_percentiles = opts[:include_score_percentiles]
|
229
|
+
warnings = opts[:warnings]
|
223
230
|
|
224
231
|
raise("event must be a non-empty string") if (!event.is_a? String) || event.empty?
|
225
232
|
raise("properties cannot be empty") if properties.empty?
|
@@ -232,8 +239,12 @@ module Sift
|
|
232
239
|
query["return_route_info"] = "true" if return_route_info
|
233
240
|
query["force_workflow_run"] = "true" if force_workflow_run
|
234
241
|
query["abuse_types"] = abuse_types.join(",") if abuse_types
|
235
|
-
|
236
|
-
|
242
|
+
|
243
|
+
if include_score_percentiles == "true" || warnings == "true"
|
244
|
+
fields = []
|
245
|
+
fields << "SCORE_PERCENTILES" if include_score_percentiles == "true"
|
246
|
+
fields << "WARNINGS" if warnings == "true"
|
247
|
+
query["fields"] = fields.join(",")
|
237
248
|
end
|
238
249
|
|
239
250
|
options = {
|
@@ -275,6 +286,9 @@ module Sift
|
|
275
286
|
#
|
276
287
|
# :version::
|
277
288
|
# Overrides the version of the Events API to call.
|
289
|
+
#
|
290
|
+
# :include_score_percentiles::
|
291
|
+
# include_score_percentiles(optional) : Whether to add new parameter in the query parameter.
|
278
292
|
#
|
279
293
|
# ==== Returns:
|
280
294
|
#
|
@@ -286,6 +300,7 @@ module Sift
|
|
286
300
|
api_key = opts[:api_key] || @api_key
|
287
301
|
timeout = opts[:timeout] || @timeout
|
288
302
|
version = opts[:version] || @version
|
303
|
+
include_score_percentiles = opts[:include_score_percentiles]
|
289
304
|
|
290
305
|
raise("user_id must be a non-empty string") if (!user_id.is_a? String) || user_id.to_s.empty?
|
291
306
|
raise("Bad api_key parameter") if api_key.empty?
|
@@ -293,6 +308,9 @@ module Sift
|
|
293
308
|
query = {}
|
294
309
|
query["api_key"] = api_key
|
295
310
|
query["abuse_types"] = abuse_types.join(",") if abuse_types
|
311
|
+
if include_score_percentiles == "true"
|
312
|
+
query["fields"] = "SCORE_PERCENTILES"
|
313
|
+
end
|
296
314
|
|
297
315
|
options = {
|
298
316
|
:headers => {"User-Agent" => user_agent},
|
@@ -332,6 +350,9 @@ module Sift
|
|
332
350
|
#
|
333
351
|
# :timeout::
|
334
352
|
# Overrides the timeout (in seconds) for this call.
|
353
|
+
#
|
354
|
+
# :include_score_percentiles::
|
355
|
+
# include_score_percentiles(optional) : Whether to add new parameter in the query parameter.
|
335
356
|
#
|
336
357
|
# ==== Returns:
|
337
358
|
#
|
@@ -342,6 +363,7 @@ module Sift
|
|
342
363
|
abuse_types = opts[:abuse_types]
|
343
364
|
api_key = opts[:api_key] || @api_key
|
344
365
|
timeout = opts[:timeout] || @timeout
|
366
|
+
include_score_percentiles = opts[:include_score_percentiles]
|
345
367
|
|
346
368
|
raise("user_id must be a non-empty string") if (!user_id.is_a? String) || user_id.to_s.empty?
|
347
369
|
raise("Bad api_key parameter") if api_key.empty?
|
@@ -349,6 +371,9 @@ module Sift
|
|
349
371
|
query = {}
|
350
372
|
query["api_key"] = api_key
|
351
373
|
query["abuse_types"] = abuse_types.join(",") if abuse_types
|
374
|
+
if include_score_percentiles == "true"
|
375
|
+
query["fields"] = "SCORE_PERCENTILES"
|
376
|
+
end
|
352
377
|
|
353
378
|
options = {
|
354
379
|
:headers => {"User-Agent" => user_agent},
|
@@ -785,6 +810,111 @@ module Sift
|
|
785
810
|
Response.new(response.body, response.code, response.response)
|
786
811
|
end
|
787
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
|
+
|
788
918
|
private
|
789
919
|
|
790
920
|
def handle_response(response)
|
data/lib/sift/version.rb
CHANGED
data/lib/sift.rb
CHANGED
@@ -71,6 +71,18 @@ module Sift
|
|
71
71
|
"/content/#{ERB::Util.url_encode(content_id)}/decisions"
|
72
72
|
end
|
73
73
|
|
74
|
+
# Returns the path for psp Merchant API
|
75
|
+
def self.psp_merchant_api_path(account_id)
|
76
|
+
"/v3/accounts/#{ERB::Util.url_encode(account_id)}" \
|
77
|
+
"/psp_management/merchants"
|
78
|
+
end
|
79
|
+
|
80
|
+
# Returns the path for psp Merchant with id
|
81
|
+
def self.psp_merchant_id_api_path(account_id, merchant_id)
|
82
|
+
"/v3/accounts/#{ERB::Util.url_encode(account_id)}" \
|
83
|
+
"/psp_management/merchants/#{ERB::Util.url_encode(merchant_id)}"
|
84
|
+
end
|
85
|
+
|
74
86
|
# Module-scoped public API key
|
75
87
|
class << self
|
76
88
|
attr_accessor :api_key
|