Skip to content

Commit d1eeccf

Browse files
authored
Merge pull request #48 from SiftScience/jburnim_api_v204
Add support for Sift Science's version-204 API.
2 parents 78f8dd3 + 15b044b commit d1eeccf

File tree

10 files changed

+931
-159
lines changed

10 files changed

+931
-159
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ install:
88
- pip install -e .[test]
99
# command to run tests
1010
script:
11-
- python tests/client_test.py
11+
- unit2

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License
22

3-
Copyright (c) 2013-2014 Sift Science (https://siftscience.com)
3+
Copyright (c) 2013-2016 Sift Science (https://siftscience.com)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# Sift Science Python Bindings ![TravisCI](https://travis-ci.org/SiftScience/sift-python.png?branch=master)
22

3-
Bindings for Sift Science's [Events](https://siftscience.com/resources/references/events-api.html), [Labels](https://siftscience.com/resources/references/labels-api.html), and [Score](https://siftscience.com/resources/references/score-api.html) APIs.
3+
Bindings for Sift Science's APIs -- including the
4+
[Events](https://siftscience.com/resources/references/events-api.html),
5+
[Labels](https://siftscience.com/resources/references/labels-api.html),
6+
and
7+
[Score](https://siftscience.com/resources/references/score-api.html)
8+
APIs.
9+
410

511
## Installation
612

7-
Set up a virtual environment with virtualenv (otherwise you will need to
8-
make the pip calls as sudo):
13+
Set up a virtual environment with virtualenv (otherwise you will need
14+
to make the pip calls as sudo):
915

1016
virtualenv venv
1117
source venv/bin/activate
@@ -33,11 +39,19 @@ Python 3:
3339

3440
## Documentation
3541

36-
Please see [here](https://siftscience.com/docs/api/python) for the most up-to-date documentation.
42+
Please see [here](https://siftscience.com/docs/api/python) for the
43+
most up-to-date documentation.
3744

3845
## Changelog
3946

40-
Please see [the CHANGELOG](https://github.com/SiftScience/sift-python/blob/master/CHANGES.md) for a history of all changes. Note, that in v2.0.0.0, the API semantics were changed to raise an exception in the case of error to be more pythonic. Client code will need to be updated to catch `sift.client.ApiException` exceptions.
47+
Please see
48+
[the CHANGELOG](https://github.com/SiftScience/sift-python/blob/master/CHANGES.md)
49+
for a history of all changes.
50+
51+
Note, that in v2.0.0.0, the API semantics were changed to raise an
52+
exception in the case of error to be more pythonic. Client code will
53+
need to be updated to catch `sift.client.ApiException` exceptions.
54+
4155

4256
## Usage
4357

@@ -47,11 +61,13 @@ Here's an example:
4761

4862
import sift.client
4963

50-
sift.api_key = '<your api key here>'
64+
sift.api_key = '<your API key here>'
65+
sift.account_id = '<your account ID here>'
5166
client = sift.Client()
5267

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

70+
5571
# Track a transaction event -- note this is a blocking call
5672
properties = {
5773
"$user_id" : user_id,
@@ -89,26 +105,51 @@ except sift.client.ApiException:
89105

90106
try:
91107
# Label the user with user_id 23056 as Bad with all optional fields
92-
response = client.label(user_id,{ "$is_bad" : True, "$reasons" : ["$chargeback", ],
93-
"$description" : "Chargeback issued",
94-
"$source" : "Manual Review",
95-
"$analyst" : "analyst.name@your_domain.com"})
108+
response = client.label(user_id, {
109+
"$is_bad" : True,
110+
"$abuse_type" : "payment_abuse",
111+
"$description" : "Chargeback issued",
112+
"$source" : "Manual Review",
113+
"$analyst" : "analyst.name@your_domain.com"
114+
})
96115
except sift.client.ApiException:
97116
# request failed
98117

99118

100119
# Remove a label from a user with user_id 23056
101120
try:
102-
response = client.unlabel(user_id)
121+
response = client.unlabel(user_id, abuse_type='content_abuse')
122+
except sift.client.ApiException:
123+
# request failed
124+
125+
126+
# Get the status of a workflow run
127+
try:
128+
response = client.get_workflow_status('my_run_id');
129+
except sift.client.ApiException:
130+
# request failed
131+
132+
133+
# Get the latest decisions for a user
134+
try:
135+
response = client.get_user_decisions('example_user');
136+
except sift.client.ApiException:
137+
# request failed
138+
139+
140+
# Get the latest decisions for an order
141+
try:
142+
response = client.get_order_decisions('example_order');
103143
except sift.client.ApiException:
104144
# request failed
105145

106146
```
107147

148+
108149
## Testing
109150

110151
Before submitting a change, make sure the following commands run without
111152
errors from the root dir of the repository:
112153

113-
PYTHONPATH=. python tests/client_test.py
114-
PYTHONPATH=. python3 tests/client_test.py
154+
python -m unittest discover
155+
python3 -m unittest discover

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
extras_require={
3737
'test': [
3838
'mock >= 1.0.1',
39+
'unittest2 >= 1, < 2',
3940
],
4041
},
4142

sift/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
api_key = None
2+
account_id = None
23
from .client import Client

0 commit comments

Comments
 (0)