1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.cloud.dialogflow.cx.v3beta1; 18 19 import com.google.api.core.ApiFuture; 20 import com.google.api.core.ApiFutures; 21 import com.google.api.core.BetaApi; 22 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; 27 import com.google.api.gax.rpc.UnaryCallable; 28 import com.google.cloud.dialogflow.cx.v3beta1.stub.WebhooksStub; 29 import com.google.cloud.dialogflow.cx.v3beta1.stub.WebhooksStubSettings; 30 import com.google.cloud.location.GetLocationRequest; 31 import com.google.cloud.location.ListLocationsRequest; 32 import com.google.cloud.location.ListLocationsResponse; 33 import com.google.cloud.location.Location; 34 import com.google.common.util.concurrent.MoreExecutors; 35 import com.google.protobuf.Empty; 36 import com.google.protobuf.FieldMask; 37 import java.io.IOException; 38 import java.util.List; 39 import java.util.concurrent.TimeUnit; 40 import javax.annotation.Generated; 41 42 // AUTO-GENERATED DOCUMENTATION AND CLASS. 43 /** 44 * Service Description: Service for managing [Webhooks][google.cloud.dialogflow.cx.v3beta1.Webhook]. 45 * 46 * <p>This class provides the ability to make remote calls to the backing service through method 47 * calls that map to API methods. Sample code to get started: 48 * 49 * <pre>{@code 50 * // This snippet has been automatically generated and should be regarded as a code template only. 51 * // It will require modifications to work: 52 * // - It may require correct/in-range values for request initialization. 53 * // - It may require specifying regional endpoints when creating the service client as shown in 54 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 55 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 56 * WebhookName name = WebhookName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[WEBHOOK]"); 57 * Webhook response = webhooksClient.getWebhook(name); 58 * } 59 * }</pre> 60 * 61 * <p>Note: close() needs to be called on the WebhooksClient object to clean up resources such as 62 * threads. In the example above, try-with-resources is used, which automatically calls close(). 63 * 64 * <p>The surface of this class includes several types of Java methods for each of the API's 65 * methods: 66 * 67 * <ol> 68 * <li>A "flattened" method. With this type of method, the fields of the request type have been 69 * converted into function parameters. It may be the case that not all fields are available as 70 * parameters, and not every API method will have a flattened method entry point. 71 * <li>A "request object" method. This type of method only takes one parameter, a request object, 72 * which must be constructed before the call. Not every API method will have a request object 73 * method. 74 * <li>A "callable" method. This type of method takes no parameters and returns an immutable API 75 * callable object, which can be used to initiate calls to the service. 76 * </ol> 77 * 78 * <p>See the individual methods for example code. 79 * 80 * <p>Many parameters require resource names to be formatted in a particular way. To assist with 81 * these names, this class includes a format method for each type of name, and additionally a parse 82 * method to extract the individual identifiers contained within names that are returned. 83 * 84 * <p>This class can be customized by passing in a custom instance of WebhooksSettings to create(). 85 * For example: 86 * 87 * <p>To customize credentials: 88 * 89 * <pre>{@code 90 * // This snippet has been automatically generated and should be regarded as a code template only. 91 * // It will require modifications to work: 92 * // - It may require correct/in-range values for request initialization. 93 * // - It may require specifying regional endpoints when creating the service client as shown in 94 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 95 * WebhooksSettings webhooksSettings = 96 * WebhooksSettings.newBuilder() 97 * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) 98 * .build(); 99 * WebhooksClient webhooksClient = WebhooksClient.create(webhooksSettings); 100 * }</pre> 101 * 102 * <p>To customize the endpoint: 103 * 104 * <pre>{@code 105 * // This snippet has been automatically generated and should be regarded as a code template only. 106 * // It will require modifications to work: 107 * // - It may require correct/in-range values for request initialization. 108 * // - It may require specifying regional endpoints when creating the service client as shown in 109 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 110 * WebhooksSettings webhooksSettings = 111 * WebhooksSettings.newBuilder().setEndpoint(myEndpoint).build(); 112 * WebhooksClient webhooksClient = WebhooksClient.create(webhooksSettings); 113 * }</pre> 114 * 115 * <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over 116 * the wire: 117 * 118 * <pre>{@code 119 * // This snippet has been automatically generated and should be regarded as a code template only. 120 * // It will require modifications to work: 121 * // - It may require correct/in-range values for request initialization. 122 * // - It may require specifying regional endpoints when creating the service client as shown in 123 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 124 * WebhooksSettings webhooksSettings = WebhooksSettings.newHttpJsonBuilder().build(); 125 * WebhooksClient webhooksClient = WebhooksClient.create(webhooksSettings); 126 * }</pre> 127 * 128 * <p>Please refer to the GitHub repository's samples for more quickstart code snippets. 129 */ 130 @BetaApi 131 @Generated("by gapic-generator-java") 132 public class WebhooksClient implements BackgroundResource { 133 private final WebhooksSettings settings; 134 private final WebhooksStub stub; 135 136 /** Constructs an instance of WebhooksClient with default settings. */ create()137 public static final WebhooksClient create() throws IOException { 138 return create(WebhooksSettings.newBuilder().build()); 139 } 140 141 /** 142 * Constructs an instance of WebhooksClient, using the given settings. The channels are created 143 * based on the settings passed in, or defaults for any settings that are not set. 144 */ create(WebhooksSettings settings)145 public static final WebhooksClient create(WebhooksSettings settings) throws IOException { 146 return new WebhooksClient(settings); 147 } 148 149 /** 150 * Constructs an instance of WebhooksClient, using the given stub for making calls. This is for 151 * advanced usage - prefer using create(WebhooksSettings). 152 */ create(WebhooksStub stub)153 public static final WebhooksClient create(WebhooksStub stub) { 154 return new WebhooksClient(stub); 155 } 156 157 /** 158 * Constructs an instance of WebhooksClient, using the given settings. This is protected so that 159 * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. 160 */ WebhooksClient(WebhooksSettings settings)161 protected WebhooksClient(WebhooksSettings settings) throws IOException { 162 this.settings = settings; 163 this.stub = ((WebhooksStubSettings) settings.getStubSettings()).createStub(); 164 } 165 WebhooksClient(WebhooksStub stub)166 protected WebhooksClient(WebhooksStub stub) { 167 this.settings = null; 168 this.stub = stub; 169 } 170 getSettings()171 public final WebhooksSettings getSettings() { 172 return settings; 173 } 174 getStub()175 public WebhooksStub getStub() { 176 return stub; 177 } 178 179 // AUTO-GENERATED DOCUMENTATION AND METHOD. 180 /** 181 * Returns the list of all webhooks in the specified agent. 182 * 183 * <p>Sample code: 184 * 185 * <pre>{@code 186 * // This snippet has been automatically generated and should be regarded as a code template only. 187 * // It will require modifications to work: 188 * // - It may require correct/in-range values for request initialization. 189 * // - It may require specifying regional endpoints when creating the service client as shown in 190 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 191 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 192 * AgentName parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]"); 193 * for (Webhook element : webhooksClient.listWebhooks(parent).iterateAll()) { 194 * // doThingsWith(element); 195 * } 196 * } 197 * }</pre> 198 * 199 * @param parent Required. The agent to list all webhooks for. Format: `projects/<Project 200 * ID>/locations/<Location ID>/agents/<Agent ID>`. 201 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 202 */ listWebhooks(AgentName parent)203 public final ListWebhooksPagedResponse listWebhooks(AgentName parent) { 204 ListWebhooksRequest request = 205 ListWebhooksRequest.newBuilder() 206 .setParent(parent == null ? null : parent.toString()) 207 .build(); 208 return listWebhooks(request); 209 } 210 211 // AUTO-GENERATED DOCUMENTATION AND METHOD. 212 /** 213 * Returns the list of all webhooks in the specified agent. 214 * 215 * <p>Sample code: 216 * 217 * <pre>{@code 218 * // This snippet has been automatically generated and should be regarded as a code template only. 219 * // It will require modifications to work: 220 * // - It may require correct/in-range values for request initialization. 221 * // - It may require specifying regional endpoints when creating the service client as shown in 222 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 223 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 224 * String parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]").toString(); 225 * for (Webhook element : webhooksClient.listWebhooks(parent).iterateAll()) { 226 * // doThingsWith(element); 227 * } 228 * } 229 * }</pre> 230 * 231 * @param parent Required. The agent to list all webhooks for. Format: `projects/<Project 232 * ID>/locations/<Location ID>/agents/<Agent ID>`. 233 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 234 */ listWebhooks(String parent)235 public final ListWebhooksPagedResponse listWebhooks(String parent) { 236 ListWebhooksRequest request = ListWebhooksRequest.newBuilder().setParent(parent).build(); 237 return listWebhooks(request); 238 } 239 240 // AUTO-GENERATED DOCUMENTATION AND METHOD. 241 /** 242 * Returns the list of all webhooks in the specified agent. 243 * 244 * <p>Sample code: 245 * 246 * <pre>{@code 247 * // This snippet has been automatically generated and should be regarded as a code template only. 248 * // It will require modifications to work: 249 * // - It may require correct/in-range values for request initialization. 250 * // - It may require specifying regional endpoints when creating the service client as shown in 251 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 252 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 253 * ListWebhooksRequest request = 254 * ListWebhooksRequest.newBuilder() 255 * .setParent(AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]").toString()) 256 * .setPageSize(883849137) 257 * .setPageToken("pageToken873572522") 258 * .build(); 259 * for (Webhook element : webhooksClient.listWebhooks(request).iterateAll()) { 260 * // doThingsWith(element); 261 * } 262 * } 263 * }</pre> 264 * 265 * @param request The request object containing all of the parameters for the API call. 266 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 267 */ listWebhooks(ListWebhooksRequest request)268 public final ListWebhooksPagedResponse listWebhooks(ListWebhooksRequest request) { 269 return listWebhooksPagedCallable().call(request); 270 } 271 272 // AUTO-GENERATED DOCUMENTATION AND METHOD. 273 /** 274 * Returns the list of all webhooks in the specified agent. 275 * 276 * <p>Sample code: 277 * 278 * <pre>{@code 279 * // This snippet has been automatically generated and should be regarded as a code template only. 280 * // It will require modifications to work: 281 * // - It may require correct/in-range values for request initialization. 282 * // - It may require specifying regional endpoints when creating the service client as shown in 283 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 284 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 285 * ListWebhooksRequest request = 286 * ListWebhooksRequest.newBuilder() 287 * .setParent(AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]").toString()) 288 * .setPageSize(883849137) 289 * .setPageToken("pageToken873572522") 290 * .build(); 291 * ApiFuture<Webhook> future = webhooksClient.listWebhooksPagedCallable().futureCall(request); 292 * // Do something. 293 * for (Webhook element : future.get().iterateAll()) { 294 * // doThingsWith(element); 295 * } 296 * } 297 * }</pre> 298 */ 299 public final UnaryCallable<ListWebhooksRequest, ListWebhooksPagedResponse> listWebhooksPagedCallable()300 listWebhooksPagedCallable() { 301 return stub.listWebhooksPagedCallable(); 302 } 303 304 // AUTO-GENERATED DOCUMENTATION AND METHOD. 305 /** 306 * Returns the list of all webhooks in the specified agent. 307 * 308 * <p>Sample code: 309 * 310 * <pre>{@code 311 * // This snippet has been automatically generated and should be regarded as a code template only. 312 * // It will require modifications to work: 313 * // - It may require correct/in-range values for request initialization. 314 * // - It may require specifying regional endpoints when creating the service client as shown in 315 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 316 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 317 * ListWebhooksRequest request = 318 * ListWebhooksRequest.newBuilder() 319 * .setParent(AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]").toString()) 320 * .setPageSize(883849137) 321 * .setPageToken("pageToken873572522") 322 * .build(); 323 * while (true) { 324 * ListWebhooksResponse response = webhooksClient.listWebhooksCallable().call(request); 325 * for (Webhook element : response.getWebhooksList()) { 326 * // doThingsWith(element); 327 * } 328 * String nextPageToken = response.getNextPageToken(); 329 * if (!Strings.isNullOrEmpty(nextPageToken)) { 330 * request = request.toBuilder().setPageToken(nextPageToken).build(); 331 * } else { 332 * break; 333 * } 334 * } 335 * } 336 * }</pre> 337 */ listWebhooksCallable()338 public final UnaryCallable<ListWebhooksRequest, ListWebhooksResponse> listWebhooksCallable() { 339 return stub.listWebhooksCallable(); 340 } 341 342 // AUTO-GENERATED DOCUMENTATION AND METHOD. 343 /** 344 * Retrieves the specified webhook. 345 * 346 * <p>Sample code: 347 * 348 * <pre>{@code 349 * // This snippet has been automatically generated and should be regarded as a code template only. 350 * // It will require modifications to work: 351 * // - It may require correct/in-range values for request initialization. 352 * // - It may require specifying regional endpoints when creating the service client as shown in 353 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 354 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 355 * WebhookName name = WebhookName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[WEBHOOK]"); 356 * Webhook response = webhooksClient.getWebhook(name); 357 * } 358 * }</pre> 359 * 360 * @param name Required. The name of the webhook. Format: `projects/<Project 361 * ID>/locations/<Location ID>/agents/<Agent ID>/webhooks/<Webhook ID>`. 362 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 363 */ getWebhook(WebhookName name)364 public final Webhook getWebhook(WebhookName name) { 365 GetWebhookRequest request = 366 GetWebhookRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 367 return getWebhook(request); 368 } 369 370 // AUTO-GENERATED DOCUMENTATION AND METHOD. 371 /** 372 * Retrieves the specified webhook. 373 * 374 * <p>Sample code: 375 * 376 * <pre>{@code 377 * // This snippet has been automatically generated and should be regarded as a code template only. 378 * // It will require modifications to work: 379 * // - It may require correct/in-range values for request initialization. 380 * // - It may require specifying regional endpoints when creating the service client as shown in 381 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 382 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 383 * String name = WebhookName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[WEBHOOK]").toString(); 384 * Webhook response = webhooksClient.getWebhook(name); 385 * } 386 * }</pre> 387 * 388 * @param name Required. The name of the webhook. Format: `projects/<Project 389 * ID>/locations/<Location ID>/agents/<Agent ID>/webhooks/<Webhook ID>`. 390 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 391 */ getWebhook(String name)392 public final Webhook getWebhook(String name) { 393 GetWebhookRequest request = GetWebhookRequest.newBuilder().setName(name).build(); 394 return getWebhook(request); 395 } 396 397 // AUTO-GENERATED DOCUMENTATION AND METHOD. 398 /** 399 * Retrieves the specified webhook. 400 * 401 * <p>Sample code: 402 * 403 * <pre>{@code 404 * // This snippet has been automatically generated and should be regarded as a code template only. 405 * // It will require modifications to work: 406 * // - It may require correct/in-range values for request initialization. 407 * // - It may require specifying regional endpoints when creating the service client as shown in 408 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 409 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 410 * GetWebhookRequest request = 411 * GetWebhookRequest.newBuilder() 412 * .setName(WebhookName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[WEBHOOK]").toString()) 413 * .build(); 414 * Webhook response = webhooksClient.getWebhook(request); 415 * } 416 * }</pre> 417 * 418 * @param request The request object containing all of the parameters for the API call. 419 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 420 */ getWebhook(GetWebhookRequest request)421 public final Webhook getWebhook(GetWebhookRequest request) { 422 return getWebhookCallable().call(request); 423 } 424 425 // AUTO-GENERATED DOCUMENTATION AND METHOD. 426 /** 427 * Retrieves the specified webhook. 428 * 429 * <p>Sample code: 430 * 431 * <pre>{@code 432 * // This snippet has been automatically generated and should be regarded as a code template only. 433 * // It will require modifications to work: 434 * // - It may require correct/in-range values for request initialization. 435 * // - It may require specifying regional endpoints when creating the service client as shown in 436 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 437 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 438 * GetWebhookRequest request = 439 * GetWebhookRequest.newBuilder() 440 * .setName(WebhookName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[WEBHOOK]").toString()) 441 * .build(); 442 * ApiFuture<Webhook> future = webhooksClient.getWebhookCallable().futureCall(request); 443 * // Do something. 444 * Webhook response = future.get(); 445 * } 446 * }</pre> 447 */ getWebhookCallable()448 public final UnaryCallable<GetWebhookRequest, Webhook> getWebhookCallable() { 449 return stub.getWebhookCallable(); 450 } 451 452 // AUTO-GENERATED DOCUMENTATION AND METHOD. 453 /** 454 * Creates a webhook in the specified agent. 455 * 456 * <p>Sample code: 457 * 458 * <pre>{@code 459 * // This snippet has been automatically generated and should be regarded as a code template only. 460 * // It will require modifications to work: 461 * // - It may require correct/in-range values for request initialization. 462 * // - It may require specifying regional endpoints when creating the service client as shown in 463 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 464 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 465 * AgentName parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]"); 466 * Webhook webhook = Webhook.newBuilder().build(); 467 * Webhook response = webhooksClient.createWebhook(parent, webhook); 468 * } 469 * }</pre> 470 * 471 * @param parent Required. The agent to create a webhook for. Format: `projects/<Project 472 * ID>/locations/<Location ID>/agents/<Agent ID>`. 473 * @param webhook Required. The webhook to create. 474 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 475 */ createWebhook(AgentName parent, Webhook webhook)476 public final Webhook createWebhook(AgentName parent, Webhook webhook) { 477 CreateWebhookRequest request = 478 CreateWebhookRequest.newBuilder() 479 .setParent(parent == null ? null : parent.toString()) 480 .setWebhook(webhook) 481 .build(); 482 return createWebhook(request); 483 } 484 485 // AUTO-GENERATED DOCUMENTATION AND METHOD. 486 /** 487 * Creates a webhook in the specified agent. 488 * 489 * <p>Sample code: 490 * 491 * <pre>{@code 492 * // This snippet has been automatically generated and should be regarded as a code template only. 493 * // It will require modifications to work: 494 * // - It may require correct/in-range values for request initialization. 495 * // - It may require specifying regional endpoints when creating the service client as shown in 496 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 497 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 498 * String parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]").toString(); 499 * Webhook webhook = Webhook.newBuilder().build(); 500 * Webhook response = webhooksClient.createWebhook(parent, webhook); 501 * } 502 * }</pre> 503 * 504 * @param parent Required. The agent to create a webhook for. Format: `projects/<Project 505 * ID>/locations/<Location ID>/agents/<Agent ID>`. 506 * @param webhook Required. The webhook to create. 507 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 508 */ createWebhook(String parent, Webhook webhook)509 public final Webhook createWebhook(String parent, Webhook webhook) { 510 CreateWebhookRequest request = 511 CreateWebhookRequest.newBuilder().setParent(parent).setWebhook(webhook).build(); 512 return createWebhook(request); 513 } 514 515 // AUTO-GENERATED DOCUMENTATION AND METHOD. 516 /** 517 * Creates a webhook in the specified agent. 518 * 519 * <p>Sample code: 520 * 521 * <pre>{@code 522 * // This snippet has been automatically generated and should be regarded as a code template only. 523 * // It will require modifications to work: 524 * // - It may require correct/in-range values for request initialization. 525 * // - It may require specifying regional endpoints when creating the service client as shown in 526 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 527 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 528 * CreateWebhookRequest request = 529 * CreateWebhookRequest.newBuilder() 530 * .setParent(AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]").toString()) 531 * .setWebhook(Webhook.newBuilder().build()) 532 * .build(); 533 * Webhook response = webhooksClient.createWebhook(request); 534 * } 535 * }</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 */ createWebhook(CreateWebhookRequest request)540 public final Webhook createWebhook(CreateWebhookRequest request) { 541 return createWebhookCallable().call(request); 542 } 543 544 // AUTO-GENERATED DOCUMENTATION AND METHOD. 545 /** 546 * Creates a webhook in the specified agent. 547 * 548 * <p>Sample code: 549 * 550 * <pre>{@code 551 * // This snippet has been automatically generated and should be regarded as a code template only. 552 * // It will require modifications to work: 553 * // - It may require correct/in-range values for request initialization. 554 * // - It may require specifying regional endpoints when creating the service client as shown in 555 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 556 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 557 * CreateWebhookRequest request = 558 * CreateWebhookRequest.newBuilder() 559 * .setParent(AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]").toString()) 560 * .setWebhook(Webhook.newBuilder().build()) 561 * .build(); 562 * ApiFuture<Webhook> future = webhooksClient.createWebhookCallable().futureCall(request); 563 * // Do something. 564 * Webhook response = future.get(); 565 * } 566 * }</pre> 567 */ createWebhookCallable()568 public final UnaryCallable<CreateWebhookRequest, Webhook> createWebhookCallable() { 569 return stub.createWebhookCallable(); 570 } 571 572 // AUTO-GENERATED DOCUMENTATION AND METHOD. 573 /** 574 * Updates the specified webhook. 575 * 576 * <p>Sample code: 577 * 578 * <pre>{@code 579 * // This snippet has been automatically generated and should be regarded as a code template only. 580 * // It will require modifications to work: 581 * // - It may require correct/in-range values for request initialization. 582 * // - It may require specifying regional endpoints when creating the service client as shown in 583 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 584 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 585 * Webhook webhook = Webhook.newBuilder().build(); 586 * FieldMask updateMask = FieldMask.newBuilder().build(); 587 * Webhook response = webhooksClient.updateWebhook(webhook, updateMask); 588 * } 589 * }</pre> 590 * 591 * @param webhook Required. The webhook to update. 592 * @param updateMask The mask to control which fields get updated. If the mask is not present, all 593 * fields will be updated. 594 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 595 */ updateWebhook(Webhook webhook, FieldMask updateMask)596 public final Webhook updateWebhook(Webhook webhook, FieldMask updateMask) { 597 UpdateWebhookRequest request = 598 UpdateWebhookRequest.newBuilder().setWebhook(webhook).setUpdateMask(updateMask).build(); 599 return updateWebhook(request); 600 } 601 602 // AUTO-GENERATED DOCUMENTATION AND METHOD. 603 /** 604 * Updates the specified webhook. 605 * 606 * <p>Sample code: 607 * 608 * <pre>{@code 609 * // This snippet has been automatically generated and should be regarded as a code template only. 610 * // It will require modifications to work: 611 * // - It may require correct/in-range values for request initialization. 612 * // - It may require specifying regional endpoints when creating the service client as shown in 613 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 614 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 615 * UpdateWebhookRequest request = 616 * UpdateWebhookRequest.newBuilder() 617 * .setWebhook(Webhook.newBuilder().build()) 618 * .setUpdateMask(FieldMask.newBuilder().build()) 619 * .build(); 620 * Webhook response = webhooksClient.updateWebhook(request); 621 * } 622 * }</pre> 623 * 624 * @param request The request object containing all of the parameters for the API call. 625 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 626 */ updateWebhook(UpdateWebhookRequest request)627 public final Webhook updateWebhook(UpdateWebhookRequest request) { 628 return updateWebhookCallable().call(request); 629 } 630 631 // AUTO-GENERATED DOCUMENTATION AND METHOD. 632 /** 633 * Updates the specified webhook. 634 * 635 * <p>Sample code: 636 * 637 * <pre>{@code 638 * // This snippet has been automatically generated and should be regarded as a code template only. 639 * // It will require modifications to work: 640 * // - It may require correct/in-range values for request initialization. 641 * // - It may require specifying regional endpoints when creating the service client as shown in 642 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 643 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 644 * UpdateWebhookRequest request = 645 * UpdateWebhookRequest.newBuilder() 646 * .setWebhook(Webhook.newBuilder().build()) 647 * .setUpdateMask(FieldMask.newBuilder().build()) 648 * .build(); 649 * ApiFuture<Webhook> future = webhooksClient.updateWebhookCallable().futureCall(request); 650 * // Do something. 651 * Webhook response = future.get(); 652 * } 653 * }</pre> 654 */ updateWebhookCallable()655 public final UnaryCallable<UpdateWebhookRequest, Webhook> updateWebhookCallable() { 656 return stub.updateWebhookCallable(); 657 } 658 659 // AUTO-GENERATED DOCUMENTATION AND METHOD. 660 /** 661 * Deletes the specified webhook. 662 * 663 * <p>Sample code: 664 * 665 * <pre>{@code 666 * // This snippet has been automatically generated and should be regarded as a code template only. 667 * // It will require modifications to work: 668 * // - It may require correct/in-range values for request initialization. 669 * // - It may require specifying regional endpoints when creating the service client as shown in 670 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 671 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 672 * WebhookName name = WebhookName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[WEBHOOK]"); 673 * webhooksClient.deleteWebhook(name); 674 * } 675 * }</pre> 676 * 677 * @param name Required. The name of the webhook to delete. Format: `projects/<Project 678 * ID>/locations/<Location ID>/agents/<Agent ID>/webhooks/<Webhook ID>`. 679 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 680 */ deleteWebhook(WebhookName name)681 public final void deleteWebhook(WebhookName name) { 682 DeleteWebhookRequest request = 683 DeleteWebhookRequest.newBuilder().setName(name == null ? null : name.toString()).build(); 684 deleteWebhook(request); 685 } 686 687 // AUTO-GENERATED DOCUMENTATION AND METHOD. 688 /** 689 * Deletes the specified webhook. 690 * 691 * <p>Sample code: 692 * 693 * <pre>{@code 694 * // This snippet has been automatically generated and should be regarded as a code template only. 695 * // It will require modifications to work: 696 * // - It may require correct/in-range values for request initialization. 697 * // - It may require specifying regional endpoints when creating the service client as shown in 698 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 699 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 700 * String name = WebhookName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[WEBHOOK]").toString(); 701 * webhooksClient.deleteWebhook(name); 702 * } 703 * }</pre> 704 * 705 * @param name Required. The name of the webhook to delete. Format: `projects/<Project 706 * ID>/locations/<Location ID>/agents/<Agent ID>/webhooks/<Webhook ID>`. 707 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 708 */ deleteWebhook(String name)709 public final void deleteWebhook(String name) { 710 DeleteWebhookRequest request = DeleteWebhookRequest.newBuilder().setName(name).build(); 711 deleteWebhook(request); 712 } 713 714 // AUTO-GENERATED DOCUMENTATION AND METHOD. 715 /** 716 * Deletes the specified webhook. 717 * 718 * <p>Sample code: 719 * 720 * <pre>{@code 721 * // This snippet has been automatically generated and should be regarded as a code template only. 722 * // It will require modifications to work: 723 * // - It may require correct/in-range values for request initialization. 724 * // - It may require specifying regional endpoints when creating the service client as shown in 725 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 726 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 727 * DeleteWebhookRequest request = 728 * DeleteWebhookRequest.newBuilder() 729 * .setName(WebhookName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[WEBHOOK]").toString()) 730 * .setForce(true) 731 * .build(); 732 * webhooksClient.deleteWebhook(request); 733 * } 734 * }</pre> 735 * 736 * @param request The request object containing all of the parameters for the API call. 737 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 738 */ deleteWebhook(DeleteWebhookRequest request)739 public final void deleteWebhook(DeleteWebhookRequest request) { 740 deleteWebhookCallable().call(request); 741 } 742 743 // AUTO-GENERATED DOCUMENTATION AND METHOD. 744 /** 745 * Deletes the specified webhook. 746 * 747 * <p>Sample code: 748 * 749 * <pre>{@code 750 * // This snippet has been automatically generated and should be regarded as a code template only. 751 * // It will require modifications to work: 752 * // - It may require correct/in-range values for request initialization. 753 * // - It may require specifying regional endpoints when creating the service client as shown in 754 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 755 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 756 * DeleteWebhookRequest request = 757 * DeleteWebhookRequest.newBuilder() 758 * .setName(WebhookName.of("[PROJECT]", "[LOCATION]", "[AGENT]", "[WEBHOOK]").toString()) 759 * .setForce(true) 760 * .build(); 761 * ApiFuture<Empty> future = webhooksClient.deleteWebhookCallable().futureCall(request); 762 * // Do something. 763 * future.get(); 764 * } 765 * }</pre> 766 */ deleteWebhookCallable()767 public final UnaryCallable<DeleteWebhookRequest, Empty> deleteWebhookCallable() { 768 return stub.deleteWebhookCallable(); 769 } 770 771 // AUTO-GENERATED DOCUMENTATION AND METHOD. 772 /** 773 * Lists information about the supported locations for this service. 774 * 775 * <p>Sample code: 776 * 777 * <pre>{@code 778 * // This snippet has been automatically generated and should be regarded as a code template only. 779 * // It will require modifications to work: 780 * // - It may require correct/in-range values for request initialization. 781 * // - It may require specifying regional endpoints when creating the service client as shown in 782 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 783 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 784 * ListLocationsRequest request = 785 * ListLocationsRequest.newBuilder() 786 * .setName("name3373707") 787 * .setFilter("filter-1274492040") 788 * .setPageSize(883849137) 789 * .setPageToken("pageToken873572522") 790 * .build(); 791 * for (Location element : webhooksClient.listLocations(request).iterateAll()) { 792 * // doThingsWith(element); 793 * } 794 * } 795 * }</pre> 796 * 797 * @param request The request object containing all of the parameters for the API call. 798 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 799 */ listLocations(ListLocationsRequest request)800 public final ListLocationsPagedResponse listLocations(ListLocationsRequest request) { 801 return listLocationsPagedCallable().call(request); 802 } 803 804 // AUTO-GENERATED DOCUMENTATION AND METHOD. 805 /** 806 * Lists information about the supported locations for this service. 807 * 808 * <p>Sample code: 809 * 810 * <pre>{@code 811 * // This snippet has been automatically generated and should be regarded as a code template only. 812 * // It will require modifications to work: 813 * // - It may require correct/in-range values for request initialization. 814 * // - It may require specifying regional endpoints when creating the service client as shown in 815 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 816 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 817 * ListLocationsRequest request = 818 * ListLocationsRequest.newBuilder() 819 * .setName("name3373707") 820 * .setFilter("filter-1274492040") 821 * .setPageSize(883849137) 822 * .setPageToken("pageToken873572522") 823 * .build(); 824 * ApiFuture<Location> future = webhooksClient.listLocationsPagedCallable().futureCall(request); 825 * // Do something. 826 * for (Location element : future.get().iterateAll()) { 827 * // doThingsWith(element); 828 * } 829 * } 830 * }</pre> 831 */ 832 public final UnaryCallable<ListLocationsRequest, ListLocationsPagedResponse> listLocationsPagedCallable()833 listLocationsPagedCallable() { 834 return stub.listLocationsPagedCallable(); 835 } 836 837 // AUTO-GENERATED DOCUMENTATION AND METHOD. 838 /** 839 * Lists information about the supported locations for this service. 840 * 841 * <p>Sample code: 842 * 843 * <pre>{@code 844 * // This snippet has been automatically generated and should be regarded as a code template only. 845 * // It will require modifications to work: 846 * // - It may require correct/in-range values for request initialization. 847 * // - It may require specifying regional endpoints when creating the service client as shown in 848 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 849 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 850 * ListLocationsRequest request = 851 * ListLocationsRequest.newBuilder() 852 * .setName("name3373707") 853 * .setFilter("filter-1274492040") 854 * .setPageSize(883849137) 855 * .setPageToken("pageToken873572522") 856 * .build(); 857 * while (true) { 858 * ListLocationsResponse response = webhooksClient.listLocationsCallable().call(request); 859 * for (Location element : response.getLocationsList()) { 860 * // doThingsWith(element); 861 * } 862 * String nextPageToken = response.getNextPageToken(); 863 * if (!Strings.isNullOrEmpty(nextPageToken)) { 864 * request = request.toBuilder().setPageToken(nextPageToken).build(); 865 * } else { 866 * break; 867 * } 868 * } 869 * } 870 * }</pre> 871 */ listLocationsCallable()872 public final UnaryCallable<ListLocationsRequest, ListLocationsResponse> listLocationsCallable() { 873 return stub.listLocationsCallable(); 874 } 875 876 // AUTO-GENERATED DOCUMENTATION AND METHOD. 877 /** 878 * Gets information about a location. 879 * 880 * <p>Sample code: 881 * 882 * <pre>{@code 883 * // This snippet has been automatically generated and should be regarded as a code template only. 884 * // It will require modifications to work: 885 * // - It may require correct/in-range values for request initialization. 886 * // - It may require specifying regional endpoints when creating the service client as shown in 887 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 888 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 889 * GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build(); 890 * Location response = webhooksClient.getLocation(request); 891 * } 892 * }</pre> 893 * 894 * @param request The request object containing all of the parameters for the API call. 895 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 896 */ getLocation(GetLocationRequest request)897 public final Location getLocation(GetLocationRequest request) { 898 return getLocationCallable().call(request); 899 } 900 901 // AUTO-GENERATED DOCUMENTATION AND METHOD. 902 /** 903 * Gets information about a location. 904 * 905 * <p>Sample code: 906 * 907 * <pre>{@code 908 * // This snippet has been automatically generated and should be regarded as a code template only. 909 * // It will require modifications to work: 910 * // - It may require correct/in-range values for request initialization. 911 * // - It may require specifying regional endpoints when creating the service client as shown in 912 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 913 * try (WebhooksClient webhooksClient = WebhooksClient.create()) { 914 * GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build(); 915 * ApiFuture<Location> future = webhooksClient.getLocationCallable().futureCall(request); 916 * // Do something. 917 * Location response = future.get(); 918 * } 919 * }</pre> 920 */ getLocationCallable()921 public final UnaryCallable<GetLocationRequest, Location> getLocationCallable() { 922 return stub.getLocationCallable(); 923 } 924 925 @Override close()926 public final void close() { 927 stub.close(); 928 } 929 930 @Override shutdown()931 public void shutdown() { 932 stub.shutdown(); 933 } 934 935 @Override isShutdown()936 public boolean isShutdown() { 937 return stub.isShutdown(); 938 } 939 940 @Override isTerminated()941 public boolean isTerminated() { 942 return stub.isTerminated(); 943 } 944 945 @Override shutdownNow()946 public void shutdownNow() { 947 stub.shutdownNow(); 948 } 949 950 @Override awaitTermination(long duration, TimeUnit unit)951 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 952 return stub.awaitTermination(duration, unit); 953 } 954 955 public static class ListWebhooksPagedResponse 956 extends AbstractPagedListResponse< 957 ListWebhooksRequest, 958 ListWebhooksResponse, 959 Webhook, 960 ListWebhooksPage, 961 ListWebhooksFixedSizeCollection> { 962 createAsync( PageContext<ListWebhooksRequest, ListWebhooksResponse, Webhook> context, ApiFuture<ListWebhooksResponse> futureResponse)963 public static ApiFuture<ListWebhooksPagedResponse> createAsync( 964 PageContext<ListWebhooksRequest, ListWebhooksResponse, Webhook> context, 965 ApiFuture<ListWebhooksResponse> futureResponse) { 966 ApiFuture<ListWebhooksPage> futurePage = 967 ListWebhooksPage.createEmptyPage().createPageAsync(context, futureResponse); 968 return ApiFutures.transform( 969 futurePage, 970 input -> new ListWebhooksPagedResponse(input), 971 MoreExecutors.directExecutor()); 972 } 973 ListWebhooksPagedResponse(ListWebhooksPage page)974 private ListWebhooksPagedResponse(ListWebhooksPage page) { 975 super(page, ListWebhooksFixedSizeCollection.createEmptyCollection()); 976 } 977 } 978 979 public static class ListWebhooksPage 980 extends AbstractPage<ListWebhooksRequest, ListWebhooksResponse, Webhook, ListWebhooksPage> { 981 ListWebhooksPage( PageContext<ListWebhooksRequest, ListWebhooksResponse, Webhook> context, ListWebhooksResponse response)982 private ListWebhooksPage( 983 PageContext<ListWebhooksRequest, ListWebhooksResponse, Webhook> context, 984 ListWebhooksResponse response) { 985 super(context, response); 986 } 987 createEmptyPage()988 private static ListWebhooksPage createEmptyPage() { 989 return new ListWebhooksPage(null, null); 990 } 991 992 @Override createPage( PageContext<ListWebhooksRequest, ListWebhooksResponse, Webhook> context, ListWebhooksResponse response)993 protected ListWebhooksPage createPage( 994 PageContext<ListWebhooksRequest, ListWebhooksResponse, Webhook> context, 995 ListWebhooksResponse response) { 996 return new ListWebhooksPage(context, response); 997 } 998 999 @Override createPageAsync( PageContext<ListWebhooksRequest, ListWebhooksResponse, Webhook> context, ApiFuture<ListWebhooksResponse> futureResponse)1000 public ApiFuture<ListWebhooksPage> createPageAsync( 1001 PageContext<ListWebhooksRequest, ListWebhooksResponse, Webhook> context, 1002 ApiFuture<ListWebhooksResponse> futureResponse) { 1003 return super.createPageAsync(context, futureResponse); 1004 } 1005 } 1006 1007 public static class ListWebhooksFixedSizeCollection 1008 extends AbstractFixedSizeCollection< 1009 ListWebhooksRequest, 1010 ListWebhooksResponse, 1011 Webhook, 1012 ListWebhooksPage, 1013 ListWebhooksFixedSizeCollection> { 1014 ListWebhooksFixedSizeCollection(List<ListWebhooksPage> pages, int collectionSize)1015 private ListWebhooksFixedSizeCollection(List<ListWebhooksPage> pages, int collectionSize) { 1016 super(pages, collectionSize); 1017 } 1018 createEmptyCollection()1019 private static ListWebhooksFixedSizeCollection createEmptyCollection() { 1020 return new ListWebhooksFixedSizeCollection(null, 0); 1021 } 1022 1023 @Override createCollection( List<ListWebhooksPage> pages, int collectionSize)1024 protected ListWebhooksFixedSizeCollection createCollection( 1025 List<ListWebhooksPage> pages, int collectionSize) { 1026 return new ListWebhooksFixedSizeCollection(pages, collectionSize); 1027 } 1028 } 1029 1030 public static class ListLocationsPagedResponse 1031 extends AbstractPagedListResponse< 1032 ListLocationsRequest, 1033 ListLocationsResponse, 1034 Location, 1035 ListLocationsPage, 1036 ListLocationsFixedSizeCollection> { 1037 createAsync( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ApiFuture<ListLocationsResponse> futureResponse)1038 public static ApiFuture<ListLocationsPagedResponse> createAsync( 1039 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 1040 ApiFuture<ListLocationsResponse> futureResponse) { 1041 ApiFuture<ListLocationsPage> futurePage = 1042 ListLocationsPage.createEmptyPage().createPageAsync(context, futureResponse); 1043 return ApiFutures.transform( 1044 futurePage, 1045 input -> new ListLocationsPagedResponse(input), 1046 MoreExecutors.directExecutor()); 1047 } 1048 ListLocationsPagedResponse(ListLocationsPage page)1049 private ListLocationsPagedResponse(ListLocationsPage page) { 1050 super(page, ListLocationsFixedSizeCollection.createEmptyCollection()); 1051 } 1052 } 1053 1054 public static class ListLocationsPage 1055 extends AbstractPage< 1056 ListLocationsRequest, ListLocationsResponse, Location, ListLocationsPage> { 1057 ListLocationsPage( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ListLocationsResponse response)1058 private ListLocationsPage( 1059 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 1060 ListLocationsResponse response) { 1061 super(context, response); 1062 } 1063 createEmptyPage()1064 private static ListLocationsPage createEmptyPage() { 1065 return new ListLocationsPage(null, null); 1066 } 1067 1068 @Override createPage( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ListLocationsResponse response)1069 protected ListLocationsPage createPage( 1070 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 1071 ListLocationsResponse response) { 1072 return new ListLocationsPage(context, response); 1073 } 1074 1075 @Override createPageAsync( PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, ApiFuture<ListLocationsResponse> futureResponse)1076 public ApiFuture<ListLocationsPage> createPageAsync( 1077 PageContext<ListLocationsRequest, ListLocationsResponse, Location> context, 1078 ApiFuture<ListLocationsResponse> futureResponse) { 1079 return super.createPageAsync(context, futureResponse); 1080 } 1081 } 1082 1083 public static class ListLocationsFixedSizeCollection 1084 extends AbstractFixedSizeCollection< 1085 ListLocationsRequest, 1086 ListLocationsResponse, 1087 Location, 1088 ListLocationsPage, 1089 ListLocationsFixedSizeCollection> { 1090 ListLocationsFixedSizeCollection(List<ListLocationsPage> pages, int collectionSize)1091 private ListLocationsFixedSizeCollection(List<ListLocationsPage> pages, int collectionSize) { 1092 super(pages, collectionSize); 1093 } 1094 createEmptyCollection()1095 private static ListLocationsFixedSizeCollection createEmptyCollection() { 1096 return new ListLocationsFixedSizeCollection(null, 0); 1097 } 1098 1099 @Override createCollection( List<ListLocationsPage> pages, int collectionSize)1100 protected ListLocationsFixedSizeCollection createCollection( 1101 List<ListLocationsPage> pages, int collectionSize) { 1102 return new ListLocationsFixedSizeCollection(pages, collectionSize); 1103 } 1104 } 1105 } 1106