Class ProgramsServiceClient (0.4.0)

GitHub RepositoryProduct Reference

Service Description: Service for program management.

Programs provide a mechanism for adding functionality to merchant accounts. A typical example of this is the Free product listings program, which enables products from a merchant's store to be shown across Google for free.

This service exposes methods to retrieve a merchant's participation in all available programs, in addition to methods for explicitly enabling or disabling participation in each program.

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 (ProgramsServiceClient programsServiceClient = ProgramsServiceClient.create()) {
   ProgramName name = ProgramName.of("[ACCOUNT]", "[PROGRAM]");
   Program response = programsServiceClient.getProgram(name);
 }
 

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

GetProgram

Retrieves the specified program for the account.

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

  • getProgram(GetProgramRequest request)

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

  • getProgram(ProgramName name)

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

  • getProgramCallable()

ListPrograms

Retrieves all programs for the account.

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

  • listPrograms(ListProgramsRequest request)

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

  • listPrograms(AccountName parent)

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

  • listProgramsPagedCallable()

  • listProgramsCallable()

EnableProgram

Enable participation in the specified program for the account. Executing this method requires admin access.

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

  • enableProgram(EnableProgramRequest request)

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

  • enableProgram(ProgramName name)

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

  • enableProgramCallable()

DisableProgram

Disable participation in the specified program for the account. Executing this method requires admin access.

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

  • disableProgram(DisableProgramRequest request)

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

  • disableProgram(ProgramName name)

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

  • disableProgramCallable()

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 ProgramsServiceSettings 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
 ProgramsServiceSettings programsServiceSettings =
     ProgramsServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 ProgramsServiceClient programsServiceClient =
     ProgramsServiceClient.create(programsServiceSettings);
 

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
 ProgramsServiceSettings programsServiceSettings =
     ProgramsServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 ProgramsServiceClient programsServiceClient =
     ProgramsServiceClient.create(programsServiceSettings);
 

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
 ProgramsServiceSettings programsServiceSettings =
     ProgramsServiceSettings.newHttpJsonBuilder().build();
 ProgramsServiceClient programsServiceClient =
     ProgramsServiceClient.create(programsServiceSettings);
 

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

Inheritance

java.lang.Object > ProgramsServiceClient

Static Methods

create()

public static final ProgramsServiceClient create()

Constructs an instance of ProgramsServiceClient with default settings.

Returns
Type Description
ProgramsServiceClient
Exceptions
Type Description
IOException

create(ProgramsServiceSettings settings)

public static final ProgramsServiceClient create(ProgramsServiceSettings settings)

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

create(ProgramsServiceStub stub)

public static final ProgramsServiceClient create(ProgramsServiceStub stub)

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

Parameter
Name Description
stub ProgramsServiceStub
Returns
Type Description
ProgramsServiceClient

Constructors

ProgramsServiceClient(ProgramsServiceSettings settings)

protected ProgramsServiceClient(ProgramsServiceSettings settings)

Constructs an instance of ProgramsServiceClient, 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 ProgramsServiceSettings

ProgramsServiceClient(ProgramsServiceStub stub)

protected ProgramsServiceClient(ProgramsServiceStub stub)
Parameter
Name Description
stub ProgramsServiceStub

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

disableProgram(DisableProgramRequest request)

public final Program disableProgram(DisableProgramRequest request)

Disable participation in the specified program for the account. Executing this method requires admin access.

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 (ProgramsServiceClient programsServiceClient = ProgramsServiceClient.create()) {
   DisableProgramRequest request =
       DisableProgramRequest.newBuilder()
           .setName(ProgramName.of("[ACCOUNT]", "[PROGRAM]").toString())
           .build();
   Program response = programsServiceClient.disableProgram(request);
 }
 
Parameter
Name Description
request DisableProgramRequest

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

Returns
Type Description
Program

disableProgram(ProgramName name)

public final Program disableProgram(ProgramName name)

Disable participation in the specified program for the account. Executing this method requires admin access.

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 (ProgramsServiceClient programsServiceClient = ProgramsServiceClient.create()) {
   ProgramName name = ProgramName.of("[ACCOUNT]", "[PROGRAM]");
   Program response = programsServiceClient.disableProgram(name);
 }
 
Parameter
Name Description
name ProgramName

Required. The name of the program for which to disable participation for the given account. Format: accounts/{account}/programs/{program}

Returns
Type Description
Program

disableProgram(String name)

public final Program disableProgram(String name)

Disable participation in the specified program for the account. Executing this method requires admin access.

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 (ProgramsServiceClient programsServiceClient = ProgramsServiceClient.create()) {
   String name = ProgramName.of("[ACCOUNT]", "[PROGRAM]").toString();
   Program response = programsServiceClient.disableProgram(name);
 }
 
Parameter
Name Description
name String

Required. The name of the program for which to disable participation for the given account. Format: accounts/{account}/programs/{program}

Returns
Type Description
Program

disableProgramCallable()

public final UnaryCallable<DisableProgramRequest,Program> disableProgramCallable()

Disable participation in the specified program for the account. Executing this method requires admin access.

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 (ProgramsServiceClient programsServiceClient = ProgramsServiceClient.create()) {
   DisableProgramRequest request =
       DisableProgramRequest.newBuilder()
           .setName(ProgramName.of("[ACCOUNT]", "[PROGRAM]").toString())
           .build();
   ApiFuture<Program> future =
       programsServiceClient.disableProgramCallable().futureCall(request);
   // Do something.
   Program response = future.get();
 }
 
Returns
Type Description
UnaryCallable<DisableProgramRequest,Program>

enableProgram(EnableProgramRequest request)

public final Program enableProgram(EnableProgramRequest request)

Enable participation in the specified program for the account. Executing this method requires admin access.

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 (ProgramsServiceClient programsServiceClient = ProgramsServiceClient.create()) {
   EnableProgramRequest request =
       EnableProgramRequest.newBuilder()
           .setName(ProgramName.of("[ACCOUNT]", "[PROGRAM]").toString())
           .build();
   Program response = programsServiceClient.enableProgram(request);
 }
 
Parameter
Name Description
request EnableProgramRequest

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

Returns
Type Description
Program

enableProgram(ProgramName name)

public final Program enableProgram(ProgramName name)

Enable participation in the specified program for the account. Executing this method requires admin access.

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 (ProgramsServiceClient programsServiceClient = ProgramsServiceClient.create()) {
   ProgramName name = ProgramName.of("[ACCOUNT]", "[PROGRAM]");
   Program response = programsServiceClient.enableProgram(name);
 }
 
Parameter
Name Description
name ProgramName

Required. The name of the program for which to enable participation for the given account. Format: accounts/{account}/programs/{program}

Returns
Type Description
Program

enableProgram(String name)

public final Program enableProgram(String name)

Enable participation in the specified program for the account. Executing this method requires admin access.

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 (ProgramsServiceClient programsServiceClient = ProgramsServiceClient.create()) {
   String name = ProgramName.of("[ACCOUNT]", "[PROGRAM]").toString();
   Program response = programsServiceClient.enableProgram(name);
 }
 
Parameter
Name Description
name String

Required. The name of the program for which to enable participation for the given account. Format: accounts/{account}/programs/{program}

Returns
Type Description
Program

enableProgramCallable()

public final UnaryCallable<EnableProgramRequest,Program> enableProgramCallable()

Enable participation in the specified program for the account. Executing this method requires admin access.

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 (ProgramsServiceClient programsServiceClient = ProgramsServiceClient.create()) {
   EnableProgramRequest request =
       EnableProgramRequest.newBuilder()
           .setName(ProgramName.of("[ACCOUNT]", "[PROGRAM]").toString())
           .build();
   ApiFuture<Program> future = programsServiceClient.enableProgramCallable().futureCall(request);
   // Do something.
   Program response = future.get();
 }
 
Returns
Type Description
UnaryCallable<EnableProgramRequest,Program>

getProgram(GetProgramRequest request)

public final Program getProgram(GetProgramRequest request)

Retrieves the specified program for the account.

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 (ProgramsServiceClient programsServiceClient = ProgramsServiceClient.create()) {
   GetProgramRequest request =
       GetProgramRequest.newBuilder()
           .setName(ProgramName.of("[ACCOUNT]", "[PROGRAM]").toString())
           .build();
   Program response = programsServiceClient.getProgram(request);
 }
 
Parameter
Name Description
request GetProgramRequest

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

Returns
Type Description
Program

getProgram(ProgramName name)

public final Program getProgram(ProgramName name)

Retrieves the specified program for the account.

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 (ProgramsServiceClient programsServiceClient = ProgramsServiceClient.create()) {
   ProgramName name = ProgramName.of("[ACCOUNT]", "[PROGRAM]");
   Program response = programsServiceClient.getProgram(name);
 }
 
Parameter
Name Description
name ProgramName

Required. The name of the program to retrieve. Format: accounts/{account}/programs/{program}

Returns
Type Description
Program

getProgram(String name)

public final Program getProgram(String name)

Retrieves the specified program for the account.

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 (ProgramsServiceClient programsServiceClient = ProgramsServiceClient.create()) {
   String name = ProgramName.of("[ACCOUNT]", "[PROGRAM]").toString();
   Program response = programsServiceClient.getProgram(name);
 }
 
Parameter
Name Description
name String

Required. The name of the program to retrieve. Format: accounts/{account}/programs/{program}

Returns
Type Description
Program

getProgramCallable()

public final UnaryCallable<GetProgramRequest,Program> getProgramCallable()

Retrieves the specified program for the account.

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 (ProgramsServiceClient programsServiceClient = ProgramsServiceClient.create()) {
   GetProgramRequest request =
       GetProgramRequest.newBuilder()
           .setName(ProgramName.of("[ACCOUNT]", "[PROGRAM]").toString())
           .build();
   ApiFuture<Program> future = programsServiceClient.getProgramCallable().futureCall(request);
   // Do something.
   Program response = future.get();
 }
 
Returns
Type Description
UnaryCallable<GetProgramRequest,Program>

getSettings()

public final ProgramsServiceSettings getSettings()
Returns
Type Description
ProgramsServiceSettings

getStub()

public ProgramsServiceStub getStub()
Returns
Type Description
ProgramsServiceStub

isShutdown()

public boolean isShutdown()
Returns
Type Description
boolean

isTerminated()

public boolean isTerminated()
Returns
Type Description
boolean

listPrograms(AccountName parent)

public final ProgramsServiceClient.ListProgramsPagedResponse listPrograms(AccountName parent)

Retrieves all programs for the account.

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 (ProgramsServiceClient programsServiceClient = ProgramsServiceClient.create()) {
   AccountName parent = AccountName.of("[ACCOUNT]");
   for (Program element : programsServiceClient.listPrograms(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
parent AccountName

Required. The name of the account for which to retrieve all programs. Format: accounts/{account}

Returns
Type Description
ProgramsServiceClient.ListProgramsPagedResponse

listPrograms(ListProgramsRequest request)

public final ProgramsServiceClient.ListProgramsPagedResponse listPrograms(ListProgramsRequest request)

Retrieves all programs for the account.

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 (ProgramsServiceClient programsServiceClient = ProgramsServiceClient.create()) {
   ListProgramsRequest request =
       ListProgramsRequest.newBuilder()
           .setParent(AccountName.of("[ACCOUNT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   for (Program element : programsServiceClient.listPrograms(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
request ListProgramsRequest

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

Returns
Type Description
ProgramsServiceClient.ListProgramsPagedResponse

listPrograms(String parent)

public final ProgramsServiceClient.ListProgramsPagedResponse listPrograms(String parent)

Retrieves all programs for the account.

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 (ProgramsServiceClient programsServiceClient = ProgramsServiceClient.create()) {
   String parent = AccountName.of("[ACCOUNT]").toString();
   for (Program element : programsServiceClient.listPrograms(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
parent String

Required. The name of the account for which to retrieve all programs. Format: accounts/{account}

Returns
Type Description
ProgramsServiceClient.ListProgramsPagedResponse

listProgramsCallable()

public final UnaryCallable<ListProgramsRequest,ListProgramsResponse> listProgramsCallable()

Retrieves all programs for the account.

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 (ProgramsServiceClient programsServiceClient = ProgramsServiceClient.create()) {
   ListProgramsRequest request =
       ListProgramsRequest.newBuilder()
           .setParent(AccountName.of("[ACCOUNT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   while (true) {
     ListProgramsResponse response = programsServiceClient.listProgramsCallable().call(request);
     for (Program element : response.getProgramsList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
Type Description
UnaryCallable<ListProgramsRequest,ListProgramsResponse>

listProgramsPagedCallable()

public final UnaryCallable<ListProgramsRequest,ProgramsServiceClient.ListProgramsPagedResponse> listProgramsPagedCallable()

Retrieves all programs for the account.

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 (ProgramsServiceClient programsServiceClient = ProgramsServiceClient.create()) {
   ListProgramsRequest request =
       ListProgramsRequest.newBuilder()
           .setParent(AccountName.of("[ACCOUNT]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   ApiFuture<Program> future =
       programsServiceClient.listProgramsPagedCallable().futureCall(request);
   // Do something.
   for (Program element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
Type Description
UnaryCallable<ListProgramsRequest,ListProgramsPagedResponse>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()