Class DeveloperKnowledgeClient (0.1.0)

GitHub RepositoryProduct Reference

Service Description: The Developer Knowledge API provides programmatic access to Google's public developer documentation, enabling you to integrate this knowledge base into your own applications and workflows.

The API is designed to be the canonical source for machine-readable access to Google's developer documentation.

A typical use case is to first use DeveloperKnowledge.SearchDocumentChunks to find relevant page URIs based on a query, and then use DeveloperKnowledge.GetDocument or DeveloperKnowledge.BatchGetDocuments to fetch the full content of the top results.

All document content is provided in Markdown format.

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 (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) {
   DocumentName name = DocumentName.of("[DOCUMENT]");
   Document response = developerKnowledgeClient.getDocument(name);
 }
 

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

SearchDocumentChunks

Searches for developer knowledge across Google's developer documentation. Returns DocumentChunks based on the user's query. There may be many chunks from the same Document. To retrieve full documents, use DeveloperKnowledge.GetDocument or DeveloperKnowledge.BatchGetDocuments with the DocumentChunk.parent returned in the SearchDocumentChunksResponse.results.

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

  • searchDocumentChunks(SearchDocumentChunksRequest request)

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

  • searchDocumentChunksPagedCallable()

  • searchDocumentChunksCallable()

GetDocument

Retrieves a single document with its full Markdown content.

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

  • getDocument(GetDocumentRequest request)

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

  • getDocument(DocumentName name)

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

  • getDocumentCallable()

BatchGetDocuments

Retrieves multiple documents, each with its full Markdown content.

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

  • batchGetDocuments(BatchGetDocumentsRequest request)

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

  • batchGetDocumentsCallable()

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 DeveloperKnowledgeSettings 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
 DeveloperKnowledgeSettings developerKnowledgeSettings =
     DeveloperKnowledgeSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 DeveloperKnowledgeClient developerKnowledgeClient =
     DeveloperKnowledgeClient.create(developerKnowledgeSettings);
 

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
 DeveloperKnowledgeSettings developerKnowledgeSettings =
     DeveloperKnowledgeSettings.newBuilder().setEndpoint(myEndpoint).build();
 DeveloperKnowledgeClient developerKnowledgeClient =
     DeveloperKnowledgeClient.create(developerKnowledgeSettings);
 

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
 DeveloperKnowledgeSettings developerKnowledgeSettings =
     DeveloperKnowledgeSettings.newHttpJsonBuilder().build();
 DeveloperKnowledgeClient developerKnowledgeClient =
     DeveloperKnowledgeClient.create(developerKnowledgeSettings);
 

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

Inheritance

java.lang.Object > DeveloperKnowledgeClient

Static Methods

create()

public static final DeveloperKnowledgeClient create()

Constructs an instance of DeveloperKnowledgeClient with default settings.

Returns
Type Description
DeveloperKnowledgeClient
Exceptions
Type Description
IOException

create(DeveloperKnowledgeSettings settings)

public static final DeveloperKnowledgeClient create(DeveloperKnowledgeSettings settings)

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

create(DeveloperKnowledgeStub stub)

public static final DeveloperKnowledgeClient create(DeveloperKnowledgeStub stub)

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

Parameter
Name Description
stub DeveloperKnowledgeStub
Returns
Type Description
DeveloperKnowledgeClient

Constructors

DeveloperKnowledgeClient(DeveloperKnowledgeSettings settings)

protected DeveloperKnowledgeClient(DeveloperKnowledgeSettings settings)

Constructs an instance of DeveloperKnowledgeClient, 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 DeveloperKnowledgeSettings

DeveloperKnowledgeClient(DeveloperKnowledgeStub stub)

protected DeveloperKnowledgeClient(DeveloperKnowledgeStub stub)
Parameter
Name Description
stub DeveloperKnowledgeStub

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

batchGetDocuments(BatchGetDocumentsRequest request)

public final BatchGetDocumentsResponse batchGetDocuments(BatchGetDocumentsRequest request)

Retrieves multiple documents, each with its full Markdown content.

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 (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) {
   BatchGetDocumentsRequest request =
       BatchGetDocumentsRequest.newBuilder()
           .addAllNames(new ArrayList<String>())
           .setView(DocumentView.forNumber(0))
           .build();
   BatchGetDocumentsResponse response = developerKnowledgeClient.batchGetDocuments(request);
 }
 
Parameter
Name Description
request BatchGetDocumentsRequest

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

Returns
Type Description
BatchGetDocumentsResponse

batchGetDocumentsCallable()

public final UnaryCallable<BatchGetDocumentsRequest,BatchGetDocumentsResponse> batchGetDocumentsCallable()

Retrieves multiple documents, each with its full Markdown content.

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 (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) {
   BatchGetDocumentsRequest request =
       BatchGetDocumentsRequest.newBuilder()
           .addAllNames(new ArrayList<String>())
           .setView(DocumentView.forNumber(0))
           .build();
   ApiFuture<BatchGetDocumentsResponse> future =
       developerKnowledgeClient.batchGetDocumentsCallable().futureCall(request);
   // Do something.
   BatchGetDocumentsResponse response = future.get();
 }
 
Returns
Type Description
UnaryCallable<BatchGetDocumentsRequest,BatchGetDocumentsResponse>

close()

public final void close()

getDocument(DocumentName name)

public final Document getDocument(DocumentName name)

Retrieves a single document with its full Markdown content.

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 (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) {
   DocumentName name = DocumentName.of("[DOCUMENT]");
   Document response = developerKnowledgeClient.getDocument(name);
 }
 
Parameter
Name Description
name DocumentName

Required. Specifies the name of the document to retrieve. Format: documents/{uri_without_scheme} Example: documents/docs.cloud.google.com/storage/docs/creating-buckets

Returns
Type Description
Document

getDocument(GetDocumentRequest request)

public final Document getDocument(GetDocumentRequest request)

Retrieves a single document with its full Markdown content.

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 (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) {
   GetDocumentRequest request =
       GetDocumentRequest.newBuilder()
           .setName(DocumentName.of("[DOCUMENT]").toString())
           .setView(DocumentView.forNumber(0))
           .build();
   Document response = developerKnowledgeClient.getDocument(request);
 }
 
Parameter
Name Description
request GetDocumentRequest

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

Returns
Type Description
Document

getDocument(String name)

public final Document getDocument(String name)

Retrieves a single document with its full Markdown content.

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 (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) {
   String name = DocumentName.of("[DOCUMENT]").toString();
   Document response = developerKnowledgeClient.getDocument(name);
 }
 
Parameter
Name Description
name String

Required. Specifies the name of the document to retrieve. Format: documents/{uri_without_scheme} Example: documents/docs.cloud.google.com/storage/docs/creating-buckets

Returns
Type Description
Document

getDocumentCallable()

public final UnaryCallable<GetDocumentRequest,Document> getDocumentCallable()

Retrieves a single document with its full Markdown content.

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 (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) {
   GetDocumentRequest request =
       GetDocumentRequest.newBuilder()
           .setName(DocumentName.of("[DOCUMENT]").toString())
           .setView(DocumentView.forNumber(0))
           .build();
   ApiFuture<Document> future =
       developerKnowledgeClient.getDocumentCallable().futureCall(request);
   // Do something.
   Document response = future.get();
 }
 
Returns
Type Description
UnaryCallable<GetDocumentRequest,Document>

getSettings()

public final DeveloperKnowledgeSettings getSettings()
Returns
Type Description
DeveloperKnowledgeSettings

getStub()

public DeveloperKnowledgeStub getStub()
Returns
Type Description
DeveloperKnowledgeStub

isShutdown()

public boolean isShutdown()
Returns
Type Description
boolean

isTerminated()

public boolean isTerminated()
Returns
Type Description
boolean

searchDocumentChunks(SearchDocumentChunksRequest request)

public final DeveloperKnowledgeClient.SearchDocumentChunksPagedResponse searchDocumentChunks(SearchDocumentChunksRequest request)

Searches for developer knowledge across Google's developer documentation. Returns DocumentChunks based on the user's query. There may be many chunks from the same Document. To retrieve full documents, use DeveloperKnowledge.GetDocument or DeveloperKnowledge.BatchGetDocuments with the DocumentChunk.parent returned in the SearchDocumentChunksResponse.results.

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 (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) {
   SearchDocumentChunksRequest request =
       SearchDocumentChunksRequest.newBuilder()
           .setQuery("query107944136")
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setFilter("filter-1274492040")
           .build();
   for (DocumentChunk element :
       developerKnowledgeClient.searchDocumentChunks(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
Name Description
request SearchDocumentChunksRequest

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

Returns
Type Description
DeveloperKnowledgeClient.SearchDocumentChunksPagedResponse

searchDocumentChunksCallable()

public final UnaryCallable<SearchDocumentChunksRequest,SearchDocumentChunksResponse> searchDocumentChunksCallable()

Searches for developer knowledge across Google's developer documentation. Returns DocumentChunks based on the user's query. There may be many chunks from the same Document. To retrieve full documents, use DeveloperKnowledge.GetDocument or DeveloperKnowledge.BatchGetDocuments with the DocumentChunk.parent returned in the SearchDocumentChunksResponse.results.

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 (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) {
   SearchDocumentChunksRequest request =
       SearchDocumentChunksRequest.newBuilder()
           .setQuery("query107944136")
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setFilter("filter-1274492040")
           .build();
   while (true) {
     SearchDocumentChunksResponse response =
         developerKnowledgeClient.searchDocumentChunksCallable().call(request);
     for (DocumentChunk element : response.getResultsList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
Type Description
UnaryCallable<SearchDocumentChunksRequest,SearchDocumentChunksResponse>

searchDocumentChunksPagedCallable()

public final UnaryCallable<SearchDocumentChunksRequest,DeveloperKnowledgeClient.SearchDocumentChunksPagedResponse> searchDocumentChunksPagedCallable()

Searches for developer knowledge across Google's developer documentation. Returns DocumentChunks based on the user's query. There may be many chunks from the same Document. To retrieve full documents, use DeveloperKnowledge.GetDocument or DeveloperKnowledge.BatchGetDocuments with the DocumentChunk.parent returned in the SearchDocumentChunksResponse.results.

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 (DeveloperKnowledgeClient developerKnowledgeClient = DeveloperKnowledgeClient.create()) {
   SearchDocumentChunksRequest request =
       SearchDocumentChunksRequest.newBuilder()
           .setQuery("query107944136")
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .setFilter("filter-1274492040")
           .build();
   ApiFuture<DocumentChunk> future =
       developerKnowledgeClient.searchDocumentChunksPagedCallable().futureCall(request);
   // Do something.
   for (DocumentChunk element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
Type Description
UnaryCallable<SearchDocumentChunksRequest,SearchDocumentChunksPagedResponse>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()