コード例 #1
0
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
print 25*"#"
print "Adding locations to new pass..."
location_list_1=[{"latitude":37.4471107, "longitude":-122.16206219999998,
                    "streetAddress1":"408 Florence St", "streetAddress2":"",
コード例 #2
0
# 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!
コード例 #3
0
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)

the_template = Template()
the_template.header = get_response["templateHeader"]
the_template.fields_model = get_response["fieldsModel"]
print the_template
print 25*"#","\n"

# Delete that template
print 25*"#"
print "Delete Template #%d" % the_template_id
Template.delete(the_template_id)

# And then try to retrieve it:
print "Attempted to retrieve deleted template #%s" % the_template_id
try: