Google Maps FleetEngine V1 Client - Class TripServiceClient (0.1.4)

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

Service Description: Trip 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.

createTrip

Creates a trip in the Fleet Engine and returns the new trip.

The async variant is TripServiceClient::createTripAsync() .

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

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\Trip
Example
use Google\ApiCore\ApiException;
use Google\Maps\FleetEngine\V1\Client\TripServiceClient;
use Google\Maps\FleetEngine\V1\CreateTripRequest;
use Google\Maps\FleetEngine\V1\Trip;

/**
 * @param string $formattedParent 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. Please see
 *                                {@see TripServiceClient::tripName()} for help formatting this field.
 * @param string $tripId          Unique Trip 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_trip_sample(string $formattedParent, string $tripId): void
{
    // Create a client.
    $tripServiceClient = new TripServiceClient();

    // Prepare the request message.
    $trip = new Trip();
    $request = (new CreateTripRequest())
        ->setParent($formattedParent)
        ->setTripId($tripId)
        ->setTrip($trip);

    // Call the API and handle any network failures.
    try {
        /** @var Trip $response */
        $response = $tripServiceClient->createTrip($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
{
    $formattedParent = TripServiceClient::tripName('[PROVIDER]', '[TRIP]');
    $tripId = '[TRIP_ID]';

    create_trip_sample($formattedParent, $tripId);
}

getTrip

Get information about a single trip.

The async variant is TripServiceClient::getTripAsync() .

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

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\Trip
Example
use Google\ApiCore\ApiException;
use Google\Maps\FleetEngine\V1\Client\TripServiceClient;
use Google\Maps\FleetEngine\V1\GetTripRequest;
use Google\Maps\FleetEngine\V1\Trip;

/**
 * @param string $formattedName Must be in the format `providers/{provider}/trips/{trip}`.
 *                              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 TripServiceClient::tripName()} for help formatting this field.
 */
function get_trip_sample(string $formattedName): void
{
    // Create a client.
    $tripServiceClient = new TripServiceClient();

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

    // Call the API and handle any network failures.
    try {
        /** @var Trip $response */
        $response = $tripServiceClient->getTrip($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 = TripServiceClient::tripName('[PROVIDER]', '[TRIP]');

    get_trip_sample($formattedName);
}

reportBillableTrip

Report billable trip usage.

The async variant is TripServiceClient::reportBillableTripAsync() .

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

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.

Example
use Google\ApiCore\ApiException;
use Google\Maps\FleetEngine\V1\Client\TripServiceClient;
use Google\Maps\FleetEngine\V1\ReportBillableTripRequest;

/**
 * @param string $name        Must be in the format
 *                            `providers/{provider}/billableTrips/{billable_trip}`. 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 $countryCode Two letter country code of the country where the trip takes
 *                            place. Price is defined according to country code.
 */
function report_billable_trip_sample(string $name, string $countryCode): void
{
    // Create a client.
    $tripServiceClient = new TripServiceClient();

    // Prepare the request message.
    $request = (new ReportBillableTripRequest())
        ->setName($name)
        ->setCountryCode($countryCode);

    // Call the API and handle any network failures.
    try {
        $tripServiceClient->reportBillableTrip($request);
        printf('Call completed successfully.' . PHP_EOL);
    } 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]';
    $countryCode = '[COUNTRY_CODE]';

    report_billable_trip_sample($name, $countryCode);
}

searchTrips

Get all the trips for a specific vehicle.

The async variant is TripServiceClient::searchTripsAsync() .

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

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\TripServiceClient;
use Google\Maps\FleetEngine\V1\SearchTripsRequest;
use Google\Maps\FleetEngine\V1\Trip;

/**
 * @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.
 */
function search_trips_sample(string $parent): void
{
    // Create a client.
    $tripServiceClient = new TripServiceClient();

    // Prepare the request message.
    $request = (new SearchTripsRequest())
        ->setParent($parent);

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

        /** @var Trip $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]';

    search_trips_sample($parent);
}

updateTrip

Updates trip data.

The async variant is TripServiceClient::updateTripAsync() .

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

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\Trip
Example
use Google\ApiCore\ApiException;
use Google\Maps\FleetEngine\V1\Client\TripServiceClient;
use Google\Maps\FleetEngine\V1\Trip;
use Google\Maps\FleetEngine\V1\UpdateTripRequest;
use Google\Protobuf\FieldMask;

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

    // Prepare the request message.
    $trip = new Trip();
    $updateMask = new FieldMask();
    $request = (new UpdateTripRequest())
        ->setName($name)
        ->setTrip($trip)
        ->setUpdateMask($updateMask);

    // Call the API and handle any network failures.
    try {
        /** @var Trip $response */
        $response = $tripServiceClient->updateTrip($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_trip_sample($name);
}

createTripAsync

Parameters
Name Description
request Google\Maps\FleetEngine\V1\CreateTripRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Maps\FleetEngine\V1\Trip>

getTripAsync

Parameters
Name Description
request Google\Maps\FleetEngine\V1\GetTripRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Maps\FleetEngine\V1\Trip>

reportBillableTripAsync

Parameters
Name Description
request Google\Maps\FleetEngine\V1\ReportBillableTripRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<void>

searchTripsAsync

Parameters
Name Description
request Google\Maps\FleetEngine\V1\SearchTripsRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse>

updateTripAsync

Parameters
Name Description
request Google\Maps\FleetEngine\V1\UpdateTripRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Maps\FleetEngine\V1\Trip>

static::tripName

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

Parameters
Name Description
provider string
trip string
Returns
Type Description
string The formatted trip 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

  • trip: providers/{provider}/trips/{trip}

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.