Skip to content

Commit

Permalink
[ADDED] Feature to set, get, rollback Route Status
Browse files Browse the repository at this point in the history
  • Loading branch information
r4m-juan committed May 2, 2023
1 parent f0555ef commit 71b7a41
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 3 deletions.
2 changes: 1 addition & 1 deletion VERSION.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# VERSION.py - MAINTAINER's. Don't edit, if you don't know what are you doing
# ==============================================================================

VERSION = (0, 1, 4, 4)
VERSION = (0, 1, 5, 0)
RELEASE_SUFFIX = ''

VERSION_STRING = '.'.join([str(x) for x in VERSION])
Expand Down
24 changes: 24 additions & 0 deletions examples/route_status/get_route_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-

import argparse

from route4me import Route4Me


def main(api_key, route_id):
r4m = Route4Me(api_key)

route = r4m.route_status
print('Route ID: {}'.format(route_id))
response = route.get_route_status(route_id=route_id)
print(response)


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Get a Route')
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='Route4Me Route ID',
type=str, required=True)
args = parser.parse_args()
main(args.api_key, args.route_id)
24 changes: 24 additions & 0 deletions examples/route_status/get_route_status_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-

import argparse

from route4me import Route4Me


def main(api_key, route_id):
r4m = Route4Me(api_key)

route = r4m.route_status
print('Route ID: {}'.format(route_id))
response = route.get_route_status_history(route_id=route_id)
print(response)


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Get a Route')
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='Route4Me Route ID',
type=str, required=True)
args = parser.parse_args()
main(args.api_key, args.route_id)
24 changes: 24 additions & 0 deletions examples/route_status/rollback_route_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-

import argparse

from route4me import Route4Me


def main(api_key, route_id):
r4m = Route4Me(api_key)

route = r4m.route_status
print('Route ID: {}'.format(route_id))
response = route.rollback_route_status(route_id=route_id)
print(response)


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Get a Route')
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='Route4Me Route ID',
type=str, required=True)
args = parser.parse_args()
main(args.api_key, args.route_id)
31 changes: 31 additions & 0 deletions examples/route_status/set_route_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-

import argparse

from route4me import Route4Me


def main(api_key, route_id, status, lat, lng):
r4m = Route4Me(api_key)

route = r4m.route_status
print('Route ID: {}'.format(route_id))
print('Latitude: {} - Longitude: {}'.format(lat, lng))
response = route.set_route_status(route_id=route_id, status=status, lat=lat, lng=lng)
print(response)


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Get a Route')
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='Route4Me Route ID',
type=str, required=True)
parser.add_argument('--status', dest='status', help='Route Status: planned, started, paused, completed',
type=str, required=True)
parser.add_argument('--lat', dest='lat', help='Latitude',
type=float, required=True)
parser.add_argument('--lng', dest='lng', help='Longitude',
type=float, required=True)
args = parser.parse_args()
main(args.api_key, args.route_id, args.status, args.lat, args.lng)
2 changes: 2 additions & 0 deletions route4me/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .vehicles import Vehicle
from .telematics import Telematics
from .api_endpoints import API_HOST
from .route_status import RouteStatus


HEADERS = {
Expand Down Expand Up @@ -60,6 +61,7 @@ def __init__(self,
self.redirects = redirects
self.verify_ssl = verify_ssl
self.proxies = proxies
self.route_status = RouteStatus(self)

def _make_request(self, url, params, data, request_method):
"""
Expand Down
2 changes: 2 additions & 0 deletions route4me/api_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# codebeat:disable[TOO_MANY_FUNCTIONS, LOC, ABC, ARITY, TOTAL_LOC]

MAIN_HOST = 'https://api.route4me.com'
API_V5 = 'https://wh.route4me.com/modules/api/v5.0'

ACTIVITY_FEED = '{0}/api.v4/activity_feed.php'.format(MAIN_HOST)
ADDRESSBOOK = '{0}/api.v4/address_book.php'.format(MAIN_HOST)
Expand Down Expand Up @@ -46,3 +47,4 @@
ZIPCODE_TERRITORIES = 'https://rapid.route4me.com/street_data/territories'

EXPORTER_V5 = 'https://wh.route4me.com/modules/api/v5.0/route-export/{route_id}/export'
ROUTE_STATUS_V5 = '{}/route-status'.format(API_V5)
6 changes: 6 additions & 0 deletions route4me/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,9 @@ def auto_enum(*sequential, **named):
SERVICE="SERVICE",
VISIT="VISIT",
DRIVEBY="DRIVEBY")

ROUTE_STATUS = enum(PLANNED="planned",
STARTED="started",
PAUSED="paused",
RESUMED="resumed",
COMPLETED="completed")
56 changes: 56 additions & 0 deletions route4me/route_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-

from datetime import datetime
from .base import Base
from .api_endpoints import ROUTE_STATUS_V5


class RouteStatus(Base):
"""
Route Status
- Planned
- Started
- Paused
- Resumed
- Completed
"""

def __init__(self, api):
"""
Routes
:param api: Route4Me API Instance
"""
self.params = {'api_key': api.key, }
Base.__init__(self, api)

def get_route_status(self, route_id):
response = self.api._request_get("{}/{}".format(ROUTE_STATUS_V5, route_id),
self.params)
return response.json()

def get_route_status_history(self, route_id):
response = self.api._request_get("{}/{}/history".format(ROUTE_STATUS_V5, route_id),
self.params)
return response.json()

def set_route_status(self, route_id, status, lat, lng, event_timestamp=None):
if event_timestamp is None:
event_timestamp = int(datetime.now().timestamp())
data = {
"status": status,
"lat": lat,
'lng': lng,
'event_timestamp': event_timestamp,
}
response = self.api._request_post("{}/{}".format(ROUTE_STATUS_V5, route_id),
self.params,
json=data)
return response.json()

def rollback_route_status(self, route_id):
response = self.api._request_get("{}/{}/rollback".format(ROUTE_STATUS_V5, route_id),
self.params)
return response.json()
4 changes: 2 additions & 2 deletions route4me/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
# VERSION.py - MAINTAINER's. Don't edit, if you don't know what are you doing
# ==============================================================================

VERSION = (0, 1, 4, 4)
VERSION = (0, 1, 5, 0)
RELEASE_SUFFIX = ''

VERSION_STRING = '.'.join([str(x) for x in VERSION])
RELEASE_STRING = "v{}{}".format(VERSION_STRING, RELEASE_SUFFIX)

PROJECT = 'Route4Me Python SDK'
COPYRIGHT = '2016-2023 © Route4Me Python Team'
COPYRIGHT = '2016-2021 © Route4Me Python Team'
AUTHOR = 'Route4Me Python Team (SDK)'
AUTHOR_EMAIL = '[email protected]'
TITLE = 'route4me'
Expand Down

0 comments on commit 71b7a41

Please sign in to comment.