Skip to content

Commit

Permalink
Added Route Exporter API V5
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan authored and Juan committed Aug 3, 2021
1 parent 31ec652 commit 842ef08
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
21 changes: 21 additions & 0 deletions examples/routes/export_route_v5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
import argparse

from route4me import Route4Me


def main(api_key, route_id):
route4me = Route4Me(api_key)
route = route4me.route
exported_route = route.export_route_v5(route_id)

print(exported_route)

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Route Exporter API V5')
parser.add_argument('--api_key', dest='api_key', help='Route4Me API KEY',
type=str, required=True)
parser.add_argument('--route_id', dest='route_id', help='Route ID',
type=str, required=True)
args = parser.parse_args()
main(args.api_key, args.route_id)
2 changes: 2 additions & 0 deletions route4me/api_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@
VEHICLES_HOST = '{}/api/vehicles/view_vehicles.php'.format(MAIN_HOST)
WEBINAR_REGISTER = '{0}/actions/webinar_register.php'.format(MAIN_HOST)
ZIPCODE_TERRITORIES = 'https://rapid.route4me.com/street_data/territories'

EXPORTER_V5 = 'https://wh.route4me.com/modules/api/v5.0/route-export/{route_id}/export'
25 changes: 22 additions & 3 deletions route4me/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import json

from .api_endpoints import ROUTE_HOST, EXPORTER, \
ADDRESS_HOST, GET_ACTIVITIES_HOST, DUPLICATE_ROUTE, SHARE_ROUTE_HOST, \
MERGE_ROUTES_HOST, RESEQUENCE_ROUTE
from .api_endpoints import ROUTE_HOST, EXPORTER
from .api_endpoints import ADDRESS_HOST, GET_ACTIVITIES_HOST, DUPLICATE_ROUTE, SHARE_ROUTE_HOST
from .api_endpoints import MERGE_ROUTES_HOST, RESEQUENCE_ROUTE
from .api_endpoints import EXPORTER_V5
from .base import Base
from .exceptions import ParamValueException

Expand Down Expand Up @@ -325,6 +326,7 @@ def export_route(self, route_id, output_format='csv'):
:param output_format:
:return: response as a object
"""
print("DEPRECATED. Please use export_route_v5")
data = {'route_id': route_id, 'strExportFormat': output_format}
self.response = self.api._make_request(EXPORTER, {}, data,
self.api._request_post)
Expand All @@ -334,4 +336,21 @@ def _update_route(self, params, data):
params.update({'api_key': self.api.key})
return self.api._request_put(ROUTE_HOST, request_params=params, json=data)

def export_route_v5(self, route_id, output_format='csv', all_custom_fields=True, columns=None):
"""
Get Route from given post data
:param route_id:
:param output_format:
:return: response as a object
"""
params = {
'api_key': self.params['api_key'],
}
data = {'all_custom_fields': all_custom_fields, 'format': output_format}
if columns is not None:
data["columns"] = columns
self.response = self.api._make_request(EXPORTER_V5.format(route_id=route_id), params, data,
self.api._request_post)
return self.response.content

# codebeat:enable[TOO_MANY_FUNCTIONS]

0 comments on commit 842ef08

Please sign in to comment.