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

Commit 3bebbb2

Browse files
feat: add Key support (#17)
* [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>
1 parent e84bd5d commit 3bebbb2

34 files changed

+13759
-107
lines changed

google-cloud-recaptchaenterprise/src/main/java/com/google/cloud/recaptchaenterprise/v1beta1/RecaptchaEnterpriseServiceV1Beta1Client.java

+351
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,35 @@
1515
*/
1616
package com.google.cloud.recaptchaenterprise.v1beta1;
1717

18+
import com.google.api.core.ApiFunction;
19+
import com.google.api.core.ApiFuture;
20+
import com.google.api.core.ApiFutures;
1821
import com.google.api.core.BetaApi;
1922
import com.google.api.gax.core.BackgroundResource;
23+
import com.google.api.gax.paging.AbstractFixedSizeCollection;
24+
import com.google.api.gax.paging.AbstractPage;
25+
import com.google.api.gax.paging.AbstractPagedListResponse;
26+
import com.google.api.gax.rpc.PageContext;
2027
import com.google.api.gax.rpc.UnaryCallable;
2128
import com.google.cloud.recaptchaenterprise.v1beta1.stub.RecaptchaEnterpriseServiceV1Beta1Stub;
2229
import com.google.cloud.recaptchaenterprise.v1beta1.stub.RecaptchaEnterpriseServiceV1Beta1StubSettings;
30+
import com.google.common.util.concurrent.MoreExecutors;
31+
import com.google.protobuf.Empty;
2332
import com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentRequest;
2433
import com.google.recaptchaenterprise.v1beta1.AnnotateAssessmentResponse;
2534
import com.google.recaptchaenterprise.v1beta1.Assessment;
2635
import com.google.recaptchaenterprise.v1beta1.AssessmentName;
2736
import com.google.recaptchaenterprise.v1beta1.CreateAssessmentRequest;
37+
import com.google.recaptchaenterprise.v1beta1.CreateKeyRequest;
38+
import com.google.recaptchaenterprise.v1beta1.DeleteKeyRequest;
39+
import com.google.recaptchaenterprise.v1beta1.GetKeyRequest;
40+
import com.google.recaptchaenterprise.v1beta1.Key;
41+
import com.google.recaptchaenterprise.v1beta1.ListKeysRequest;
42+
import com.google.recaptchaenterprise.v1beta1.ListKeysResponse;
2843
import com.google.recaptchaenterprise.v1beta1.ProjectName;
44+
import com.google.recaptchaenterprise.v1beta1.UpdateKeyRequest;
2945
import java.io.IOException;
46+
import java.util.List;
3047
import java.util.concurrent.TimeUnit;
3148
import javax.annotation.Generated;
3249

@@ -372,6 +389,270 @@ public final AnnotateAssessmentResponse annotateAssessment(AnnotateAssessmentReq
372389
return stub.annotateAssessmentCallable();
373390
}
374391

392+
// AUTO-GENERATED DOCUMENTATION AND METHOD
393+
/**
394+
* Creates a new reCAPTCHA Enterprise key.
395+
*
396+
* <p>Sample code:
397+
*
398+
* <pre><code>
399+
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
400+
* ProjectName parent = ProjectName.of("[PROJECT]");
401+
* Key key = Key.newBuilder().build();
402+
* CreateKeyRequest request = CreateKeyRequest.newBuilder()
403+
* .setParent(parent.toString())
404+
* .setKey(key)
405+
* .build();
406+
* Key response = recaptchaEnterpriseServiceV1Beta1Client.createKey(request);
407+
* }
408+
* </code></pre>
409+
*
410+
* @param request The request object containing all of the parameters for the API call.
411+
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
412+
*/
413+
public final Key createKey(CreateKeyRequest request) {
414+
return createKeyCallable().call(request);
415+
}
416+
417+
// AUTO-GENERATED DOCUMENTATION AND METHOD
418+
/**
419+
* Creates a new reCAPTCHA Enterprise key.
420+
*
421+
* <p>Sample code:
422+
*
423+
* <pre><code>
424+
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
425+
* ProjectName parent = ProjectName.of("[PROJECT]");
426+
* Key key = Key.newBuilder().build();
427+
* CreateKeyRequest request = CreateKeyRequest.newBuilder()
428+
* .setParent(parent.toString())
429+
* .setKey(key)
430+
* .build();
431+
* ApiFuture&lt;Key&gt; future = recaptchaEnterpriseServiceV1Beta1Client.createKeyCallable().futureCall(request);
432+
* // Do something
433+
* Key response = future.get();
434+
* }
435+
* </code></pre>
436+
*/
437+
public final UnaryCallable<CreateKeyRequest, Key> createKeyCallable() {
438+
return stub.createKeyCallable();
439+
}
440+
441+
// AUTO-GENERATED DOCUMENTATION AND METHOD
442+
/**
443+
* Returns the list of all keys that belong to a project.
444+
*
445+
* <p>Sample code:
446+
*
447+
* <pre><code>
448+
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
449+
* ProjectName parent = ProjectName.of("[PROJECT]");
450+
* ListKeysRequest request = ListKeysRequest.newBuilder()
451+
* .setParent(parent.toString())
452+
* .build();
453+
* for (Key element : recaptchaEnterpriseServiceV1Beta1Client.listKeys(request).iterateAll()) {
454+
* // doThingsWith(element);
455+
* }
456+
* }
457+
* </code></pre>
458+
*
459+
* @param request The request object containing all of the parameters for the API call.
460+
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
461+
*/
462+
public final ListKeysPagedResponse listKeys(ListKeysRequest request) {
463+
return listKeysPagedCallable().call(request);
464+
}
465+
466+
// AUTO-GENERATED DOCUMENTATION AND METHOD
467+
/**
468+
* Returns the list of all keys that belong to a project.
469+
*
470+
* <p>Sample code:
471+
*
472+
* <pre><code>
473+
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
474+
* ProjectName parent = ProjectName.of("[PROJECT]");
475+
* ListKeysRequest request = ListKeysRequest.newBuilder()
476+
* .setParent(parent.toString())
477+
* .build();
478+
* ApiFuture&lt;ListKeysPagedResponse&gt; future = recaptchaEnterpriseServiceV1Beta1Client.listKeysPagedCallable().futureCall(request);
479+
* // Do something
480+
* for (Key element : future.get().iterateAll()) {
481+
* // doThingsWith(element);
482+
* }
483+
* }
484+
* </code></pre>
485+
*/
486+
public final UnaryCallable<ListKeysRequest, ListKeysPagedResponse> listKeysPagedCallable() {
487+
return stub.listKeysPagedCallable();
488+
}
489+
490+
// AUTO-GENERATED DOCUMENTATION AND METHOD
491+
/**
492+
* Returns the list of all keys that belong to a project.
493+
*
494+
* <p>Sample code:
495+
*
496+
* <pre><code>
497+
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
498+
* ProjectName parent = ProjectName.of("[PROJECT]");
499+
* ListKeysRequest request = ListKeysRequest.newBuilder()
500+
* .setParent(parent.toString())
501+
* .build();
502+
* while (true) {
503+
* ListKeysResponse response = recaptchaEnterpriseServiceV1Beta1Client.listKeysCallable().call(request);
504+
* for (Key element : response.getKeysList()) {
505+
* // doThingsWith(element);
506+
* }
507+
* String nextPageToken = response.getNextPageToken();
508+
* if (!Strings.isNullOrEmpty(nextPageToken)) {
509+
* request = request.toBuilder().setPageToken(nextPageToken).build();
510+
* } else {
511+
* break;
512+
* }
513+
* }
514+
* }
515+
* </code></pre>
516+
*/
517+
public final UnaryCallable<ListKeysRequest, ListKeysResponse> listKeysCallable() {
518+
return stub.listKeysCallable();
519+
}
520+
521+
// AUTO-GENERATED DOCUMENTATION AND METHOD
522+
/**
523+
* Returns the specified key.
524+
*
525+
* <p>Sample code:
526+
*
527+
* <pre><code>
528+
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
529+
* KeyName name = KeyName.of("[PROJECT]", "[KEY]");
530+
* GetKeyRequest request = GetKeyRequest.newBuilder()
531+
* .setName(name.toString())
532+
* .build();
533+
* Key response = recaptchaEnterpriseServiceV1Beta1Client.getKey(request);
534+
* }
535+
* </code></pre>
536+
*
537+
* @param request The request object containing all of the parameters for the API call.
538+
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
539+
*/
540+
public final Key getKey(GetKeyRequest request) {
541+
return getKeyCallable().call(request);
542+
}
543+
544+
// AUTO-GENERATED DOCUMENTATION AND METHOD
545+
/**
546+
* Returns the specified key.
547+
*
548+
* <p>Sample code:
549+
*
550+
* <pre><code>
551+
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
552+
* KeyName name = KeyName.of("[PROJECT]", "[KEY]");
553+
* GetKeyRequest request = GetKeyRequest.newBuilder()
554+
* .setName(name.toString())
555+
* .build();
556+
* ApiFuture&lt;Key&gt; future = recaptchaEnterpriseServiceV1Beta1Client.getKeyCallable().futureCall(request);
557+
* // Do something
558+
* Key response = future.get();
559+
* }
560+
* </code></pre>
561+
*/
562+
public final UnaryCallable<GetKeyRequest, Key> getKeyCallable() {
563+
return stub.getKeyCallable();
564+
}
565+
566+
// AUTO-GENERATED DOCUMENTATION AND METHOD
567+
/**
568+
* Updates the specified key.
569+
*
570+
* <p>Sample code:
571+
*
572+
* <pre><code>
573+
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
574+
* KeyName key = KeyName.of("[PROJECT]", "[KEY]");
575+
* UpdateKeyRequest request = UpdateKeyRequest.newBuilder()
576+
* .setKey(key.toString())
577+
* .build();
578+
* Key response = recaptchaEnterpriseServiceV1Beta1Client.updateKey(request);
579+
* }
580+
* </code></pre>
581+
*
582+
* @param request The request object containing all of the parameters for the API call.
583+
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
584+
*/
585+
public final Key updateKey(UpdateKeyRequest request) {
586+
return updateKeyCallable().call(request);
587+
}
588+
589+
// AUTO-GENERATED DOCUMENTATION AND METHOD
590+
/**
591+
* Updates the specified key.
592+
*
593+
* <p>Sample code:
594+
*
595+
* <pre><code>
596+
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
597+
* KeyName key = KeyName.of("[PROJECT]", "[KEY]");
598+
* UpdateKeyRequest request = UpdateKeyRequest.newBuilder()
599+
* .setKey(key.toString())
600+
* .build();
601+
* ApiFuture&lt;Key&gt; future = recaptchaEnterpriseServiceV1Beta1Client.updateKeyCallable().futureCall(request);
602+
* // Do something
603+
* Key response = future.get();
604+
* }
605+
* </code></pre>
606+
*/
607+
public final UnaryCallable<UpdateKeyRequest, Key> updateKeyCallable() {
608+
return stub.updateKeyCallable();
609+
}
610+
611+
// AUTO-GENERATED DOCUMENTATION AND METHOD
612+
/**
613+
* Deletes the specified key.
614+
*
615+
* <p>Sample code:
616+
*
617+
* <pre><code>
618+
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
619+
* KeyName name = KeyName.of("[PROJECT]", "[KEY]");
620+
* DeleteKeyRequest request = DeleteKeyRequest.newBuilder()
621+
* .setName(name.toString())
622+
* .build();
623+
* recaptchaEnterpriseServiceV1Beta1Client.deleteKey(request);
624+
* }
625+
* </code></pre>
626+
*
627+
* @param request The request object containing all of the parameters for the API call.
628+
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
629+
*/
630+
public final void deleteKey(DeleteKeyRequest request) {
631+
deleteKeyCallable().call(request);
632+
}
633+
634+
// AUTO-GENERATED DOCUMENTATION AND METHOD
635+
/**
636+
* Deletes the specified key.
637+
*
638+
* <p>Sample code:
639+
*
640+
* <pre><code>
641+
* try (RecaptchaEnterpriseServiceV1Beta1Client recaptchaEnterpriseServiceV1Beta1Client = RecaptchaEnterpriseServiceV1Beta1Client.create()) {
642+
* KeyName name = KeyName.of("[PROJECT]", "[KEY]");
643+
* DeleteKeyRequest request = DeleteKeyRequest.newBuilder()
644+
* .setName(name.toString())
645+
* .build();
646+
* ApiFuture&lt;Void&gt; future = recaptchaEnterpriseServiceV1Beta1Client.deleteKeyCallable().futureCall(request);
647+
* // Do something
648+
* future.get();
649+
* }
650+
* </code></pre>
651+
*/
652+
public final UnaryCallable<DeleteKeyRequest, Empty> deleteKeyCallable() {
653+
return stub.deleteKeyCallable();
654+
}
655+
375656
@Override
376657
public final void close() {
377658
stub.close();
@@ -401,4 +682,74 @@ public void shutdownNow() {
401682
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
402683
return stub.awaitTermination(duration, unit);
403684
}
685+
686+
public static class ListKeysPagedResponse
687+
extends AbstractPagedListResponse<
688+
ListKeysRequest, ListKeysResponse, Key, ListKeysPage, ListKeysFixedSizeCollection> {
689+
690+
public static ApiFuture<ListKeysPagedResponse> createAsync(
691+
PageContext<ListKeysRequest, ListKeysResponse, Key> context,
692+
ApiFuture<ListKeysResponse> futureResponse) {
693+
ApiFuture<ListKeysPage> futurePage =
694+
ListKeysPage.createEmptyPage().createPageAsync(context, futureResponse);
695+
return ApiFutures.transform(
696+
futurePage,
697+
new ApiFunction<ListKeysPage, ListKeysPagedResponse>() {
698+
@Override
699+
public ListKeysPagedResponse apply(ListKeysPage input) {
700+
return new ListKeysPagedResponse(input);
701+
}
702+
},
703+
MoreExecutors.directExecutor());
704+
}
705+
706+
private ListKeysPagedResponse(ListKeysPage page) {
707+
super(page, ListKeysFixedSizeCollection.createEmptyCollection());
708+
}
709+
}
710+
711+
public static class ListKeysPage
712+
extends AbstractPage<ListKeysRequest, ListKeysResponse, Key, ListKeysPage> {
713+
714+
private ListKeysPage(
715+
PageContext<ListKeysRequest, ListKeysResponse, Key> context, ListKeysResponse response) {
716+
super(context, response);
717+
}
718+
719+
private static ListKeysPage createEmptyPage() {
720+
return new ListKeysPage(null, null);
721+
}
722+
723+
@Override
724+
protected ListKeysPage createPage(
725+
PageContext<ListKeysRequest, ListKeysResponse, Key> context, ListKeysResponse response) {
726+
return new ListKeysPage(context, response);
727+
}
728+
729+
@Override
730+
public ApiFuture<ListKeysPage> createPageAsync(
731+
PageContext<ListKeysRequest, ListKeysResponse, Key> context,
732+
ApiFuture<ListKeysResponse> futureResponse) {
733+
return super.createPageAsync(context, futureResponse);
734+
}
735+
}
736+
737+
public static class ListKeysFixedSizeCollection
738+
extends AbstractFixedSizeCollection<
739+
ListKeysRequest, ListKeysResponse, Key, ListKeysPage, ListKeysFixedSizeCollection> {
740+
741+
private ListKeysFixedSizeCollection(List<ListKeysPage> pages, int collectionSize) {
742+
super(pages, collectionSize);
743+
}
744+
745+
private static ListKeysFixedSizeCollection createEmptyCollection() {
746+
return new ListKeysFixedSizeCollection(null, 0);
747+
}
748+
749+
@Override
750+
protected ListKeysFixedSizeCollection createCollection(
751+
List<ListKeysPage> pages, int collectionSize) {
752+
return new ListKeysFixedSizeCollection(pages, collectionSize);
753+
}
754+
}
404755
}

0 commit comments

Comments
 (0)