Skip to content

Commit 0544b4a

Browse files
Merge pull request #91 from SiftScience/API-7683
API-7683: Add support for warnings in Events API
2 parents 05c9957 + 009f91c commit 0544b4a

6 files changed

Lines changed: 60 additions & 6 deletions

File tree

HISTORY

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
=== 4.5.0 2024-05-16
2+
- Support for warnings in Events API
3+
14
=== 4.4.0 2023-10-05
25
- Score percentiles in Score API
36

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# sift-ruby
2-
[![CircleCI](https://circleci.com/gh/SiftScience/sift-ruby.svg?style=svg)](https://circleci.com/gh/SiftScience/sift-ruby)
32

43
The official Ruby bindings for the latest version (v205) of the [Sift API](https://sift.com/developers/docs/java/apis-overview).
54

@@ -39,8 +38,22 @@ client = Sift::Client.new(api_key: '<your_api_key_here>', account_id: '<your_acc
3938

4039
```
4140

42-
### Sending a transaction event
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).
4344

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:**
4457
```ruby
4558
event = "$transaction"
4659

lib/sift/client.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ def user_agent
205205
# :include_score_percentiles::
206206
# include_score_percentiles(optional) : Whether to add new parameter in the query parameter.
207207
#
208+
# :warnings::
209+
# warnings(optional) : Whether to add list of warnings (if any) to response.
210+
#
208211
# ==== Returns:
209212
#
210213
# In the case of a network error (timeout, broken connection, etc.),
@@ -223,6 +226,7 @@ def track(event, properties = {}, opts = {})
223226
force_workflow_run = opts[:force_workflow_run]
224227
abuse_types = opts[:abuse_types]
225228
include_score_percentiles = opts[:include_score_percentiles]
229+
warnings = opts[:warnings]
226230

227231
raise("event must be a non-empty string") if (!event.is_a? String) || event.empty?
228232
raise("properties cannot be empty") if properties.empty?
@@ -235,8 +239,12 @@ def track(event, properties = {}, opts = {})
235239
query["return_route_info"] = "true" if return_route_info
236240
query["force_workflow_run"] = "true" if force_workflow_run
237241
query["abuse_types"] = abuse_types.join(",") if abuse_types
238-
if include_score_percentiles == "true"
239-
query["fields"] = "SCORE_PERCENTILES"
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(",")
240248
end
241249

242250
options = {

lib/sift/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module Sift
2-
VERSION = "4.4.0"
2+
VERSION = "4.5.0"
33
API_VERSION = "205"
44
end

spec/unit/client_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ def action_response_json
110110
}
111111
end
112112

113+
def warnings
114+
{
115+
:count => 1,
116+
:items => [{
117+
:message => 'Invalid currency'
118+
}]
119+
}
120+
end
121+
113122
def percentile_response_json
114123
{
115124
:user_id => 'billy_jones_301',
@@ -689,4 +698,25 @@ def fully_qualified_api_endpoint
689698
expect(response.body["scores"]["payment_abuse"]["score"]).to eq(0.78)
690699
end
691700

701+
it "Successfully submits a v205 event with WARNINGS" do
702+
response_json =
703+
{ :status => 0, :error_message => "OK", :warnings => warnings}
704+
stub_request(:post, "https://api.siftscience.com/v205/events?fields=WARNINGS").
705+
with { | request|
706+
parsed_body = JSON.parse(request.body)
707+
expect(parsed_body).to include("$api_key" => "overridden")
708+
}.to_return(:status => 200, :body => MultiJson.dump(response_json), :headers => {})
709+
710+
api_key = "foobar"
711+
event = "$transaction"
712+
properties = valid_transaction_properties
713+
714+
response = Sift::Client.new(:api_key => api_key, :version => "205")
715+
.track(event, properties, :api_key => "overridden",:warnings => "true")
716+
expect(response.ok?).to eq(true)
717+
expect(response.api_status).to eq(0)
718+
expect(response.api_error_message).to eq("OK")
719+
expect(response.body["warnings"]["count"]).to eq(1)
720+
expect(response.body["warnings"]["items"][0]["message"]).to eq("Invalid currency")
721+
end
692722
end

test_integration_app/events_api/test_events_api.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def transaction()
122122
}
123123
}
124124

125-
return @@client.track("$transaction", properties)
125+
return @@client.track("$transaction", properties, :warnings => 'true')
126126
end
127127

128128
def create_order()

0 commit comments

Comments
 (0)