def get_a_driver_performance_summary_by_its_id(self, id): """Does a GET request to /v1.0/driver_performance_summaries/{id}. Summary statistics on performance of drivers.**Access Controls** |Role: |Vehicle Query|Vehicle Follow|Driver Query|Driver Follow|Driver Dispatch|Driver Duty |HR |Admin | |-------|-------------|--------------|------------|-------------|------ ---------|------------|------------|------------| |Access:| **DENY** | **DENY** | ALLOW | ALLOW | **DENY** | **DENY** | ALLOW | ALLOW | Args: id (string): ID of the Driver Performance Summary of interest Returns: DriverPerformanceSummary: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info( 'get_a_driver_performance_summary_by_its_id called.') # Prepare query URL self.logger.info( 'Preparing query URL for get_a_driver_performance_summary_by_its_id.' ) _url_path = '/v1.0/driver_performance_summaries/{id}' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'id': id}) _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for get_a_driver_performance_summary_by_its_id.' ) _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for get_a_driver_performance_summary_by_its_id.' ) _request = self.http_client.get(_query_url, headers=_headers) BasicAuth.apply(_request) _context = self.execute_request( _request, name='get_a_driver_performance_summary_by_its_id') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for get_a_driver_performance_summary_by_its_id.' ) if _context.response.status_code == 401: raise APIException('', _context) elif _context.response.status_code == 429: raise APIException('', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, DriverPerformanceSummary.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_driver_availability_factors(self, driver_id, start_time, stop_time): """Does a GET request to /v1.0/drivers/{driverId}/availability_factors/. Clients can request all the factors contributing to driver availability for a given driver, over a given time period. **Access Controls** |Role: |Vehicle Query|Vehicle Follow|Driver Query|Driver Follow|Driver Dispatch|Driver Duty |HR |Admin | |-------|-------------|--------------|------------|-------------|------ ---------|------------|------------|------------| |Access:| **DENY** | **DENY** | ALLOW | ALLOW | **DENY** | **DENY** | **DENY** | ALLOW | Args: driver_id (string): The id of the driver who created this status change. start_time (string): the start-date of the search stop_time (string): the stop-date of the search Returns: GetDriverAvailabilityFactorsResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_driver_availability_factors called.') # Prepare query URL self.logger.info( 'Preparing query URL for get_driver_availability_factors.') _url_path = '/v1.0/drivers/{driverId}/availability_factors/' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'driverId': driver_id}) _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = { 'startTime': start_time, 'stopTime': stop_time } _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for get_driver_availability_factors.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for get_driver_availability_factors.' ) _request = self.http_client.get(_query_url, headers=_headers) BasicAuth.apply(_request) _context = self.execute_request( _request, name='get_driver_availability_factors') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for get_driver_availability_factors.') if _context.response.status_code == 400: raise APIException( 'Error: startTime or stopTime parameters invalid', _context) elif _context.response.status_code == 401: raise APIException('', _context) elif _context.response.status_code == 404: raise APIException('Error: driverId Not Found', _context) elif _context.response.status_code == 413: raise APIException('', _context) elif _context.response.status_code == 429: raise APIException('', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, GetDriverAvailabilityFactorsResponse.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def follow_fleet_log_events(self, token=None): """Does a GET request to /v1.0/event_logs/feed. Clients can follow a feed of Log Event entries as they are added to the TSP system; following is accomplished via polling an endpoint and providing a 'token' which evolves the window of new entries with each query in the polling. **Access Controls** |Role: |Vehicle Query|Vehicle Follow|Driver Query|Driver Follow|Driver Dispatch|Driver Duty |HR |Admin | |-------|-------------|--------------|------------|-------------|------ ---------|------------|------------|------------| |Access:| **DENY** | **DENY** | **DENY** | ALLOW | ALLOW | **DENY** | ALLOW | ALLOW | Args: token (string, optional): a since-token, pass-in the token previously returned to 'follow' new Log Events; pass in a `null` or omit this token to start with a new token set to 'now'. Returns: FollowFleetLogEventsResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('follow_fleet_log_events called.') # Prepare query URL self.logger.info( 'Preparing query URL for follow_fleet_log_events.') _url_path = '/v1.0/event_logs/feed' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = {'token': token} _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for follow_fleet_log_events.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for follow_fleet_log_events.') _request = self.http_client.get(_query_url, headers=_headers) BasicAuth.apply(_request) _context = self.execute_request(_request, name='follow_fleet_log_events') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for follow_fleet_log_events.') if _context.response.status_code == 400: raise APIException('Error: token parameter invalid', _context) elif _context.response.status_code == 401: raise APIException('', _context) elif _context.response.status_code == 429: raise APIException('', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, FollowFleetLogEventsResponse.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def create_a_vehicle_route(self, vehicle_id, body): """Does a POST request to /v1.0/vehicles/{vehicleId}/routes. Clients can request the creation of a new route for a given vehicle, providing start & stop location along with additional instructions in a *Externally Sourced Route Start Stop Details* object. **Access Controls** |Role: |Vehicle Query|Vehicle Follow|Driver Query|Driver Follow|Driver Dispatch|Driver Duty |HR |Admin | |-------|-------------|--------------|------------|-------------|------ ---------|------------|------------|------------| |Access:| **DENY** | **DENY** | **DENY** | **DENY** | ALLOW | **DENY** | **DENY** | ALLOW | Args: vehicle_id (string): The vehicle id to associate this route to body (ExternallySourcedRouteStartStopDetails): TODO: type description here. Example: Returns: CreateAVehicleRouteResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('create_a_vehicle_route called.') # Prepare query URL self.logger.info('Preparing query URL for create_a_vehicle_route.') _url_path = '/v1.0/vehicles/{vehicleId}/routes' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'vehicleId': vehicle_id}) _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for create_a_vehicle_route.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for create_a_vehicle_route.') _request = self.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) BasicAuth.apply(_request) _context = self.execute_request(_request, name='create_a_vehicle_route') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for create_a_vehicle_route.') if _context.response.status_code == 401: raise APIException('', _context) elif _context.response.status_code == 404: raise APIException('Error: vehicleId Not Found', _context) elif _context.response.status_code == 429: raise APIException('', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, CreateAVehicleRouteResponse.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def update_driver_duty_status(self, driver_id, body): """Does a PATCH request to /v1.0/drivers/{driverId}/duty_status. Clients can send custom-integrated duty status changes to the TSP to trigger duty status changes for a given driver by pushing data to this endpoint. **Access Controls** |Role: |Vehicle Query|Vehicle Follow|Driver Query|Driver Follow|Driver Dispatch|Driver Duty |HR |Admin | |-------|-------------|--------------|------------|-------------|------ ---------|------------|------------|------------| |Access:| **DENY** | **DENY** | **DENY** | **DENY** | **DENY** | ALLOW | **DENY** | ALLOW | Args: driver_id (string): The id of the driver who created this status change. body (ExternallyTriggeredDutyStatusChange): TODO: type description here. Example: Returns: void: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('update_driver_duty_status called.') # Prepare query URL self.logger.info( 'Preparing query URL for update_driver_duty_status.') _url_path = '/v1.0/drivers/{driverId}/duty_status' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'driverId': driver_id}) _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for update_driver_duty_status.') _headers = {'content-type': 'application/json; charset=utf-8'} # Prepare and execute request self.logger.info( 'Preparing and executing request for update_driver_duty_status.' ) _request = self.http_client.patch( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) BasicAuth.apply(_request) _context = self.execute_request(_request, name='update_driver_duty_status') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for update_driver_duty_status.') if _context.response.status_code == 401: raise APIException('', _context) elif _context.response.status_code == 404: raise APIException('Error: driverId Not Found', _context) elif _context.response.status_code == 429: raise APIException('', _context) self.validate_response(_context) except Exception as e: self.logger.error(e, exc_info=True) raise
def test_if_complete_export_ready(self, day_of): """Does a GET request to /v1.0/export/allrecords/status. If the file is ready the response will include a URL where the complete file can be fetched; if the file is not yet ready then a `202` return code will be returned. **Access Controls** |Role: |Vehicle Query|Vehicle Follow|Driver Query|Driver Follow|Driver Dispatch|Driver Duty |HR |Admin | |-------|-------------|--------------|------------|-------------|------ ---------|------------|------------|------------| |Access:| **DENY** | **DENY** | ALLOW | **DENY** | **DENY** | **DENY** | **DENY** | ALLOW | Args: day_of (string): the day of interest, specified by any timestamp within that day, including 0000h Returns: TestIfCompleteExportReadyResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('test_if_complete_export_ready called.') # Prepare query URL self.logger.info( 'Preparing query URL for test_if_complete_export_ready.') _url_path = '/v1.0/export/allrecords/status' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = {'dayOf': day_of} _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for test_if_complete_export_ready.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for test_if_complete_export_ready.' ) _request = self.http_client.get(_query_url, headers=_headers) BasicAuth.apply(_request) _context = self.execute_request( _request, name='test_if_complete_export_ready') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for test_if_complete_export_ready.') if _context.response.status_code == 400: raise APIException('Error: dayOf parameter invalid', _context) elif _context.response.status_code == 401: raise APIException('', _context) elif _context.response.status_code == 413: raise APIException('', _context) elif _context.response.status_code == 429: raise APIException('', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, TestIfCompleteExportReadyResponse.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def check_current_state_of_health(self): """Does a GET request to /v1.0/health/current. Clients can request the current service state of health. The response to this query will be a data structure indicating everything is good or showing some details as to why the service is not presently at 100%. Clients must treat any response other than code 200, code 401, or code 429 as equivalent to `SERVICESTATUS_MAJOR_OUTAGE`. **Access Controls** |Role: |Vehicle Query|Vehicle Follow|Driver Query|Driver Follow|Driver Dispatch|Driver Duty |HR |Admin | |-------|-------------|--------------|------------|-------------|------ ---------|------------|------------|------------| |Access:| ALLOW | ALLOW | ALLOW | ALLOW | ALLOW | ALLOW | ALLOW | ALLOW | Returns: StateOfHealth: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('check_current_state_of_health called.') # Prepare query URL self.logger.info( 'Preparing query URL for check_current_state_of_health.') _url_path = '/v1.0/health/current' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for check_current_state_of_health.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for check_current_state_of_health.' ) _request = self.http_client.get(_query_url, headers=_headers) BasicAuth.apply(_request) _context = self.execute_request( _request, name='check_current_state_of_health') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for check_current_state_of_health.') if _context.response.status_code == 401: raise APIException('', _context) elif _context.response.status_code == 429: raise APIException('', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, StateOfHealth.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def update_driver_route_stop(self, vehicle_id, route_id, body): """Does a PUT request to /v1.0/vehicles/{vehicleId}/routes/{routeId}. Clients can update a Driver's destination; sending data to this endpoint, using a previously obtained `routeId` will change the destination of the route, hence also changing the stopId associated with the route. **Access Controls** |Role: |Vehicle Query|Vehicle Follow|Driver Query|Driver Follow|Driver Dispatch|Driver Duty |HR |Admin | |-------|-------------|--------------|------------|-------------|------ ---------|------------|------------|------------| |Access:| **DENY** | **DENY** | **DENY** | **DENY** | ALLOW | **DENY** | **DENY** | ALLOW | Args: vehicle_id (string): The vehicle id to associate this route to route_id (string): the id of the route created, to be used for later updates to the route body (ExternallySourcedRouteStopDetails): TODO: type description here. Example: Returns: UpdateDriverRouteStopResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('update_driver_route_stop called.') # Prepare query URL self.logger.info( 'Preparing query URL for update_driver_route_stop.') _url_path = '/v1.0/vehicles/{vehicleId}/routes/{routeId}' _url_path = APIHelper.append_url_with_template_parameters( _url_path, { 'vehicleId': vehicle_id, 'routeId': route_id }) _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for update_driver_route_stop.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for update_driver_route_stop.' ) _request = self.http_client.put( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) BasicAuth.apply(_request) _context = self.execute_request(_request, name='update_driver_route_stop') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for update_driver_route_stop.') if _context.response.status_code == 401: raise APIException('', _context) elif _context.response.status_code == 404: raise APIException('Error: vehicleId or routeId Not Found', _context) elif _context.response.status_code == 429: raise APIException('', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, UpdateDriverRouteStopResponse.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def update_stop_geographic_details(self, stop_id, body): """Does a PATCH request to /v1.0/stops/{stopId}. Clients can update the _geographic details_ of a stop; the *Stop Geographic Details* are the specific location for the truck and trailer to park and a polygon of geographic points indicating the entryway onto a facility (i.e. where the truck should drive on approach). Sending data to this endpoint, using a previously returned `stopId` will update the geograhic details of the stop and any other routes using this stop will also be updated. **Access Controls** |Role: |Vehicle Query|Vehicle Follow|Driver Query|Driver Follow|Driver Dispatch|Driver Duty |HR |Admin | |-------|-------------|--------------|------------|-------------|------ ---------|------------|------------|------------| |Access:| **DENY** | **DENY** | **DENY** | **DENY** | ALLOW | **DENY** | **DENY** | ALLOW | Args: stop_id (string): The stop id to update body (ExternallySourcedStopGeographicDetails): TODO: type description here. Example: Returns: UpdateStopGeographicDetailsResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('update_stop_geographic_details called.') # Prepare query URL self.logger.info( 'Preparing query URL for update_stop_geographic_details.') _url_path = '/v1.0/stops/{stopId}' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'stopId': stop_id}) _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for update_stop_geographic_details.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for update_stop_geographic_details.' ) _request = self.http_client.patch( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) BasicAuth.apply(_request) _context = self.execute_request( _request, name='update_stop_geographic_details') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for update_stop_geographic_details.') if _context.response.status_code == 401: raise APIException('', _context) elif _context.response.status_code == 404: raise APIException('Error: stopId Not Found', _context) elif _context.response.status_code == 429: raise APIException('', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, UpdateStopGeographicDetailsResponse.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_fleet_latest_locations(self, page=None, count=None): """Does a GET request to /v1.0/fleet/locations/latest. Clients can retrieve the (coarse) vehicle locations (of all vehicles) over a given time period. **Access Controls** |Role: |Vehicle Query|Vehicle Follow|Driver Query|Driver Follow|Driver Dispatch|Driver Duty |HR |Admin | |-------|-------------|--------------|------------|-------------|------ ---------|------------|------------|------------| |Access:| ALLOW | ALLOW | ALLOW | ALLOW | ALLOW | **DENY** | **DENY** | ALLOW | Args: page (float, optional): the page to select for paginated response count (float, optional): the number of items to return Returns: VehicleLocationTimeHistory: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_fleet_latest_locations called.') # Prepare query URL self.logger.info( 'Preparing query URL for get_fleet_latest_locations.') _url_path = '/v1.0/fleet/locations/latest' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = {'page': page, 'count': count} _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for get_fleet_latest_locations.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for get_fleet_latest_locations.' ) _request = self.http_client.get(_query_url, headers=_headers) BasicAuth.apply(_request) _context = self.execute_request(_request, name='get_fleet_latest_locations') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for get_fleet_latest_locations.') if _context.response.status_code == 400: raise APIException('Error: page or count parameters invalid', _context) elif _context.response.status_code == 401: raise APIException('', _context) elif _context.response.status_code == 429: raise APIException('', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, VehicleLocationTimeHistory.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def send_message_to_a_vehicle(self, vehicle_id, body): """Does a POST request to /v1.0/vehicles/{vehicleId}/message. **Access Controls** |Role: |Vehicle Query|Vehicle Follow|Driver Query|Driver Follow|Driver Dispatch|Driver Duty |HR |Admin | |-------|-------------|--------------|------------|-------------|------ ---------|------------|------------|------------| |Access:| **DENY** | **DENY** | **DENY** | **DENY** | ALLOW | **DENY** | **DENY** | ALLOW | Args: vehicle_id (string): The vehicle id to send the message to body (ExternallySourcedVehicleDisplayMessages): TODO: type description here. Example: Returns: void: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('send_message_to_a_vehicle called.') # Prepare query URL self.logger.info( 'Preparing query URL for send_message_to_a_vehicle.') _url_path = '/v1.0/vehicles/{vehicleId}/message' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'vehicleId': vehicle_id}) _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for send_message_to_a_vehicle.') _headers = {'content-type': 'application/json; charset=utf-8'} # Prepare and execute request self.logger.info( 'Preparing and executing request for send_message_to_a_vehicle.' ) _request = self.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) BasicAuth.apply(_request) _context = self.execute_request(_request, name='send_message_to_a_vehicle') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for send_message_to_a_vehicle.') if _context.response.status_code == 401: raise APIException('', _context) elif _context.response.status_code == 404: raise APIException('Error: vehicleId not found', _context) elif _context.response.status_code == 429: raise APIException('', _context) self.validate_response(_context) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_a_translation_table(self, accept_language): """Does a GET request to /v1.0/i18n. Based on [LinguiJS formats](https://lingui.js.org/ref/catalog-formats.html); where the preferred format is gettext PO files, which are closely represented here. Unfortunately the Lingui JS raw format and JSON formats cannot be represented in API Blueprint's formal spec language.Clients can retrieve the current translation table for this TSP's Open Telematics API for given language (provided in the request headers.) **Access Controls** |Role: |Vehicle Query|Vehicle Follow|Driver Query|Driver Follow|Driver Dispatch|Driver Duty |HR |Admin | |-------|-------------|--------------|------------|-------------|------ ---------|------------|------------|------------| |Access:| ALLOW | ALLOW | ALLOW | ALLOW | ALLOW | ALLOW | ALLOW | ALLOW | Args: accept_language (string): TODO: type description here. Example: Returns: GetATranslationTableResponse: Response from the API. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_a_translation_table called.') # Prepare query URL self.logger.info( 'Preparing query URL for get_a_translation_table.') _url_path = '/v1.0/i18n' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for get_a_translation_table.') _headers = { 'accept': 'application/json', 'Accept-Language': accept_language } # Prepare and execute request self.logger.info( 'Preparing and executing request for get_a_translation_table.') _request = self.http_client.get(_query_url, headers=_headers) BasicAuth.apply(_request) _context = self.execute_request(_request, name='get_a_translation_table') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for get_a_translation_table.') if _context.response.status_code == 401: raise APIException('', _context) elif _context.response.status_code == 406: raise APIException('', _context) elif _context.response.status_code == 429: raise APIException('', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, GetATranslationTableResponse.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise