Created
April 23, 2013 16:42
-
-
Save luiscastillocr/5445264 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from base import http_get, url_builder, compare | |
import settings | |
import json | |
def get_route_kml_by_oauth(privacy_setting): | |
route_key = create_route_key(privacy_setting) | |
querystring = "get_route_kml?route_key=%s" % route_key | |
expected = 'application/vnd.google-earth.kml+xml' | |
result = http_get(url_builder(querystring), auth='oauth') | |
# API3 returns a valid kml file only if the route is found | |
compare(result.headers['content-type'],expected) | |
delete_route_key(route_key) | |
def get_route_kml_by_basic_auth(privacy_setting): | |
route_key = create_route_key(privacy_setting) | |
querystring = "get_route_kml?route_key=%s" % route_key | |
expected = 'application/vnd.google-earth.kml+xml' | |
result = http_get(url_builder(querystring), auth='basic') | |
# API3 returns a valid kml file only if the route is found | |
compare(result.headers['content-type'],expected) | |
delete_route_key(route_key) | |
def get_route_kml_by_server_token(privacy_setting): | |
route_key = create_route_key(privacy_setting) | |
querystring = "get_route_kml?route_key=%s" % route_key | |
expected = 'application/vnd.google-earth.kml+xml' | |
result = http_get(url_builder(querystring), auth='server-token') | |
# API3 returns a valid kml file only if the route is found | |
compare(result.headers['content-type'],expected) | |
delete_route_key(route_key) | |
def get_private_route_kml_by_server_token(privacy_setting): | |
route_key = create_route_key(privacy_setting) | |
querystring = "get_route_kml?route_key=%s" % route_key | |
expected = 'text/plain; charset=UTF-8' | |
result = http_get(url_builder(querystring), auth='server-token') | |
# API3 returns a valid kml file only if the route is found | |
compare(result.headers['content-type'],expected) | |
delete_route_key(route_key) | |
def create_route_key(privacy_setting): | |
public_flag = 1 | |
if privacy_setting == 0 or privacy_setting == 1: | |
public_flag = 0 | |
querystring = 'create_route?r=&route_key=&anonymous_flag=&public_flag=%s&privacy_setting=%s&average_rating=3&route_name=APIRoute&route_type_id=2&city=Cartago&state=&country=CostaRica&zip=&total_distance=12.34&route_description=BikeTraining&tags=&start_point_type=gym&commute_flag=0&event_flag=0&route_difficulty_rating=&route_obstacle_rating=&route_surface_rating=&route_data=lng1,lat1,[markerId]&xref=&send_social=' % (public_flag, privacy_setting) | |
response = http_get(url_builder(querystring),'oauth') | |
json_response = json.loads(response.text) | |
new_route_key = json_response['result']['output'].get('route_key') | |
return new_route_key | |
def delete_route_key(route_key): | |
querystring = "delete_route?r=&route_key=%s&route_id=" % route_key | |
result = http_get(url_builder(querystring), 'oauth') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment