def add_query_parameter(self, name, value): """ Add a query parameter to the HttpRequest. Args: name (string): The name of the query parameter. value (string): The value of the query parameter. """ self.query_url = APIHelper.append_url_with_query_parameters(self.query_url, {name:value}) self.query_url = APIHelper.clean_url(self.query_url)
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 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 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 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