Skip to content

Commit

Permalink
add action call for python
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaSuckro committed Mar 27, 2017
1 parent 2805967 commit a0604d2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
33 changes: 33 additions & 0 deletions modules/ui/app/resources/samplecode/python/action.py
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')
4 changes: 2 additions & 2 deletions modules/ui/app/resources/samplecode/python/impression.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import requests
import json

def get_impression(application, experiment, user):
def post_impression(application, experiment, user):
"""
Records an impression for the given user and experiment.
Expand All @@ -26,4 +26,4 @@ def get_impression(application, experiment, user):
experiment = 'ExperimentName'
user = 'UserName'

print('Impression recorded' if get_impression(application, experiment, user) else 'Impression not recorded')
print('Impression recorded' if post_impression(application, experiment, user) else 'Impression not recorded')

0 comments on commit a0604d2

Please sign in to comment.