Class PromotionsServiceClient (0.3.0)

GitHub RepositoryProduct Reference

Service Description: Service to manage promotions for products.

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 (PromotionsServiceClient promotionsServiceClient = PromotionsServiceClient.create()) {
   InsertPromotionRequest request =
       InsertPromotionRequest.newBuilder()
           .setParent("parent-995424086")
           .setPromotion(Promotion.newBuilder().build())
           .setDataSource("dataSource1272470629")
           .build();
   Promotion response = promotionsServiceClient.insertPromotion(request);
 }
 

Note: close() needs to be called on the PromotionsServiceClient 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

InsertPromotion

Inserts a promotion for your Merchant Center account. If the promotion already exists, then it updates the promotion instead.

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

  • insertPromotion(InsertPromotionRequest request)

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

  • insertPromotionCallable()

GetPromotion

Retrieves the promotion from your Merchant Center account.

After inserting or updating a promotion input, it may take several minutes before the updated promotion can be retrieved.

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

  • getPromotion(GetPromotionRequest request)

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

  • getPromotion(PromotionName name)

  • getPromotion(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.

  • getPromotionCallable()

ListPromotions

Lists the promotions in your Merchant Center account. The response might contain fewer items than specified by pageSize. Rely on pageToken to determine if there are more items to be requested.

After inserting or updating a promotion, it may take several minutes before the updated processed promotion can be retrieved.

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

  • listPromotions(ListPromotionsRequest request)

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

  • listPromotions(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.

  • listPromotionsPagedCallable()

  • listPromotionsCallable()

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 PromotionsServiceSettings 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
 PromotionsServiceSettings promotionsServiceSettings =
     PromotionsServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 PromotionsServiceClient promotionsServiceClient =
     PromotionsServiceClient.create(promotionsServiceSettings);
 

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
 PromotionsServiceSettings promotionsServiceSettings =
     PromotionsServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 PromotionsServiceClient promotionsServiceClient =
     PromotionsServiceClient.create(promotionsServiceSettings);
 

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:


 // 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
 PromotionsServiceSettings promotionsServiceSettings =
     PromotionsServiceSettings.newHttpJsonBuilder().build();
 PromotionsServiceClient promotionsServiceClient =
     PromotionsServiceClient.create(promotionsServiceSettings);
 

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

Inheritance

java.lang.Object > PromotionsServiceClient

Static Methods

create()

public static final PromotionsServiceClient create()

Constructs an instance of PromotionsServiceClient with default settings.

Returns
Type Description
PromotionsServiceClient
Exceptions
Type Description
IOException

create(PromotionsServiceSettings settings)

public static final PromotionsServiceClient create(PromotionsServiceSettings settings)

Constructs an instance of PromotionsServiceClient, 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 PromotionsServiceSettings
Returns
Type Description
PromotionsServiceClient
Exceptions
Type Description
IOException

create(PromotionsServiceStub stub)

public static final PromotionsServiceClient create(PromotionsServiceStub stub)

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

Parameter
Name Description
stub PromotionsServiceStub
Returns
Type Description
PromotionsServiceClient

Constructors

PromotionsServiceClient(PromotionsServiceSettings settings)

protected PromotionsServiceClient(PromotionsServiceSettings settings)

Constructs an instance of PromotionsServiceClient, 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 PromotionsServiceSettings

PromotionsServiceClient(PromotionsServiceStub stub)

protected PromotionsServiceClient(PromotionsServiceStub stub)
Parameter
Name Description
stub PromotionsServiceStub

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()

getPromotion(GetPromotionRequest request)

public final Promotion getPromotion(GetPromotionRequest request)

Retrieves the promotion from your Merchant Center account.

After inserting or updating a promotion input, it may take several minutes before the updated promotion can be retrieved.

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 (PromotionsServiceClient promotionsServiceClient = PromotionsServiceClient.create()) {
   GetPromotionRequest request =
       GetPromotionRequest.newBuilder()
           .setName(PromotionName.of("[ACCOUNT]", "[PROMOTION]").toString())
           .build();
   Promotion response = promotionsServiceClient.getPromotion(request);
 }
 
Parameter
Name Description
request GetPromotionRequest

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

Returns
Type Description
Promotion

getPromotion(PromotionName name)

public final Promotion getPromotion(PromotionName name)

Retrieves the promotion from your Merchant Center account.

After inserting or updating a promotion input, it may take several minutes before the updated promotion can be retrieved.

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 (PromotionsServiceClient promotionsServiceClient = PromotionsServiceClient.create()) {
   PromotionName name = PromotionName.of("[ACCOUNT]", "[PROMOTION]");
   Promotion response = promotionsServiceClient.getPromotion(name);
 }
 
Parameter
Name Description
name PromotionName

Required. The name of the promotion to retrieve. Format: accounts/{account}/promotions/{promotions}

Returns
Type Description
Promotion

getPromotion(String name)

public final Promotion getPromotion(String name)

Retrieves the promotion from your Merchant Center account.

After inserting or updating a promotion input, it may take several minutes before the updated promotion can be retrieved.

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 (PromotionsServiceClient promotionsServiceClient = PromotionsServiceClient.create()) {
   String name = PromotionName.of("[ACCOUNT]", "[PROMOTION]").toString();
   Promotion response = promotionsServiceClient.getPromotion(name);
 }
 
Parameter
Name Description
name String

Required. The name of the promotion to retrieve. Format: accounts/{account}/promotions/{promotions}

Returns
Type Description
Promotion

getPromotionCallable()

public final UnaryCallable<GetPromotionRequest,Promotion> getPromotionCallable()

Retrieves the promotion from your Merchant Center account.

After inserting or updating a promotion input, it may take several minutes before the updated promotion can be retrieved.

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 (PromotionsServiceClient promotionsServiceClient = PromotionsServiceClient.create()) {
   GetPromotionRequest request =
       GetPromotionRequest.newBuilder()
           .setName(PromotionName.of("[ACCOUNT]", "[PROMOTION]").toString())
           .build();
   ApiFuture<Promotion> future =
       promotionsServiceClient.getPromotionCallable().futureCall(request);
   // Do something.
   Promotion response = future.get();
 }
 
Returns
Type Description
UnaryCallable<GetPromotionRequest,Promotion>

getSettings()

public final PromotionsServiceSettings getSettings()
Returns
Type Description
PromotionsServiceSettings

getStub()

public PromotionsServiceStub getStub()
Returns
Type Description
PromotionsServiceStub

insertPromotion(InsertPromotionRequest request)

public final Promotion insertPromotion(InsertPromotionRequest request)

Inserts a promotion for your Merchant Center account. If the promotion already exists, then it updates the promotion instead.

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 (PromotionsServiceClient promotionsServiceClient = PromotionsServiceClient.create()) {
   InsertPromotionRequest request =
       InsertPromotionRequest.newBuilder()
           .setParent("parent-995424086")
           .setPromotion(Promotion.newBuilder().build())
           .setDataSource("dataSource1272470629")
           .build();
   Promotion response = promotionsServiceClient.insertPromotion(request);
 }
 
Parameter
Name Description
request InsertPromotionRequest

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

Returns
Type Description
Promotion

insertPromotionCallable()

public final UnaryCallable<InsertPromotionRequest,Promotion> insertPromotionCallable()

Inserts a promotion for your Merchant Center account. If the promotion already exists, then it updates the promotion instead.

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 (PromotionsServiceClient promotionsServiceClient = PromotionsServiceClient.create()) {
   InsertPromotionRequest request =
       InsertPromotionRequest.newBuilder()
           .setParent("parent-995424086")
           .setPromotion(Promotion.newBuilder().build())
           .setDataSource("dataSource1272470629")
           .build();
   ApiFuture<Promotion> future =
       promotionsServiceClient.insertPromotionCallable().futureCall(request);
   // Do something.
   Promotion response = future.get();
 }
 
Returns
Type Description
UnaryCallable<InsertPromotionRequest,Promotion>

isShutdown()

public boolean isShutdown()
Returns
Type Description
boolean

isTerminated()

public boolean isTerminated()
Returns
Type Description
boolean

listPromotions(ListPromotionsRequest request)

public final PromotionsServiceClient.ListPromotionsPagedResponse listPromotions(ListPromotionsRequest request)

Lists the promotions in your Merchant Center account. The response might contain fewer items than specified by pageSize. Rely on pageToken to determine if there are more items to be requested.

After inserting or updating a promotion, it may take several minutes before the updated processed promotion can be retrieved.

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 (PromotionsServiceClient promotionsServiceClient = PromotionsServiceClient.create()) {
   ListPromotionsRequest request =
       ListPromotionsRequest.newBuilder()
           .setParent("parent-995424086")
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   for (Promotion element : promotionsServiceClient.listPromotions(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
request ListPromotionsRequest

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

Returns
Type Description
PromotionsServiceClient.ListPromotionsPagedResponse

listPromotions(String parent)

public final PromotionsServiceClient.ListPromotionsPagedResponse listPromotions(String parent)

Lists the promotions in your Merchant Center account. The response might contain fewer items than specified by pageSize. Rely on pageToken to determine if there are more items to be requested.

After inserting or updating a promotion, it may take several minutes before the updated processed promotion can be retrieved.

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 (PromotionsServiceClient promotionsServiceClient = PromotionsServiceClient.create()) {
   String parent = "parent-995424086";
   for (Promotion element : promotionsServiceClient.listPromotions(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
parent String

Required. The account to list processed promotions for. Format: accounts/{account}

Returns
Type Description
PromotionsServiceClient.ListPromotionsPagedResponse

listPromotionsCallable()

public final UnaryCallable<ListPromotionsRequest,ListPromotionsResponse> listPromotionsCallable()

Lists the promotions in your Merchant Center account. The response might contain fewer items than specified by pageSize. Rely on pageToken to determine if there are more items to be requested.

After inserting or updating a promotion, it may take several minutes before the updated processed promotion can be retrieved.

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 (PromotionsServiceClient promotionsServiceClient = PromotionsServiceClient.create()) {
   ListPromotionsRequest request =
       ListPromotionsRequest.newBuilder()
           .setParent("parent-995424086")
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   while (true) {
     ListPromotionsResponse response =
         promotionsServiceClient.listPromotionsCallable().call(request);
     for (Promotion element : response.getPromotionsList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
Type Description
UnaryCallable<ListPromotionsRequest,ListPromotionsResponse>

listPromotionsPagedCallable()

public final UnaryCallable<ListPromotionsRequest,PromotionsServiceClient.ListPromotionsPagedResponse> listPromotionsPagedCallable()

Lists the promotions in your Merchant Center account. The response might contain fewer items than specified by pageSize. Rely on pageToken to determine if there are more items to be requested.

After inserting or updating a promotion, it may take several minutes before the updated processed promotion can be retrieved.

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 (PromotionsServiceClient promotionsServiceClient = PromotionsServiceClient.create()) {
   ListPromotionsRequest request =
       ListPromotionsRequest.newBuilder()
           .setParent("parent-995424086")
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   ApiFuture<Promotion> future =
       promotionsServiceClient.listPromotionsPagedCallable().futureCall(request);
   // Do something.
   for (Promotion element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
Type Description
UnaryCallable<ListPromotionsRequest,ListPromotionsPagedResponse>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()