Skip to content

Commit

Permalink
Adds support for version 204 of the Sift Science API.
Browse files Browse the repository at this point in the history
Version 204 of the Sift Science API is now called by default -- this
is an incompatible change, as some fields are no longer returned in
the v204 API (unless they are explicitly requested).

Also cleans up all Client methods (and the constructor) using a Hash
argument for optional paramaters.  This is an incompatible change.

Also adds support for the Workflow Status API, User Decisions API, and
Order Decisions API.
  • Loading branch information
jburnim committed Jul 18, 2016
1 parent 77e994f commit 0c5fca2
Show file tree
Hide file tree
Showing 10 changed files with 823 additions and 190 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ script: "bundle exec rake spec"
rvm:
- 1.9.3
- 2.0.0
- 2.1.5
- 2.2.1
before_install:
- gem install bundler
- bundle --version
env:
# None for now
gemfile:
Expand Down
7 changes: 7 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
=== 2.0.0.0 2016-07-19
* adds support for v204 of Sift Science's APIs
* adds Workflow Status API, User Decisions API, Order Decisions API
* v204 APIs are now called by default -- this is an incompatible change
(use :version => 203 to call the previous API version)
* uses Hash arg for optional params in Client methods -- incompatible change

=== 1.1.7.2 2015-04-13
* Fixed backwards compatibility issue

Expand Down
47 changes: 36 additions & 11 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
= Sift Science Ruby bindings {<img src="https://travis-ci.org/SiftScience/sift-ruby.png?branch=master" alt="Build Status" />}[https://travis-ci.org/SiftScience/sift-ruby]


== Requirements

* Ruby 1.8.7 or above. (Ruby 1.8.6 might work if you load ActiveSupport.)
Expand All @@ -12,6 +13,7 @@ For development only:
* webmock, 1.16 or greater
* rake, any version


== Installation

If you want to build the gem from source:
Expand All @@ -22,16 +24,19 @@ Alternatively, you can install the gem from Rubyforge:

$ gem install sift


== Usage

require "sift"

Sift.api_key = '<your_api_key_here>'
Sift.account_id = '<your_account_id_here>'
client = Sift::Client.new()

# send a transaction event -- note this is blocking
event = "$transaction"

user_id = "23056" # User ID's may only contain a-z, A-Z, 0-9, =, ., -, _, +, @, :, &, ^, %, !, $
user_id = "23056" # User ID's may only contain a-z, A-Z, 0-9, =, ., -, _, +, @, :, &, ^, %, !, $

properties = {
"$user_id" => user_id,
Expand All @@ -50,20 +55,39 @@ Alternatively, you can install the gem from Rubyforge:
}

response = client.track(event, properties)

response.ok? # returns true or false

response.http_status_code # HTTP response code, 200 is ok.

response.api_status # status field in the return body, Link to Error Codes

response.api_error_message # Error message associated with status Error Code
response.ok? # returns true or false
response.body # API response body
response.http_status_code # HTTP response code, 200 is ok.
response.api_status # status field in the return body, Link to Error Codes
response.api_error_message # Error message associated with status Error Code

# Request a score forthe user with user_id 23056

# Request a score for the user with user_id 23056
response = client.score(user_id)



# Label the user with user_id 23056 as Bad with all optional fields
response = client.label(user_id,{ "$is_bad" => true, "$reasons" => ["$chargeback", ], "$description" => "Chargeback issued", "$source" => "Manual Review", "$analyst" => "analyst.name@your_domain.com"})
response = client.label(user_id, {
"$is_bad" => true,
"$abuse_type" => "payment_abuse",
"$description" => "Chargeback issued",
"$source" => "Manual Review",
"$analyst" => "analyst.name@your_domain.com"
})


# Get the status of a workflow run
response = client.get_workflow_status('my_run_id')


# Get the latest decisions for a user
response = client.get_user_decisions('example_user_id')


# Get the latest decisions for an order
response = client.get_order_decisions('example_order_id')


== Building

Expand All @@ -78,6 +102,7 @@ Building and publishing the gem is captured by the following steps:
$ rake install
$ rake release


== Testing

To run the various tests use the rake command as follows:
Expand Down
41 changes: 33 additions & 8 deletions lib/sift.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,46 @@

module Sift

# Returns the path for the current API version
def self.current_rest_api_path
"/v#{API_VERSION}/events"
# Returns the path for the specified API version
def self.rest_api_path(version=API_VERSION)
"/v#{version}/events"
end

def self.current_users_label_api_path(user_id)
# This API version is a minor version ahead of the /events API
"/v#{API_VERSION}/users/#{URI.encode(user_id)}/labels"
# Returns the Score API path for the specified user ID and API version
def self.score_api_path(user_id, version=API_VERSION)
"/v#{version}/score/#{URI.encode(user_id)}/"
end

# Adding module scoped public API key

# Returns the users API path for the specified user ID and API version
def self.users_label_api_path(user_id, version=API_VERSION)
"/v#{version}/users/#{URI.encode(user_id)}/labels"
end

# Returns the path for the Workflow Status API
def self.workflow_status_path(account_id, run_id)
"/v3/accounts/#{account_id}/workflows/runs/#{run_id}"
end

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

# Returns the path for Orders Decisions API
def self.order_decisions_api_path(account_id, order_id)
"/v3/accounts/#{account_id}/orders/#{order_id}/decisions"
end

# Module-scoped public API key
class << self
attr_accessor :api_key
end

# Module-scoped account ID
class << self
attr_accessor :account_id
end

# Sets the Output logger to use within the client. This can be left uninitializaed
# but is useful for debugging.
def self.logger=(logger)
Expand Down
Loading

0 comments on commit 0c5fca2

Please sign in to comment.