Skip to content

Instantly share code, notes, and snippets.

@evanemolo
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanemolo/11380480 to your computer and use it in GitHub Desktop.
Save evanemolo/11380480 to your computer and use it in GitHub Desktop.
Perka - generate a visitor
# Customer Check-in Script
import requests
def init():
checkin_type = raw_input('Enter 1 for "points" or 2 for "punches": ')
new_customer_data = create_customer()
if checkin_type == '1':
checkin_customer('points', new_customer_data)
elif checkin_type == '2':
checkin_customer('punchcard', new_customer_data)
else:
print 'Invalid entry. Exit.'
def create_customer():
auth_info = requests.get('http://api-local.perka.com/1/card/customer')
json_res = auth_info.json()
customer_data = dict()
customer_data['token'] = json_res['access_token']
customer_data['customer_uuid'] = json_res['data']['perkaUser'][0]['uuid']
return customer_data
def checkin_customer(checkin_type, customer_data):
checkin_url = 'http://api-local.perka.com/1/card/customer/checkin'
# Payload value is simply a uuid representing the data sent
payload_value = 'c3986529-c267-3371-884e-044648d72022'
headers = {'Authorization':'Bearer ' + customer_data['token'],
'Content-Type': 'application/json'}
token = customer_data['token']
customer_uuid = customer_data['customer_uuid']
merchant_location_uuid = ''
if checkin_type == 'points':
points_merchant_location_uuid = '833d193c-5300-3129-8ba1-20409fc76faa'
merchant_location_uuid = points_merchant_location_uuid
else:
punchcard_merchant_location_uuid = '1940699b-9835-4228-8f06-2eea885c0d47'
merchant_location_uuid = punchcard_merchant_location_uuid
checkin_data_strings = (payload_value, customer_uuid, merchant_location_uuid,
payload_value)
checkin_data = '{"data":{"customerCheckin":[{"uuid":"%s","customerUuid":"%s", \
"merchantLocationUuid":"%s"}]},"value":"%s"}' % checkin_data_strings
checkin_post = requests.post(checkin_url, checkin_data, headers=headers)
if checkin_post.status_code == 200:
curl_strings = (token, payload_value, customer_uuid, merchant_location_uuid,
payload_value)
print 'Customer generated! Status code: %s' % (checkin_post.status_code)
print 'Run the following curl command to return the customer as present: \n'
print 'curl -X POST -H "Authorization:Bearer %s" -H "Content-Type: application/json" -d \'{"data":{"customerCheckin":[{"uuid":"%s", "customerUuid":"%s","merchantLocationUuid":"%s"}]},"value":"%s"}\' http://api-local.perka.com/1/card/customer/checkin' % curl_strings
else:
print 'Something failed...'
print checkin_post.text
return None
init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment