Google Maps FleetEngine V1 Client - Class VehicleServiceClient (0.1.3)

Reference documentation and code samples for the Google Maps FleetEngine V1 Client class VehicleServiceClient.

Service Description: Vehicle management service.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.

Namespace

Google \ Maps \ FleetEngine \ V1 \ Client

Methods

__construct

Constructor.

Parameters
Name Description
options array

Optional. Options for configuring the service API wrapper.

↳ apiEndpoint string

The address of the API remote host. May optionally include the port, formatted as "

↳ credentials string|array|FetchAuthTokenInterface|CredentialsWrapper

The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored.

↳ credentialsConfig array

Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() .

↳ disableRetries bool

Determines whether or not retries defined by the client configuration should be disabled. Defaults to false.

↳ clientConfig string|array

Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder.

↳ transport string|TransportInterface

The transport used for executing network requests. May be either the string rest or grpc. Defaults to grpc if gRPC support is detected on the system. Advanced usage: Additionally, it is possible to pass in an already instantiated Google\ApiCore\Transport\TransportInterface object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored.

↳ transportConfig array

Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options.

↳ clientCertSource callable

A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS.

createVehicle

Instantiates a new vehicle associated with an on-demand rideshare or deliveries provider. Each Vehicle must have a unique vehicle ID.

The following Vehicle fields are required when creating a Vehicle:

  • vehicleState
  • supportedTripTypes
  • maximumCapacity
  • vehicleType

The following Vehicle fields are ignored when creating a Vehicle:

  • name
  • currentTrips
  • availableCapacity
  • current_route_segment
  • current_route_segment_end_point
  • current_route_segment_version
  • current_route_segment_traffic
  • route
  • waypoints
  • waypoints_version
  • remaining_distance_meters
  • remaining_time_seconds
  • eta_to_next_waypoint
  • navigation_status

All other fields are optional and used if provided.

The async variant is Google\Maps\FleetEngine\V1\Client\VehicleServiceClient::createVehicleAsync() .

Parameters
Name Description
request Google\Maps\FleetEngine\V1\CreateVehicleRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Maps\FleetEngine\V1\Vehicle
Example
use Google\ApiCore\ApiException;
use Google\Maps\FleetEngine\V1\Client\VehicleServiceClient;
use Google\Maps\FleetEngine\V1\CreateVehicleRequest;
use Google\Maps\FleetEngine\V1\Vehicle;
use Google\Maps\FleetEngine\V1\Vehicle\VehicleType;

/**
 * @param string $parent    Must be in the format `providers/{provider}`.
 *                          The provider must be the Project ID (for example, `sample-cloud-project`)
 *                          of the Google Cloud Project of which the service account making
 *                          this call is a member.
 * @param string $vehicleId Unique Vehicle ID.
 *                          Subject to the following restrictions:
 *
 *                          * Must be a valid Unicode string.
 *                          * Limited to a maximum length of 64 characters.
 *                          * Normalized according to [Unicode Normalization Form C]
 *                          (http://www.unicode.org/reports/tr15/).
 *                          * May not contain any of the following ASCII characters: '/', ':', '?',
 *                          ',', or '#'.
 */
function create_vehicle_sample(string $parent, string $vehicleId): void
{
    // Create a client.
    $vehicleServiceClient = new VehicleServiceClient();

    // Prepare the request message.
    $vehicleVehicleType = new VehicleType();
    $vehicle = (new Vehicle())
        ->setVehicleType($vehicleVehicleType);
    $request = (new CreateVehicleRequest())
        ->setParent($parent)
        ->setVehicleId($vehicleId)
        ->setVehicle($vehicle);

    // Call the API and handle any network failures.
    try {
        /** @var Vehicle $response */
        $response = $vehicleServiceClient->createVehicle($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $parent = '[PARENT]';
    $vehicleId = '[VEHICLE_ID]';

    create_vehicle_sample($parent, $vehicleId);
}

getVehicle

Returns a vehicle from the Fleet Engine.

The async variant is Google\Maps\FleetEngine\V1\Client\VehicleServiceClient::getVehicleAsync() .

Parameters
Name Description
request Google\Maps\FleetEngine\V1\GetVehicleRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Maps\FleetEngine\V1\Vehicle
Example
use Google\ApiCore\ApiException;
use Google\Maps\FleetEngine\V1\Client\VehicleServiceClient;
use Google\Maps\FleetEngine\V1\GetVehicleRequest;
use Google\Maps\FleetEngine\V1\Vehicle;

/**
 * @param string $formattedName Must be in the format
 *                              `providers/{provider}/vehicles/{vehicle}`.
 *                              The provider must be the Project ID (for example, `sample-cloud-project`)
 *                              of the Google Cloud Project of which the service account making
 *                              this call is a member. Please see
 *                              {@see VehicleServiceClient::vehicleName()} for help formatting this field.
 */
function get_vehicle_sample(string $formattedName): void
{
    // Create a client.
    $vehicleServiceClient = new VehicleServiceClient();

    // Prepare the request message.
    $request = (new GetVehicleRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var Vehicle $response */
        $response = $vehicleServiceClient->getVehicle($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = VehicleServiceClient::vehicleName('[PROVIDER]', '[VEHICLE]');

    get_vehicle_sample($formattedName);
}

listVehicles

Returns a paginated list of vehicles associated with a provider that match the request options.

The async variant is Google\Maps\FleetEngine\V1\Client\VehicleServiceClient::listVehiclesAsync() .

Parameters
Name Description
request Google\Maps\FleetEngine\V1\ListVehiclesRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Maps\FleetEngine\V1\Client\VehicleServiceClient;
use Google\Maps\FleetEngine\V1\ListVehiclesRequest;
use Google\Maps\FleetEngine\V1\Vehicle;
use Google\Maps\FleetEngine\V1\Vehicle\VehicleType\Category;

/**
 * @param string $parent                       Must be in the format `providers/{provider}`.
 *                                             The provider must be the Project ID (for example, `sample-cloud-project`)
 *                                             of the Google Cloud Project of which the service account making
 *                                             this call is a member.
 * @param int    $vehicleTypeCategoriesElement Restricts the response to vehicles with one of the specified type
 *                                             categories. `UNKNOWN` is not allowed.
 */
function list_vehicles_sample(string $parent, int $vehicleTypeCategoriesElement): void
{
    // Create a client.
    $vehicleServiceClient = new VehicleServiceClient();

    // Prepare the request message.
    $vehicleTypeCategories = [$vehicleTypeCategoriesElement,];
    $request = (new ListVehiclesRequest())
        ->setParent($parent)
        ->setVehicleTypeCategories($vehicleTypeCategories);

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $vehicleServiceClient->listVehicles($request);

        /** @var Vehicle $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $parent = '[PARENT]';
    $vehicleTypeCategoriesElement = Category::UNKNOWN;

    list_vehicles_sample($parent, $vehicleTypeCategoriesElement);
}

searchVehicles

Returns a list of vehicles that match the request options.

The async variant is Google\Maps\FleetEngine\V1\Client\VehicleServiceClient::searchVehiclesAsync() .

Parameters
Name Description
request Google\Maps\FleetEngine\V1\SearchVehiclesRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Maps\FleetEngine\V1\SearchVehiclesResponse
Example
use Google\ApiCore\ApiException;
use Google\Maps\FleetEngine\V1\Client\VehicleServiceClient;
use Google\Maps\FleetEngine\V1\SearchVehiclesRequest;
use Google\Maps\FleetEngine\V1\SearchVehiclesRequest\VehicleMatchOrder;
use Google\Maps\FleetEngine\V1\SearchVehiclesResponse;
use Google\Maps\FleetEngine\V1\TerminalLocation;
use Google\Maps\FleetEngine\V1\TripType;
use Google\Maps\FleetEngine\V1\Vehicle\VehicleType;
use Google\Type\LatLng;

/**
 * @param string $parent             Must be in the format `providers/{provider}`.
 *                                   The provider must be the Project ID (for example, `sample-cloud-project`)
 *                                   of the Google Cloud Project of which the service account making
 *                                   this call is a member.
 * @param int    $pickupRadiusMeters Defines the vehicle search radius around the pickup point. Only
 *                                   vehicles within the search radius will be returned. Value must be between
 *                                   400 and 10000 meters (inclusive).
 * @param int    $count              Specifies the maximum number of vehicles to return. The value
 *                                   must be between 1 and 50 (inclusive).
 * @param int    $minimumCapacity    Specifies the number of passengers being considered for a trip.
 *                                   The value must be greater than or equal to one. The driver is not
 *                                   considered in the capacity value.
 * @param int    $tripTypesElement   Represents the type of proposed trip. Must include exactly one
 *                                   type. `UNKNOWN_TRIP_TYPE` is not allowed. Restricts the search to only
 *                                   those vehicles that can support that trip type.
 * @param int    $orderBy            Specifies the desired ordering criterion for results.
 */
function search_vehicles_sample(
    string $parent,
    int $pickupRadiusMeters,
    int $count,
    int $minimumCapacity,
    int $tripTypesElement,
    int $orderBy
): void {
    // Create a client.
    $vehicleServiceClient = new VehicleServiceClient();

    // Prepare the request message.
    $pickupPointPoint = new LatLng();
    $pickupPoint = (new TerminalLocation())
        ->setPoint($pickupPointPoint);
    $tripTypes = [$tripTypesElement,];
    $vehicleTypes = [new VehicleType()];
    $request = (new SearchVehiclesRequest())
        ->setParent($parent)
        ->setPickupPoint($pickupPoint)
        ->setPickupRadiusMeters($pickupRadiusMeters)
        ->setCount($count)
        ->setMinimumCapacity($minimumCapacity)
        ->setTripTypes($tripTypes)
        ->setVehicleTypes($vehicleTypes)
        ->setOrderBy($orderBy);

    // Call the API and handle any network failures.
    try {
        /** @var SearchVehiclesResponse $response */
        $response = $vehicleServiceClient->searchVehicles($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $parent = '[PARENT]';
    $pickupRadiusMeters = 0;
    $count = 0;
    $minimumCapacity = 0;
    $tripTypesElement = TripType::UNKNOWN_TRIP_TYPE;
    $orderBy = VehicleMatchOrder::UNKNOWN_VEHICLE_MATCH_ORDER;

    search_vehicles_sample(
        $parent,
        $pickupRadiusMeters,
        $count,
        $minimumCapacity,
        $tripTypesElement,
        $orderBy
    );
}

updateVehicle

Writes updated vehicle data to the Fleet Engine.

When updating a Vehicle, the following fields cannot be updated since they are managed by the server:

  • currentTrips
  • availableCapacity
  • current_route_segment_version
  • waypoints_version

The vehicle name also cannot be updated.

If the attributes field is updated, all the vehicle's attributes are replaced with the attributes provided in the request. If you want to update only some attributes, see the UpdateVehicleAttributes method. Likewise, the waypoints field can be updated, but must contain all the waypoints currently on the vehicle, and no other waypoints.

The async variant is Google\Maps\FleetEngine\V1\Client\VehicleServiceClient::updateVehicleAsync() .

Parameters
Name Description
request Google\Maps\FleetEngine\V1\UpdateVehicleRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Maps\FleetEngine\V1\Vehicle
Example
use Google\ApiCore\ApiException;
use Google\Maps\FleetEngine\V1\Client\VehicleServiceClient;
use Google\Maps\FleetEngine\V1\UpdateVehicleRequest;
use Google\Maps\FleetEngine\V1\Vehicle;
use Google\Maps\FleetEngine\V1\Vehicle\VehicleType;
use Google\Protobuf\FieldMask;

/**
 * @param string $name Must be in the format
 *                     `providers/{provider}/vehicles/{vehicle}`.
 *                     The {provider} must be the Project ID (for example, `sample-cloud-project`)
 *                     of the Google Cloud Project of which the service account making
 *                     this call is a member.
 */
function update_vehicle_sample(string $name): void
{
    // Create a client.
    $vehicleServiceClient = new VehicleServiceClient();

    // Prepare the request message.
    $vehicleVehicleType = new VehicleType();
    $vehicle = (new Vehicle())
        ->setVehicleType($vehicleVehicleType);
    $updateMask = new FieldMask();
    $request = (new UpdateVehicleRequest())
        ->setName($name)
        ->setVehicle($vehicle)
        ->setUpdateMask($updateMask);

    // Call the API and handle any network failures.
    try {
        /** @var Vehicle $response */
        $response = $vehicleServiceClient->updateVehicle($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $name = '[NAME]';

    update_vehicle_sample($name);
}

updateVehicleAttributes

Partially updates a vehicle's attributes.

Only the attributes mentioned in the request will be updated, other attributes will NOT be altered. Note: this is different in UpdateVehicle, where the whole attributes field will be replaced by the one in UpdateVehicleRequest, attributes not in the request would be removed.

The async variant is Google\Maps\FleetEngine\V1\Client\VehicleServiceClient::updateVehicleAttributesAsync() .

Parameters
Name Description
request Google\Maps\FleetEngine\V1\UpdateVehicleAttributesRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Maps\FleetEngine\V1\UpdateVehicleAttributesResponse
Example
use Google\ApiCore\ApiException;
use Google\Maps\FleetEngine\V1\Client\VehicleServiceClient;
use Google\Maps\FleetEngine\V1\UpdateVehicleAttributesRequest;
use Google\Maps\FleetEngine\V1\UpdateVehicleAttributesResponse;
use Google\Maps\FleetEngine\V1\VehicleAttribute;

/**
 * @param string $name Must be in the format `providers/{provider}/vehicles/{vehicle}`.
 *                     The provider must be the Project ID (for example, `sample-cloud-project`)
 *                     of the Google Cloud Project of which the service account making
 *                     this call is a member.
 */
function update_vehicle_attributes_sample(string $name): void
{
    // Create a client.
    $vehicleServiceClient = new VehicleServiceClient();

    // Prepare the request message.
    $attributes = [new VehicleAttribute()];
    $request = (new UpdateVehicleAttributesRequest())
        ->setName($name)
        ->setAttributes($attributes);

    // Call the API and handle any network failures.
    try {
        /** @var UpdateVehicleAttributesResponse $response */
        $response = $vehicleServiceClient->updateVehicleAttributes($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $name = '[NAME]';

    update_vehicle_attributes_sample($name);
}

createVehicleAsync

Parameters
Name Description
request Google\Maps\FleetEngine\V1\CreateVehicleRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

getVehicleAsync

Parameters
Name Description
request Google\Maps\FleetEngine\V1\GetVehicleRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

listVehiclesAsync

Parameters
Name Description
request Google\Maps\FleetEngine\V1\ListVehiclesRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

searchVehiclesAsync

Parameters
Name Description
request Google\Maps\FleetEngine\V1\SearchVehiclesRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

updateVehicleAsync

Parameters
Name Description
request Google\Maps\FleetEngine\V1\UpdateVehicleRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

updateVehicleAttributesAsync

Parameters
Name Description
request Google\Maps\FleetEngine\V1\UpdateVehicleAttributesRequest
optionalArgs = [] array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface

static::vehicleName

Formats a string containing the fully-qualified path to represent a vehicle resource.

Parameters
Name Description
provider string
vehicle string
Returns
Type Description
string The formatted vehicle resource.

static::parseName

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported: Template: Pattern

  • vehicle: providers/{provider}/vehicles/{vehicle}

The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.

Parameters
Name Description
formattedName string

The formatted name string

template string

Optional name of template to match

Returns
Type Description
array An associative array from name component IDs to component values.