-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADDED] Feature to set, get, rollback Route Status
- Loading branch information
Showing
10 changed files
with
172 additions
and
3 deletions.
There are no files selected for viewing
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
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
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) |
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
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) |
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
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) |
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
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) |
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
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
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
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
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() |
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