# STEP 2:
# You'll always configure the api, providing your api key.
# This is required!
PassTools.configure(api_key = my_api_key)

# Our model DB...
user_db = [{"first_name": "James", "last_name":"Bond"},
           {"first_name": "Jimi", "last_name":"Hendrix"},
           {"first_name": "Johnny", "last_name":"Appleseed"}]

# You'll have selected the template you want to use...you can find the template ID in the Template Builder UI
selected_template_id = 604

# Retrieve your template, so you can modify the data and create passes from it
get_response = Template.get(selected_template_id)

the_fields_model = get_response["fieldsModel"]

# Now for each user in your DB, grab the user data, modify the template.fields_model, create a pass and download it:
for user_record in user_db:
    the_fields_model["fname"]["value"] = user_record["first_name"]
    the_fields_model["lname"]["value"] = user_record["last_name"]

    create_response = Pass.create(selected_template_id, the_fields_model)

    new_pass_id = create_response["id"]
    print "NEW PASS CREATED. ID: %s, First: %s, Last: %s" % (new_pass_id, user_record["first_name"], user_record["last_name"])
    Pass.download(new_pass_id, "/tmp/%s_%s.pkpass" % (user_record["first_name"], user_record["last_name"]))

# Now distribute the passes to your users!
Ejemplo n.º 2
0
# STEP 2:
# You'll always configure the api, providing your api key.
# This is required!
PassTools.configure(api_key = my_api_key)

# The 'list' operation retrieves a list of headers of templates created by the user referenced by the api_key.
# As headers, the retrieved items do not include the complete template.fields_model,
# but instead are intended to provide quick lookup info.
# Note the default sort order of the list is most-recent-first, and default page size = 10.

print 25*"#"
print "Retrieve default list of existing Templates owned by this user"
print "Note that the list is accompanied by some meta-info about total template count, page-size, etc."
print "And that the list of template headers proper is under the 'templateHeaders' key\n"

list_response = Template.list()
print "Total count of templates for this user:"******"Page size", list_response['pageSize']
print "Page number", list_response['page']
print "Order by", list_response['orderField']
print "Order direction", list_response['orderDirection']
for item in list_response['templateHeaders']:
    print item
print 25*"#", "\n"

# Use get() to retrieve the full form of one template--we'll just use the last ID in the list above.
# You might retrieve a template, for example, in preparation for creating an pass.
print 25*"#"
the_template_id = int(list_response['templateHeaders'][0]["id"])
print "Retrieve existing Template #%d" % the_template_id
get_response = Template.get(the_template_id)
Ejemplo n.º 3
0
from passtools.pt_template import Template

# API User:
# STEP 1: Retrieve your API key from your Account view on the PassTools website
my_api_key = "your-key-goes-in-here"

# STEP 2:
# You'll always configure the api, providing your api key.
# This is required!
PassTools.configure(api_key = my_api_key)

# Let's create a new pass from a template.
# Start by retrieving a template using the same method used in Ex1_Templates.py
# The first two steps are a bit contrived, since you would know the ID of the template
# you wanted to use, but for this example we'll get the whole list and use the latest
list_response = Template.list()
template_header_list = list_response["templateHeaders"]
the_template_id = template_header_list[0]['id']

get_response = Template.get(the_template_id)

# Now create a new pass from the template.
test_pass = Pass.create(the_template_id, get_response['fieldsModel'])

print 25*"#"
print "New Pass at start"
print test_pass
print 25*"#"

# Add a location to that pass. Locations are passed as a list of dicts, length 1 or more
# A pass can have a maximum of 10 locations
Ejemplo n.º 4
0
# STEP 2:
# You'll always configure the api, providing your api key.
# This is required!
PassTools.configure(api_key = my_api_key)

#######################
# TEMPLATES:
#######################
# First, we'll demonstrate using 'list' to retrieve a default list of headers for templates we own
print 25*"#"
print "Retrieve default list of existing Templates owned by this user"
print "Note that the list is accompanied by some meta-info about total template count, page-size, etc."
print "And that the list of template headers proper is under the 'templateHeaders' key\n"

list_response = Template.list()
report_templates(list_response)
print 25*"#", "\n"

print "Alter pageSize, default sort"

list_response = Template.list(pageSize=3)
report_templates(list_response)
print 25*"#", "\n"

print "Alter pageSize, sort by name, ascending"
# By the way: available sort order keys are "name", "id", "created", and "updated"

list_response = Template.list(pageSize=7, direction="asc", order="Name")
report_templates(list_response)
print 25*"#", "\n"