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

# First, we'll use 'list' to retrieve a list of pass headers we own (in abbreviated format)
# Note that, as with templates, default sort order of the list is most-recent-first
# and default page-size = 10
print 25*"#"
print "Retrieve default list of existing Passes owned by this user"
print "Note that the list is accompanied by some meta-info about total pass count, page-size, etc."
print "And that the list of pass descriptions proper is under the 'Passes' key\n"
print "Note also that you can retrieve passes associated with a specific template"

list_response = Pass.list()
print "Total count of passes 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['Passes']:
    print item
print 25*"#", "\n"

# Next, we'll retrieve the full form of a pass
# You might retrieve a pass, for example, in preparation for updating it.
# Normally, you'd know the ID of the pass you wanted--we'll just grab an id from the list above
print 25*"#"
the_pass_id = int(list_response['Passes'][0]['id'])

#######################
# PASSES:
#######################
# Now a few examples with passes. Same methods hold.

# First, we'll use 'list' to retrieve a default list of passes we own (in abbreviated format)
# Note that, as with templates, default sort order of the list is most-recent-first.
print 25*"#"
print "Retrieve default list of existing Passes owned by this user"
print "Note that the list is accompanied by some meta-info about total pass count, page-size, etc."
print "And that the list of pass descriptions proper is under the 'Passes' key\n"
print "Note also that you can retrieve passes associated with a specific template"

list_response = Pass.list()
report_passes(list_response)
print 25*"#", "\n"


print 25*"#"
print "Retrieve second page of existing Passes, 15 per page, owned by this user, ascending sort by creation date"
list_response = Pass.list(pageSize=15, page=2, direction="desc", order="created")
report_passes(list_response)
print 25*"#", "\n"

# Let's get passes associated with a specific template
# You would normally know which template ID you were interested in, but we'll just grab a known-good one
the_template_id = int(list_response["Passes"][-1]["templateId"])
print 25*"#"
print "Retrieve 2nd page of 3-per-page passes associated with template %s" % the_template_id