-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2805967
commit a0604d2
Showing
2 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import requests | ||
import json | ||
|
||
def post_action(application, experiment, user): | ||
""" | ||
Records an action for the given user and experiment. | ||
Args: | ||
application: the application the experiment runs in | ||
experiment: the running experiment for which the event should be recorded | ||
user: the user who should be assigned | ||
""" | ||
|
||
urlAssignment = "http://abtesting.intuit.com/api/v1/events/applications/%s/experiments/%s/users/%s" %(application, experiment, user); | ||
|
||
headers = {'content-type': 'application/json'} | ||
# The actoin name can be freely assigned and an additional payload is | ||
# used for segmentation rules or available for later analysis | ||
events = {'events':[{'name':'ButtonClicked', 'payload':'{\'state\':\'CA\'}'}]} | ||
|
||
r = requests.post(urlAssignment, data = json.dumps(events), headers=headers) | ||
print(r.status_code) | ||
print(r.text) | ||
if r.status_code == 201: # when the request returns 201 the action was recorded correctly | ||
return True | ||
return False | ||
|
||
if __name__ == "__main__": | ||
application = 'ApplicationName' | ||
experiment = 'ExperimentName' | ||
user = 'UserName' | ||
|
||
print('Action recorded' if post_action(application, experiment, user) else 'Action not recorded') |
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