示例#1
0
# 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)

# Pick the pass to work on
# This example script is more interesting if you installed that pass on multiple phones.
test_pass_id = your-pass-id-goes-here

# Retrieve the full form of that pass
print 25*"#"
print "Retrieving Pass #%s" % test_pass_id
get_response = Pass.get(test_pass_id)

print "Retrieved Pass..."
print get_response
print 25*"#"

# Now update the pass...
# Make a copy of the fields to operate on
working_copy = copy.deepcopy(get_response["passFields"])

# modify fields here:
working_copy["primary1"]["value"] = "Push Happens!"
working_copy["secondary1"]["value"] = "Push Happens Again!"

# Call 'update', passing the modifications as input.
update_response = Pass.update(test_pass_id, working_copy)
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":"",
                    "city":"Palo Alto", "region":"CA", "regionCode":"94301",
                    "country":"US", "relevantText":"Palo Alto Office!"}]
add_response = Pass.add_locations(test_pass['id'], location_list_1)
print "ADD_RESP", add_response

print "After adding 1 location..."
after_first_add = Pass.get(test_pass['id'])
print after_first_add
print 25*"#"

# Add multiple locations at one time
print 25*"#"
print "Adding locations to new pass..."
location_list_2 =[{"latitude":45.5255003, "longitude":-122.6821440,
                   "streetAddress1":"334 NW 11th Ave", "streetAddress2":"",
                   "city":"Portland", "region":"OR", "regionCode":"97209",
                   "country":"US", "relevantText":"Portland Office!"},
                  {"latitude":37.7723721, "longitude":-122.4057149,
                   "streetAddress1":"41 Decatur", "streetAddress2":"",
                   "city":"San Francisco", "region":"CA", "regionCode":"94103",
                   "country":"US", "relevantText":"SF Office!"}]
add_response = Pass.add_locations(test_pass['id'], location_list_2)
from passtools import PassTools
from passtools.pt_pass import Pass

# 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)

# Retrieve the current form of the pass, using the pass ID.
current_pass_id = 2039
starting_pass = Pass.get(current_pass_id)

# Let's a copy of the fields to operate on
pass_fields = copy.deepcopy(starting_pass["passFields"])

print "Starting:"
print "Offer:", pass_fields["offer"]["value"]
print "Exp_date:", pass_fields["exp_date"]["value"]

# Now set the new data. We're going to imagine that our initial offer just expired, and we're setting a '15% off'
# offer to extend 'til the end of the year:

# NOTE: date values must be passed in iso-8601 format
pass_fields["exp_date"]["value"] = "2013-01-01T12:01Z"
pass_fields["offer"]["value"] = "15% Off!!!"
示例#4
0
print "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'])

print "Retrieving Pass #%s" % the_pass_id
get_response = Pass.get(the_pass_id)

print "Retrieved Pass..."
print get_response
print 25*"#"

# Now 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 probably 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()
the_template_id = int(list_response['templateHeaders'][0]["id"])
get_response = Template.get(the_template_id)
the_template_fields_model = get_response["fieldsModel"]

# With the template in hand, you could modify any values for fields you defined in that template, so
print 25*"#"
print "New Pass at start"
print test_pass
print 25*"#"

# And let's update the "relevantDate" field in that pass
# Note that as of this writing, the RelevantDate argument is not format-validated
# so you _must_ ensure that the date you pass in confirms to ISO-8601
pass_fields = copy.deepcopy(test_pass["passFields"])
print 25*"#"
print "Start pass update..."
if "relevantDate" in pass_fields:
    pass_fields["relevantDate"]["value"] = "2012-01-01T12:00-08:00"

    # Call 'update', passing the modifications as input
    update_response = Pass.update(test_pass['id'], pass_fields)
    print update_response

    # At this point, you could retrieve the updated pass, download it, etc.
    updated_pass = Pass.get(test_pass['id'])

    print "Updated Pass..."
    print updated_pass
    print 25*"#"
    # The update will be returned; note that the ID is the same, the serial number is the same,
    # and the change to RelevantDate has been incorporated.

else:
    print "No relevantDate to update"