Пример #1
0
    def get_base_uri(cls, server=Server.DEFAULT):
        """Generates the appropriate base URI for the environment and the server.

        Args:
            server (Configuration.Server): The server enum for which the base URI is required.

        Returns:
            String: The base URI.

        """
        parameters = {
            "defaultHost": cls.default_host,
        }
        return APIHelper.append_url_with_template_parameters(
            cls.environments[cls.environment][server], parameters, False)
Пример #2
0
    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
Пример #3
0
    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
Пример #4
0
    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
Пример #5
0
    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
Пример #6
0
    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
Пример #7
0
    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
Пример #8
0
    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