Created
March 13, 2012 00:26
-
-
Save jasontan/2025642 to your computer and use it in GitHub Desktop.
Sift Science Python API Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# | |
# Example of how to use Sift Science API. Designed to work with Python | |
# 2.6 and above. To run: python ./sift_example.py | |
import sift_client | |
def main(): | |
sift_url = "https://api.siftscience.com/api/score" | |
sift_api_key = "z123" | |
sift = sift_client.SiftClient(sift_url, sift_api_key) | |
sift.connect() | |
# First John logs in... | |
sift.post_event({ "type" : "login", | |
"user_key" : "john", | |
"user_ip" : "100.101.102.103", | |
"user_device_id" : "windows/chrome/{arial,georgia,helvetica,times}" | |
}) | |
# Then John posts something new to sell... | |
sift.post_event({ "type" : "item", | |
"user_key" : "john", | |
"title" : "Fantastic watch for sale", | |
"description" : "A timeless classic.", | |
"photo_url" : "http://www.myecommerce.com/your/url/here", | |
"unique_key" : "35124561", | |
"user_ip" : "100.101.102.103", | |
"user_device_id" : "windows/chrome/{arial,georgia,helvetica,times}" | |
}) | |
# Then Jane messages John... | |
sift.post_event({ "type" : "message", | |
"content" : "Hi, I'm interested in your watch. Where was it made?", | |
"user_key" : "jane", | |
"user_ip" : "100.101.102.103", | |
"user_email" : "scammer@scamsrus.com", | |
"recipient_key" : "john", | |
"occurred_at" : "2011-07-27T18:50:58Z", | |
"user_device_id" : "windows/chrome/{arial,georgia,helvetica,times}", | |
"extras" : {"user_messages_frequently" : "true"} | |
}) | |
# Then Jane purchases from John | |
sift.post_event({ "type" : "purchase", | |
"user_key" : "jane", | |
"user_ip" : "100.101.102.103", # Same as John, suspicious... | |
"user_email" : "scammer@scamsrus.com", | |
"billing_line1" : "1321 Guerrero St", # Billing address, to help match with IP. | |
"billing_city" : "San Francisco", | |
"billing_state" : "CA", | |
"billing_zip" : "94110", | |
"billing_account" : "zx281sXnSAQ4301nD", # A salted hash of the credit card number | |
"billing_bin" : "123456", | |
"user_device_id" : "windows/chrome/{arial,georgia,helvetica,times}", | |
"item_key" : "35124561", # Matches what you provided in new_item | |
"extras" : {"num_profile_fields" : 3, | |
"installed_iphone_app" : False, | |
"fb_id" : "abc", | |
"fraud_score" : 0.1} | |
}) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment