Skip to content

Commit

Permalink
Merge pull request #59 from SiftScience/get_session_decisions
Browse files Browse the repository at this point in the history
(For Mohammed) Add get session decisions
  • Loading branch information
mlegore authored Jun 4, 2018
2 parents 89d7216 + dee34a2 commit 463d7ed
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 2 deletions.
3 changes: 3 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
=== 3.1.0 2018-06-04
- Adds support for get session decisions to [Decisions API](https://siftscience.com/developers/docs/curl/decisions-api)

=== 3.0.1 2018-04-06
- Improved documentation on HISTORY and README.MD

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ response = client.get_user_decisions('example_user_id')
# Get the latest decisions for an order
response = client.get_order_decisions('example_order_id')

# Get the latest decisions for a session
response = client.get_session_decisions('example_user_id', 'example_session_id')

# Get the latest decisions for an content
response = client.get_content_decisions('example_user_id', 'example_order_id')
```
Expand Down
5 changes: 5 additions & 0 deletions lib/sift.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def self.order_decisions_api_path(account_id, order_id)
"/v3/accounts/#{account_id}/orders/#{order_id}/decisions"
end

# Returns the path for Session Decisions API
def self.session_decisions_api_path(account_id, user_id, session_id)
"/v3/accounts/#{account_id}/users/#{user_id}/sessions/#{session_id}/decisions"
end

# Returns the path for Content Decisions API
def self.content_decisions_api_path(account_id, user_id, content_id)
"/v3/accounts/#{account_id}/users/#{user_id}/content/#{content_id}/decisions"
Expand Down
39 changes: 39 additions & 0 deletions lib/sift/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,45 @@ def get_order_decisions(order_id, opts = {})
Response.new(response.body, response.code, response.response)
end

# Gets the decision status of a session.
#
# See https://siftscience.com/developers/docs/ruby/decisions-api/decision-status .
#
# ==== Parameters
#
# user_id::
# The ID of the user in the session.
#
# session_id::
# The ID of a session.
#
# opts (optional)::
# A Hash of optional parameters for this request --
#
# :account_id::
# Overrides the account id for this call.
#
# :api_key::
# Overrides the API key for this call.
#
# :timeout::
# Overrides the timeout (in seconds) for this call.
#
def get_session_decisions(user_id, session_id, opts = {})
account_id = opts[:account_id] || @account_id
api_key = opts[:api_key] || @api_key
timeout = opts[:timeout] || @timeout

options = {
:headers => { "User-Agent" => user_agent },
:basic_auth => { :username => api_key, :password => "" }
}
options.merge!(:timeout => timeout) unless timeout.nil?

uri = API3_ENDPOINT + Sift.session_decisions_api_path(account_id, user_id, session_id)
response = self.class.get(uri, options)
Response.new(response.body, response.code, response.response)
end

# Gets the decision status of a piece of content.
#
Expand Down
2 changes: 1 addition & 1 deletion lib/sift/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Sift
VERSION = "3.0.1"
VERSION = "3.1.0"
API_VERSION = "205"
end
14 changes: 13 additions & 1 deletion spec/unit/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def fully_qualified_api_endpoint
end


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

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

it "Successfully make a session decisions request" do
response_text = '{"decisions":{"account_takeover":{"decision":{"id":"session_decision"},"time":1468707128659,"webhook_succeeded":false}}}'

stub_request(:get, "https://foobar:@api3.siftscience.com/v3/accounts/ACCT/users/example_user/sessions/example_session/decisions")
.to_return(:status => 200, :body => response_text, :headers => {})

client = Sift::Client.new(:api_key => "foobar", :account_id => "ACCT")
response = client.get_session_decisions("example_user", "example_session")

expect(response.ok?).to eq(true)
expect(response.body["decisions"]["account_takeover"]["decision"]["id"]).to eq("session_decision")
end

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

0 comments on commit 463d7ed

Please sign in to comment.