Skip to content

Commit 463d7ed

Browse files
authored
Merge pull request #59 from SiftScience/get_session_decisions
(For Mohammed) Add get session decisions
2 parents 89d7216 + dee34a2 commit 463d7ed

6 files changed

Lines changed: 64 additions & 2 deletions

File tree

HISTORY

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
=== 3.1.0 2018-06-04
2+
- Adds support for get session decisions to [Decisions API](https://siftscience.com/developers/docs/curl/decisions-api)
3+
14
=== 3.0.1 2018-04-06
25
- Improved documentation on HISTORY and README.MD
36

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ response = client.get_user_decisions('example_user_id')
207207
# Get the latest decisions for an order
208208
response = client.get_order_decisions('example_order_id')
209209

210+
# Get the latest decisions for a session
211+
response = client.get_session_decisions('example_user_id', 'example_session_id')
212+
210213
# Get the latest decisions for an content
211214
response = client.get_content_decisions('example_user_id', 'example_order_id')
212215
```

lib/sift.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ def self.order_decisions_api_path(account_id, order_id)
3333
"/v3/accounts/#{account_id}/orders/#{order_id}/decisions"
3434
end
3535

36+
# Returns the path for Session Decisions API
37+
def self.session_decisions_api_path(account_id, user_id, session_id)
38+
"/v3/accounts/#{account_id}/users/#{user_id}/sessions/#{session_id}/decisions"
39+
end
40+
3641
# Returns the path for Content Decisions API
3742
def self.content_decisions_api_path(account_id, user_id, content_id)
3843
"/v3/accounts/#{account_id}/users/#{user_id}/content/#{content_id}/decisions"

lib/sift/client.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,45 @@ def get_order_decisions(order_id, opts = {})
504504
Response.new(response.body, response.code, response.response)
505505
end
506506

507+
# Gets the decision status of a session.
508+
#
509+
# See https://siftscience.com/developers/docs/ruby/decisions-api/decision-status .
510+
#
511+
# ==== Parameters
512+
#
513+
# user_id::
514+
# The ID of the user in the session.
515+
#
516+
# session_id::
517+
# The ID of a session.
518+
#
519+
# opts (optional)::
520+
# A Hash of optional parameters for this request --
521+
#
522+
# :account_id::
523+
# Overrides the account id for this call.
524+
#
525+
# :api_key::
526+
# Overrides the API key for this call.
527+
#
528+
# :timeout::
529+
# Overrides the timeout (in seconds) for this call.
530+
#
531+
def get_session_decisions(user_id, session_id, opts = {})
532+
account_id = opts[:account_id] || @account_id
533+
api_key = opts[:api_key] || @api_key
534+
timeout = opts[:timeout] || @timeout
535+
536+
options = {
537+
:headers => { "User-Agent" => user_agent },
538+
:basic_auth => { :username => api_key, :password => "" }
539+
}
540+
options.merge!(:timeout => timeout) unless timeout.nil?
541+
542+
uri = API3_ENDPOINT + Sift.session_decisions_api_path(account_id, user_id, session_id)
543+
response = self.class.get(uri, options)
544+
Response.new(response.body, response.code, response.response)
545+
end
507546

508547
# Gets the decision status of a piece of content.
509548
#

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 = "3.0.1"
2+
VERSION = "3.1.0"
33
API_VERSION = "205"
44
end

spec/unit/client_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def fully_qualified_api_endpoint
363363
end
364364

365365

366-
it "Successfully make a user decisions request" do
366+
it "Successfully make a user decisions request" do
367367
response_text = '{"decisions":{"content_abuse":{"decision":{"id":"user_decision"},"time":1468707128659,"webhook_succeeded":false}}}'
368368

369369
stub_request(:get, "https://foobar:@api3.siftscience.com/v3/accounts/ACCT/users/example_user/decisions")
@@ -390,6 +390,18 @@ def fully_qualified_api_endpoint
390390
expect(response.body["decisions"]["payment_abuse"]["decision"]["id"]).to eq("decision7")
391391
end
392392

393+
it "Successfully make a session decisions request" do
394+
response_text = '{"decisions":{"account_takeover":{"decision":{"id":"session_decision"},"time":1468707128659,"webhook_succeeded":false}}}'
395+
396+
stub_request(:get, "https://foobar:@api3.siftscience.com/v3/accounts/ACCT/users/example_user/sessions/example_session/decisions")
397+
.to_return(:status => 200, :body => response_text, :headers => {})
398+
399+
client = Sift::Client.new(:api_key => "foobar", :account_id => "ACCT")
400+
response = client.get_session_decisions("example_user", "example_session")
401+
402+
expect(response.ok?).to eq(true)
403+
expect(response.body["decisions"]["account_takeover"]["decision"]["id"]).to eq("session_decision")
404+
end
393405

394406
it "Successfully make an content decisions request" do
395407
response_text = '{"decisions":{"content_abuse":{"decision":{"id":"decision7"},"time":1468599638005,"webhook_succeeded":false}}}'

0 commit comments

Comments
 (0)