Google Cloud Web Risk V1beta1 Client - Class WebRiskServiceV1Beta1Client (1.2.7)

Reference documentation and code samples for the Google Cloud Web Risk V1beta1 Client class WebRiskServiceV1Beta1Client.

Service Description: Web Risk v1beta1 API defines an interface to detect malicious URLs on your website and in client applications.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:

$webRiskServiceV1Beta1Client = new Google\Cloud\WebRisk\V1beta1\WebRiskServiceV1Beta1Client();
try {
    $threatType = Google\Cloud\WebRisk\V1beta1\ThreatType::THREAT_TYPE_UNSPECIFIED;
    $constraints = new Google\Cloud\WebRisk\V1beta1\ComputeThreatListDiffRequest\Constraints();
    $response = $webRiskServiceV1Beta1Client->computeThreatListDiff($threatType, $constraints);
} finally {
    $webRiskServiceV1Beta1Client->close();
}

Methods

__construct

Constructor.

Parameters
NameDescription
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.

computeThreatListDiff

Gets the most recent threat list diffs.

Parameters
NameDescription
threatType int

The ThreatList to update. For allowed values, use constants defined on {@see \Google\Cloud\WebRisk\V1beta1\ThreatType}

constraints Google\Cloud\WebRisk\V1beta1\ComputeThreatListDiffRequest\Constraints

Required. The constraints associated with this request.

optionalArgs array

Optional.

↳ versionToken string

The current version token of the client for the requested list (the client version that was received from the last successful diff).

↳ 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
TypeDescription
Google\Cloud\WebRisk\V1beta1\ComputeThreatListDiffResponse
Example
use Google\ApiCore\ApiException;
use Google\Cloud\WebRisk\V1beta1\ComputeThreatListDiffRequest\Constraints;
use Google\Cloud\WebRisk\V1beta1\ComputeThreatListDiffResponse;
use Google\Cloud\WebRisk\V1beta1\ThreatType;
use Google\Cloud\WebRisk\V1beta1\WebRiskServiceV1Beta1Client;

/**
 * @param int $threatType The ThreatList to update.
 */
function compute_threat_list_diff_sample(int $threatType): void
{
    // Create a client.
    $webRiskServiceV1Beta1Client = new WebRiskServiceV1Beta1Client();

    // Prepare any non-scalar elements to be passed along with the request.
    $constraints = new Constraints();

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

/**
 * 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
{
    $threatType = ThreatType::THREAT_TYPE_UNSPECIFIED;

    compute_threat_list_diff_sample($threatType);
}

searchHashes

Gets the full hashes that match the requested hash prefix.

This is used after a hash prefix is looked up in a threatList and there is a match. The client side threatList only holds partial hashes so the client must query this method to determine if there is a full hash match of a threat.

Parameters
NameDescription
threatTypes int[]

Required. The ThreatLists to search in. For allowed values, use constants defined on {@see \Google\Cloud\WebRisk\V1beta1\ThreatType}

optionalArgs array

Optional.

↳ hashPrefix string

A hash prefix, consisting of the most significant 4-32 bytes of a SHA256 hash. For JSON requests, this field is base64-encoded.

↳ 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
TypeDescription
Google\Cloud\WebRisk\V1beta1\SearchHashesResponse
Example
use Google\ApiCore\ApiException;
use Google\Cloud\WebRisk\V1beta1\SearchHashesResponse;
use Google\Cloud\WebRisk\V1beta1\ThreatType;
use Google\Cloud\WebRisk\V1beta1\WebRiskServiceV1Beta1Client;

/**
 * @param int $threatTypesElement The ThreatLists to search in.
 */
function search_hashes_sample(int $threatTypesElement): void
{
    // Create a client.
    $webRiskServiceV1Beta1Client = new WebRiskServiceV1Beta1Client();

    // Prepare any non-scalar elements to be passed along with the request.
    $threatTypes = [$threatTypesElement,];

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

/**
 * 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
{
    $threatTypesElement = ThreatType::THREAT_TYPE_UNSPECIFIED;

    search_hashes_sample($threatTypesElement);
}

searchUris

This method is used to check whether a URI is on a given threatList.

Parameters
NameDescription
uri string

Required. The URI to be checked for matches.

threatTypes int[]

Required. The ThreatLists to search in. For allowed values, use constants defined on {@see \Google\Cloud\WebRisk\V1beta1\ThreatType}

optionalArgs 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
TypeDescription
Google\Cloud\WebRisk\V1beta1\SearchUrisResponse
Example
use Google\ApiCore\ApiException;
use Google\Cloud\WebRisk\V1beta1\SearchUrisResponse;
use Google\Cloud\WebRisk\V1beta1\ThreatType;
use Google\Cloud\WebRisk\V1beta1\WebRiskServiceV1Beta1Client;

/**
 * @param string $uri                The URI to be checked for matches.
 * @param int    $threatTypesElement The ThreatLists to search in.
 */
function search_uris_sample(string $uri, int $threatTypesElement): void
{
    // Create a client.
    $webRiskServiceV1Beta1Client = new WebRiskServiceV1Beta1Client();

    // Prepare any non-scalar elements to be passed along with the request.
    $threatTypes = [$threatTypesElement,];

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

/**
 * 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
{
    $uri = '[URI]';
    $threatTypesElement = ThreatType::THREAT_TYPE_UNSPECIFIED;

    search_uris_sample($uri, $threatTypesElement);
}

Constants

SERVICE_NAME

Value: 'google.cloud.webrisk.v1beta1.WebRiskServiceV1Beta1'

The name of the service.

SERVICE_ADDRESS

Value: 'webrisk.googleapis.com'

The default address of the service.

DEFAULT_SERVICE_PORT

Value: 443

The default port of the service.

CODEGEN_NAME

Value: 'gapic'

The name of the code generator, to be included in the agent header.