-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(For Jintae or Gary) Add session level decision (#54)
* Add support for session level decisions
- Loading branch information
Showing
6 changed files
with
107 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,9 +80,9 @@ To learn more about the decisions endpoint visit our [developer docs](https://si | |
Get a list of your decisions. | ||
|
||
**Optional Params** | ||
- `entity_type`: `:user` or `:order` | ||
- `entity_type`: `:user` or `:order` or `:session` | ||
- `abuse_types`: `["payment_abuse", "content_abuse", "content_abuse", | ||
"account_abuse", "legacy"]` | ||
"account_abuse", "legacy", "account_takeover"]` | ||
|
||
**Returns** | ||
|
||
|
@@ -124,6 +124,7 @@ Applies a decision to an entity. Visit our [developer docs](http://siftscience.c | |
|
||
**Other Params** | ||
- `order_id`: when applying a decision to an order, you must pass in the `order_id` | ||
- `session_id`: when applying a decision to a session, you must pass in the `session_id` | ||
- `analyst`: when `source` is set to `manual_review`, this field *is required* | ||
|
||
**Returns** | ||
|
@@ -148,6 +149,15 @@ response = client.apply_decision({ | |
order_id: "ORDER_1234" | ||
}) | ||
|
||
# apply decision to "[email protected]"'s session | ||
response = client.apply_decision({ | ||
decision_id: "block_bad_session", | ||
source: "manual_review", | ||
analyst: "bob@your_company.com", | ||
user_id: "[email protected]", | ||
session_id: "SESSION_ID_1234" | ||
}) | ||
|
||
# Make sure you handle the response after applying a decision: | ||
|
||
if response.ok? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module Sift | ||
VERSION = "2.1.1" | ||
VERSION = "2.2.0" | ||
API_VERSION = "204" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,42 @@ class Decision | |
end | ||
end | ||
|
||
context "without a valid user_id or session_id" do | ||
it "will return a response object with the error message" do | ||
configs = { | ||
source: "manual", | ||
analyst: "[email protected]", | ||
description: "be blocking errrday allday", | ||
decision: decision, | ||
"session_id" => nil, | ||
user_id: "user_1234" | ||
} | ||
|
||
applier = ApplyTo.new(api_key, decision_id, configs) | ||
|
||
response = applier.run | ||
non_empty_string_error = | ||
Validate::Primitive::ERROR_MESSAGES[:non_empty_string] | ||
error_message = "session_id #{non_empty_string_error}, got NilClass" | ||
|
||
expect(response.ok?).to be(false) | ||
expect(response.body["error_message"]).to eq(error_message) | ||
|
||
## Invalid user_id | ||
|
||
configs.delete(:user_id) | ||
configs.delete("session_id") | ||
|
||
applier = ApplyTo.new(api_key, decision_id, configs) | ||
|
||
response = applier.run | ||
error_message = "user_id #{non_empty_string_error}, got NilClass" | ||
|
||
expect(response.ok?).to be(false) | ||
expect(response.body["error_message"]).to eq(error_message) | ||
end | ||
end | ||
|
||
context "when api returns an error code" do | ||
it "will return a response with the information" do | ||
configs = { | ||
|
@@ -141,7 +177,7 @@ class Decision | |
end | ||
end | ||
|
||
describe "private#path" do | ||
describe "#run" do | ||
it "will construct the right path given the configs" do | ||
user_id = "[email protected]" | ||
order_id = "ORDER_1235" | ||
|
@@ -156,8 +192,8 @@ class Decision | |
"/users/#{CGI.escape(user_id)}" + | ||
"/decisions" | ||
|
||
|
||
expect(applier.send(:path)).to eq(path) | ||
expect("https://api3.siftscience.com/v3/accounts/account_id" + | ||
"/users/bad_user%40example.com/decisions").to eq(path) | ||
|
||
applier = ApplyTo.new(api_key, decision_id, { | ||
user_id: user_id, | ||
|
@@ -169,11 +205,47 @@ class Decision | |
"/v3/accounts/#{decision.account_id}/users/" + | ||
"#{CGI.escape(user_id)}/orders/#{CGI.escape(order_id)}" + | ||
"/decisions" | ||
|
||
expect("https://api3.siftscience.com/v3/accounts/account_id" + | ||
"/users/bad_user%40example.com/orders/ORDER_1235/decisions").to eq(path) | ||
end | ||
end | ||
|
||
describe "#run" do | ||
it "will construct the right path given the configs" do | ||
user_id = "[email protected]" | ||
session_id = "gigtleqddo84l8cm15qe4il" | ||
|
||
applier = ApplyTo.new(api_key, decision_id, { | ||
user_id: user_id, | ||
account_id: decision.account_id, | ||
}) | ||
|
||
path = Client::API3_ENDPOINT + | ||
"/v3/accounts/#{decision.account_id}" + | ||
"/users/#{CGI.escape(user_id)}" + | ||
"/decisions" | ||
|
||
expect(applier.send(:path)).to eq(path) | ||
expect("https://api3.siftscience.com/v3/accounts/account_id" + | ||
"/users/bad_user%40example.com/decisions").to eq(path) | ||
|
||
applier = ApplyTo.new(api_key, decision_id, { | ||
user_id: user_id, | ||
account_id: decision.account_id, | ||
session_id: session_id | ||
}) | ||
|
||
path = Client::API3_ENDPOINT + | ||
"/v3/accounts/#{decision.account_id}/users/" + | ||
"#{CGI.escape(user_id)}/sessions/#{CGI.escape(session_id)}" + | ||
"/decisions" | ||
|
||
expect("https://api3.siftscience.com/v3/accounts/account_id" + | ||
"/users/bad_user%40example.com/sessions/gigtleqddo84l8cm15qe4il/decisions").to eq(path) | ||
end | ||
end | ||
|
||
|
||
# TODO(Kaoru): When we move to webmock 2 we won't need to do this | ||
# hackery | ||
# | ||
|