Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Commit

Permalink
feat: add Key support (#17)
Browse files Browse the repository at this point in the history
* [CHANGE ME] Re-generated  to pick up changes in the API or client library generator.

* fix: allow proto interface changes

Co-authored-by: Jeff Ching <chingor@google.com>
  • Loading branch information
yoshi-automation and chingor13 committed Dec 23, 2019
1 parent e84bd5d commit 3bebbb2
Show file tree
Hide file tree
Showing 34 changed files with 13,759 additions and 107 deletions.
Expand Up @@ -15,18 +15,35 @@
*/
package com.google.cloud.recaptchaenterprise.v1beta1;

import com.google.api.core.ApiFunction;
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.api.core.BetaApi;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.paging.AbstractFixedSizeCollection;
import com.google.api.gax.paging.AbstractPage;
import com.google.api.gax.paging.AbstractPagedListResponse;
import com.google.api.gax.rpc.PageContext;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.recaptchaenterprise.v1beta1.stub.RecaptchaEnterpriseServiceV1Beta1Stub;
import com.google.cloud.recaptchaenterprise.v1beta1.stub.RecaptchaEnterpriseServiceV1Beta1StubSettings;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.protobuf.Empty;
import com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentRequest;
import com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentResponse;
import com.google.recaptchaenterprise.v1beta1.Assessment;
import com.google.recaptchaenterprise.v1beta1.AssessmentName;
import com.google.recaptchaenterprise.v1beta1.CreateAssessmentRequest;
import com.google.recaptchaenterprise.v1beta1.CreateKeyRequest;
import com.google.recaptchaenterprise.v1beta1.DeleteKeyRequest;
import com.google.recaptchaenterprise.v1beta1.GetKeyRequest;
import com.google.recaptchaenterprise.v1beta1.Key;
import com.google.recaptchaenterprise.v1beta1.ListKeysRequest;
import com.google.recaptchaenterprise.v1beta1.ListKeysResponse;
import com.google.recaptchaenterprise.v1beta1.ProjectName;
import com.google.recaptchaenterprise.v1beta1.UpdateKeyRequest;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.annotation.Generated;

Expand Down Expand Up @@ -372,6 +389,270 @@ public final AnnotateAssessmentResponse annotateAssessment(AnnotateAssessmentReq
return stub.annotateAssessmentCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Creates a new reCAPTCHA Enterprise key.
*
* <p>Sample code:
*
* <pre><code>
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
* ProjectName parent = ProjectName.of("[PROJECT]");
* Key key = Key.newBuilder().build();
* CreateKeyRequest request = CreateKeyRequest.newBuilder()
* .setParent(parent.toString())
* .setKey(key)
* .build();
* Key response = recaptchaEnterpriseServiceV1Beta1Client.createKey(request);
* }
* </code></pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final Key createKey(CreateKeyRequest request) {
return createKeyCallable().call(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Creates a new reCAPTCHA Enterprise key.
*
* <p>Sample code:
*
* <pre><code>
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
* ProjectName parent = ProjectName.of("[PROJECT]");
* Key key = Key.newBuilder().build();
* CreateKeyRequest request = CreateKeyRequest.newBuilder()
* .setParent(parent.toString())
* .setKey(key)
* .build();
* ApiFuture&lt;Key&gt; future = recaptchaEnterpriseServiceV1Beta1Client.createKeyCallable().futureCall(request);
* // Do something
* Key response = future.get();
* }
* </code></pre>
*/
public final UnaryCallable<CreateKeyRequest, Key> createKeyCallable() {
return stub.createKeyCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Returns the list of all keys that belong to a project.
*
* <p>Sample code:
*
* <pre><code>
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
* ProjectName parent = ProjectName.of("[PROJECT]");
* ListKeysRequest request = ListKeysRequest.newBuilder()
* .setParent(parent.toString())
* .build();
* for (Key element : recaptchaEnterpriseServiceV1Beta1Client.listKeys(request).iterateAll()) {
* // doThingsWith(element);
* }
* }
* </code></pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final ListKeysPagedResponse listKeys(ListKeysRequest request) {
return listKeysPagedCallable().call(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Returns the list of all keys that belong to a project.
*
* <p>Sample code:
*
* <pre><code>
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
* ProjectName parent = ProjectName.of("[PROJECT]");
* ListKeysRequest request = ListKeysRequest.newBuilder()
* .setParent(parent.toString())
* .build();
* ApiFuture&lt;ListKeysPagedResponse&gt; future = recaptchaEnterpriseServiceV1Beta1Client.listKeysPagedCallable().futureCall(request);
* // Do something
* for (Key element : future.get().iterateAll()) {
* // doThingsWith(element);
* }
* }
* </code></pre>
*/
public final UnaryCallable<ListKeysRequest, ListKeysPagedResponse> listKeysPagedCallable() {
return stub.listKeysPagedCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Returns the list of all keys that belong to a project.
*
* <p>Sample code:
*
* <pre><code>
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
* ProjectName parent = ProjectName.of("[PROJECT]");
* ListKeysRequest request = ListKeysRequest.newBuilder()
* .setParent(parent.toString())
* .build();
* while (true) {
* ListKeysResponse response = recaptchaEnterpriseServiceV1Beta1Client.listKeysCallable().call(request);
* for (Key element : response.getKeysList()) {
* // doThingsWith(element);
* }
* String nextPageToken = response.getNextPageToken();
* if (!Strings.isNullOrEmpty(nextPageToken)) {
* request = request.toBuilder().setPageToken(nextPageToken).build();
* } else {
* break;
* }
* }
* }
* </code></pre>
*/
public final UnaryCallable<ListKeysRequest, ListKeysResponse> listKeysCallable() {
return stub.listKeysCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Returns the specified key.
*
* <p>Sample code:
*
* <pre><code>
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
* KeyName name = KeyName.of("[PROJECT]", "[KEY]");
* GetKeyRequest request = GetKeyRequest.newBuilder()
* .setName(name.toString())
* .build();
* Key response = recaptchaEnterpriseServiceV1Beta1Client.getKey(request);
* }
* </code></pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final Key getKey(GetKeyRequest request) {
return getKeyCallable().call(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Returns the specified key.
*
* <p>Sample code:
*
* <pre><code>
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
* KeyName name = KeyName.of("[PROJECT]", "[KEY]");
* GetKeyRequest request = GetKeyRequest.newBuilder()
* .setName(name.toString())
* .build();
* ApiFuture&lt;Key&gt; future = recaptchaEnterpriseServiceV1Beta1Client.getKeyCallable().futureCall(request);
* // Do something
* Key response = future.get();
* }
* </code></pre>
*/
public final UnaryCallable<GetKeyRequest, Key> getKeyCallable() {
return stub.getKeyCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Updates the specified key.
*
* <p>Sample code:
*
* <pre><code>
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
* KeyName key = KeyName.of("[PROJECT]", "[KEY]");
* UpdateKeyRequest request = UpdateKeyRequest.newBuilder()
* .setKey(key.toString())
* .build();
* Key response = recaptchaEnterpriseServiceV1Beta1Client.updateKey(request);
* }
* </code></pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final Key updateKey(UpdateKeyRequest request) {
return updateKeyCallable().call(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Updates the specified key.
*
* <p>Sample code:
*
* <pre><code>
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
* KeyName key = KeyName.of("[PROJECT]", "[KEY]");
* UpdateKeyRequest request = UpdateKeyRequest.newBuilder()
* .setKey(key.toString())
* .build();
* ApiFuture&lt;Key&gt; future = recaptchaEnterpriseServiceV1Beta1Client.updateKeyCallable().futureCall(request);
* // Do something
* Key response = future.get();
* }
* </code></pre>
*/
public final UnaryCallable<UpdateKeyRequest, Key> updateKeyCallable() {
return stub.updateKeyCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Deletes the specified key.
*
* <p>Sample code:
*
* <pre><code>
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
* KeyName name = KeyName.of("[PROJECT]", "[KEY]");
* DeleteKeyRequest request = DeleteKeyRequest.newBuilder()
* .setName(name.toString())
* .build();
* recaptchaEnterpriseServiceV1Beta1Client.deleteKey(request);
* }
* </code></pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final void deleteKey(DeleteKeyRequest request) {
deleteKeyCallable().call(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Deletes the specified key.
*
* <p>Sample code:
*
* <pre><code>
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
* KeyName name = KeyName.of("[PROJECT]", "[KEY]");
* DeleteKeyRequest request = DeleteKeyRequest.newBuilder()
* .setName(name.toString())
* .build();
* ApiFuture&lt;Void&gt; future = recaptchaEnterpriseServiceV1Beta1Client.deleteKeyCallable().futureCall(request);
* // Do something
* future.get();
* }
* </code></pre>
*/
public final UnaryCallable<DeleteKeyRequest, Empty> deleteKeyCallable() {
return stub.deleteKeyCallable();
}

@Override
public final void close() {
stub.close();
Expand Down Expand Up @@ -401,4 +682,74 @@ public void shutdownNow() {
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
return stub.awaitTermination(duration, unit);
}

public static class ListKeysPagedResponse
extends AbstractPagedListResponse<
ListKeysRequest, ListKeysResponse, Key, ListKeysPage, ListKeysFixedSizeCollection> {

public static ApiFuture<ListKeysPagedResponse> createAsync(
PageContext<ListKeysRequest, ListKeysResponse, Key> context,
ApiFuture<ListKeysResponse> futureResponse) {
ApiFuture<ListKeysPage> futurePage =
ListKeysPage.createEmptyPage().createPageAsync(context, futureResponse);
return ApiFutures.transform(
futurePage,
new ApiFunction<ListKeysPage, ListKeysPagedResponse>() {
@Override
public ListKeysPagedResponse apply(ListKeysPage input) {
return new ListKeysPagedResponse(input);
}
},
MoreExecutors.directExecutor());
}

private ListKeysPagedResponse(ListKeysPage page) {
super(page, ListKeysFixedSizeCollection.createEmptyCollection());
}
}

public static class ListKeysPage
extends AbstractPage<ListKeysRequest, ListKeysResponse, Key, ListKeysPage> {

private ListKeysPage(
PageContext<ListKeysRequest, ListKeysResponse, Key> context, ListKeysResponse response) {
super(context, response);
}

private static ListKeysPage createEmptyPage() {
return new ListKeysPage(null, null);
}

@Override
protected ListKeysPage createPage(
PageContext<ListKeysRequest, ListKeysResponse, Key> context, ListKeysResponse response) {
return new ListKeysPage(context, response);
}

@Override
public ApiFuture<ListKeysPage> createPageAsync(
PageContext<ListKeysRequest, ListKeysResponse, Key> context,
ApiFuture<ListKeysResponse> futureResponse) {
return super.createPageAsync(context, futureResponse);
}
}

public static class ListKeysFixedSizeCollection
extends AbstractFixedSizeCollection<
ListKeysRequest, ListKeysResponse, Key, ListKeysPage, ListKeysFixedSizeCollection> {

private ListKeysFixedSizeCollection(List<ListKeysPage> pages, int collectionSize) {
super(pages, collectionSize);
}

private static ListKeysFixedSizeCollection createEmptyCollection() {
return new ListKeysFixedSizeCollection(null, 0);
}

@Override
protected ListKeysFixedSizeCollection createCollection(
List<ListKeysPage> pages, int collectionSize) {
return new ListKeysFixedSizeCollection(pages, collectionSize);
}
}
}

0 comments on commit 3bebbb2

Please sign in to comment.