Class AdUnitServiceClient (0.11.0)

GitHub RepositoryProduct Reference

Service Description: Provides methods for handling AdUnit objects.

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:


 // This snippet 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 as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (AdUnitServiceClient adUnitServiceClient = AdUnitServiceClient.create()) {
   AdUnitName name = AdUnitName.of("[NETWORK_CODE]", "[AD_UNIT]");
   AdUnit response = adUnitServiceClient.getAdUnit(name);
 }
 

Note: close() needs to be called on the AdUnitServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

Methods
Method Description Method Variants

GetAdUnit

API to retrieve an AdUnit object.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getAdUnit(GetAdUnitRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getAdUnit(AdUnitName name)

  • getAdUnit(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getAdUnitCallable()

ListAdUnits

API to retrieve a list of AdUnit objects.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listAdUnits(ListAdUnitsRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • listAdUnits(NetworkName parent)

  • listAdUnits(String parent)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listAdUnitsPagedCallable()

  • listAdUnitsCallable()

ListAdUnitSizes

API to retrieve a list of AdUnitSize objects.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listAdUnitSizes(ListAdUnitSizesRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • listAdUnitSizes(NetworkName parent)

  • listAdUnitSizes(String parent)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listAdUnitSizesPagedCallable()

  • listAdUnitSizesCallable()

See the individual methods for example code.

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 parse method to extract the individual identifiers contained within names that are returned.

This class can be customized by passing in a custom instance of AdUnitServiceSettings to create(). For example:

To customize credentials:


 // This snippet 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 as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 AdUnitServiceSettings adUnitServiceSettings =
     AdUnitServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 AdUnitServiceClient adUnitServiceClient = AdUnitServiceClient.create(adUnitServiceSettings);
 

To customize the endpoint:


 // This snippet 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 as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 AdUnitServiceSettings adUnitServiceSettings =
     AdUnitServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 AdUnitServiceClient adUnitServiceClient = AdUnitServiceClient.create(adUnitServiceSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

Inheritance

java.lang.Object > AdUnitServiceClient

Static Methods

create()

public static final AdUnitServiceClient create()

Constructs an instance of AdUnitServiceClient with default settings.

Returns
Type Description
AdUnitServiceClient
Exceptions
Type Description
IOException

create(AdUnitServiceSettings settings)

public static final AdUnitServiceClient create(AdUnitServiceSettings settings)

Constructs an instance of AdUnitServiceClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.

Parameter
Name Description
settings AdUnitServiceSettings
Returns
Type Description
AdUnitServiceClient
Exceptions
Type Description
IOException

create(AdUnitServiceStub stub)

public static final AdUnitServiceClient create(AdUnitServiceStub stub)

Constructs an instance of AdUnitServiceClient, using the given stub for making calls. This is for advanced usage - prefer using create(AdUnitServiceSettings).

Parameter
Name Description
stub AdUnitServiceStub
Returns
Type Description
AdUnitServiceClient

Constructors

AdUnitServiceClient(AdUnitServiceSettings settings)

protected AdUnitServiceClient(AdUnitServiceSettings settings)

Constructs an instance of AdUnitServiceClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.

Parameter
Name Description
settings AdUnitServiceSettings

AdUnitServiceClient(AdUnitServiceStub stub)

protected AdUnitServiceClient(AdUnitServiceStub stub)
Parameter
Name Description
stub AdUnitServiceStub

Methods

awaitTermination(long duration, TimeUnit unit)

public boolean awaitTermination(long duration, TimeUnit unit)
Parameters
Name Description
duration long
unit TimeUnit
Returns
Type Description
boolean
Exceptions
Type Description
InterruptedException

close()

public final void close()

getAdUnit(AdUnitName name)

public final AdUnit getAdUnit(AdUnitName name)

API to retrieve an AdUnit object.

Sample code:


 // This snippet 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 as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (AdUnitServiceClient adUnitServiceClient = AdUnitServiceClient.create()) {
   AdUnitName name = AdUnitName.of("[NETWORK_CODE]", "[AD_UNIT]");
   AdUnit response = adUnitServiceClient.getAdUnit(name);
 }
 
Parameter
Name Description
name AdUnitName

Required. The resource name of the AdUnit. Format: networks/{network_code}/adUnits/{ad_unit_id}

Returns
Type Description
AdUnit

getAdUnit(GetAdUnitRequest request)

public final AdUnit getAdUnit(GetAdUnitRequest request)

API to retrieve an AdUnit object.

Sample code:


 // This snippet 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 as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (AdUnitServiceClient adUnitServiceClient = AdUnitServiceClient.create()) {
   GetAdUnitRequest request =
       GetAdUnitRequest.newBuilder()
           .setName(AdUnitName.of("[NETWORK_CODE]", "[AD_UNIT]").toString())
           .build();
   AdUnit response = adUnitServiceClient.getAdUnit(request);
 }
 
Parameter
Name Description
request GetAdUnitRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
AdUnit

getAdUnit(String name)

public final AdUnit getAdUnit(String name)

API to retrieve an AdUnit object.

Sample code:


 // This snippet 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 as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (AdUnitServiceClient adUnitServiceClient = AdUnitServiceClient.create()) {
   String name = AdUnitName.of("[NETWORK_CODE]", "[AD_UNIT]").toString();
   AdUnit response = adUnitServiceClient.getAdUnit(name);
 }
 
Parameter
Name Description
name String

Required. The resource name of the AdUnit. Format: networks/{network_code}/adUnits/{ad_unit_id}

Returns
Type Description
AdUnit

getAdUnitCallable()

public final UnaryCallable<GetAdUnitRequest,AdUnit> getAdUnitCallable()

API to retrieve an AdUnit object.

Sample code:


 // This snippet 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 as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (AdUnitServiceClient adUnitServiceClient = AdUnitServiceClient.create()) {
   GetAdUnitRequest request =
       GetAdUnitRequest.newBuilder()
           .setName(AdUnitName.of("[NETWORK_CODE]", "[AD_UNIT]").toString())
           .build();
   ApiFuture<AdUnit> future = adUnitServiceClient.getAdUnitCallable().futureCall(request);
   // Do something.
   AdUnit response = future.get();
 }
 
Returns
Type Description
UnaryCallable<GetAdUnitRequest,AdUnit>

getSettings()

public final AdUnitServiceSettings getSettings()
Returns
Type Description
AdUnitServiceSettings

getStub()

public AdUnitServiceStub getStub()
Returns
Type Description
AdUnitServiceStub

isShutdown()

public boolean isShutdown()
Returns
Type Description
boolean

isTerminated()

public boolean isTerminated()
Returns
Type Description
boolean

listAdUnitSizes(ListAdUnitSizesRequest request)

public final AdUnitServiceClient.ListAdUnitSizesPagedResponse listAdUnitSizes(ListAdUnitSizesRequest request)

API to retrieve a list of AdUnitSize objects.

Sample code:


 // This snippet 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 as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (AdUnitServiceClient adUnitServiceClient = AdUnitServiceClient.create()) {
   ListAdUnitSizesRequest request =
       ListAdUnitSizesRequest.newBuilder()
           .setParent(NetworkName.of("[NETWORK_CODE]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setFilter("filter-1274492040")
           .setOrderBy("orderBy-1207110587")
           .setSkip(3532159)
           .build();
   for (AdUnitSize element : adUnitServiceClient.listAdUnitSizes(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
request ListAdUnitSizesRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
AdUnitServiceClient.ListAdUnitSizesPagedResponse

listAdUnitSizes(NetworkName parent)

public final AdUnitServiceClient.ListAdUnitSizesPagedResponse listAdUnitSizes(NetworkName parent)

API to retrieve a list of AdUnitSize objects.

Sample code:


 // This snippet 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 as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (AdUnitServiceClient adUnitServiceClient = AdUnitServiceClient.create()) {
   NetworkName parent = NetworkName.of("[NETWORK_CODE]");
   for (AdUnitSize element : adUnitServiceClient.listAdUnitSizes(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
parent NetworkName

Required. The parent, which owns this collection of AdUnitSizes. Format: networks/{network_code}

Returns
Type Description
AdUnitServiceClient.ListAdUnitSizesPagedResponse

listAdUnitSizes(String parent)

public final AdUnitServiceClient.ListAdUnitSizesPagedResponse listAdUnitSizes(String parent)

API to retrieve a list of AdUnitSize objects.

Sample code:


 // This snippet 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 as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (AdUnitServiceClient adUnitServiceClient = AdUnitServiceClient.create()) {
   String parent = NetworkName.of("[NETWORK_CODE]").toString();
   for (AdUnitSize element : adUnitServiceClient.listAdUnitSizes(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
parent String

Required. The parent, which owns this collection of AdUnitSizes. Format: networks/{network_code}

Returns
Type Description
AdUnitServiceClient.ListAdUnitSizesPagedResponse

listAdUnitSizesCallable()

public final UnaryCallable<ListAdUnitSizesRequest,ListAdUnitSizesResponse> listAdUnitSizesCallable()

API to retrieve a list of AdUnitSize objects.

Sample code:


 // This snippet 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 as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (AdUnitServiceClient adUnitServiceClient = AdUnitServiceClient.create()) {
   ListAdUnitSizesRequest request =
       ListAdUnitSizesRequest.newBuilder()
           .setParent(NetworkName.of("[NETWORK_CODE]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setFilter("filter-1274492040")
           .setOrderBy("orderBy-1207110587")
           .setSkip(3532159)
           .build();
   while (true) {
     ListAdUnitSizesResponse response =
         adUnitServiceClient.listAdUnitSizesCallable().call(request);
     for (AdUnitSize element : response.getAdUnitSizesList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
Type Description
UnaryCallable<ListAdUnitSizesRequest,ListAdUnitSizesResponse>

listAdUnitSizesPagedCallable()

public final UnaryCallable<ListAdUnitSizesRequest,AdUnitServiceClient.ListAdUnitSizesPagedResponse> listAdUnitSizesPagedCallable()

API to retrieve a list of AdUnitSize objects.

Sample code:


 // This snippet 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 as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (AdUnitServiceClient adUnitServiceClient = AdUnitServiceClient.create()) {
   ListAdUnitSizesRequest request =
       ListAdUnitSizesRequest.newBuilder()
           .setParent(NetworkName.of("[NETWORK_CODE]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setFilter("filter-1274492040")
           .setOrderBy("orderBy-1207110587")
           .setSkip(3532159)
           .build();
   ApiFuture<AdUnitSize> future =
       adUnitServiceClient.listAdUnitSizesPagedCallable().futureCall(request);
   // Do something.
   for (AdUnitSize element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
Type Description
UnaryCallable<ListAdUnitSizesRequest,ListAdUnitSizesPagedResponse>

listAdUnits(ListAdUnitsRequest request)

public final AdUnitServiceClient.ListAdUnitsPagedResponse listAdUnits(ListAdUnitsRequest request)

API to retrieve a list of AdUnit objects.

Sample code:


 // This snippet 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 as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (AdUnitServiceClient adUnitServiceClient = AdUnitServiceClient.create()) {
   ListAdUnitsRequest request =
       ListAdUnitsRequest.newBuilder()
           .setParent(NetworkName.of("[NETWORK_CODE]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setFilter("filter-1274492040")
           .setOrderBy("orderBy-1207110587")
           .setSkip(3532159)
           .build();
   for (AdUnit element : adUnitServiceClient.listAdUnits(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
request ListAdUnitsRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
AdUnitServiceClient.ListAdUnitsPagedResponse

listAdUnits(NetworkName parent)

public final AdUnitServiceClient.ListAdUnitsPagedResponse listAdUnits(NetworkName parent)

API to retrieve a list of AdUnit objects.

Sample code:


 // This snippet 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 as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (AdUnitServiceClient adUnitServiceClient = AdUnitServiceClient.create()) {
   NetworkName parent = NetworkName.of("[NETWORK_CODE]");
   for (AdUnit element : adUnitServiceClient.listAdUnits(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
parent NetworkName

Required. The parent, which owns this collection of AdUnits. Format: networks/{network_code}

Returns
Type Description
AdUnitServiceClient.ListAdUnitsPagedResponse

listAdUnits(String parent)

public final AdUnitServiceClient.ListAdUnitsPagedResponse listAdUnits(String parent)

API to retrieve a list of AdUnit objects.

Sample code:


 // This snippet 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 as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (AdUnitServiceClient adUnitServiceClient = AdUnitServiceClient.create()) {
   String parent = NetworkName.of("[NETWORK_CODE]").toString();
   for (AdUnit element : adUnitServiceClient.listAdUnits(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
parent String

Required. The parent, which owns this collection of AdUnits. Format: networks/{network_code}

Returns
Type Description
AdUnitServiceClient.ListAdUnitsPagedResponse

listAdUnitsCallable()

public final UnaryCallable<ListAdUnitsRequest,ListAdUnitsResponse> listAdUnitsCallable()

API to retrieve a list of AdUnit objects.

Sample code:


 // This snippet 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 as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (AdUnitServiceClient adUnitServiceClient = AdUnitServiceClient.create()) {
   ListAdUnitsRequest request =
       ListAdUnitsRequest.newBuilder()
           .setParent(NetworkName.of("[NETWORK_CODE]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setFilter("filter-1274492040")
           .setOrderBy("orderBy-1207110587")
           .setSkip(3532159)
           .build();
   while (true) {
     ListAdUnitsResponse response = adUnitServiceClient.listAdUnitsCallable().call(request);
     for (AdUnit element : response.getAdUnitsList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
Type Description
UnaryCallable<ListAdUnitsRequest,ListAdUnitsResponse>

listAdUnitsPagedCallable()

public final UnaryCallable<ListAdUnitsRequest,AdUnitServiceClient.ListAdUnitsPagedResponse> listAdUnitsPagedCallable()

API to retrieve a list of AdUnit objects.

Sample code:


 // This snippet 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 as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (AdUnitServiceClient adUnitServiceClient = AdUnitServiceClient.create()) {
   ListAdUnitsRequest request =
       ListAdUnitsRequest.newBuilder()
           .setParent(NetworkName.of("[NETWORK_CODE]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setFilter("filter-1274492040")
           .setOrderBy("orderBy-1207110587")
           .setSkip(3532159)
           .build();
   ApiFuture<AdUnit> future = adUnitServiceClient.listAdUnitsPagedCallable().futureCall(request);
   // Do something.
   for (AdUnit element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
Type Description
UnaryCallable<ListAdUnitsRequest,ListAdUnitsPagedResponse>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()