Sift Science Ruby bindings <img src=“travis-ci.org/SiftScience/sift-ruby.png?branch=master” alt=“Build Status” />
Requirements
* Ruby 1.8.7 or above. (Ruby 1.8.6 might work if you load ActiveSupport.)
* HTTParty, 0.11.0 or greater
* Multi Json, 1.0 or greater
For development only:
* bundler
* rspec, 2.14.1 or greater
* webmock, 1.16 or greater
* rake, any version
Installation
If you want to build the gem from source:
$ gem build sift.gemspec
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, =, ., -, _, +, @, :, &, ^, %, !, $
properties = {
"$user_id" => user_id,
"$user_email" => "[email protected]",
"$seller_user_id" => "2371",
"seller_user_email" => "[email protected]",
"$transaction_id" => "573050",
"$payment_method" => {
"$payment_type" => "$credit_card",
"$payment_gateway" => "$braintree",
"$card_bin" => "542486",
"$card_last4" => "4444"
},
"$currency_code" => "USD",
"$amount" => 15230000,
}
response = client.track(event, properties)
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. # Error message associated with status Error Code
# 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,
"$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
Building and publishing the gem is captured by the following steps:
$ gem build sift.gemspec
$ gem push sift-<current version>.gem
$ bundle
$ rake -T
$ rake build
$ rake install
$ rake release
Testing
To run the various tests use the rake command as follows:
$ rake spec