diff --git a/src/main/java/com/google/api/codegen/transformer/SurfaceNamer.java b/src/main/java/com/google/api/codegen/transformer/SurfaceNamer.java index dfdcba132b..dd0dcc278f 100644 --- a/src/main/java/com/google/api/codegen/transformer/SurfaceNamer.java +++ b/src/main/java/com/google/api/codegen/transformer/SurfaceNamer.java @@ -619,7 +619,7 @@ public String getApiWrapperClassName(InterfaceConfig interfaceConfig) { } /** The name of the implementation class that implements a particular proto interface. */ - public String getApiWrapperClassImplName(Interface apiInterface) { + public String getApiWrapperClassImplName(InterfaceConfig interfaceConfig) { return getNotImplementedString("SurfaceNamer.getApiWrapperClassImplName"); } diff --git a/src/main/java/com/google/api/codegen/transformer/csharp/CSharpGapicClientTransformer.java b/src/main/java/com/google/api/codegen/transformer/csharp/CSharpGapicClientTransformer.java index 2ce91fb734..47dead4188 100644 --- a/src/main/java/com/google/api/codegen/transformer/csharp/CSharpGapicClientTransformer.java +++ b/src/main/java/com/google/api/codegen/transformer/csharp/CSharpGapicClientTransformer.java @@ -175,7 +175,7 @@ private StaticLangApiView generateApiClass(GapicInterfaceContext context) { apiClass.doc(serviceTransformer.generateServiceDoc(context, null)); apiClass.name(namer.getApiWrapperClassName(context.getInterfaceConfig())); - apiClass.implName(namer.getApiWrapperClassImplName(context.getInterface())); + apiClass.implName(namer.getApiWrapperClassImplName(context.getInterfaceConfig())); apiClass.grpcServiceName(namer.getGrpcContainerTypeName(context.getInterface())); apiClass.grpcTypeName(namer.getGrpcServiceClassName(context.getInterface())); apiClass.settingsClassName( diff --git a/src/main/java/com/google/api/codegen/transformer/csharp/CSharpSurfaceNamer.java b/src/main/java/com/google/api/codegen/transformer/csharp/CSharpSurfaceNamer.java index 39d9ccf2d3..3cf98ce50d 100644 --- a/src/main/java/com/google/api/codegen/transformer/csharp/CSharpSurfaceNamer.java +++ b/src/main/java/com/google/api/codegen/transformer/csharp/CSharpSurfaceNamer.java @@ -18,6 +18,7 @@ import com.google.api.codegen.config.FieldConfig; import com.google.api.codegen.config.GapicInterfaceConfig; import com.google.api.codegen.config.GapicMethodConfig; +import com.google.api.codegen.config.InterfaceConfig; import com.google.api.codegen.config.ResourceNameConfig; import com.google.api.codegen.config.ResourceNameType; import com.google.api.codegen.config.SingleResourceNameConfig; @@ -353,8 +354,8 @@ public String getGrpcServiceClassName(Interface apiInterface) { } @Override - public String getApiWrapperClassImplName(Interface apiInterface) { - return publicClassName(Name.upperCamel(apiInterface.getSimpleName(), "ClientImpl")); + public String getApiWrapperClassImplName(InterfaceConfig interfaceConfig) { + return publicClassName(Name.upperCamel(getInterfaceName(interfaceConfig), "ClientImpl")); } @Override diff --git a/src/main/java/com/google/api/codegen/transformer/php/PhpGapicSurfaceTransformer.java b/src/main/java/com/google/api/codegen/transformer/php/PhpGapicSurfaceTransformer.java index 772fe519e5..53636a537c 100644 --- a/src/main/java/com/google/api/codegen/transformer/php/PhpGapicSurfaceTransformer.java +++ b/src/main/java/com/google/api/codegen/transformer/php/PhpGapicSurfaceTransformer.java @@ -36,6 +36,7 @@ import com.google.api.codegen.transformer.SurfaceNamer; import com.google.api.codegen.util.php.PhpTypeTable; import com.google.api.codegen.viewmodel.ApiMethodView; +import com.google.api.codegen.viewmodel.DynamicLangXApiSubclassView; import com.google.api.codegen.viewmodel.DynamicLangXApiView; import com.google.api.codegen.viewmodel.GrpcStreamingDetailView; import com.google.api.codegen.viewmodel.LongRunningOperationDetailView; @@ -59,7 +60,8 @@ public class PhpGapicSurfaceTransformer implements ModelToViewTransformer { private final FileHeaderTransformer fileHeaderTransformer = new FileHeaderTransformer(new PhpImportSectionTransformer()); - private static final String XAPI_TEMPLATE_FILENAME = "php/main.snip"; + private static final String API_TEMPLATE_FILENAME = "php/partial_veneer_client.snip"; + private static final String API_IMPL_TEMPLATE_FILENAME = "php/client_impl.snip"; public PhpGapicSurfaceTransformer( GapicProductConfig productConfig, GapicCodePathMapper pathMapper) { @@ -74,7 +76,7 @@ public PhpGapicSurfaceTransformer( @Override public List getTemplateFileNames() { - return Arrays.asList(XAPI_TEMPLATE_FILENAME); + return Arrays.asList(API_TEMPLATE_FILENAME, API_IMPL_TEMPLATE_FILENAME); } @Override @@ -108,58 +110,69 @@ public List transform(GapicInterfaceContext context) { List methods = generateApiMethods(context); - DynamicLangXApiView.Builder xapiClass = DynamicLangXApiView.newBuilder(); + DynamicLangXApiView.Builder apiImplClass = DynamicLangXApiView.newBuilder(); - xapiClass.doc(serviceTransformer.generateServiceDoc(context, methods.get(0))); + apiImplClass.doc(serviceTransformer.generateServiceDoc(context, methods.get(0))); - xapiClass.templateFileName(XAPI_TEMPLATE_FILENAME); - xapiClass.protoFilename(context.getInterface().getFile().getSimpleName()); - String name = namer.getApiWrapperClassName(context.getInterfaceConfig()); - xapiClass.name(name); + apiImplClass.templateFileName(API_IMPL_TEMPLATE_FILENAME); + apiImplClass.protoFilename(context.getInterface().getFile().getSimpleName()); + String implName = namer.getApiWrapperClassImplName(context.getInterfaceConfig()); + apiImplClass.name(implName); ProductServiceConfig productServiceConfig = new ProductServiceConfig(); - xapiClass.serviceAddress( + apiImplClass.serviceAddress( productServiceConfig.getServiceAddress(context.getInterface().getModel())); - xapiClass.servicePort(productServiceConfig.getServicePort()); - xapiClass.serviceTitle(productServiceConfig.getTitle(context.getInterface().getModel())); - xapiClass.authScopes(productServiceConfig.getAuthScopes(context.getInterface().getModel())); + apiImplClass.servicePort(productServiceConfig.getServicePort()); + apiImplClass.serviceTitle(productServiceConfig.getTitle(context.getInterface().getModel())); + apiImplClass.authScopes(productServiceConfig.getAuthScopes(context.getInterface().getModel())); - xapiClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context)); - xapiClass.formatResourceFunctions( + apiImplClass.pathTemplates(pathTemplateTransformer.generatePathTemplates(context)); + apiImplClass.formatResourceFunctions( pathTemplateTransformer.generateFormatResourceFunctions(context)); - xapiClass.parseResourceFunctions( + apiImplClass.parseResourceFunctions( pathTemplateTransformer.generateParseResourceFunctions(context)); - xapiClass.pathTemplateGetterFunctions( + apiImplClass.pathTemplateGetterFunctions( pathTemplateTransformer.generatePathTemplateGetterFunctions(context)); - xapiClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptors(context)); - xapiClass.hasPageStreamingMethods(context.getInterfaceConfig().hasPageStreamingMethods()); - xapiClass.hasBatchingMethods(context.getInterfaceConfig().hasBatchingMethods()); - xapiClass.longRunningDescriptors(createLongRunningDescriptors(context)); - xapiClass.hasLongRunningOperations(context.getInterfaceConfig().hasLongRunningOperations()); - xapiClass.grpcStreamingDescriptors(createGrpcStreamingDescriptors(context)); - - xapiClass.methodKeys(generateMethodKeys(context)); - xapiClass.clientConfigPath(namer.getClientConfigPath(context.getInterface())); - xapiClass.interfaceKey(context.getInterface().getFullName()); + apiImplClass.pageStreamingDescriptors(pageStreamingTransformer.generateDescriptors(context)); + apiImplClass.hasPageStreamingMethods(context.getInterfaceConfig().hasPageStreamingMethods()); + apiImplClass.hasBatchingMethods(context.getInterfaceConfig().hasBatchingMethods()); + apiImplClass.longRunningDescriptors(createLongRunningDescriptors(context)); + apiImplClass.hasLongRunningOperations(context.getInterfaceConfig().hasLongRunningOperations()); + apiImplClass.grpcStreamingDescriptors(createGrpcStreamingDescriptors(context)); + + apiImplClass.methodKeys(generateMethodKeys(context)); + apiImplClass.clientConfigPath(namer.getClientConfigPath(context.getInterface())); + apiImplClass.interfaceKey(context.getInterface().getFullName()); String grpcClientTypeName = namer.getAndSaveNicknameForGrpcClientTypeName( context.getModelTypeTable(), context.getInterface()); - xapiClass.grpcClientTypeName(grpcClientTypeName); + apiImplClass.grpcClientTypeName(grpcClientTypeName); - xapiClass.apiMethods(methods); + apiImplClass.apiMethods(methods); - xapiClass.stubs(grpcStubTransformer.generateGrpcStubs(context)); + apiImplClass.stubs(grpcStubTransformer.generateGrpcStubs(context)); - xapiClass.hasDefaultServiceAddress(context.getInterfaceConfig().hasDefaultServiceAddress()); - xapiClass.hasDefaultServiceScopes(context.getInterfaceConfig().hasDefaultServiceScopes()); + apiImplClass.hasDefaultServiceAddress(context.getInterfaceConfig().hasDefaultServiceAddress()); + apiImplClass.hasDefaultServiceScopes(context.getInterfaceConfig().hasDefaultServiceScopes()); - xapiClass.toolkitVersion(GeneratorVersionProvider.getGeneratorVersion()); + apiImplClass.toolkitVersion(GeneratorVersionProvider.getGeneratorVersion()); // must be done as the last step to catch all imports - xapiClass.fileHeader(fileHeaderTransformer.generateFileHeader(context)); + apiImplClass.fileHeader(fileHeaderTransformer.generateFileHeader(context)); + + apiImplClass.outputPath(outputPath + "/" + implName + ".php"); - xapiClass.outputPath(outputPath + "/" + name + ".php"); + surfaceData.add(apiImplClass.build()); + + String name = namer.getApiWrapperClassName(context.getInterfaceConfig()); - surfaceData.add(xapiClass.build()); + DynamicLangXApiSubclassView.Builder apiClass = DynamicLangXApiSubclassView.newBuilder(); + apiClass.templateFileName(API_TEMPLATE_FILENAME); + apiClass.protoFilename(context.getInterface().getFile().getSimpleName()); + apiClass.name(name); + apiClass.parentName(implName); + apiClass.fileHeader(fileHeaderTransformer.generateFileHeader(context)); + apiClass.outputPath(outputPath + "/" + name + ".php"); + surfaceData.add(apiClass.build()); return surfaceData; } diff --git a/src/main/java/com/google/api/codegen/transformer/php/PhpSurfaceNamer.java b/src/main/java/com/google/api/codegen/transformer/php/PhpSurfaceNamer.java index 0569a25277..c9a948e295 100644 --- a/src/main/java/com/google/api/codegen/transformer/php/PhpSurfaceNamer.java +++ b/src/main/java/com/google/api/codegen/transformer/php/PhpSurfaceNamer.java @@ -17,6 +17,7 @@ import com.google.api.codegen.ServiceMessages; import com.google.api.codegen.config.GapicInterfaceConfig; import com.google.api.codegen.config.GapicMethodConfig; +import com.google.api.codegen.config.InterfaceConfig; import com.google.api.codegen.config.SingleResourceNameConfig; import com.google.api.codegen.config.VisibilityConfig; import com.google.api.codegen.transformer.ModelTypeFormatterImpl; @@ -123,6 +124,11 @@ public String getFullyQualifiedApiWrapperClassName(GapicInterfaceConfig interfac return getPackageName() + "\\" + getApiWrapperClassName(interfaceConfig); } + @Override + public String getApiWrapperClassImplName(InterfaceConfig interfaceConfig) { + return publicClassName(Name.upperCamel(getInterfaceName(interfaceConfig), "GapicClient")); + } + @Override public String getGrpcClientTypeName(Interface apiInterface) { return qualifiedName(getGrpcClientTypeName(apiInterface, "GrpcClient")); diff --git a/src/main/java/com/google/api/codegen/viewmodel/DynamicLangXApiSubclassView.java b/src/main/java/com/google/api/codegen/viewmodel/DynamicLangXApiSubclassView.java new file mode 100644 index 0000000000..27807e2e8b --- /dev/null +++ b/src/main/java/com/google/api/codegen/viewmodel/DynamicLangXApiSubclassView.java @@ -0,0 +1,59 @@ +/* Copyright 2016 Google Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.api.codegen.viewmodel; + +import com.google.api.codegen.SnippetSetRunner; +import com.google.auto.value.AutoValue; + +@AutoValue +public abstract class DynamicLangXApiSubclassView implements ViewModel { + public abstract String templateFileName(); + + public abstract FileHeaderView fileHeader(); + + public abstract String protoFilename(); + + public abstract String name(); + + public abstract String parentName(); + + public abstract String outputPath(); + + @Override + public String resourceRoot() { + return SnippetSetRunner.SNIPPET_RESOURCE_ROOT; + } + + public static Builder newBuilder() { + return new AutoValue_DynamicLangXApiSubclassView.Builder(); + } + + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder templateFileName(String val); + + public abstract Builder fileHeader(FileHeaderView val); + + public abstract Builder protoFilename(String simpleName); + + public abstract Builder name(String val); + + public abstract Builder parentName(String val); + + public abstract Builder outputPath(String val); + + public abstract DynamicLangXApiSubclassView build(); + } +} diff --git a/src/main/resources/com/google/api/codegen/php/main.snip b/src/main/resources/com/google/api/codegen/php/client_impl.snip similarity index 100% rename from src/main/resources/com/google/api/codegen/php/main.snip rename to src/main/resources/com/google/api/codegen/php/client_impl.snip diff --git a/src/main/resources/com/google/api/codegen/php/partial_veneer_client.snip b/src/main/resources/com/google/api/codegen/php/partial_veneer_client.snip new file mode 100644 index 0000000000..11d7136f94 --- /dev/null +++ b/src/main/resources/com/google/api/codegen/php/partial_veneer_client.snip @@ -0,0 +1,28 @@ +@extends "php/common.snip" + +@snippet generate(xapiClass) + {@renderFileHeader(xapiClass.fileHeader, generatedCodeWarning(xapiClass))} + + /** + * {@@inheritdoc} + */ + class {@xapiClass.name} extends {@xapiClass.parentName} + { + // This class is intentionally empty, and is intended to hold manual additions to the generated {@@see {@xapiClass.name}Impl} class. + } +@end + +@private generatedCodeWarning(xapiClass) + /* + * GENERATED CODE WARNING + * This file was generated from the file + * https://github.com/google/googleapis/blob/master/{@xapiClass.protoFilename} + * and updates to that file get reflected here through a refresh process. + * + * EXPERIMENTAL: this client library class has not yet been declared beta. This class may change + * more frequently than those which have been declared beta or 1.0, including changes which break + * backwards compatibility. + * + * @@experimental + */ +@end diff --git a/src/test/java/com/google/api/codegen/testdata/php_client_impl_library.baseline b/src/test/java/com/google/api/codegen/testdata/php_client_impl_library.baseline new file mode 100644 index 0000000000..98e4233b14 --- /dev/null +++ b/src/test/java/com/google/api/codegen/testdata/php_client_impl_library.baseline @@ -0,0 +1,2353 @@ +============== file: src/Example/Library/V1/LibraryServiceGapicClient.php ============== +&"`'@. + * + * EXPERIMENTAL: this client library class has not yet been declared beta. This class may change + * more frequently than those which have been declared beta or 1.0, including changes which break + * backwards compatibility. + * + * 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: + * + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $shelf = new Shelf(); + * $response = $libraryServiceClient->createShelf($shelf); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * 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. + * @experimental + */ +class LibraryServiceGapicClient +{ + /** + * The default address of the service. + */ + const SERVICE_ADDRESS = 'library-example.googleapis.com'; + + /** + * The default port of the service. + */ + const DEFAULT_SERVICE_PORT = 443; + + /** + * The default timeout for non-retrying methods. + */ + const DEFAULT_TIMEOUT_MILLIS = 30000; + + /** + * The name of the code generator, to be included in the agent header. + */ + const CODEGEN_NAME = 'gapic'; + + /** + * The code generator version, to be included in the agent header. + */ + const CODEGEN_VERSION = '0.0.5'; + + private static $shelfNameTemplate; + private static $bookNameTemplate; + private static $returnNameTemplate; + + private $grpcCredentialsHelper; + private $libraryServiceStub; + private $labelerStub; + private $scopes; + private $defaultCallSettings; + private $descriptors; + private $operationsClient; + + /** + * Formats a string containing the fully-qualified path to represent + * a shelf resource. + * + * @param string $shelfId + * @return string The formatted shelf resource. + * @experimental + */ + public static function formatShelfName($shelfId) + { + return self::getShelfNameTemplate()->render([ + 'shelf_id' => $shelfId, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a book resource. + * + * @param string $shelfId + * @param string $bookId + * @return string The formatted book resource. + * @experimental + */ + public static function formatBookName($shelfId, $bookId) + { + return self::getBookNameTemplate()->render([ + 'shelf_id' => $shelfId, + 'book_id' => $bookId, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a return resource. + * + * @param string $shelf + * @param string $book + * @param string $return + * @return string The formatted return resource. + * @experimental + */ + public static function formatReturnName($shelf, $book, $return) + { + return self::getReturnNameTemplate()->render([ + 'shelf' => $shelf, + 'book' => $book, + 'return' => $return, + ]); + } + + /** + * Parses the shelf_id from the given fully-qualified path which + * represents a shelf resource. + * + * @param string $shelfName The fully-qualified shelf resource. + * @return string The extracted shelf_id value. + * @experimental + */ + public static function parseShelfIdFromShelfName($shelfName) + { + return self::getShelfNameTemplate()->match($shelfName)['shelf_id']; + } + + /** + * Parses the shelf_id from the given fully-qualified path which + * represents a book resource. + * + * @param string $bookName The fully-qualified book resource. + * @return string The extracted shelf_id value. + * @experimental + */ + public static function parseShelfIdFromBookName($bookName) + { + return self::getBookNameTemplate()->match($bookName)['shelf_id']; + } + + /** + * Parses the book_id from the given fully-qualified path which + * represents a book resource. + * + * @param string $bookName The fully-qualified book resource. + * @return string The extracted book_id value. + * @experimental + */ + public static function parseBookIdFromBookName($bookName) + { + return self::getBookNameTemplate()->match($bookName)['book_id']; + } + + /** + * Parses the shelf from the given fully-qualified path which + * represents a return resource. + * + * @param string $returnName The fully-qualified return resource. + * @return string The extracted shelf value. + * @experimental + */ + public static function parseShelfFromReturnName($returnName) + { + return self::getReturnNameTemplate()->match($returnName)['shelf']; + } + + /** + * Parses the book from the given fully-qualified path which + * represents a return resource. + * + * @param string $returnName The fully-qualified return resource. + * @return string The extracted book value. + * @experimental + */ + public static function parseBookFromReturnName($returnName) + { + return self::getReturnNameTemplate()->match($returnName)['book']; + } + + /** + * Parses the return from the given fully-qualified path which + * represents a return resource. + * + * @param string $returnName The fully-qualified return resource. + * @return string The extracted return value. + * @experimental + */ + public static function parseReturnFromReturnName($returnName) + { + return self::getReturnNameTemplate()->match($returnName)['return']; + } + + + private static function getShelfNameTemplate() + { + if (self::$shelfNameTemplate == null) { + self::$shelfNameTemplate = new PathTemplate('shelves/{shelf_id}'); + } + + return self::$shelfNameTemplate; + } + + private static function getBookNameTemplate() + { + if (self::$bookNameTemplate == null) { + self::$bookNameTemplate = new PathTemplate('shelves/{shelf_id}/books/{book_id}'); + } + + return self::$bookNameTemplate; + } + + private static function getReturnNameTemplate() + { + if (self::$returnNameTemplate == null) { + self::$returnNameTemplate = new PathTemplate('shelves/{shelf}/books/{book}/returns/{return}'); + } + + return self::$returnNameTemplate; + } + + private static function getPageStreamingDescriptors() + { + $listShelvesPageStreamingDescriptor = + new PageStreamingDescriptor([ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getShelves', + ]); + $listBooksPageStreamingDescriptor = + new PageStreamingDescriptor([ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'requestPageSizeGetMethod' => 'getPageSize', + 'requestPageSizeSetMethod' => 'setPageSize', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getBooks', + ]); + $listStringsPageStreamingDescriptor = + new PageStreamingDescriptor([ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'requestPageSizeGetMethod' => 'getPageSize', + 'requestPageSizeSetMethod' => 'setPageSize', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getStrings', + ]); + $findRelatedBooksPageStreamingDescriptor = + new PageStreamingDescriptor([ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'requestPageSizeGetMethod' => 'getPageSize', + 'requestPageSizeSetMethod' => 'setPageSize', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getNames', + ]); + + $pageStreamingDescriptors = [ + 'listShelves' => $listShelvesPageStreamingDescriptor, + 'listBooks' => $listBooksPageStreamingDescriptor, + 'listStrings' => $listStringsPageStreamingDescriptor, + 'findRelatedBooks' => $findRelatedBooksPageStreamingDescriptor, + ]; + + return $pageStreamingDescriptors; + } + + private static function getLongRunningDescriptors() + { + return [ + 'getBigBook' => [ + 'operationReturnType' => '\Google\Example\Library\V1\Book', + 'metadataReturnType' => '\Google\Example\Library\V1\GetBigBookMetadata', + ], + 'getBigNothing' => [ + 'operationReturnType' => '\Google\Protobuf\GPBEmpty', + 'metadataReturnType' => '\Google\Example\Library\V1\GetBigBookMetadata', + ], + ]; + } + + private static function getGrpcStreamingDescriptors() + { + return [ + 'streamShelves' => [ + 'grpcStreamingType' => 'ServerStreaming', + 'resourcesGetMethod' => 'getShelves', + ], + 'streamBooks' => [ + 'grpcStreamingType' => 'ServerStreaming', + ], + 'discussBook' => [ + 'grpcStreamingType' => 'BidiStreaming', + ], + 'monologAboutBook' => [ + 'grpcStreamingType' => 'ClientStreaming', + ], + ]; + } + + private static function getGapicVersion() + { + if (file_exists(__DIR__ . "/../VERSION")) { + return trim(file_get_contents(__DIR__ . "/../VERSION")); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + return \Google\Cloud\ServiceBuilder::VERSION; + } else { + return; + } + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return \Google\GAX\LongRunning\OperationsClient + * @experimental + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started + * by a long running API method. If $methodName is not provided, or does + * not match a long running API method, then the operation can still be + * resumed, but the OperationResponse object will not deserialize the + * final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * @return \Google\GAX\OperationResponse + * @experimental + */ + public function resumeOperation($operationName, $methodName = null) + { + $lroDescriptors = LibraryServiceGapicClient::getLongRunningDescriptors(); + if (!is_null($methodName) && array_key_exists($methodName, $lroDescriptors)) { + $options = $lroDescriptors[$methodName]; + } else { + $options = []; + } + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + // TODO(garrettjones): add channel (when supported in gRPC) + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $serviceAddress The domain name of the API remote host. + * Default 'library-example.googleapis.com'. + * @type mixed $port The port on which to connect to the remote host. Default 443. + * @type \Grpc\ChannelCredentials $sslCreds + * A `ChannelCredentials` for use with an SSL-enabled channel. + * Default: a credentials object returned from + * \Grpc\ChannelCredentials::createSsl() + * @type array $scopes A string array of scopes to use when acquiring credentials. + * Default the scopes for the Google Example Library API. + * @type array $retryingOverride + * An associative array of string => RetryOptions, where the keys + * are method names (e.g. 'createFoo'), that overrides default retrying + * settings. A value of null indicates that the method in question should + * not retry. + * @type int $timeoutMillis The timeout in milliseconds to use for calls + * that don't use retries. For calls that use retries, + * set the timeout in RetryOptions. + * Default: 30000 (30 seconds) + * @type \Google\Auth\CredentialsLoader $credentialsLoader + * A CredentialsLoader object created using the + * Google\Auth library. + * } + * @experimental + */ + public function __construct($options = []) + { + $defaultOptions = [ + 'serviceAddress' => self::SERVICE_ADDRESS, + 'port' => self::DEFAULT_SERVICE_PORT, + 'scopes' => [ + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/library', + ], + 'retryingOverride' => null, + 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, + 'libName' => null, + 'libVersion' => null, + ]; + $options = array_merge($defaultOptions, $options); + + if (array_key_exists('operationsClient', $options)) { + $this->operationsClient = $options['operationsClient']; + } else { + $operationsClientOptions = $options; + unset($operationsClientOptions['timeoutMillis']); + unset($operationsClientOptions['retryingOverride']); + $this->operationsClient = new OperationsClient($operationsClientOptions); + } + + $gapicVersion = $options['libVersion'] ?: self::getGapicVersion(); + + $headerDescriptor = new AgentHeaderDescriptor([ + 'libName' => $options['libName'], + 'libVersion' => $options['libVersion'], + 'gapicVersion' => $gapicVersion, + ]); + + $defaultDescriptors = ['headerDescriptor' => $headerDescriptor]; + $this->descriptors = [ + 'createShelf' => $defaultDescriptors, + 'getShelf' => $defaultDescriptors, + 'listShelves' => $defaultDescriptors, + 'deleteShelf' => $defaultDescriptors, + 'mergeShelves' => $defaultDescriptors, + 'createBook' => $defaultDescriptors, + 'publishSeries' => $defaultDescriptors, + 'getBook' => $defaultDescriptors, + 'listBooks' => $defaultDescriptors, + 'deleteBook' => $defaultDescriptors, + 'updateBook' => $defaultDescriptors, + 'moveBook' => $defaultDescriptors, + 'listStrings' => $defaultDescriptors, + 'addComments' => $defaultDescriptors, + 'getBookFromArchive' => $defaultDescriptors, + 'getBookFromAnywhere' => $defaultDescriptors, + 'getBookFromAbsolutelyAnywhere' => $defaultDescriptors, + 'updateBookIndex' => $defaultDescriptors, + 'streamShelves' => $defaultDescriptors, + 'streamBooks' => $defaultDescriptors, + 'discussBook' => $defaultDescriptors, + 'monologAboutBook' => $defaultDescriptors, + 'findRelatedBooks' => $defaultDescriptors, + 'addTag' => $defaultDescriptors, + 'addLabel' => $defaultDescriptors, + 'getBigBook' => $defaultDescriptors, + 'getBigNothing' => $defaultDescriptors, + 'testOptionalRequiredFlatteningParams' => $defaultDescriptors, + ]; + $pageStreamingDescriptors = self::getPageStreamingDescriptors(); + foreach ($pageStreamingDescriptors as $method => $pageStreamingDescriptor) { + $this->descriptors[$method]['pageStreamingDescriptor'] = $pageStreamingDescriptor; + } + $longRunningDescriptors = self::getLongRunningDescriptors(); + foreach ($longRunningDescriptors as $method => $longRunningDescriptor) { + $this->descriptors[$method]['longRunningDescriptor'] = $longRunningDescriptor + ['operationsClient' => $this->operationsClient]; + } + $grpcStreamingDescriptors = self::getGrpcStreamingDescriptors(); + foreach ($grpcStreamingDescriptors as $method => $grpcStreamingDescriptor) { + $this->descriptors[$method]['grpcStreamingDescriptor'] = $grpcStreamingDescriptor; + } + + $clientConfigJsonString = file_get_contents(__DIR__ . '/resources/library_service_client_config.json'); + $clientConfig = json_decode($clientConfigJsonString, true); + $this->defaultCallSettings = + CallSettings::load('google.example.library.v1.LibraryService', + $clientConfig, + $options['retryingOverride'], + GrpcConstants::getStatusCodeNames(), + $options['timeoutMillis']); + + $this->scopes = $options['scopes']; + + $createStubOptions = []; + if (array_key_exists('sslCreds', $options)) { + $createStubOptions['sslCreds'] = $options['sslCreds']; + } + $grpcCredentialsHelperOptions = array_diff_key($options, $defaultOptions); + $this->grpcCredentialsHelper = new GrpcCredentialsHelper($this->scopes, $grpcCredentialsHelperOptions); + + $createLibraryServiceStubFunction = function ($hostname, $opts) { + return new LibraryServiceGrpcClient($hostname, $opts); + }; + if (array_key_exists('createLibraryServiceStubFunction', $options)) { + $createLibraryServiceStubFunction = $options['createLibraryServiceStubFunction']; + } + $this->libraryServiceStub = $this->grpcCredentialsHelper->createStub( + $createLibraryServiceStubFunction, + $options['serviceAddress'], + $options['port'], + $createStubOptions); + $createLabelerStubFunction = function ($hostname, $opts) { + return new LabelerGrpcClient($hostname, $opts); + }; + if (array_key_exists('createLabelerStubFunction', $options)) { + $createLabelerStubFunction = $options['createLabelerStubFunction']; + } + $this->labelerStub = $this->grpcCredentialsHelper->createStub( + $createLabelerStubFunction, + $options['serviceAddress'], + $options['port'], + $createStubOptions); + } + + /** + * Creates a shelf, and returns the new Shelf. + * RPC method comment may include special characters: <>&"`'@. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $shelf = new Shelf(); + * $response = $libraryServiceClient->createShelf($shelf); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param Shelf $shelf The shelf to create. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\Shelf + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function createShelf($shelf, $optionalArgs = []) + { + $request = new CreateShelfRequest(); + $request->setShelf($shelf); + + $mergedSettings = $this->defaultCallSettings['createShelf']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'CreateShelf', $mergedSettings, $this->descriptors['createShelf']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Gets a shelf. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); + * $options = ""; + * $response = $libraryServiceClient->getShelf($formattedName, $options); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the shelf to retrieve. + * @param string $options To test 'options' parameter name conflict. + * @param array $optionalArgs { + * Optional. + * @type SomeMessage $message + * Field to verify that message-type query parameter gets flattened. + * @type StringBuilder $stringBuilder + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\Shelf + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function getShelf($name, $options, $optionalArgs = []) + { + $request = new GetShelfRequest(); + $request->setName($name); + $request->setOptions($options); + if (isset($optionalArgs['message'])) { + $request->setMessage($optionalArgs['message']); + } + if (isset($optionalArgs['stringBuilder'])) { + $request->setStringBuilder($optionalArgs['stringBuilder']); + } + + $mergedSettings = $this->defaultCallSettings['getShelf']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'GetShelf', $mergedSettings, $this->descriptors['getShelf']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Lists shelves. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * + * // Iterate through all elements + * $pagedResponse = $libraryServiceClient->listShelves(); + * foreach ($pagedResponse->iterateAllElements() as $element) { + * // doSomethingWith($element); + * } + * + * // OR iterate over pages of elements, with the maximum page size set to 5 + * $pagedResponse = $libraryServiceClient->listShelves(['pageSize' => 5]); + * foreach ($pagedResponse->iteratePages() as $page) { + * foreach ($page as $element) { + * // doSomethingWith($element); + * } + * } + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param array $optionalArgs { + * Optional. + * @type string $pageToken + * A page token is used to specify a page of values to be returned. + * If no page token is specified (the default), the first page + * of values will be returned. Any page token used here must have + * been generated by a previous call to the API. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\GAX\PagedListResponse + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function listShelves($optionalArgs = []) + { + $request = new ListShelvesRequest(); + if (isset($optionalArgs['pageToken'])) { + $request->setPageToken($optionalArgs['pageToken']); + } + + $mergedSettings = $this->defaultCallSettings['listShelves']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'ListShelves', $mergedSettings, $this->descriptors['listShelves']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Deletes a shelf. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); + * $libraryServiceClient->deleteShelf($formattedName); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the shelf to delete. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function deleteShelf($name, $optionalArgs = []) + { + $request = new DeleteShelfRequest(); + $request->setName($name); + + $mergedSettings = $this->defaultCallSettings['deleteShelf']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'DeleteShelf', $mergedSettings, $this->descriptors['deleteShelf']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Merges two shelves by adding all books from the shelf named + * `other_shelf_name` to shelf `name`, and deletes + * `other_shelf_name`. Returns the updated shelf. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); + * $formattedOtherShelfName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); + * $response = $libraryServiceClient->mergeShelves($formattedName, $formattedOtherShelfName); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the shelf we're adding books to. + * @param string $otherShelfName The name of the shelf we're removing books from and deleting. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\Shelf + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function mergeShelves($name, $otherShelfName, $optionalArgs = []) + { + $request = new MergeShelvesRequest(); + $request->setName($name); + $request->setOtherShelfName($otherShelfName); + + $mergedSettings = $this->defaultCallSettings['mergeShelves']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'MergeShelves', $mergedSettings, $this->descriptors['mergeShelves']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Creates a book. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); + * $book = new Book(); + * $response = $libraryServiceClient->createBook($formattedName, $book); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the shelf in which the book is created. + * @param Book $book The book to create. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\Book + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function createBook($name, $book, $optionalArgs = []) + { + $request = new CreateBookRequest(); + $request->setName($name); + $request->setBook($book); + + $mergedSettings = $this->defaultCallSettings['createBook']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'CreateBook', $mergedSettings, $this->descriptors['createBook']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Creates a series of books. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $shelf = new Shelf(); + * $books = []; + * $seriesString = "foobar"; + * $seriesUuid = new SeriesUuid(); + * $seriesUuid->setSeriesString($seriesString); + * $response = $libraryServiceClient->publishSeries($shelf, $books, $seriesUuid); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param Shelf $shelf The shelf in which the series is created. + * @param Book[] $books The books to publish in the series. + * @param SeriesUuid $seriesUuid Uniquely identifies the series to the publishing house. + * @param array $optionalArgs { + * Optional. + * @type int $edition + * The edition of the series + * @type bool $reviewCopy + * If the book is in a pre-publish state + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\PublishSeriesResponse + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function publishSeries($shelf, $books, $seriesUuid, $optionalArgs = []) + { + $request = new PublishSeriesRequest(); + $request->setShelf($shelf); + $request->setBooks($books); + $request->setSeriesUuid($seriesUuid); + if (isset($optionalArgs['edition'])) { + $request->setEdition($optionalArgs['edition']); + } + if (isset($optionalArgs['reviewCopy'])) { + $request->setReviewCopy($optionalArgs['reviewCopy']); + } + + $mergedSettings = $this->defaultCallSettings['publishSeries']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'PublishSeries', $mergedSettings, $this->descriptors['publishSeries']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Gets a book. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $response = $libraryServiceClient->getBook($formattedName); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to retrieve. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\Book + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function getBook($name, $optionalArgs = []) + { + $request = new GetBookRequest(); + $request->setName($name); + + $mergedSettings = $this->defaultCallSettings['getBook']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'GetBook', $mergedSettings, $this->descriptors['getBook']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Lists books in a shelf. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); + * // Iterate through all elements + * $pagedResponse = $libraryServiceClient->listBooks($formattedName); + * foreach ($pagedResponse->iterateAllElements() as $element) { + * // doSomethingWith($element); + * } + * + * // OR iterate over pages of elements, with the maximum page size set to 5 + * $pagedResponse = $libraryServiceClient->listBooks($formattedName, ['pageSize' => 5]); + * foreach ($pagedResponse->iteratePages() as $page) { + * foreach ($page as $element) { + * // doSomethingWith($element); + * } + * } + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the shelf whose books we'd like to list. + * @param array $optionalArgs { + * Optional. + * @type int $pageSize + * The maximum number of resources contained in the underlying API + * response. The API may return fewer values in a page, even if + * there are additional values to be retrieved. + * @type string $pageToken + * A page token is used to specify a page of values to be returned. + * If no page token is specified (the default), the first page + * of values will be returned. Any page token used here must have + * been generated by a previous call to the API. + * @type string $filter + * To test python built-in wrapping. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\GAX\PagedListResponse + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function listBooks($name, $optionalArgs = []) + { + $request = new ListBooksRequest(); + $request->setName($name); + if (isset($optionalArgs['pageSize'])) { + $request->setPageSize($optionalArgs['pageSize']); + } + if (isset($optionalArgs['pageToken'])) { + $request->setPageToken($optionalArgs['pageToken']); + } + if (isset($optionalArgs['filter'])) { + $request->setFilter($optionalArgs['filter']); + } + + $mergedSettings = $this->defaultCallSettings['listBooks']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'ListBooks', $mergedSettings, $this->descriptors['listBooks']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Deletes a book. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $libraryServiceClient->deleteBook($formattedName); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to delete. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function deleteBook($name, $optionalArgs = []) + { + $request = new DeleteBookRequest(); + $request->setName($name); + + $mergedSettings = $this->defaultCallSettings['deleteBook']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'DeleteBook', $mergedSettings, $this->descriptors['deleteBook']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Updates a book. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $book = new Book(); + * $response = $libraryServiceClient->updateBook($formattedName, $book); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to update. + * @param Book $book The book to update with. + * @param array $optionalArgs { + * Optional. + * @type FieldMask $updateMask + * A field mask to apply, rendered as an HTTP parameter. + * @type \Google\Example\Library\V1\FieldMask $physicalMask + * To test Python import clash resolution. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\Book + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function updateBook($name, $book, $optionalArgs = []) + { + $request = new UpdateBookRequest(); + $request->setName($name); + $request->setBook($book); + if (isset($optionalArgs['updateMask'])) { + $request->setUpdateMask($optionalArgs['updateMask']); + } + if (isset($optionalArgs['physicalMask'])) { + $request->setPhysicalMask($optionalArgs['physicalMask']); + } + + $mergedSettings = $this->defaultCallSettings['updateBook']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'UpdateBook', $mergedSettings, $this->descriptors['updateBook']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Moves a book to another shelf, and returns the new book. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $formattedOtherShelfName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); + * $response = $libraryServiceClient->moveBook($formattedName, $formattedOtherShelfName); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to move. + * @param string $otherShelfName The name of the destination shelf. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\Book + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function moveBook($name, $otherShelfName, $optionalArgs = []) + { + $request = new MoveBookRequest(); + $request->setName($name); + $request->setOtherShelfName($otherShelfName); + + $mergedSettings = $this->defaultCallSettings['moveBook']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'MoveBook', $mergedSettings, $this->descriptors['moveBook']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Lists a primitive resource. To test go page streaming. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * + * // Iterate through all elements + * $pagedResponse = $libraryServiceClient->listStrings(); + * foreach ($pagedResponse->iterateAllElements() as $element) { + * // doSomethingWith($element); + * } + * + * // OR iterate over pages of elements, with the maximum page size set to 5 + * $pagedResponse = $libraryServiceClient->listStrings(['pageSize' => 5]); + * foreach ($pagedResponse->iteratePages() as $page) { + * foreach ($page as $element) { + * // doSomethingWith($element); + * } + * } + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param array $optionalArgs { + * Optional. + * @type string $name + * @type int $pageSize + * The maximum number of resources contained in the underlying API + * response. The API may return fewer values in a page, even if + * there are additional values to be retrieved. + * @type string $pageToken + * A page token is used to specify a page of values to be returned. + * If no page token is specified (the default), the first page + * of values will be returned. Any page token used here must have + * been generated by a previous call to the API. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\GAX\PagedListResponse + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function listStrings($optionalArgs = []) + { + $request = new ListStringsRequest(); + if (isset($optionalArgs['name'])) { + $request->setName($optionalArgs['name']); + } + if (isset($optionalArgs['pageSize'])) { + $request->setPageSize($optionalArgs['pageSize']); + } + if (isset($optionalArgs['pageToken'])) { + $request->setPageToken($optionalArgs['pageToken']); + } + + $mergedSettings = $this->defaultCallSettings['listStrings']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'ListStrings', $mergedSettings, $this->descriptors['listStrings']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Adds comments to a book + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $comment = ""; + * $stage = Stage::UNSET; + * $alignment = Alignment::CHAR; + * $commentsElement = new Comment(); + * $commentsElement->setComment($comment); + * $commentsElement->setStage($stage); + * $commentsElement->setAlignment($alignment); + * $comments = [$commentsElement]; + * $libraryServiceClient->addComments($formattedName, $comments); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name + * @param Comment[] $comments + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function addComments($name, $comments, $optionalArgs = []) + { + $request = new AddCommentsRequest(); + $request->setName($name); + $request->setComments($comments); + + $mergedSettings = $this->defaultCallSettings['addComments']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'AddComments', $mergedSettings, $this->descriptors['addComments']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Gets a book from an archive. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatArchivedBookName("[ARCHIVE_PATH]", "[BOOK_ID]"); + * $response = $libraryServiceClient->getBookFromArchive($formattedName); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to retrieve. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\BookFromArchive + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function getBookFromArchive($name, $optionalArgs = []) + { + $request = new GetBookFromArchiveRequest(); + $request->setName($name); + + $mergedSettings = $this->defaultCallSettings['getBookFromArchive']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'GetBookFromArchive', $mergedSettings, $this->descriptors['getBookFromArchive']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Gets a book from a shelf or archive. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $formattedAltBookName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $response = $libraryServiceClient->getBookFromAnywhere($formattedName, $formattedAltBookName); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to retrieve. + * @param string $altBookName An alternate book name, used to test restricting flattened field to a + * single resource name type in a oneof. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\BookFromAnywhere + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function getBookFromAnywhere($name, $altBookName, $optionalArgs = []) + { + $request = new GetBookFromAnywhereRequest(); + $request->setName($name); + $request->setAltBookName($altBookName); + + $mergedSettings = $this->defaultCallSettings['getBookFromAnywhere']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'GetBookFromAnywhere', $mergedSettings, $this->descriptors['getBookFromAnywhere']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Test proper OneOf-Any resource name mapping + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $response = $libraryServiceClient->getBookFromAbsolutelyAnywhere($formattedName); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to retrieve. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\BookFromAnywhere + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function getBookFromAbsolutelyAnywhere($name, $optionalArgs = []) + { + $request = new GetBookFromAbsolutelyAnywhereRequest(); + $request->setName($name); + + $mergedSettings = $this->defaultCallSettings['getBookFromAbsolutelyAnywhere']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'GetBookFromAbsolutelyAnywhere', $mergedSettings, $this->descriptors['getBookFromAbsolutelyAnywhere']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Updates the index of a book. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $indexName = "default index"; + * $indexMapItem = ""; + * $indexMap = ["default_key" => $indexMapItem,]; + * $libraryServiceClient->updateBookIndex($formattedName, $indexName, $indexMap); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to update. + * @param string $indexName The name of the index for the book + * @param array $indexMap The index to update the book with + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function updateBookIndex($name, $indexName, $indexMap, $optionalArgs = []) + { + $request = new UpdateBookIndexRequest(); + $request->setName($name); + $request->setIndexName($indexName); + $request->setIndexMap($indexMap); + + $mergedSettings = $this->defaultCallSettings['updateBookIndex']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'UpdateBookIndex', $mergedSettings, $this->descriptors['updateBookIndex']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Test server streaming + * gRPC streaming methods don't have an HTTP equivalent and don't need to have the google.api.http option. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * + * // Read all responses until the stream is complete + * $stream = $libraryServiceClient->streamShelves(); + * foreach ($stream->readAll() as $element) { + * // doSomethingWith($element); + * } + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param array $optionalArgs { + * Optional. + * @type int $timeoutMillis + * Timeout to use for this call. + * } + * + * @return \Google\GAX\ServerStream + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function streamShelves($optionalArgs = []) + { + $request = new StreamShelvesRequest(); + + $mergedSettings = $this->defaultCallSettings['streamShelves']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'StreamShelves', $mergedSettings, $this->descriptors['streamShelves']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Test server streaming, non-paged responses. + * gRPC streaming methods don't have an HTTP equivalent and don't need to have the google.api.http option. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $name = ""; + * // Read all responses until the stream is complete + * $stream = $libraryServiceClient->streamBooks($name); + * foreach ($stream->readAll() as $element) { + * // doSomethingWith($element); + * } + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the shelf whose books we'd like to list. + * @param array $optionalArgs { + * Optional. + * @type int $timeoutMillis + * Timeout to use for this call. + * } + * + * @return \Google\GAX\ServerStream + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function streamBooks($name, $optionalArgs = []) + { + $request = new StreamBooksRequest(); + $request->setName($name); + + $mergedSettings = $this->defaultCallSettings['streamBooks']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'StreamBooks', $mergedSettings, $this->descriptors['streamBooks']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Test bidi-streaming. + * gRPC streaming methods don't have an HTTP equivalent and don't need to have the google.api.http option. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $name = ""; + * $request = new DiscussBookRequest(); + * $request->setName($name); + * $requests = [$request]; + * + * // Write all requests to the server, then read all responses until the + * // stream is complete + * $stream = $libraryServiceClient->discussBook(); + * $stream->writeAll($requests); + * foreach ($stream->closeWriteAndReadAll() as $element) { + * // doSomethingWith($element); + * } + * + * // OR write requests individually, making read() calls if + * // required. Call closeWrite() once writes are complete, and read the + * // remaining responses from the server. + * $stream = $libraryServiceClient->discussBook(); + * foreach ($requests as $request) { + * $stream->write($request); + * // if required, read a single response from the stream + * $element = $stream->read(); + * // doSomethingWith($element) + * } + * $stream->closeWrite(); + * $element = $stream->read(); + * while (!is_null($element)) { + * // doSomethingWith($element) + * $element = $stream->read(); + * } + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param array $optionalArgs { + * Optional. + * @type int $timeoutMillis + * Timeout to use for this call. + * } + * + * @return \Google\GAX\BidiStream + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function discussBook($optionalArgs = []) + { + $mergedSettings = $this->defaultCallSettings['discussBook']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'DiscussBook', $mergedSettings, $this->descriptors['discussBook']); + + return $callable( + null, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Test client streaming. + * gRPC streaming methods don't have an HTTP equivalent and don't need to have the google.api.http option. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $name = ""; + * $request = new DiscussBookRequest(); + * $request->setName($name); + * $requests = [$request]; + * + * // Write data to server and wait for a response + * $stream = $libraryServiceClient->monologAboutBook(); + * $result = $stream->writeAllAndReadResponse($requests); + * // doSomethingWith($result) + * + * // OR write data as it becomes available, then wait for a response + * $stream = $libraryServiceClient->monologAboutBook(); + * foreach ($requests as $request) { + * $stream->write($request); + * } + * $result = $stream->readResponse(); + * // doSomethingWith($result) + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param array $optionalArgs { + * Optional. + * @type int $timeoutMillis + * Timeout to use for this call. + * } + * + * @return \Google\GAX\ClientStream + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function monologAboutBook($optionalArgs = []) + { + $mergedSettings = $this->defaultCallSettings['monologAboutBook']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'MonologAboutBook', $mergedSettings, $this->descriptors['monologAboutBook']); + + return $callable( + null, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $namesElement = ""; + * $names = [$namesElement]; + * $shelves = []; + * // Iterate through all elements + * $pagedResponse = $libraryServiceClient->findRelatedBooks($names, $shelves); + * foreach ($pagedResponse->iterateAllElements() as $element) { + * // doSomethingWith($element); + * } + * + * // OR iterate over pages of elements, with the maximum page size set to 5 + * $pagedResponse = $libraryServiceClient->findRelatedBooks($names, $shelves, ['pageSize' => 5]); + * foreach ($pagedResponse->iteratePages() as $page) { + * foreach ($page as $element) { + * // doSomethingWith($element); + * } + * } + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string[] $names + * @param string[] $shelves + * @param array $optionalArgs { + * Optional. + * @type int $pageSize + * The maximum number of resources contained in the underlying API + * response. The API may return fewer values in a page, even if + * there are additional values to be retrieved. + * @type string $pageToken + * A page token is used to specify a page of values to be returned. + * If no page token is specified (the default), the first page + * of values will be returned. Any page token used here must have + * been generated by a previous call to the API. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\GAX\PagedListResponse + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function findRelatedBooks($names, $shelves, $optionalArgs = []) + { + $request = new FindRelatedBooksRequest(); + $request->setNames($names); + $request->setShelves($shelves); + if (isset($optionalArgs['pageSize'])) { + $request->setPageSize($optionalArgs['pageSize']); + } + if (isset($optionalArgs['pageToken'])) { + $request->setPageToken($optionalArgs['pageToken']); + } + + $mergedSettings = $this->defaultCallSettings['findRelatedBooks']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'FindRelatedBooks', $mergedSettings, $this->descriptors['findRelatedBooks']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Adds a tag to the book. This RPC is a mixin. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedResource = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $tag = ""; + * $response = $libraryServiceClient->addTag($formattedResource, $tag); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $resource REQUIRED: The resource which the tag is being added to. + * Resource is usually specified as a path, such as, + * projects/{project}/zones/{zone}/disks/{disk}. + * @param string $tag REQUIRED: The tag to add. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Tagger\V1\AddTagResponse + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function addTag($resource, $tag, $optionalArgs = []) + { + $request = new AddTagRequest(); + $request->setResource($resource); + $request->setTag($tag); + + $mergedSettings = $this->defaultCallSettings['addTag']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'AddTag', $mergedSettings, $this->descriptors['addTag']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Adds a label to the entity. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedResource = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $label = ""; + * $response = $libraryServiceClient->addLabel($formattedResource, $label); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $resource REQUIRED: The resource which the label is being added to. + * Resource is usually specified as a path, such as, + * projects/{project}/zones/{zone}/disks/{disk}. + * @param string $label REQUIRED: The label to add. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Tagger\V1\AddLabelResponse + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function addLabel($resource, $label, $optionalArgs = []) + { + $request = new AddLabelRequest(); + $request->setResource($resource); + $request->setLabel($label); + + $mergedSettings = $this->defaultCallSettings['addLabel']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->labelerStub, 'AddLabel', $mergedSettings, $this->descriptors['addLabel']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Test long-running operations + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $operationResponse = $libraryServiceClient->getBigBook($formattedName); + * $operationResponse->pollUntilComplete(); + * if ($operationResponse->operationSucceeded()) { + * $result = $operationResponse->getResult(); + * // doSomethingWith($result) + * } else { + * $error = $operationResponse->getError(); + * // handleError($error) + * } + * + * // OR start the operation, keep the operation name, and resume later + * $operationResponse = $libraryServiceClient->getBigBook($formattedName); + * $operationName = $operationResponse->getName(); + * // ... do other work + * $newOperationResponse = $libraryServiceClient->resumeOperation($operationName, 'getBigBook'); + * while (!$newOperationResponse->isDone()) { + * // ... do other work + * $newOperationResponse->reload(); + * } + * if ($newOperationResponse->operationSucceeded()) { + * $result = $newOperationResponse->getResult(); + * // doSomethingWith($result) + * } else { + * $error = $newOperationResponse->getError(); + * // handleError($error) + * } + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to retrieve. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Longrunning\Operation + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function getBigBook($name, $optionalArgs = []) + { + $request = new GetBookRequest(); + $request->setName($name); + + $mergedSettings = $this->defaultCallSettings['getBigBook']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'GetBigBook', $mergedSettings, $this->descriptors['getBigBook']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Test long-running operations with empty return type. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $operationResponse = $libraryServiceClient->getBigNothing($formattedName); + * $operationResponse->pollUntilComplete(); + * if ($operationResponse->operationSucceeded()) { + * // operation succeeded and returns no value + * } else { + * $error = $operationResponse->getError(); + * // handleError($error) + * } + * + * // OR start the operation, keep the operation name, and resume later + * $operationResponse = $libraryServiceClient->getBigNothing($formattedName); + * $operationName = $operationResponse->getName(); + * // ... do other work + * $newOperationResponse = $libraryServiceClient->resumeOperation($operationName, 'getBigNothing'); + * while (!$newOperationResponse->isDone()) { + * // ... do other work + * $newOperationResponse->reload(); + * } + * if ($newOperationResponse->operationSucceeded()) { + * // operation succeeded and returns no value + * } else { + * $error = $newOperationResponse->getError(); + * // handleError($error) + * } + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to retrieve. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Longrunning\Operation + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function getBigNothing($name, $optionalArgs = []) + { + $request = new GetBookRequest(); + $request->setName($name); + + $mergedSettings = $this->defaultCallSettings['getBigNothing']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'GetBigNothing', $mergedSettings, $this->descriptors['getBigNothing']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Test optional flattening parameters of all types + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $requiredSingularInt32 = 0; + * $requiredSingularInt64 = 0; + * $requiredSingularFloat = 0.0; + * $requiredSingularDouble = 0.0; + * $requiredSingularBool = false; + * $requiredSingularEnum = InnerEnum::ZERO; + * $requiredSingularString = ""; + * $requiredSingularBytes = ""; + * $requiredSingularMessage = new InnerMessage(); + * $requiredSingularResourceName = ""; + * $requiredSingularResourceNameOneof = ""; + * $requiredSingularFixed32 = 0; + * $requiredSingularFixed64 = 0; + * $requiredRepeatedInt32 = []; + * $requiredRepeatedInt64 = []; + * $requiredRepeatedFloat = []; + * $requiredRepeatedDouble = []; + * $requiredRepeatedBool = []; + * $requiredRepeatedEnum = []; + * $requiredRepeatedString = []; + * $requiredRepeatedBytes = []; + * $requiredRepeatedMessage = []; + * $formattedRequiredRepeatedResourceName = []; + * $formattedRequiredRepeatedResourceNameOneof = []; + * $requiredRepeatedFixed32 = []; + * $requiredRepeatedFixed64 = []; + * $requiredMap = []; + * $response = $libraryServiceClient->testOptionalRequiredFlatteningParams($requiredSingularInt32, $requiredSingularInt64, $requiredSingularFloat, $requiredSingularDouble, $requiredSingularBool, $requiredSingularEnum, $requiredSingularString, $requiredSingularBytes, $requiredSingularMessage, $requiredSingularResourceName, $requiredSingularResourceNameOneof, $requiredSingularFixed32, $requiredSingularFixed64, $requiredRepeatedInt32, $requiredRepeatedInt64, $requiredRepeatedFloat, $requiredRepeatedDouble, $requiredRepeatedBool, $requiredRepeatedEnum, $requiredRepeatedString, $requiredRepeatedBytes, $requiredRepeatedMessage, $formattedRequiredRepeatedResourceName, $formattedRequiredRepeatedResourceNameOneof, $requiredRepeatedFixed32, $requiredRepeatedFixed64, $requiredMap); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param int $requiredSingularInt32 + * @param int $requiredSingularInt64 + * @param float $requiredSingularFloat + * @param float $requiredSingularDouble + * @param bool $requiredSingularBool + * @param int $requiredSingularEnum For allowed values, use constants defined on {@see \Google\Example\Library\V1\TestOptionalRequiredFlatteningParamsRequest_InnerEnum} + * @param string $requiredSingularString + * @param string $requiredSingularBytes + * @param InnerMessage $requiredSingularMessage + * @param string $requiredSingularResourceName + * @param string $requiredSingularResourceNameOneof + * @param int $requiredSingularFixed32 + * @param int $requiredSingularFixed64 + * @param int[] $requiredRepeatedInt32 + * @param int[] $requiredRepeatedInt64 + * @param float[] $requiredRepeatedFloat + * @param float[] $requiredRepeatedDouble + * @param bool[] $requiredRepeatedBool + * @param int[] $requiredRepeatedEnum For allowed values, use constants defined on {@see \Google\Example\Library\V1\TestOptionalRequiredFlatteningParamsRequest_InnerEnum} + * @param string[] $requiredRepeatedString + * @param string[] $requiredRepeatedBytes + * @param InnerMessage[] $requiredRepeatedMessage + * @param string[] $requiredRepeatedResourceName + * @param string[] $requiredRepeatedResourceNameOneof + * @param int[] $requiredRepeatedFixed32 + * @param int[] $requiredRepeatedFixed64 + * @param array $requiredMap + * @param array $optionalArgs { + * Optional. + * @type int $optionalSingularInt32 + * @type int $optionalSingularInt64 + * @type float $optionalSingularFloat + * @type float $optionalSingularDouble + * @type bool $optionalSingularBool + * @type int $optionalSingularEnum + * For allowed values, use constants defined on {@see \Google\Example\Library\V1\TestOptionalRequiredFlatteningParamsRequest_InnerEnum} + * @type string $optionalSingularString + * @type string $optionalSingularBytes + * @type InnerMessage $optionalSingularMessage + * @type string $optionalSingularResourceName + * @type string $optionalSingularResourceNameOneof + * @type int $optionalSingularFixed32 + * @type int $optionalSingularFixed64 + * @type int[] $optionalRepeatedInt32 + * @type int[] $optionalRepeatedInt64 + * @type float[] $optionalRepeatedFloat + * @type float[] $optionalRepeatedDouble + * @type bool[] $optionalRepeatedBool + * @type int[] $optionalRepeatedEnum + * For allowed values, use constants defined on {@see \Google\Example\Library\V1\TestOptionalRequiredFlatteningParamsRequest_InnerEnum} + * @type string[] $optionalRepeatedString + * @type string[] $optionalRepeatedBytes + * @type InnerMessage[] $optionalRepeatedMessage + * @type string[] $optionalRepeatedResourceName + * @type string[] $optionalRepeatedResourceNameOneof + * @type int[] $optionalRepeatedFixed32 + * @type int[] $optionalRepeatedFixed64 + * @type array $optionalMap + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\TestOptionalRequiredFlatteningParamsResponse + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function testOptionalRequiredFlatteningParams($requiredSingularInt32, $requiredSingularInt64, $requiredSingularFloat, $requiredSingularDouble, $requiredSingularBool, $requiredSingularEnum, $requiredSingularString, $requiredSingularBytes, $requiredSingularMessage, $requiredSingularResourceName, $requiredSingularResourceNameOneof, $requiredSingularFixed32, $requiredSingularFixed64, $requiredRepeatedInt32, $requiredRepeatedInt64, $requiredRepeatedFloat, $requiredRepeatedDouble, $requiredRepeatedBool, $requiredRepeatedEnum, $requiredRepeatedString, $requiredRepeatedBytes, $requiredRepeatedMessage, $requiredRepeatedResourceName, $requiredRepeatedResourceNameOneof, $requiredRepeatedFixed32, $requiredRepeatedFixed64, $requiredMap, $optionalArgs = []) + { + $request = new TestOptionalRequiredFlatteningParamsRequest(); + $request->setRequiredSingularInt32($requiredSingularInt32); + $request->setRequiredSingularInt64($requiredSingularInt64); + $request->setRequiredSingularFloat($requiredSingularFloat); + $request->setRequiredSingularDouble($requiredSingularDouble); + $request->setRequiredSingularBool($requiredSingularBool); + $request->setRequiredSingularEnum($requiredSingularEnum); + $request->setRequiredSingularString($requiredSingularString); + $request->setRequiredSingularBytes($requiredSingularBytes); + $request->setRequiredSingularMessage($requiredSingularMessage); + $request->setRequiredSingularResourceName($requiredSingularResourceName); + $request->setRequiredSingularResourceNameOneof($requiredSingularResourceNameOneof); + $request->setRequiredSingularFixed32($requiredSingularFixed32); + $request->setRequiredSingularFixed64($requiredSingularFixed64); + $request->setRequiredRepeatedInt32($requiredRepeatedInt32); + $request->setRequiredRepeatedInt64($requiredRepeatedInt64); + $request->setRequiredRepeatedFloat($requiredRepeatedFloat); + $request->setRequiredRepeatedDouble($requiredRepeatedDouble); + $request->setRequiredRepeatedBool($requiredRepeatedBool); + $request->setRequiredRepeatedEnum($requiredRepeatedEnum); + $request->setRequiredRepeatedString($requiredRepeatedString); + $request->setRequiredRepeatedBytes($requiredRepeatedBytes); + $request->setRequiredRepeatedMessage($requiredRepeatedMessage); + $request->setRequiredRepeatedResourceName($requiredRepeatedResourceName); + $request->setRequiredRepeatedResourceNameOneof($requiredRepeatedResourceNameOneof); + $request->setRequiredRepeatedFixed32($requiredRepeatedFixed32); + $request->setRequiredRepeatedFixed64($requiredRepeatedFixed64); + $request->setRequiredMap($requiredMap); + if (isset($optionalArgs['optionalSingularInt32'])) { + $request->setOptionalSingularInt32($optionalArgs['optionalSingularInt32']); + } + if (isset($optionalArgs['optionalSingularInt64'])) { + $request->setOptionalSingularInt64($optionalArgs['optionalSingularInt64']); + } + if (isset($optionalArgs['optionalSingularFloat'])) { + $request->setOptionalSingularFloat($optionalArgs['optionalSingularFloat']); + } + if (isset($optionalArgs['optionalSingularDouble'])) { + $request->setOptionalSingularDouble($optionalArgs['optionalSingularDouble']); + } + if (isset($optionalArgs['optionalSingularBool'])) { + $request->setOptionalSingularBool($optionalArgs['optionalSingularBool']); + } + if (isset($optionalArgs['optionalSingularEnum'])) { + $request->setOptionalSingularEnum($optionalArgs['optionalSingularEnum']); + } + if (isset($optionalArgs['optionalSingularString'])) { + $request->setOptionalSingularString($optionalArgs['optionalSingularString']); + } + if (isset($optionalArgs['optionalSingularBytes'])) { + $request->setOptionalSingularBytes($optionalArgs['optionalSingularBytes']); + } + if (isset($optionalArgs['optionalSingularMessage'])) { + $request->setOptionalSingularMessage($optionalArgs['optionalSingularMessage']); + } + if (isset($optionalArgs['optionalSingularResourceName'])) { + $request->setOptionalSingularResourceName($optionalArgs['optionalSingularResourceName']); + } + if (isset($optionalArgs['optionalSingularResourceNameOneof'])) { + $request->setOptionalSingularResourceNameOneof($optionalArgs['optionalSingularResourceNameOneof']); + } + if (isset($optionalArgs['optionalSingularFixed32'])) { + $request->setOptionalSingularFixed32($optionalArgs['optionalSingularFixed32']); + } + if (isset($optionalArgs['optionalSingularFixed64'])) { + $request->setOptionalSingularFixed64($optionalArgs['optionalSingularFixed64']); + } + if (isset($optionalArgs['optionalRepeatedInt32'])) { + $request->setOptionalRepeatedInt32($optionalArgs['optionalRepeatedInt32']); + } + if (isset($optionalArgs['optionalRepeatedInt64'])) { + $request->setOptionalRepeatedInt64($optionalArgs['optionalRepeatedInt64']); + } + if (isset($optionalArgs['optionalRepeatedFloat'])) { + $request->setOptionalRepeatedFloat($optionalArgs['optionalRepeatedFloat']); + } + if (isset($optionalArgs['optionalRepeatedDouble'])) { + $request->setOptionalRepeatedDouble($optionalArgs['optionalRepeatedDouble']); + } + if (isset($optionalArgs['optionalRepeatedBool'])) { + $request->setOptionalRepeatedBool($optionalArgs['optionalRepeatedBool']); + } + if (isset($optionalArgs['optionalRepeatedEnum'])) { + $request->setOptionalRepeatedEnum($optionalArgs['optionalRepeatedEnum']); + } + if (isset($optionalArgs['optionalRepeatedString'])) { + $request->setOptionalRepeatedString($optionalArgs['optionalRepeatedString']); + } + if (isset($optionalArgs['optionalRepeatedBytes'])) { + $request->setOptionalRepeatedBytes($optionalArgs['optionalRepeatedBytes']); + } + if (isset($optionalArgs['optionalRepeatedMessage'])) { + $request->setOptionalRepeatedMessage($optionalArgs['optionalRepeatedMessage']); + } + if (isset($optionalArgs['optionalRepeatedResourceName'])) { + $request->setOptionalRepeatedResourceName($optionalArgs['optionalRepeatedResourceName']); + } + if (isset($optionalArgs['optionalRepeatedResourceNameOneof'])) { + $request->setOptionalRepeatedResourceNameOneof($optionalArgs['optionalRepeatedResourceNameOneof']); + } + if (isset($optionalArgs['optionalRepeatedFixed32'])) { + $request->setOptionalRepeatedFixed32($optionalArgs['optionalRepeatedFixed32']); + } + if (isset($optionalArgs['optionalRepeatedFixed64'])) { + $request->setOptionalRepeatedFixed64($optionalArgs['optionalRepeatedFixed64']); + } + if (isset($optionalArgs['optionalMap'])) { + $request->setOptionalMap($optionalArgs['optionalMap']); + } + + $mergedSettings = $this->defaultCallSettings['testOptionalRequiredFlatteningParams']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'TestOptionalRequiredFlatteningParams', $mergedSettings, $this->descriptors['testOptionalRequiredFlatteningParams']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Initiates an orderly shutdown in which preexisting calls continue but new + * calls are immediately cancelled. + * @experimental + */ + public function close() + { + $this->libraryServiceStub->close(); + $this->labelerStub->close(); + } + + private function createCredentialsCallback() + { + return $this->grpcCredentialsHelper->createCallCredentialsCallback(); + } +} diff --git a/src/test/java/com/google/api/codegen/testdata/php_main_impl_library.baseline b/src/test/java/com/google/api/codegen/testdata/php_main_impl_library.baseline new file mode 100644 index 0000000000..c11f139d31 --- /dev/null +++ b/src/test/java/com/google/api/codegen/testdata/php_main_impl_library.baseline @@ -0,0 +1,2353 @@ +============== file: src/Example/Library/V1/LibraryServiceGapic.php ============== +&"`'@. + * + * EXPERIMENTAL: this client library class has not yet been declared beta. This class may change + * more frequently than those which have been declared beta or 1.0, including changes which break + * backwards compatibility. + * + * 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: + * + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $shelf = new Shelf(); + * $response = $libraryServiceClient->createShelf($shelf); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * 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. + * @experimental + */ +class LibraryServiceGapic +{ + /** + * The default address of the service. + */ + const SERVICE_ADDRESS = 'library-example.googleapis.com'; + + /** + * The default port of the service. + */ + const DEFAULT_SERVICE_PORT = 443; + + /** + * The default timeout for non-retrying methods. + */ + const DEFAULT_TIMEOUT_MILLIS = 30000; + + /** + * The name of the code generator, to be included in the agent header. + */ + const CODEGEN_NAME = 'gapic'; + + /** + * The code generator version, to be included in the agent header. + */ + const CODEGEN_VERSION = '0.0.5'; + + private static $shelfNameTemplate; + private static $bookNameTemplate; + private static $returnNameTemplate; + + private $grpcCredentialsHelper; + private $libraryServiceStub; + private $labelerStub; + private $scopes; + private $defaultCallSettings; + private $descriptors; + private $operationsClient; + + /** + * Formats a string containing the fully-qualified path to represent + * a shelf resource. + * + * @param string $shelfId + * @return string The formatted shelf resource. + * @experimental + */ + public static function formatShelfName($shelfId) + { + return self::getShelfNameTemplate()->render([ + 'shelf_id' => $shelfId, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a book resource. + * + * @param string $shelfId + * @param string $bookId + * @return string The formatted book resource. + * @experimental + */ + public static function formatBookName($shelfId, $bookId) + { + return self::getBookNameTemplate()->render([ + 'shelf_id' => $shelfId, + 'book_id' => $bookId, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent + * a return resource. + * + * @param string $shelf + * @param string $book + * @param string $return + * @return string The formatted return resource. + * @experimental + */ + public static function formatReturnName($shelf, $book, $return) + { + return self::getReturnNameTemplate()->render([ + 'shelf' => $shelf, + 'book' => $book, + 'return' => $return, + ]); + } + + /** + * Parses the shelf_id from the given fully-qualified path which + * represents a shelf resource. + * + * @param string $shelfName The fully-qualified shelf resource. + * @return string The extracted shelf_id value. + * @experimental + */ + public static function parseShelfIdFromShelfName($shelfName) + { + return self::getShelfNameTemplate()->match($shelfName)['shelf_id']; + } + + /** + * Parses the shelf_id from the given fully-qualified path which + * represents a book resource. + * + * @param string $bookName The fully-qualified book resource. + * @return string The extracted shelf_id value. + * @experimental + */ + public static function parseShelfIdFromBookName($bookName) + { + return self::getBookNameTemplate()->match($bookName)['shelf_id']; + } + + /** + * Parses the book_id from the given fully-qualified path which + * represents a book resource. + * + * @param string $bookName The fully-qualified book resource. + * @return string The extracted book_id value. + * @experimental + */ + public static function parseBookIdFromBookName($bookName) + { + return self::getBookNameTemplate()->match($bookName)['book_id']; + } + + /** + * Parses the shelf from the given fully-qualified path which + * represents a return resource. + * + * @param string $returnName The fully-qualified return resource. + * @return string The extracted shelf value. + * @experimental + */ + public static function parseShelfFromReturnName($returnName) + { + return self::getReturnNameTemplate()->match($returnName)['shelf']; + } + + /** + * Parses the book from the given fully-qualified path which + * represents a return resource. + * + * @param string $returnName The fully-qualified return resource. + * @return string The extracted book value. + * @experimental + */ + public static function parseBookFromReturnName($returnName) + { + return self::getReturnNameTemplate()->match($returnName)['book']; + } + + /** + * Parses the return from the given fully-qualified path which + * represents a return resource. + * + * @param string $returnName The fully-qualified return resource. + * @return string The extracted return value. + * @experimental + */ + public static function parseReturnFromReturnName($returnName) + { + return self::getReturnNameTemplate()->match($returnName)['return']; + } + + + private static function getShelfNameTemplate() + { + if (self::$shelfNameTemplate == null) { + self::$shelfNameTemplate = new PathTemplate('shelves/{shelf_id}'); + } + + return self::$shelfNameTemplate; + } + + private static function getBookNameTemplate() + { + if (self::$bookNameTemplate == null) { + self::$bookNameTemplate = new PathTemplate('shelves/{shelf_id}/books/{book_id}'); + } + + return self::$bookNameTemplate; + } + + private static function getReturnNameTemplate() + { + if (self::$returnNameTemplate == null) { + self::$returnNameTemplate = new PathTemplate('shelves/{shelf}/books/{book}/returns/{return}'); + } + + return self::$returnNameTemplate; + } + + private static function getPageStreamingDescriptors() + { + $listShelvesPageStreamingDescriptor = + new PageStreamingDescriptor([ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getShelves', + ]); + $listBooksPageStreamingDescriptor = + new PageStreamingDescriptor([ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'requestPageSizeGetMethod' => 'getPageSize', + 'requestPageSizeSetMethod' => 'setPageSize', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getBooks', + ]); + $listStringsPageStreamingDescriptor = + new PageStreamingDescriptor([ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'requestPageSizeGetMethod' => 'getPageSize', + 'requestPageSizeSetMethod' => 'setPageSize', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getStrings', + ]); + $findRelatedBooksPageStreamingDescriptor = + new PageStreamingDescriptor([ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'requestPageSizeGetMethod' => 'getPageSize', + 'requestPageSizeSetMethod' => 'setPageSize', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getNames', + ]); + + $pageStreamingDescriptors = [ + 'listShelves' => $listShelvesPageStreamingDescriptor, + 'listBooks' => $listBooksPageStreamingDescriptor, + 'listStrings' => $listStringsPageStreamingDescriptor, + 'findRelatedBooks' => $findRelatedBooksPageStreamingDescriptor, + ]; + + return $pageStreamingDescriptors; + } + + private static function getLongRunningDescriptors() + { + return [ + 'getBigBook' => [ + 'operationReturnType' => '\Google\Example\Library\V1\Book', + 'metadataReturnType' => '\Google\Example\Library\V1\GetBigBookMetadata', + ], + 'getBigNothing' => [ + 'operationReturnType' => '\Google\Protobuf\GPBEmpty', + 'metadataReturnType' => '\Google\Example\Library\V1\GetBigBookMetadata', + ], + ]; + } + + private static function getGrpcStreamingDescriptors() + { + return [ + 'streamShelves' => [ + 'grpcStreamingType' => 'ServerStreaming', + 'resourcesGetMethod' => 'getShelves', + ], + 'streamBooks' => [ + 'grpcStreamingType' => 'ServerStreaming', + ], + 'discussBook' => [ + 'grpcStreamingType' => 'BidiStreaming', + ], + 'monologAboutBook' => [ + 'grpcStreamingType' => 'ClientStreaming', + ], + ]; + } + + private static function getGapicVersion() + { + if (file_exists(__DIR__ . "/../VERSION")) { + return trim(file_get_contents(__DIR__ . "/../VERSION")); + } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { + return \Google\Cloud\ServiceBuilder::VERSION; + } else { + return; + } + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return \Google\GAX\LongRunning\OperationsClient + * @experimental + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started + * by a long running API method. If $methodName is not provided, or does + * not match a long running API method, then the operation can still be + * resumed, but the OperationResponse object will not deserialize the + * final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * @return \Google\GAX\OperationResponse + * @experimental + */ + public function resumeOperation($operationName, $methodName = null) + { + $lroDescriptors = LibraryServiceGapic::getLongRunningDescriptors(); + if (!is_null($methodName) && array_key_exists($methodName, $lroDescriptors)) { + $options = $lroDescriptors[$methodName]; + } else { + $options = []; + } + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + // TODO(garrettjones): add channel (when supported in gRPC) + /** + * Constructor. + * + * @param array $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $serviceAddress The domain name of the API remote host. + * Default 'library-example.googleapis.com'. + * @type mixed $port The port on which to connect to the remote host. Default 443. + * @type \Grpc\ChannelCredentials $sslCreds + * A `ChannelCredentials` for use with an SSL-enabled channel. + * Default: a credentials object returned from + * \Grpc\ChannelCredentials::createSsl() + * @type array $scopes A string array of scopes to use when acquiring credentials. + * Default the scopes for the Google Example Library API. + * @type array $retryingOverride + * An associative array of string => RetryOptions, where the keys + * are method names (e.g. 'createFoo'), that overrides default retrying + * settings. A value of null indicates that the method in question should + * not retry. + * @type int $timeoutMillis The timeout in milliseconds to use for calls + * that don't use retries. For calls that use retries, + * set the timeout in RetryOptions. + * Default: 30000 (30 seconds) + * @type \Google\Auth\CredentialsLoader $credentialsLoader + * A CredentialsLoader object created using the + * Google\Auth library. + * } + * @experimental + */ + public function __construct($options = []) + { + $defaultOptions = [ + 'serviceAddress' => self::SERVICE_ADDRESS, + 'port' => self::DEFAULT_SERVICE_PORT, + 'scopes' => [ + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/library', + ], + 'retryingOverride' => null, + 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, + 'libName' => null, + 'libVersion' => null, + ]; + $options = array_merge($defaultOptions, $options); + + if (array_key_exists('operationsClient', $options)) { + $this->operationsClient = $options['operationsClient']; + } else { + $operationsClientOptions = $options; + unset($operationsClientOptions['timeoutMillis']); + unset($operationsClientOptions['retryingOverride']); + $this->operationsClient = new OperationsClient($operationsClientOptions); + } + + $gapicVersion = $options['libVersion'] ?: self::getGapicVersion(); + + $headerDescriptor = new AgentHeaderDescriptor([ + 'libName' => $options['libName'], + 'libVersion' => $options['libVersion'], + 'gapicVersion' => $gapicVersion, + ]); + + $defaultDescriptors = ['headerDescriptor' => $headerDescriptor]; + $this->descriptors = [ + 'createShelf' => $defaultDescriptors, + 'getShelf' => $defaultDescriptors, + 'listShelves' => $defaultDescriptors, + 'deleteShelf' => $defaultDescriptors, + 'mergeShelves' => $defaultDescriptors, + 'createBook' => $defaultDescriptors, + 'publishSeries' => $defaultDescriptors, + 'getBook' => $defaultDescriptors, + 'listBooks' => $defaultDescriptors, + 'deleteBook' => $defaultDescriptors, + 'updateBook' => $defaultDescriptors, + 'moveBook' => $defaultDescriptors, + 'listStrings' => $defaultDescriptors, + 'addComments' => $defaultDescriptors, + 'getBookFromArchive' => $defaultDescriptors, + 'getBookFromAnywhere' => $defaultDescriptors, + 'getBookFromAbsolutelyAnywhere' => $defaultDescriptors, + 'updateBookIndex' => $defaultDescriptors, + 'streamShelves' => $defaultDescriptors, + 'streamBooks' => $defaultDescriptors, + 'discussBook' => $defaultDescriptors, + 'monologAboutBook' => $defaultDescriptors, + 'findRelatedBooks' => $defaultDescriptors, + 'addTag' => $defaultDescriptors, + 'addLabel' => $defaultDescriptors, + 'getBigBook' => $defaultDescriptors, + 'getBigNothing' => $defaultDescriptors, + 'testOptionalRequiredFlatteningParams' => $defaultDescriptors, + ]; + $pageStreamingDescriptors = self::getPageStreamingDescriptors(); + foreach ($pageStreamingDescriptors as $method => $pageStreamingDescriptor) { + $this->descriptors[$method]['pageStreamingDescriptor'] = $pageStreamingDescriptor; + } + $longRunningDescriptors = self::getLongRunningDescriptors(); + foreach ($longRunningDescriptors as $method => $longRunningDescriptor) { + $this->descriptors[$method]['longRunningDescriptor'] = $longRunningDescriptor + ['operationsClient' => $this->operationsClient]; + } + $grpcStreamingDescriptors = self::getGrpcStreamingDescriptors(); + foreach ($grpcStreamingDescriptors as $method => $grpcStreamingDescriptor) { + $this->descriptors[$method]['grpcStreamingDescriptor'] = $grpcStreamingDescriptor; + } + + $clientConfigJsonString = file_get_contents(__DIR__ . '/resources/library_service_client_config.json'); + $clientConfig = json_decode($clientConfigJsonString, true); + $this->defaultCallSettings = + CallSettings::load('google.example.library.v1.LibraryService', + $clientConfig, + $options['retryingOverride'], + GrpcConstants::getStatusCodeNames(), + $options['timeoutMillis']); + + $this->scopes = $options['scopes']; + + $createStubOptions = []; + if (array_key_exists('sslCreds', $options)) { + $createStubOptions['sslCreds'] = $options['sslCreds']; + } + $grpcCredentialsHelperOptions = array_diff_key($options, $defaultOptions); + $this->grpcCredentialsHelper = new GrpcCredentialsHelper($this->scopes, $grpcCredentialsHelperOptions); + + $createLibraryServiceStubFunction = function ($hostname, $opts) { + return new LibraryServiceGrpcClient($hostname, $opts); + }; + if (array_key_exists('createLibraryServiceStubFunction', $options)) { + $createLibraryServiceStubFunction = $options['createLibraryServiceStubFunction']; + } + $this->libraryServiceStub = $this->grpcCredentialsHelper->createStub( + $createLibraryServiceStubFunction, + $options['serviceAddress'], + $options['port'], + $createStubOptions); + $createLabelerStubFunction = function ($hostname, $opts) { + return new LabelerGrpcClient($hostname, $opts); + }; + if (array_key_exists('createLabelerStubFunction', $options)) { + $createLabelerStubFunction = $options['createLabelerStubFunction']; + } + $this->labelerStub = $this->grpcCredentialsHelper->createStub( + $createLabelerStubFunction, + $options['serviceAddress'], + $options['port'], + $createStubOptions); + } + + /** + * Creates a shelf, and returns the new Shelf. + * RPC method comment may include special characters: <>&"`'@. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $shelf = new Shelf(); + * $response = $libraryServiceClient->createShelf($shelf); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param Shelf $shelf The shelf to create. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\Shelf + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function createShelf($shelf, $optionalArgs = []) + { + $request = new CreateShelfRequest(); + $request->setShelf($shelf); + + $mergedSettings = $this->defaultCallSettings['createShelf']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'CreateShelf', $mergedSettings, $this->descriptors['createShelf']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Gets a shelf. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); + * $options = ""; + * $response = $libraryServiceClient->getShelf($formattedName, $options); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the shelf to retrieve. + * @param string $options To test 'options' parameter name conflict. + * @param array $optionalArgs { + * Optional. + * @type SomeMessage $message + * Field to verify that message-type query parameter gets flattened. + * @type StringBuilder $stringBuilder + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\Shelf + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function getShelf($name, $options, $optionalArgs = []) + { + $request = new GetShelfRequest(); + $request->setName($name); + $request->setOptions($options); + if (isset($optionalArgs['message'])) { + $request->setMessage($optionalArgs['message']); + } + if (isset($optionalArgs['stringBuilder'])) { + $request->setStringBuilder($optionalArgs['stringBuilder']); + } + + $mergedSettings = $this->defaultCallSettings['getShelf']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'GetShelf', $mergedSettings, $this->descriptors['getShelf']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Lists shelves. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * + * // Iterate through all elements + * $pagedResponse = $libraryServiceClient->listShelves(); + * foreach ($pagedResponse->iterateAllElements() as $element) { + * // doSomethingWith($element); + * } + * + * // OR iterate over pages of elements, with the maximum page size set to 5 + * $pagedResponse = $libraryServiceClient->listShelves(['pageSize' => 5]); + * foreach ($pagedResponse->iteratePages() as $page) { + * foreach ($page as $element) { + * // doSomethingWith($element); + * } + * } + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param array $optionalArgs { + * Optional. + * @type string $pageToken + * A page token is used to specify a page of values to be returned. + * If no page token is specified (the default), the first page + * of values will be returned. Any page token used here must have + * been generated by a previous call to the API. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\GAX\PagedListResponse + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function listShelves($optionalArgs = []) + { + $request = new ListShelvesRequest(); + if (isset($optionalArgs['pageToken'])) { + $request->setPageToken($optionalArgs['pageToken']); + } + + $mergedSettings = $this->defaultCallSettings['listShelves']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'ListShelves', $mergedSettings, $this->descriptors['listShelves']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Deletes a shelf. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); + * $libraryServiceClient->deleteShelf($formattedName); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the shelf to delete. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function deleteShelf($name, $optionalArgs = []) + { + $request = new DeleteShelfRequest(); + $request->setName($name); + + $mergedSettings = $this->defaultCallSettings['deleteShelf']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'DeleteShelf', $mergedSettings, $this->descriptors['deleteShelf']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Merges two shelves by adding all books from the shelf named + * `other_shelf_name` to shelf `name`, and deletes + * `other_shelf_name`. Returns the updated shelf. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); + * $formattedOtherShelfName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); + * $response = $libraryServiceClient->mergeShelves($formattedName, $formattedOtherShelfName); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the shelf we're adding books to. + * @param string $otherShelfName The name of the shelf we're removing books from and deleting. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\Shelf + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function mergeShelves($name, $otherShelfName, $optionalArgs = []) + { + $request = new MergeShelvesRequest(); + $request->setName($name); + $request->setOtherShelfName($otherShelfName); + + $mergedSettings = $this->defaultCallSettings['mergeShelves']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'MergeShelves', $mergedSettings, $this->descriptors['mergeShelves']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Creates a book. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); + * $book = new Book(); + * $response = $libraryServiceClient->createBook($formattedName, $book); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the shelf in which the book is created. + * @param Book $book The book to create. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\Book + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function createBook($name, $book, $optionalArgs = []) + { + $request = new CreateBookRequest(); + $request->setName($name); + $request->setBook($book); + + $mergedSettings = $this->defaultCallSettings['createBook']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'CreateBook', $mergedSettings, $this->descriptors['createBook']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Creates a series of books. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $shelf = new Shelf(); + * $books = []; + * $seriesString = "foobar"; + * $seriesUuid = new SeriesUuid(); + * $seriesUuid->setSeriesString($seriesString); + * $response = $libraryServiceClient->publishSeries($shelf, $books, $seriesUuid); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param Shelf $shelf The shelf in which the series is created. + * @param Book[] $books The books to publish in the series. + * @param SeriesUuid $seriesUuid Uniquely identifies the series to the publishing house. + * @param array $optionalArgs { + * Optional. + * @type int $edition + * The edition of the series + * @type bool $reviewCopy + * If the book is in a pre-publish state + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\PublishSeriesResponse + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function publishSeries($shelf, $books, $seriesUuid, $optionalArgs = []) + { + $request = new PublishSeriesRequest(); + $request->setShelf($shelf); + $request->setBooks($books); + $request->setSeriesUuid($seriesUuid); + if (isset($optionalArgs['edition'])) { + $request->setEdition($optionalArgs['edition']); + } + if (isset($optionalArgs['reviewCopy'])) { + $request->setReviewCopy($optionalArgs['reviewCopy']); + } + + $mergedSettings = $this->defaultCallSettings['publishSeries']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'PublishSeries', $mergedSettings, $this->descriptors['publishSeries']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Gets a book. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $response = $libraryServiceClient->getBook($formattedName); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to retrieve. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\Book + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function getBook($name, $optionalArgs = []) + { + $request = new GetBookRequest(); + $request->setName($name); + + $mergedSettings = $this->defaultCallSettings['getBook']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'GetBook', $mergedSettings, $this->descriptors['getBook']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Lists books in a shelf. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); + * // Iterate through all elements + * $pagedResponse = $libraryServiceClient->listBooks($formattedName); + * foreach ($pagedResponse->iterateAllElements() as $element) { + * // doSomethingWith($element); + * } + * + * // OR iterate over pages of elements, with the maximum page size set to 5 + * $pagedResponse = $libraryServiceClient->listBooks($formattedName, ['pageSize' => 5]); + * foreach ($pagedResponse->iteratePages() as $page) { + * foreach ($page as $element) { + * // doSomethingWith($element); + * } + * } + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the shelf whose books we'd like to list. + * @param array $optionalArgs { + * Optional. + * @type int $pageSize + * The maximum number of resources contained in the underlying API + * response. The API may return fewer values in a page, even if + * there are additional values to be retrieved. + * @type string $pageToken + * A page token is used to specify a page of values to be returned. + * If no page token is specified (the default), the first page + * of values will be returned. Any page token used here must have + * been generated by a previous call to the API. + * @type string $filter + * To test python built-in wrapping. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\GAX\PagedListResponse + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function listBooks($name, $optionalArgs = []) + { + $request = new ListBooksRequest(); + $request->setName($name); + if (isset($optionalArgs['pageSize'])) { + $request->setPageSize($optionalArgs['pageSize']); + } + if (isset($optionalArgs['pageToken'])) { + $request->setPageToken($optionalArgs['pageToken']); + } + if (isset($optionalArgs['filter'])) { + $request->setFilter($optionalArgs['filter']); + } + + $mergedSettings = $this->defaultCallSettings['listBooks']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'ListBooks', $mergedSettings, $this->descriptors['listBooks']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Deletes a book. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $libraryServiceClient->deleteBook($formattedName); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to delete. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function deleteBook($name, $optionalArgs = []) + { + $request = new DeleteBookRequest(); + $request->setName($name); + + $mergedSettings = $this->defaultCallSettings['deleteBook']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'DeleteBook', $mergedSettings, $this->descriptors['deleteBook']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Updates a book. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $book = new Book(); + * $response = $libraryServiceClient->updateBook($formattedName, $book); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to update. + * @param Book $book The book to update with. + * @param array $optionalArgs { + * Optional. + * @type FieldMask $updateMask + * A field mask to apply, rendered as an HTTP parameter. + * @type \Google\Example\Library\V1\FieldMask $physicalMask + * To test Python import clash resolution. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\Book + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function updateBook($name, $book, $optionalArgs = []) + { + $request = new UpdateBookRequest(); + $request->setName($name); + $request->setBook($book); + if (isset($optionalArgs['updateMask'])) { + $request->setUpdateMask($optionalArgs['updateMask']); + } + if (isset($optionalArgs['physicalMask'])) { + $request->setPhysicalMask($optionalArgs['physicalMask']); + } + + $mergedSettings = $this->defaultCallSettings['updateBook']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'UpdateBook', $mergedSettings, $this->descriptors['updateBook']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Moves a book to another shelf, and returns the new book. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $formattedOtherShelfName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); + * $response = $libraryServiceClient->moveBook($formattedName, $formattedOtherShelfName); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to move. + * @param string $otherShelfName The name of the destination shelf. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\Book + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function moveBook($name, $otherShelfName, $optionalArgs = []) + { + $request = new MoveBookRequest(); + $request->setName($name); + $request->setOtherShelfName($otherShelfName); + + $mergedSettings = $this->defaultCallSettings['moveBook']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'MoveBook', $mergedSettings, $this->descriptors['moveBook']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Lists a primitive resource. To test go page streaming. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * + * // Iterate through all elements + * $pagedResponse = $libraryServiceClient->listStrings(); + * foreach ($pagedResponse->iterateAllElements() as $element) { + * // doSomethingWith($element); + * } + * + * // OR iterate over pages of elements, with the maximum page size set to 5 + * $pagedResponse = $libraryServiceClient->listStrings(['pageSize' => 5]); + * foreach ($pagedResponse->iteratePages() as $page) { + * foreach ($page as $element) { + * // doSomethingWith($element); + * } + * } + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param array $optionalArgs { + * Optional. + * @type string $name + * @type int $pageSize + * The maximum number of resources contained in the underlying API + * response. The API may return fewer values in a page, even if + * there are additional values to be retrieved. + * @type string $pageToken + * A page token is used to specify a page of values to be returned. + * If no page token is specified (the default), the first page + * of values will be returned. Any page token used here must have + * been generated by a previous call to the API. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\GAX\PagedListResponse + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function listStrings($optionalArgs = []) + { + $request = new ListStringsRequest(); + if (isset($optionalArgs['name'])) { + $request->setName($optionalArgs['name']); + } + if (isset($optionalArgs['pageSize'])) { + $request->setPageSize($optionalArgs['pageSize']); + } + if (isset($optionalArgs['pageToken'])) { + $request->setPageToken($optionalArgs['pageToken']); + } + + $mergedSettings = $this->defaultCallSettings['listStrings']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'ListStrings', $mergedSettings, $this->descriptors['listStrings']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Adds comments to a book + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $comment = ""; + * $stage = Stage::UNSET; + * $alignment = Alignment::CHAR; + * $commentsElement = new Comment(); + * $commentsElement->setComment($comment); + * $commentsElement->setStage($stage); + * $commentsElement->setAlignment($alignment); + * $comments = [$commentsElement]; + * $libraryServiceClient->addComments($formattedName, $comments); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name + * @param Comment[] $comments + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function addComments($name, $comments, $optionalArgs = []) + { + $request = new AddCommentsRequest(); + $request->setName($name); + $request->setComments($comments); + + $mergedSettings = $this->defaultCallSettings['addComments']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'AddComments', $mergedSettings, $this->descriptors['addComments']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Gets a book from an archive. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatArchivedBookName("[ARCHIVE_PATH]", "[BOOK_ID]"); + * $response = $libraryServiceClient->getBookFromArchive($formattedName); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to retrieve. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\BookFromArchive + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function getBookFromArchive($name, $optionalArgs = []) + { + $request = new GetBookFromArchiveRequest(); + $request->setName($name); + + $mergedSettings = $this->defaultCallSettings['getBookFromArchive']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'GetBookFromArchive', $mergedSettings, $this->descriptors['getBookFromArchive']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Gets a book from a shelf or archive. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $formattedAltBookName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $response = $libraryServiceClient->getBookFromAnywhere($formattedName, $formattedAltBookName); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to retrieve. + * @param string $altBookName An alternate book name, used to test restricting flattened field to a + * single resource name type in a oneof. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\BookFromAnywhere + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function getBookFromAnywhere($name, $altBookName, $optionalArgs = []) + { + $request = new GetBookFromAnywhereRequest(); + $request->setName($name); + $request->setAltBookName($altBookName); + + $mergedSettings = $this->defaultCallSettings['getBookFromAnywhere']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'GetBookFromAnywhere', $mergedSettings, $this->descriptors['getBookFromAnywhere']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Test proper OneOf-Any resource name mapping + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $response = $libraryServiceClient->getBookFromAbsolutelyAnywhere($formattedName); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to retrieve. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\BookFromAnywhere + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function getBookFromAbsolutelyAnywhere($name, $optionalArgs = []) + { + $request = new GetBookFromAbsolutelyAnywhereRequest(); + $request->setName($name); + + $mergedSettings = $this->defaultCallSettings['getBookFromAbsolutelyAnywhere']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'GetBookFromAbsolutelyAnywhere', $mergedSettings, $this->descriptors['getBookFromAbsolutelyAnywhere']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Updates the index of a book. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $indexName = "default index"; + * $indexMapItem = ""; + * $indexMap = ["default_key" => $indexMapItem,]; + * $libraryServiceClient->updateBookIndex($formattedName, $indexName, $indexMap); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to update. + * @param string $indexName The name of the index for the book + * @param array $indexMap The index to update the book with + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function updateBookIndex($name, $indexName, $indexMap, $optionalArgs = []) + { + $request = new UpdateBookIndexRequest(); + $request->setName($name); + $request->setIndexName($indexName); + $request->setIndexMap($indexMap); + + $mergedSettings = $this->defaultCallSettings['updateBookIndex']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'UpdateBookIndex', $mergedSettings, $this->descriptors['updateBookIndex']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Test server streaming + * gRPC streaming methods don't have an HTTP equivalent and don't need to have the google.api.http option. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * + * // Read all responses until the stream is complete + * $stream = $libraryServiceClient->streamShelves(); + * foreach ($stream->readAll() as $element) { + * // doSomethingWith($element); + * } + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param array $optionalArgs { + * Optional. + * @type int $timeoutMillis + * Timeout to use for this call. + * } + * + * @return \Google\GAX\ServerStream + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function streamShelves($optionalArgs = []) + { + $request = new StreamShelvesRequest(); + + $mergedSettings = $this->defaultCallSettings['streamShelves']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'StreamShelves', $mergedSettings, $this->descriptors['streamShelves']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Test server streaming, non-paged responses. + * gRPC streaming methods don't have an HTTP equivalent and don't need to have the google.api.http option. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $name = ""; + * // Read all responses until the stream is complete + * $stream = $libraryServiceClient->streamBooks($name); + * foreach ($stream->readAll() as $element) { + * // doSomethingWith($element); + * } + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the shelf whose books we'd like to list. + * @param array $optionalArgs { + * Optional. + * @type int $timeoutMillis + * Timeout to use for this call. + * } + * + * @return \Google\GAX\ServerStream + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function streamBooks($name, $optionalArgs = []) + { + $request = new StreamBooksRequest(); + $request->setName($name); + + $mergedSettings = $this->defaultCallSettings['streamBooks']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'StreamBooks', $mergedSettings, $this->descriptors['streamBooks']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Test bidi-streaming. + * gRPC streaming methods don't have an HTTP equivalent and don't need to have the google.api.http option. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $name = ""; + * $request = new DiscussBookRequest(); + * $request->setName($name); + * $requests = [$request]; + * + * // Write all requests to the server, then read all responses until the + * // stream is complete + * $stream = $libraryServiceClient->discussBook(); + * $stream->writeAll($requests); + * foreach ($stream->closeWriteAndReadAll() as $element) { + * // doSomethingWith($element); + * } + * + * // OR write requests individually, making read() calls if + * // required. Call closeWrite() once writes are complete, and read the + * // remaining responses from the server. + * $stream = $libraryServiceClient->discussBook(); + * foreach ($requests as $request) { + * $stream->write($request); + * // if required, read a single response from the stream + * $element = $stream->read(); + * // doSomethingWith($element) + * } + * $stream->closeWrite(); + * $element = $stream->read(); + * while (!is_null($element)) { + * // doSomethingWith($element) + * $element = $stream->read(); + * } + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param array $optionalArgs { + * Optional. + * @type int $timeoutMillis + * Timeout to use for this call. + * } + * + * @return \Google\GAX\BidiStream + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function discussBook($optionalArgs = []) + { + $mergedSettings = $this->defaultCallSettings['discussBook']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'DiscussBook', $mergedSettings, $this->descriptors['discussBook']); + + return $callable( + null, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Test client streaming. + * gRPC streaming methods don't have an HTTP equivalent and don't need to have the google.api.http option. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $name = ""; + * $request = new DiscussBookRequest(); + * $request->setName($name); + * $requests = [$request]; + * + * // Write data to server and wait for a response + * $stream = $libraryServiceClient->monologAboutBook(); + * $result = $stream->writeAllAndReadResponse($requests); + * // doSomethingWith($result) + * + * // OR write data as it becomes available, then wait for a response + * $stream = $libraryServiceClient->monologAboutBook(); + * foreach ($requests as $request) { + * $stream->write($request); + * } + * $result = $stream->readResponse(); + * // doSomethingWith($result) + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param array $optionalArgs { + * Optional. + * @type int $timeoutMillis + * Timeout to use for this call. + * } + * + * @return \Google\GAX\ClientStream + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function monologAboutBook($optionalArgs = []) + { + $mergedSettings = $this->defaultCallSettings['monologAboutBook']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'MonologAboutBook', $mergedSettings, $this->descriptors['monologAboutBook']); + + return $callable( + null, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $namesElement = ""; + * $names = [$namesElement]; + * $shelves = []; + * // Iterate through all elements + * $pagedResponse = $libraryServiceClient->findRelatedBooks($names, $shelves); + * foreach ($pagedResponse->iterateAllElements() as $element) { + * // doSomethingWith($element); + * } + * + * // OR iterate over pages of elements, with the maximum page size set to 5 + * $pagedResponse = $libraryServiceClient->findRelatedBooks($names, $shelves, ['pageSize' => 5]); + * foreach ($pagedResponse->iteratePages() as $page) { + * foreach ($page as $element) { + * // doSomethingWith($element); + * } + * } + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string[] $names + * @param string[] $shelves + * @param array $optionalArgs { + * Optional. + * @type int $pageSize + * The maximum number of resources contained in the underlying API + * response. The API may return fewer values in a page, even if + * there are additional values to be retrieved. + * @type string $pageToken + * A page token is used to specify a page of values to be returned. + * If no page token is specified (the default), the first page + * of values will be returned. Any page token used here must have + * been generated by a previous call to the API. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\GAX\PagedListResponse + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function findRelatedBooks($names, $shelves, $optionalArgs = []) + { + $request = new FindRelatedBooksRequest(); + $request->setNames($names); + $request->setShelves($shelves); + if (isset($optionalArgs['pageSize'])) { + $request->setPageSize($optionalArgs['pageSize']); + } + if (isset($optionalArgs['pageToken'])) { + $request->setPageToken($optionalArgs['pageToken']); + } + + $mergedSettings = $this->defaultCallSettings['findRelatedBooks']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'FindRelatedBooks', $mergedSettings, $this->descriptors['findRelatedBooks']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Adds a tag to the book. This RPC is a mixin. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedResource = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $tag = ""; + * $response = $libraryServiceClient->addTag($formattedResource, $tag); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $resource REQUIRED: The resource which the tag is being added to. + * Resource is usually specified as a path, such as, + * projects/{project}/zones/{zone}/disks/{disk}. + * @param string $tag REQUIRED: The tag to add. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Tagger\V1\AddTagResponse + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function addTag($resource, $tag, $optionalArgs = []) + { + $request = new AddTagRequest(); + $request->setResource($resource); + $request->setTag($tag); + + $mergedSettings = $this->defaultCallSettings['addTag']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'AddTag', $mergedSettings, $this->descriptors['addTag']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Adds a label to the entity. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedResource = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $label = ""; + * $response = $libraryServiceClient->addLabel($formattedResource, $label); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $resource REQUIRED: The resource which the label is being added to. + * Resource is usually specified as a path, such as, + * projects/{project}/zones/{zone}/disks/{disk}. + * @param string $label REQUIRED: The label to add. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Tagger\V1\AddLabelResponse + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function addLabel($resource, $label, $optionalArgs = []) + { + $request = new AddLabelRequest(); + $request->setResource($resource); + $request->setLabel($label); + + $mergedSettings = $this->defaultCallSettings['addLabel']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->labelerStub, 'AddLabel', $mergedSettings, $this->descriptors['addLabel']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Test long-running operations + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $operationResponse = $libraryServiceClient->getBigBook($formattedName); + * $operationResponse->pollUntilComplete(); + * if ($operationResponse->operationSucceeded()) { + * $result = $operationResponse->getResult(); + * // doSomethingWith($result) + * } else { + * $error = $operationResponse->getError(); + * // handleError($error) + * } + * + * // OR start the operation, keep the operation name, and resume later + * $operationResponse = $libraryServiceClient->getBigBook($formattedName); + * $operationName = $operationResponse->getName(); + * // ... do other work + * $newOperationResponse = $libraryServiceClient->resumeOperation($operationName, 'getBigBook'); + * while (!$newOperationResponse->isDone()) { + * // ... do other work + * $newOperationResponse->reload(); + * } + * if ($newOperationResponse->operationSucceeded()) { + * $result = $newOperationResponse->getResult(); + * // doSomethingWith($result) + * } else { + * $error = $newOperationResponse->getError(); + * // handleError($error) + * } + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to retrieve. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Longrunning\Operation + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function getBigBook($name, $optionalArgs = []) + { + $request = new GetBookRequest(); + $request->setName($name); + + $mergedSettings = $this->defaultCallSettings['getBigBook']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'GetBigBook', $mergedSettings, $this->descriptors['getBigBook']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Test long-running operations with empty return type. + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); + * $operationResponse = $libraryServiceClient->getBigNothing($formattedName); + * $operationResponse->pollUntilComplete(); + * if ($operationResponse->operationSucceeded()) { + * // operation succeeded and returns no value + * } else { + * $error = $operationResponse->getError(); + * // handleError($error) + * } + * + * // OR start the operation, keep the operation name, and resume later + * $operationResponse = $libraryServiceClient->getBigNothing($formattedName); + * $operationName = $operationResponse->getName(); + * // ... do other work + * $newOperationResponse = $libraryServiceClient->resumeOperation($operationName, 'getBigNothing'); + * while (!$newOperationResponse->isDone()) { + * // ... do other work + * $newOperationResponse->reload(); + * } + * if ($newOperationResponse->operationSucceeded()) { + * // operation succeeded and returns no value + * } else { + * $error = $newOperationResponse->getError(); + * // handleError($error) + * } + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param string $name The name of the book to retrieve. + * @param array $optionalArgs { + * Optional. + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Longrunning\Operation + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function getBigNothing($name, $optionalArgs = []) + { + $request = new GetBookRequest(); + $request->setName($name); + + $mergedSettings = $this->defaultCallSettings['getBigNothing']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'GetBigNothing', $mergedSettings, $this->descriptors['getBigNothing']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Test optional flattening parameters of all types + * + * Sample code: + * ``` + * try { + * $libraryServiceClient = new LibraryServiceClient(); + * $requiredSingularInt32 = 0; + * $requiredSingularInt64 = 0; + * $requiredSingularFloat = 0.0; + * $requiredSingularDouble = 0.0; + * $requiredSingularBool = false; + * $requiredSingularEnum = InnerEnum::ZERO; + * $requiredSingularString = ""; + * $requiredSingularBytes = ""; + * $requiredSingularMessage = new InnerMessage(); + * $requiredSingularResourceName = ""; + * $requiredSingularResourceNameOneof = ""; + * $requiredSingularFixed32 = 0; + * $requiredSingularFixed64 = 0; + * $requiredRepeatedInt32 = []; + * $requiredRepeatedInt64 = []; + * $requiredRepeatedFloat = []; + * $requiredRepeatedDouble = []; + * $requiredRepeatedBool = []; + * $requiredRepeatedEnum = []; + * $requiredRepeatedString = []; + * $requiredRepeatedBytes = []; + * $requiredRepeatedMessage = []; + * $formattedRequiredRepeatedResourceName = []; + * $formattedRequiredRepeatedResourceNameOneof = []; + * $requiredRepeatedFixed32 = []; + * $requiredRepeatedFixed64 = []; + * $requiredMap = []; + * $response = $libraryServiceClient->testOptionalRequiredFlatteningParams($requiredSingularInt32, $requiredSingularInt64, $requiredSingularFloat, $requiredSingularDouble, $requiredSingularBool, $requiredSingularEnum, $requiredSingularString, $requiredSingularBytes, $requiredSingularMessage, $requiredSingularResourceName, $requiredSingularResourceNameOneof, $requiredSingularFixed32, $requiredSingularFixed64, $requiredRepeatedInt32, $requiredRepeatedInt64, $requiredRepeatedFloat, $requiredRepeatedDouble, $requiredRepeatedBool, $requiredRepeatedEnum, $requiredRepeatedString, $requiredRepeatedBytes, $requiredRepeatedMessage, $formattedRequiredRepeatedResourceName, $formattedRequiredRepeatedResourceNameOneof, $requiredRepeatedFixed32, $requiredRepeatedFixed64, $requiredMap); + * } finally { + * $libraryServiceClient->close(); + * } + * ``` + * + * @param int $requiredSingularInt32 + * @param int $requiredSingularInt64 + * @param float $requiredSingularFloat + * @param float $requiredSingularDouble + * @param bool $requiredSingularBool + * @param int $requiredSingularEnum For allowed values, use constants defined on {@see \Google\Example\Library\V1\TestOptionalRequiredFlatteningParamsRequest_InnerEnum} + * @param string $requiredSingularString + * @param string $requiredSingularBytes + * @param InnerMessage $requiredSingularMessage + * @param string $requiredSingularResourceName + * @param string $requiredSingularResourceNameOneof + * @param int $requiredSingularFixed32 + * @param int $requiredSingularFixed64 + * @param int[] $requiredRepeatedInt32 + * @param int[] $requiredRepeatedInt64 + * @param float[] $requiredRepeatedFloat + * @param float[] $requiredRepeatedDouble + * @param bool[] $requiredRepeatedBool + * @param int[] $requiredRepeatedEnum For allowed values, use constants defined on {@see \Google\Example\Library\V1\TestOptionalRequiredFlatteningParamsRequest_InnerEnum} + * @param string[] $requiredRepeatedString + * @param string[] $requiredRepeatedBytes + * @param InnerMessage[] $requiredRepeatedMessage + * @param string[] $requiredRepeatedResourceName + * @param string[] $requiredRepeatedResourceNameOneof + * @param int[] $requiredRepeatedFixed32 + * @param int[] $requiredRepeatedFixed64 + * @param array $requiredMap + * @param array $optionalArgs { + * Optional. + * @type int $optionalSingularInt32 + * @type int $optionalSingularInt64 + * @type float $optionalSingularFloat + * @type float $optionalSingularDouble + * @type bool $optionalSingularBool + * @type int $optionalSingularEnum + * For allowed values, use constants defined on {@see \Google\Example\Library\V1\TestOptionalRequiredFlatteningParamsRequest_InnerEnum} + * @type string $optionalSingularString + * @type string $optionalSingularBytes + * @type InnerMessage $optionalSingularMessage + * @type string $optionalSingularResourceName + * @type string $optionalSingularResourceNameOneof + * @type int $optionalSingularFixed32 + * @type int $optionalSingularFixed64 + * @type int[] $optionalRepeatedInt32 + * @type int[] $optionalRepeatedInt64 + * @type float[] $optionalRepeatedFloat + * @type float[] $optionalRepeatedDouble + * @type bool[] $optionalRepeatedBool + * @type int[] $optionalRepeatedEnum + * For allowed values, use constants defined on {@see \Google\Example\Library\V1\TestOptionalRequiredFlatteningParamsRequest_InnerEnum} + * @type string[] $optionalRepeatedString + * @type string[] $optionalRepeatedBytes + * @type InnerMessage[] $optionalRepeatedMessage + * @type string[] $optionalRepeatedResourceName + * @type string[] $optionalRepeatedResourceNameOneof + * @type int[] $optionalRepeatedFixed32 + * @type int[] $optionalRepeatedFixed64 + * @type array $optionalMap + * @type \Google\GAX\RetrySettings $retrySettings + * Retry settings to use for this call. If present, then + * $timeoutMillis is ignored. + * @type int $timeoutMillis + * Timeout to use for this call. Only used if $retrySettings + * is not set. + * } + * + * @return \Google\Example\Library\V1\TestOptionalRequiredFlatteningParamsResponse + * + * @throws \Google\GAX\ApiException if the remote call fails + * @experimental + */ + public function testOptionalRequiredFlatteningParams($requiredSingularInt32, $requiredSingularInt64, $requiredSingularFloat, $requiredSingularDouble, $requiredSingularBool, $requiredSingularEnum, $requiredSingularString, $requiredSingularBytes, $requiredSingularMessage, $requiredSingularResourceName, $requiredSingularResourceNameOneof, $requiredSingularFixed32, $requiredSingularFixed64, $requiredRepeatedInt32, $requiredRepeatedInt64, $requiredRepeatedFloat, $requiredRepeatedDouble, $requiredRepeatedBool, $requiredRepeatedEnum, $requiredRepeatedString, $requiredRepeatedBytes, $requiredRepeatedMessage, $requiredRepeatedResourceName, $requiredRepeatedResourceNameOneof, $requiredRepeatedFixed32, $requiredRepeatedFixed64, $requiredMap, $optionalArgs = []) + { + $request = new TestOptionalRequiredFlatteningParamsRequest(); + $request->setRequiredSingularInt32($requiredSingularInt32); + $request->setRequiredSingularInt64($requiredSingularInt64); + $request->setRequiredSingularFloat($requiredSingularFloat); + $request->setRequiredSingularDouble($requiredSingularDouble); + $request->setRequiredSingularBool($requiredSingularBool); + $request->setRequiredSingularEnum($requiredSingularEnum); + $request->setRequiredSingularString($requiredSingularString); + $request->setRequiredSingularBytes($requiredSingularBytes); + $request->setRequiredSingularMessage($requiredSingularMessage); + $request->setRequiredSingularResourceName($requiredSingularResourceName); + $request->setRequiredSingularResourceNameOneof($requiredSingularResourceNameOneof); + $request->setRequiredSingularFixed32($requiredSingularFixed32); + $request->setRequiredSingularFixed64($requiredSingularFixed64); + $request->setRequiredRepeatedInt32($requiredRepeatedInt32); + $request->setRequiredRepeatedInt64($requiredRepeatedInt64); + $request->setRequiredRepeatedFloat($requiredRepeatedFloat); + $request->setRequiredRepeatedDouble($requiredRepeatedDouble); + $request->setRequiredRepeatedBool($requiredRepeatedBool); + $request->setRequiredRepeatedEnum($requiredRepeatedEnum); + $request->setRequiredRepeatedString($requiredRepeatedString); + $request->setRequiredRepeatedBytes($requiredRepeatedBytes); + $request->setRequiredRepeatedMessage($requiredRepeatedMessage); + $request->setRequiredRepeatedResourceName($requiredRepeatedResourceName); + $request->setRequiredRepeatedResourceNameOneof($requiredRepeatedResourceNameOneof); + $request->setRequiredRepeatedFixed32($requiredRepeatedFixed32); + $request->setRequiredRepeatedFixed64($requiredRepeatedFixed64); + $request->setRequiredMap($requiredMap); + if (isset($optionalArgs['optionalSingularInt32'])) { + $request->setOptionalSingularInt32($optionalArgs['optionalSingularInt32']); + } + if (isset($optionalArgs['optionalSingularInt64'])) { + $request->setOptionalSingularInt64($optionalArgs['optionalSingularInt64']); + } + if (isset($optionalArgs['optionalSingularFloat'])) { + $request->setOptionalSingularFloat($optionalArgs['optionalSingularFloat']); + } + if (isset($optionalArgs['optionalSingularDouble'])) { + $request->setOptionalSingularDouble($optionalArgs['optionalSingularDouble']); + } + if (isset($optionalArgs['optionalSingularBool'])) { + $request->setOptionalSingularBool($optionalArgs['optionalSingularBool']); + } + if (isset($optionalArgs['optionalSingularEnum'])) { + $request->setOptionalSingularEnum($optionalArgs['optionalSingularEnum']); + } + if (isset($optionalArgs['optionalSingularString'])) { + $request->setOptionalSingularString($optionalArgs['optionalSingularString']); + } + if (isset($optionalArgs['optionalSingularBytes'])) { + $request->setOptionalSingularBytes($optionalArgs['optionalSingularBytes']); + } + if (isset($optionalArgs['optionalSingularMessage'])) { + $request->setOptionalSingularMessage($optionalArgs['optionalSingularMessage']); + } + if (isset($optionalArgs['optionalSingularResourceName'])) { + $request->setOptionalSingularResourceName($optionalArgs['optionalSingularResourceName']); + } + if (isset($optionalArgs['optionalSingularResourceNameOneof'])) { + $request->setOptionalSingularResourceNameOneof($optionalArgs['optionalSingularResourceNameOneof']); + } + if (isset($optionalArgs['optionalSingularFixed32'])) { + $request->setOptionalSingularFixed32($optionalArgs['optionalSingularFixed32']); + } + if (isset($optionalArgs['optionalSingularFixed64'])) { + $request->setOptionalSingularFixed64($optionalArgs['optionalSingularFixed64']); + } + if (isset($optionalArgs['optionalRepeatedInt32'])) { + $request->setOptionalRepeatedInt32($optionalArgs['optionalRepeatedInt32']); + } + if (isset($optionalArgs['optionalRepeatedInt64'])) { + $request->setOptionalRepeatedInt64($optionalArgs['optionalRepeatedInt64']); + } + if (isset($optionalArgs['optionalRepeatedFloat'])) { + $request->setOptionalRepeatedFloat($optionalArgs['optionalRepeatedFloat']); + } + if (isset($optionalArgs['optionalRepeatedDouble'])) { + $request->setOptionalRepeatedDouble($optionalArgs['optionalRepeatedDouble']); + } + if (isset($optionalArgs['optionalRepeatedBool'])) { + $request->setOptionalRepeatedBool($optionalArgs['optionalRepeatedBool']); + } + if (isset($optionalArgs['optionalRepeatedEnum'])) { + $request->setOptionalRepeatedEnum($optionalArgs['optionalRepeatedEnum']); + } + if (isset($optionalArgs['optionalRepeatedString'])) { + $request->setOptionalRepeatedString($optionalArgs['optionalRepeatedString']); + } + if (isset($optionalArgs['optionalRepeatedBytes'])) { + $request->setOptionalRepeatedBytes($optionalArgs['optionalRepeatedBytes']); + } + if (isset($optionalArgs['optionalRepeatedMessage'])) { + $request->setOptionalRepeatedMessage($optionalArgs['optionalRepeatedMessage']); + } + if (isset($optionalArgs['optionalRepeatedResourceName'])) { + $request->setOptionalRepeatedResourceName($optionalArgs['optionalRepeatedResourceName']); + } + if (isset($optionalArgs['optionalRepeatedResourceNameOneof'])) { + $request->setOptionalRepeatedResourceNameOneof($optionalArgs['optionalRepeatedResourceNameOneof']); + } + if (isset($optionalArgs['optionalRepeatedFixed32'])) { + $request->setOptionalRepeatedFixed32($optionalArgs['optionalRepeatedFixed32']); + } + if (isset($optionalArgs['optionalRepeatedFixed64'])) { + $request->setOptionalRepeatedFixed64($optionalArgs['optionalRepeatedFixed64']); + } + if (isset($optionalArgs['optionalMap'])) { + $request->setOptionalMap($optionalArgs['optionalMap']); + } + + $mergedSettings = $this->defaultCallSettings['testOptionalRequiredFlatteningParams']->merge( + new CallSettings($optionalArgs)); + $callable = ApiCallable::createApiCall( + $this->libraryServiceStub, 'TestOptionalRequiredFlatteningParams', $mergedSettings, $this->descriptors['testOptionalRequiredFlatteningParams']); + + return $callable( + $request, + [], + ['call_credentials_callback' => $this->createCredentialsCallback()]); + } + + /** + * Initiates an orderly shutdown in which preexisting calls continue but new + * calls are immediately cancelled. + * @experimental + */ + public function close() + { + $this->libraryServiceStub->close(); + $this->labelerStub->close(); + } + + private function createCredentialsCallback() + { + return $this->grpcCredentialsHelper->createCallCredentialsCallback(); + } +} diff --git a/src/test/java/com/google/api/codegen/testdata/php_main_library.baseline b/src/test/java/com/google/api/codegen/testdata/php_main_library.baseline index 94b09065af..8ad67f3965 100644 --- a/src/test/java/com/google/api/codegen/testdata/php_main_library.baseline +++ b/src/test/java/com/google/api/codegen/testdata/php_main_library.baseline @@ -84,2270 +84,9 @@ use Google\Tagger\V1\AddTagRequest; use Google\Tagger\V1\LabelerGrpcClient; /** - * Service Description: This API represents a simple digital library. It lets you manage Shelf - * resources and Book resources in the library. It defines the following - * resource model: - * - * - The API has a collection of [Shelf][google.example.library.v1.Shelf] - * resources, named ``bookShelves/*`` - * - * - Each Shelf has a collection of [Book][google.example.library.v1.Book] - * resources, named `bookShelves/*/books/*` - * - * Check out [cloud docs!](https://cloud.google.com/library/example/link). - * This is [not a cloud link](http://www.google.com). - * - * Service comment may include special characters: <>&"`'@. - * - * EXPERIMENTAL: this client library class has not yet been declared beta. This class may change - * more frequently than those which have been declared beta or 1.0, including changes which break - * backwards compatibility. - * - * 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: - * - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $shelf = new Shelf(); - * $response = $libraryServiceClient->createShelf($shelf); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * 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. - * @experimental + * {@inheritdoc} */ -class LibraryServiceClient +class LibraryServiceClient extends LibraryServiceGapic { - /** - * The default address of the service. - */ - const SERVICE_ADDRESS = 'library-example.googleapis.com'; - - /** - * The default port of the service. - */ - const DEFAULT_SERVICE_PORT = 443; - - /** - * The default timeout for non-retrying methods. - */ - const DEFAULT_TIMEOUT_MILLIS = 30000; - - /** - * The name of the code generator, to be included in the agent header. - */ - const CODEGEN_NAME = 'gapic'; - - /** - * The code generator version, to be included in the agent header. - */ - const CODEGEN_VERSION = '0.0.5'; - - private static $shelfNameTemplate; - private static $bookNameTemplate; - private static $returnNameTemplate; - - private $grpcCredentialsHelper; - private $libraryServiceStub; - private $labelerStub; - private $scopes; - private $defaultCallSettings; - private $descriptors; - private $operationsClient; - - /** - * Formats a string containing the fully-qualified path to represent - * a shelf resource. - * - * @param string $shelfId - * @return string The formatted shelf resource. - * @experimental - */ - public static function formatShelfName($shelfId) - { - return self::getShelfNameTemplate()->render([ - 'shelf_id' => $shelfId, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a book resource. - * - * @param string $shelfId - * @param string $bookId - * @return string The formatted book resource. - * @experimental - */ - public static function formatBookName($shelfId, $bookId) - { - return self::getBookNameTemplate()->render([ - 'shelf_id' => $shelfId, - 'book_id' => $bookId, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent - * a return resource. - * - * @param string $shelf - * @param string $book - * @param string $return - * @return string The formatted return resource. - * @experimental - */ - public static function formatReturnName($shelf, $book, $return) - { - return self::getReturnNameTemplate()->render([ - 'shelf' => $shelf, - 'book' => $book, - 'return' => $return, - ]); - } - - /** - * Parses the shelf_id from the given fully-qualified path which - * represents a shelf resource. - * - * @param string $shelfName The fully-qualified shelf resource. - * @return string The extracted shelf_id value. - * @experimental - */ - public static function parseShelfIdFromShelfName($shelfName) - { - return self::getShelfNameTemplate()->match($shelfName)['shelf_id']; - } - - /** - * Parses the shelf_id from the given fully-qualified path which - * represents a book resource. - * - * @param string $bookName The fully-qualified book resource. - * @return string The extracted shelf_id value. - * @experimental - */ - public static function parseShelfIdFromBookName($bookName) - { - return self::getBookNameTemplate()->match($bookName)['shelf_id']; - } - - /** - * Parses the book_id from the given fully-qualified path which - * represents a book resource. - * - * @param string $bookName The fully-qualified book resource. - * @return string The extracted book_id value. - * @experimental - */ - public static function parseBookIdFromBookName($bookName) - { - return self::getBookNameTemplate()->match($bookName)['book_id']; - } - - /** - * Parses the shelf from the given fully-qualified path which - * represents a return resource. - * - * @param string $returnName The fully-qualified return resource. - * @return string The extracted shelf value. - * @experimental - */ - public static function parseShelfFromReturnName($returnName) - { - return self::getReturnNameTemplate()->match($returnName)['shelf']; - } - - /** - * Parses the book from the given fully-qualified path which - * represents a return resource. - * - * @param string $returnName The fully-qualified return resource. - * @return string The extracted book value. - * @experimental - */ - public static function parseBookFromReturnName($returnName) - { - return self::getReturnNameTemplate()->match($returnName)['book']; - } - - /** - * Parses the return from the given fully-qualified path which - * represents a return resource. - * - * @param string $returnName The fully-qualified return resource. - * @return string The extracted return value. - * @experimental - */ - public static function parseReturnFromReturnName($returnName) - { - return self::getReturnNameTemplate()->match($returnName)['return']; - } - - - private static function getShelfNameTemplate() - { - if (self::$shelfNameTemplate == null) { - self::$shelfNameTemplate = new PathTemplate('shelves/{shelf_id}'); - } - - return self::$shelfNameTemplate; - } - - private static function getBookNameTemplate() - { - if (self::$bookNameTemplate == null) { - self::$bookNameTemplate = new PathTemplate('shelves/{shelf_id}/books/{book_id}'); - } - - return self::$bookNameTemplate; - } - - private static function getReturnNameTemplate() - { - if (self::$returnNameTemplate == null) { - self::$returnNameTemplate = new PathTemplate('shelves/{shelf}/books/{book}/returns/{return}'); - } - - return self::$returnNameTemplate; - } - - private static function getPageStreamingDescriptors() - { - $listShelvesPageStreamingDescriptor = - new PageStreamingDescriptor([ - 'requestPageTokenGetMethod' => 'getPageToken', - 'requestPageTokenSetMethod' => 'setPageToken', - 'responsePageTokenGetMethod' => 'getNextPageToken', - 'resourcesGetMethod' => 'getShelves', - ]); - $listBooksPageStreamingDescriptor = - new PageStreamingDescriptor([ - 'requestPageTokenGetMethod' => 'getPageToken', - 'requestPageTokenSetMethod' => 'setPageToken', - 'requestPageSizeGetMethod' => 'getPageSize', - 'requestPageSizeSetMethod' => 'setPageSize', - 'responsePageTokenGetMethod' => 'getNextPageToken', - 'resourcesGetMethod' => 'getBooks', - ]); - $listStringsPageStreamingDescriptor = - new PageStreamingDescriptor([ - 'requestPageTokenGetMethod' => 'getPageToken', - 'requestPageTokenSetMethod' => 'setPageToken', - 'requestPageSizeGetMethod' => 'getPageSize', - 'requestPageSizeSetMethod' => 'setPageSize', - 'responsePageTokenGetMethod' => 'getNextPageToken', - 'resourcesGetMethod' => 'getStrings', - ]); - $findRelatedBooksPageStreamingDescriptor = - new PageStreamingDescriptor([ - 'requestPageTokenGetMethod' => 'getPageToken', - 'requestPageTokenSetMethod' => 'setPageToken', - 'requestPageSizeGetMethod' => 'getPageSize', - 'requestPageSizeSetMethod' => 'setPageSize', - 'responsePageTokenGetMethod' => 'getNextPageToken', - 'resourcesGetMethod' => 'getNames', - ]); - - $pageStreamingDescriptors = [ - 'listShelves' => $listShelvesPageStreamingDescriptor, - 'listBooks' => $listBooksPageStreamingDescriptor, - 'listStrings' => $listStringsPageStreamingDescriptor, - 'findRelatedBooks' => $findRelatedBooksPageStreamingDescriptor, - ]; - - return $pageStreamingDescriptors; - } - - private static function getLongRunningDescriptors() - { - return [ - 'getBigBook' => [ - 'operationReturnType' => '\Google\Example\Library\V1\Book', - 'metadataReturnType' => '\Google\Example\Library\V1\GetBigBookMetadata', - ], - 'getBigNothing' => [ - 'operationReturnType' => '\Google\Protobuf\GPBEmpty', - 'metadataReturnType' => '\Google\Example\Library\V1\GetBigBookMetadata', - ], - ]; - } - - private static function getGrpcStreamingDescriptors() - { - return [ - 'streamShelves' => [ - 'grpcStreamingType' => 'ServerStreaming', - 'resourcesGetMethod' => 'getShelves', - ], - 'streamBooks' => [ - 'grpcStreamingType' => 'ServerStreaming', - ], - 'discussBook' => [ - 'grpcStreamingType' => 'BidiStreaming', - ], - 'monologAboutBook' => [ - 'grpcStreamingType' => 'ClientStreaming', - ], - ]; - } - - private static function getGapicVersion() - { - if (file_exists(__DIR__ . "/../VERSION")) { - return trim(file_get_contents(__DIR__ . "/../VERSION")); - } elseif (class_exists('\Google\Cloud\ServiceBuilder')) { - return \Google\Cloud\ServiceBuilder::VERSION; - } else { - return; - } - } - - /** - * Return an OperationsClient object with the same endpoint as $this. - * - * @return \Google\GAX\LongRunning\OperationsClient - * @experimental - */ - public function getOperationsClient() - { - return $this->operationsClient; - } - - /** - * Resume an existing long running operation that was previously started - * by a long running API method. If $methodName is not provided, or does - * not match a long running API method, then the operation can still be - * resumed, but the OperationResponse object will not deserialize the - * final response. - * - * @param string $operationName The name of the long running operation - * @param string $methodName The name of the method used to start the operation - * @return \Google\GAX\OperationResponse - * @experimental - */ - public function resumeOperation($operationName, $methodName = null) - { - $lroDescriptors = LibraryServiceClient::getLongRunningDescriptors(); - if (!is_null($methodName) && array_key_exists($methodName, $lroDescriptors)) { - $options = $lroDescriptors[$methodName]; - } else { - $options = []; - } - $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); - $operation->reload(); - return $operation; - } - - // TODO(garrettjones): add channel (when supported in gRPC) - /** - * Constructor. - * - * @param array $options { - * Optional. Options for configuring the service API wrapper. - * - * @type string $serviceAddress The domain name of the API remote host. - * Default 'library-example.googleapis.com'. - * @type mixed $port The port on which to connect to the remote host. Default 443. - * @type \Grpc\ChannelCredentials $sslCreds - * A `ChannelCredentials` for use with an SSL-enabled channel. - * Default: a credentials object returned from - * \Grpc\ChannelCredentials::createSsl() - * @type array $scopes A string array of scopes to use when acquiring credentials. - * Default the scopes for the Google Example Library API. - * @type array $retryingOverride - * An associative array of string => RetryOptions, where the keys - * are method names (e.g. 'createFoo'), that overrides default retrying - * settings. A value of null indicates that the method in question should - * not retry. - * @type int $timeoutMillis The timeout in milliseconds to use for calls - * that don't use retries. For calls that use retries, - * set the timeout in RetryOptions. - * Default: 30000 (30 seconds) - * @type \Google\Auth\CredentialsLoader $credentialsLoader - * A CredentialsLoader object created using the - * Google\Auth library. - * } - * @experimental - */ - public function __construct($options = []) - { - $defaultOptions = [ - 'serviceAddress' => self::SERVICE_ADDRESS, - 'port' => self::DEFAULT_SERVICE_PORT, - 'scopes' => [ - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/library', - ], - 'retryingOverride' => null, - 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, - 'libName' => null, - 'libVersion' => null, - ]; - $options = array_merge($defaultOptions, $options); - - if (array_key_exists('operationsClient', $options)) { - $this->operationsClient = $options['operationsClient']; - } else { - $operationsClientOptions = $options; - unset($operationsClientOptions['timeoutMillis']); - unset($operationsClientOptions['retryingOverride']); - $this->operationsClient = new OperationsClient($operationsClientOptions); - } - - $gapicVersion = $options['libVersion'] ?: self::getGapicVersion(); - - $headerDescriptor = new AgentHeaderDescriptor([ - 'libName' => $options['libName'], - 'libVersion' => $options['libVersion'], - 'gapicVersion' => $gapicVersion, - ]); - - $defaultDescriptors = ['headerDescriptor' => $headerDescriptor]; - $this->descriptors = [ - 'createShelf' => $defaultDescriptors, - 'getShelf' => $defaultDescriptors, - 'listShelves' => $defaultDescriptors, - 'deleteShelf' => $defaultDescriptors, - 'mergeShelves' => $defaultDescriptors, - 'createBook' => $defaultDescriptors, - 'publishSeries' => $defaultDescriptors, - 'getBook' => $defaultDescriptors, - 'listBooks' => $defaultDescriptors, - 'deleteBook' => $defaultDescriptors, - 'updateBook' => $defaultDescriptors, - 'moveBook' => $defaultDescriptors, - 'listStrings' => $defaultDescriptors, - 'addComments' => $defaultDescriptors, - 'getBookFromArchive' => $defaultDescriptors, - 'getBookFromAnywhere' => $defaultDescriptors, - 'getBookFromAbsolutelyAnywhere' => $defaultDescriptors, - 'updateBookIndex' => $defaultDescriptors, - 'streamShelves' => $defaultDescriptors, - 'streamBooks' => $defaultDescriptors, - 'discussBook' => $defaultDescriptors, - 'monologAboutBook' => $defaultDescriptors, - 'findRelatedBooks' => $defaultDescriptors, - 'addTag' => $defaultDescriptors, - 'addLabel' => $defaultDescriptors, - 'getBigBook' => $defaultDescriptors, - 'getBigNothing' => $defaultDescriptors, - 'testOptionalRequiredFlatteningParams' => $defaultDescriptors, - ]; - $pageStreamingDescriptors = self::getPageStreamingDescriptors(); - foreach ($pageStreamingDescriptors as $method => $pageStreamingDescriptor) { - $this->descriptors[$method]['pageStreamingDescriptor'] = $pageStreamingDescriptor; - } - $longRunningDescriptors = self::getLongRunningDescriptors(); - foreach ($longRunningDescriptors as $method => $longRunningDescriptor) { - $this->descriptors[$method]['longRunningDescriptor'] = $longRunningDescriptor + ['operationsClient' => $this->operationsClient]; - } - $grpcStreamingDescriptors = self::getGrpcStreamingDescriptors(); - foreach ($grpcStreamingDescriptors as $method => $grpcStreamingDescriptor) { - $this->descriptors[$method]['grpcStreamingDescriptor'] = $grpcStreamingDescriptor; - } - - $clientConfigJsonString = file_get_contents(__DIR__ . '/resources/library_service_client_config.json'); - $clientConfig = json_decode($clientConfigJsonString, true); - $this->defaultCallSettings = - CallSettings::load('google.example.library.v1.LibraryService', - $clientConfig, - $options['retryingOverride'], - GrpcConstants::getStatusCodeNames(), - $options['timeoutMillis']); - - $this->scopes = $options['scopes']; - - $createStubOptions = []; - if (array_key_exists('sslCreds', $options)) { - $createStubOptions['sslCreds'] = $options['sslCreds']; - } - $grpcCredentialsHelperOptions = array_diff_key($options, $defaultOptions); - $this->grpcCredentialsHelper = new GrpcCredentialsHelper($this->scopes, $grpcCredentialsHelperOptions); - - $createLibraryServiceStubFunction = function ($hostname, $opts) { - return new LibraryServiceGrpcClient($hostname, $opts); - }; - if (array_key_exists('createLibraryServiceStubFunction', $options)) { - $createLibraryServiceStubFunction = $options['createLibraryServiceStubFunction']; - } - $this->libraryServiceStub = $this->grpcCredentialsHelper->createStub( - $createLibraryServiceStubFunction, - $options['serviceAddress'], - $options['port'], - $createStubOptions); - $createLabelerStubFunction = function ($hostname, $opts) { - return new LabelerGrpcClient($hostname, $opts); - }; - if (array_key_exists('createLabelerStubFunction', $options)) { - $createLabelerStubFunction = $options['createLabelerStubFunction']; - } - $this->labelerStub = $this->grpcCredentialsHelper->createStub( - $createLabelerStubFunction, - $options['serviceAddress'], - $options['port'], - $createStubOptions); - } - - /** - * Creates a shelf, and returns the new Shelf. - * RPC method comment may include special characters: <>&"`'@. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $shelf = new Shelf(); - * $response = $libraryServiceClient->createShelf($shelf); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param Shelf $shelf The shelf to create. - * @param array $optionalArgs { - * Optional. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\Example\Library\V1\Shelf - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function createShelf($shelf, $optionalArgs = []) - { - $request = new CreateShelfRequest(); - $request->setShelf($shelf); - - $mergedSettings = $this->defaultCallSettings['createShelf']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'CreateShelf', $mergedSettings, $this->descriptors['createShelf']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Gets a shelf. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $formattedName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); - * $options = ""; - * $response = $libraryServiceClient->getShelf($formattedName, $options); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $name The name of the shelf to retrieve. - * @param string $options To test 'options' parameter name conflict. - * @param array $optionalArgs { - * Optional. - * @type SomeMessage $message - * Field to verify that message-type query parameter gets flattened. - * @type StringBuilder $stringBuilder - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\Example\Library\V1\Shelf - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function getShelf($name, $options, $optionalArgs = []) - { - $request = new GetShelfRequest(); - $request->setName($name); - $request->setOptions($options); - if (isset($optionalArgs['message'])) { - $request->setMessage($optionalArgs['message']); - } - if (isset($optionalArgs['stringBuilder'])) { - $request->setStringBuilder($optionalArgs['stringBuilder']); - } - - $mergedSettings = $this->defaultCallSettings['getShelf']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'GetShelf', $mergedSettings, $this->descriptors['getShelf']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Lists shelves. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * - * // Iterate through all elements - * $pagedResponse = $libraryServiceClient->listShelves(); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * - * // OR iterate over pages of elements, with the maximum page size set to 5 - * $pagedResponse = $libraryServiceClient->listShelves(['pageSize' => 5]); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param array $optionalArgs { - * Optional. - * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\GAX\PagedListResponse - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function listShelves($optionalArgs = []) - { - $request = new ListShelvesRequest(); - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - - $mergedSettings = $this->defaultCallSettings['listShelves']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'ListShelves', $mergedSettings, $this->descriptors['listShelves']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Deletes a shelf. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $formattedName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); - * $libraryServiceClient->deleteShelf($formattedName); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $name The name of the shelf to delete. - * @param array $optionalArgs { - * Optional. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function deleteShelf($name, $optionalArgs = []) - { - $request = new DeleteShelfRequest(); - $request->setName($name); - - $mergedSettings = $this->defaultCallSettings['deleteShelf']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'DeleteShelf', $mergedSettings, $this->descriptors['deleteShelf']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Merges two shelves by adding all books from the shelf named - * `other_shelf_name` to shelf `name`, and deletes - * `other_shelf_name`. Returns the updated shelf. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $formattedName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); - * $formattedOtherShelfName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); - * $response = $libraryServiceClient->mergeShelves($formattedName, $formattedOtherShelfName); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $name The name of the shelf we're adding books to. - * @param string $otherShelfName The name of the shelf we're removing books from and deleting. - * @param array $optionalArgs { - * Optional. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\Example\Library\V1\Shelf - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function mergeShelves($name, $otherShelfName, $optionalArgs = []) - { - $request = new MergeShelvesRequest(); - $request->setName($name); - $request->setOtherShelfName($otherShelfName); - - $mergedSettings = $this->defaultCallSettings['mergeShelves']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'MergeShelves', $mergedSettings, $this->descriptors['mergeShelves']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Creates a book. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $formattedName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); - * $book = new Book(); - * $response = $libraryServiceClient->createBook($formattedName, $book); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $name The name of the shelf in which the book is created. - * @param Book $book The book to create. - * @param array $optionalArgs { - * Optional. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\Example\Library\V1\Book - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function createBook($name, $book, $optionalArgs = []) - { - $request = new CreateBookRequest(); - $request->setName($name); - $request->setBook($book); - - $mergedSettings = $this->defaultCallSettings['createBook']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'CreateBook', $mergedSettings, $this->descriptors['createBook']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Creates a series of books. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $shelf = new Shelf(); - * $books = []; - * $seriesString = "foobar"; - * $seriesUuid = new SeriesUuid(); - * $seriesUuid->setSeriesString($seriesString); - * $response = $libraryServiceClient->publishSeries($shelf, $books, $seriesUuid); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param Shelf $shelf The shelf in which the series is created. - * @param Book[] $books The books to publish in the series. - * @param SeriesUuid $seriesUuid Uniquely identifies the series to the publishing house. - * @param array $optionalArgs { - * Optional. - * @type int $edition - * The edition of the series - * @type bool $reviewCopy - * If the book is in a pre-publish state - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\Example\Library\V1\PublishSeriesResponse - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function publishSeries($shelf, $books, $seriesUuid, $optionalArgs = []) - { - $request = new PublishSeriesRequest(); - $request->setShelf($shelf); - $request->setBooks($books); - $request->setSeriesUuid($seriesUuid); - if (isset($optionalArgs['edition'])) { - $request->setEdition($optionalArgs['edition']); - } - if (isset($optionalArgs['reviewCopy'])) { - $request->setReviewCopy($optionalArgs['reviewCopy']); - } - - $mergedSettings = $this->defaultCallSettings['publishSeries']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'PublishSeries', $mergedSettings, $this->descriptors['publishSeries']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Gets a book. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); - * $response = $libraryServiceClient->getBook($formattedName); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $name The name of the book to retrieve. - * @param array $optionalArgs { - * Optional. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\Example\Library\V1\Book - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function getBook($name, $optionalArgs = []) - { - $request = new GetBookRequest(); - $request->setName($name); - - $mergedSettings = $this->defaultCallSettings['getBook']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'GetBook', $mergedSettings, $this->descriptors['getBook']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Lists books in a shelf. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $formattedName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); - * // Iterate through all elements - * $pagedResponse = $libraryServiceClient->listBooks($formattedName); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * - * // OR iterate over pages of elements, with the maximum page size set to 5 - * $pagedResponse = $libraryServiceClient->listBooks($formattedName, ['pageSize' => 5]); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $name The name of the shelf whose books we'd like to list. - * @param array $optionalArgs { - * Optional. - * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. - * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. - * @type string $filter - * To test python built-in wrapping. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\GAX\PagedListResponse - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function listBooks($name, $optionalArgs = []) - { - $request = new ListBooksRequest(); - $request->setName($name); - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - if (isset($optionalArgs['filter'])) { - $request->setFilter($optionalArgs['filter']); - } - - $mergedSettings = $this->defaultCallSettings['listBooks']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'ListBooks', $mergedSettings, $this->descriptors['listBooks']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Deletes a book. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); - * $libraryServiceClient->deleteBook($formattedName); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $name The name of the book to delete. - * @param array $optionalArgs { - * Optional. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function deleteBook($name, $optionalArgs = []) - { - $request = new DeleteBookRequest(); - $request->setName($name); - - $mergedSettings = $this->defaultCallSettings['deleteBook']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'DeleteBook', $mergedSettings, $this->descriptors['deleteBook']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Updates a book. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); - * $book = new Book(); - * $response = $libraryServiceClient->updateBook($formattedName, $book); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $name The name of the book to update. - * @param Book $book The book to update with. - * @param array $optionalArgs { - * Optional. - * @type FieldMask $updateMask - * A field mask to apply, rendered as an HTTP parameter. - * @type \Google\Example\Library\V1\FieldMask $physicalMask - * To test Python import clash resolution. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\Example\Library\V1\Book - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function updateBook($name, $book, $optionalArgs = []) - { - $request = new UpdateBookRequest(); - $request->setName($name); - $request->setBook($book); - if (isset($optionalArgs['updateMask'])) { - $request->setUpdateMask($optionalArgs['updateMask']); - } - if (isset($optionalArgs['physicalMask'])) { - $request->setPhysicalMask($optionalArgs['physicalMask']); - } - - $mergedSettings = $this->defaultCallSettings['updateBook']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'UpdateBook', $mergedSettings, $this->descriptors['updateBook']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Moves a book to another shelf, and returns the new book. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); - * $formattedOtherShelfName = LibraryServiceClient::formatShelfName("[SHELF_ID]"); - * $response = $libraryServiceClient->moveBook($formattedName, $formattedOtherShelfName); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $name The name of the book to move. - * @param string $otherShelfName The name of the destination shelf. - * @param array $optionalArgs { - * Optional. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\Example\Library\V1\Book - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function moveBook($name, $otherShelfName, $optionalArgs = []) - { - $request = new MoveBookRequest(); - $request->setName($name); - $request->setOtherShelfName($otherShelfName); - - $mergedSettings = $this->defaultCallSettings['moveBook']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'MoveBook', $mergedSettings, $this->descriptors['moveBook']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Lists a primitive resource. To test go page streaming. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * - * // Iterate through all elements - * $pagedResponse = $libraryServiceClient->listStrings(); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * - * // OR iterate over pages of elements, with the maximum page size set to 5 - * $pagedResponse = $libraryServiceClient->listStrings(['pageSize' => 5]); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param array $optionalArgs { - * Optional. - * @type string $name - * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. - * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\GAX\PagedListResponse - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function listStrings($optionalArgs = []) - { - $request = new ListStringsRequest(); - if (isset($optionalArgs['name'])) { - $request->setName($optionalArgs['name']); - } - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - - $mergedSettings = $this->defaultCallSettings['listStrings']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'ListStrings', $mergedSettings, $this->descriptors['listStrings']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Adds comments to a book - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); - * $comment = ""; - * $stage = Stage::UNSET; - * $alignment = Alignment::CHAR; - * $commentsElement = new Comment(); - * $commentsElement->setComment($comment); - * $commentsElement->setStage($stage); - * $commentsElement->setAlignment($alignment); - * $comments = [$commentsElement]; - * $libraryServiceClient->addComments($formattedName, $comments); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $name - * @param Comment[] $comments - * @param array $optionalArgs { - * Optional. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function addComments($name, $comments, $optionalArgs = []) - { - $request = new AddCommentsRequest(); - $request->setName($name); - $request->setComments($comments); - - $mergedSettings = $this->defaultCallSettings['addComments']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'AddComments', $mergedSettings, $this->descriptors['addComments']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Gets a book from an archive. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $formattedName = LibraryServiceClient::formatArchivedBookName("[ARCHIVE_PATH]", "[BOOK_ID]"); - * $response = $libraryServiceClient->getBookFromArchive($formattedName); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $name The name of the book to retrieve. - * @param array $optionalArgs { - * Optional. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\Example\Library\V1\BookFromArchive - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function getBookFromArchive($name, $optionalArgs = []) - { - $request = new GetBookFromArchiveRequest(); - $request->setName($name); - - $mergedSettings = $this->defaultCallSettings['getBookFromArchive']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'GetBookFromArchive', $mergedSettings, $this->descriptors['getBookFromArchive']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Gets a book from a shelf or archive. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); - * $formattedAltBookName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); - * $response = $libraryServiceClient->getBookFromAnywhere($formattedName, $formattedAltBookName); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $name The name of the book to retrieve. - * @param string $altBookName An alternate book name, used to test restricting flattened field to a - * single resource name type in a oneof. - * @param array $optionalArgs { - * Optional. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\Example\Library\V1\BookFromAnywhere - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function getBookFromAnywhere($name, $altBookName, $optionalArgs = []) - { - $request = new GetBookFromAnywhereRequest(); - $request->setName($name); - $request->setAltBookName($altBookName); - - $mergedSettings = $this->defaultCallSettings['getBookFromAnywhere']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'GetBookFromAnywhere', $mergedSettings, $this->descriptors['getBookFromAnywhere']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Test proper OneOf-Any resource name mapping - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); - * $response = $libraryServiceClient->getBookFromAbsolutelyAnywhere($formattedName); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $name The name of the book to retrieve. - * @param array $optionalArgs { - * Optional. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\Example\Library\V1\BookFromAnywhere - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function getBookFromAbsolutelyAnywhere($name, $optionalArgs = []) - { - $request = new GetBookFromAbsolutelyAnywhereRequest(); - $request->setName($name); - - $mergedSettings = $this->defaultCallSettings['getBookFromAbsolutelyAnywhere']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'GetBookFromAbsolutelyAnywhere', $mergedSettings, $this->descriptors['getBookFromAbsolutelyAnywhere']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Updates the index of a book. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); - * $indexName = "default index"; - * $indexMapItem = ""; - * $indexMap = ["default_key" => $indexMapItem,]; - * $libraryServiceClient->updateBookIndex($formattedName, $indexName, $indexMap); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $name The name of the book to update. - * @param string $indexName The name of the index for the book - * @param array $indexMap The index to update the book with - * @param array $optionalArgs { - * Optional. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function updateBookIndex($name, $indexName, $indexMap, $optionalArgs = []) - { - $request = new UpdateBookIndexRequest(); - $request->setName($name); - $request->setIndexName($indexName); - $request->setIndexMap($indexMap); - - $mergedSettings = $this->defaultCallSettings['updateBookIndex']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'UpdateBookIndex', $mergedSettings, $this->descriptors['updateBookIndex']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Test server streaming - * gRPC streaming methods don't have an HTTP equivalent and don't need to have the google.api.http option. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * - * // Read all responses until the stream is complete - * $stream = $libraryServiceClient->streamShelves(); - * foreach ($stream->readAll() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param array $optionalArgs { - * Optional. - * @type int $timeoutMillis - * Timeout to use for this call. - * } - * - * @return \Google\GAX\ServerStream - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function streamShelves($optionalArgs = []) - { - $request = new StreamShelvesRequest(); - - $mergedSettings = $this->defaultCallSettings['streamShelves']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'StreamShelves', $mergedSettings, $this->descriptors['streamShelves']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Test server streaming, non-paged responses. - * gRPC streaming methods don't have an HTTP equivalent and don't need to have the google.api.http option. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $name = ""; - * // Read all responses until the stream is complete - * $stream = $libraryServiceClient->streamBooks($name); - * foreach ($stream->readAll() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $name The name of the shelf whose books we'd like to list. - * @param array $optionalArgs { - * Optional. - * @type int $timeoutMillis - * Timeout to use for this call. - * } - * - * @return \Google\GAX\ServerStream - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function streamBooks($name, $optionalArgs = []) - { - $request = new StreamBooksRequest(); - $request->setName($name); - - $mergedSettings = $this->defaultCallSettings['streamBooks']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'StreamBooks', $mergedSettings, $this->descriptors['streamBooks']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Test bidi-streaming. - * gRPC streaming methods don't have an HTTP equivalent and don't need to have the google.api.http option. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $name = ""; - * $request = new DiscussBookRequest(); - * $request->setName($name); - * $requests = [$request]; - * - * // Write all requests to the server, then read all responses until the - * // stream is complete - * $stream = $libraryServiceClient->discussBook(); - * $stream->writeAll($requests); - * foreach ($stream->closeWriteAndReadAll() as $element) { - * // doSomethingWith($element); - * } - * - * // OR write requests individually, making read() calls if - * // required. Call closeWrite() once writes are complete, and read the - * // remaining responses from the server. - * $stream = $libraryServiceClient->discussBook(); - * foreach ($requests as $request) { - * $stream->write($request); - * // if required, read a single response from the stream - * $element = $stream->read(); - * // doSomethingWith($element) - * } - * $stream->closeWrite(); - * $element = $stream->read(); - * while (!is_null($element)) { - * // doSomethingWith($element) - * $element = $stream->read(); - * } - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param array $optionalArgs { - * Optional. - * @type int $timeoutMillis - * Timeout to use for this call. - * } - * - * @return \Google\GAX\BidiStream - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function discussBook($optionalArgs = []) - { - $mergedSettings = $this->defaultCallSettings['discussBook']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'DiscussBook', $mergedSettings, $this->descriptors['discussBook']); - - return $callable( - null, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Test client streaming. - * gRPC streaming methods don't have an HTTP equivalent and don't need to have the google.api.http option. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $name = ""; - * $request = new DiscussBookRequest(); - * $request->setName($name); - * $requests = [$request]; - * - * // Write data to server and wait for a response - * $stream = $libraryServiceClient->monologAboutBook(); - * $result = $stream->writeAllAndReadResponse($requests); - * // doSomethingWith($result) - * - * // OR write data as it becomes available, then wait for a response - * $stream = $libraryServiceClient->monologAboutBook(); - * foreach ($requests as $request) { - * $stream->write($request); - * } - * $result = $stream->readResponse(); - * // doSomethingWith($result) - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param array $optionalArgs { - * Optional. - * @type int $timeoutMillis - * Timeout to use for this call. - * } - * - * @return \Google\GAX\ClientStream - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function monologAboutBook($optionalArgs = []) - { - $mergedSettings = $this->defaultCallSettings['monologAboutBook']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'MonologAboutBook', $mergedSettings, $this->descriptors['monologAboutBook']); - - return $callable( - null, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $namesElement = ""; - * $names = [$namesElement]; - * $shelves = []; - * // Iterate through all elements - * $pagedResponse = $libraryServiceClient->findRelatedBooks($names, $shelves); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * - * // OR iterate over pages of elements, with the maximum page size set to 5 - * $pagedResponse = $libraryServiceClient->findRelatedBooks($names, $shelves, ['pageSize' => 5]); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string[] $names - * @param string[] $shelves - * @param array $optionalArgs { - * Optional. - * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. - * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\GAX\PagedListResponse - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function findRelatedBooks($names, $shelves, $optionalArgs = []) - { - $request = new FindRelatedBooksRequest(); - $request->setNames($names); - $request->setShelves($shelves); - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - - $mergedSettings = $this->defaultCallSettings['findRelatedBooks']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'FindRelatedBooks', $mergedSettings, $this->descriptors['findRelatedBooks']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Adds a tag to the book. This RPC is a mixin. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $formattedResource = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); - * $tag = ""; - * $response = $libraryServiceClient->addTag($formattedResource, $tag); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $resource REQUIRED: The resource which the tag is being added to. - * Resource is usually specified as a path, such as, - * projects/{project}/zones/{zone}/disks/{disk}. - * @param string $tag REQUIRED: The tag to add. - * @param array $optionalArgs { - * Optional. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\Tagger\V1\AddTagResponse - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function addTag($resource, $tag, $optionalArgs = []) - { - $request = new AddTagRequest(); - $request->setResource($resource); - $request->setTag($tag); - - $mergedSettings = $this->defaultCallSettings['addTag']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'AddTag', $mergedSettings, $this->descriptors['addTag']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Adds a label to the entity. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $formattedResource = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); - * $label = ""; - * $response = $libraryServiceClient->addLabel($formattedResource, $label); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $resource REQUIRED: The resource which the label is being added to. - * Resource is usually specified as a path, such as, - * projects/{project}/zones/{zone}/disks/{disk}. - * @param string $label REQUIRED: The label to add. - * @param array $optionalArgs { - * Optional. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\Tagger\V1\AddLabelResponse - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function addLabel($resource, $label, $optionalArgs = []) - { - $request = new AddLabelRequest(); - $request->setResource($resource); - $request->setLabel($label); - - $mergedSettings = $this->defaultCallSettings['addLabel']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->labelerStub, 'AddLabel', $mergedSettings, $this->descriptors['addLabel']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Test long-running operations - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); - * $operationResponse = $libraryServiceClient->getBigBook($formattedName); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * $result = $operationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * - * // OR start the operation, keep the operation name, and resume later - * $operationResponse = $libraryServiceClient->getBigBook($formattedName); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $libraryServiceClient->resumeOperation($operationName, 'getBigBook'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * $result = $newOperationResponse->getResult(); - * // doSomethingWith($result) - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $name The name of the book to retrieve. - * @param array $optionalArgs { - * Optional. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\Longrunning\Operation - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function getBigBook($name, $optionalArgs = []) - { - $request = new GetBookRequest(); - $request->setName($name); - - $mergedSettings = $this->defaultCallSettings['getBigBook']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'GetBigBook', $mergedSettings, $this->descriptors['getBigBook']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Test long-running operations with empty return type. - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $formattedName = LibraryServiceClient::formatBookName("[SHELF_ID]", "[BOOK_ID]"); - * $operationResponse = $libraryServiceClient->getBigNothing($formattedName); - * $operationResponse->pollUntilComplete(); - * if ($operationResponse->operationSucceeded()) { - * // operation succeeded and returns no value - * } else { - * $error = $operationResponse->getError(); - * // handleError($error) - * } - * - * // OR start the operation, keep the operation name, and resume later - * $operationResponse = $libraryServiceClient->getBigNothing($formattedName); - * $operationName = $operationResponse->getName(); - * // ... do other work - * $newOperationResponse = $libraryServiceClient->resumeOperation($operationName, 'getBigNothing'); - * while (!$newOperationResponse->isDone()) { - * // ... do other work - * $newOperationResponse->reload(); - * } - * if ($newOperationResponse->operationSucceeded()) { - * // operation succeeded and returns no value - * } else { - * $error = $newOperationResponse->getError(); - * // handleError($error) - * } - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param string $name The name of the book to retrieve. - * @param array $optionalArgs { - * Optional. - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\Longrunning\Operation - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function getBigNothing($name, $optionalArgs = []) - { - $request = new GetBookRequest(); - $request->setName($name); - - $mergedSettings = $this->defaultCallSettings['getBigNothing']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'GetBigNothing', $mergedSettings, $this->descriptors['getBigNothing']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Test optional flattening parameters of all types - * - * Sample code: - * ``` - * try { - * $libraryServiceClient = new LibraryServiceClient(); - * $requiredSingularInt32 = 0; - * $requiredSingularInt64 = 0; - * $requiredSingularFloat = 0.0; - * $requiredSingularDouble = 0.0; - * $requiredSingularBool = false; - * $requiredSingularEnum = InnerEnum::ZERO; - * $requiredSingularString = ""; - * $requiredSingularBytes = ""; - * $requiredSingularMessage = new InnerMessage(); - * $requiredSingularResourceName = ""; - * $requiredSingularResourceNameOneof = ""; - * $requiredSingularFixed32 = 0; - * $requiredSingularFixed64 = 0; - * $requiredRepeatedInt32 = []; - * $requiredRepeatedInt64 = []; - * $requiredRepeatedFloat = []; - * $requiredRepeatedDouble = []; - * $requiredRepeatedBool = []; - * $requiredRepeatedEnum = []; - * $requiredRepeatedString = []; - * $requiredRepeatedBytes = []; - * $requiredRepeatedMessage = []; - * $formattedRequiredRepeatedResourceName = []; - * $formattedRequiredRepeatedResourceNameOneof = []; - * $requiredRepeatedFixed32 = []; - * $requiredRepeatedFixed64 = []; - * $requiredMap = []; - * $response = $libraryServiceClient->testOptionalRequiredFlatteningParams($requiredSingularInt32, $requiredSingularInt64, $requiredSingularFloat, $requiredSingularDouble, $requiredSingularBool, $requiredSingularEnum, $requiredSingularString, $requiredSingularBytes, $requiredSingularMessage, $requiredSingularResourceName, $requiredSingularResourceNameOneof, $requiredSingularFixed32, $requiredSingularFixed64, $requiredRepeatedInt32, $requiredRepeatedInt64, $requiredRepeatedFloat, $requiredRepeatedDouble, $requiredRepeatedBool, $requiredRepeatedEnum, $requiredRepeatedString, $requiredRepeatedBytes, $requiredRepeatedMessage, $formattedRequiredRepeatedResourceName, $formattedRequiredRepeatedResourceNameOneof, $requiredRepeatedFixed32, $requiredRepeatedFixed64, $requiredMap); - * } finally { - * $libraryServiceClient->close(); - * } - * ``` - * - * @param int $requiredSingularInt32 - * @param int $requiredSingularInt64 - * @param float $requiredSingularFloat - * @param float $requiredSingularDouble - * @param bool $requiredSingularBool - * @param int $requiredSingularEnum For allowed values, use constants defined on {@see \Google\Example\Library\V1\TestOptionalRequiredFlatteningParamsRequest_InnerEnum} - * @param string $requiredSingularString - * @param string $requiredSingularBytes - * @param InnerMessage $requiredSingularMessage - * @param string $requiredSingularResourceName - * @param string $requiredSingularResourceNameOneof - * @param int $requiredSingularFixed32 - * @param int $requiredSingularFixed64 - * @param int[] $requiredRepeatedInt32 - * @param int[] $requiredRepeatedInt64 - * @param float[] $requiredRepeatedFloat - * @param float[] $requiredRepeatedDouble - * @param bool[] $requiredRepeatedBool - * @param int[] $requiredRepeatedEnum For allowed values, use constants defined on {@see \Google\Example\Library\V1\TestOptionalRequiredFlatteningParamsRequest_InnerEnum} - * @param string[] $requiredRepeatedString - * @param string[] $requiredRepeatedBytes - * @param InnerMessage[] $requiredRepeatedMessage - * @param string[] $requiredRepeatedResourceName - * @param string[] $requiredRepeatedResourceNameOneof - * @param int[] $requiredRepeatedFixed32 - * @param int[] $requiredRepeatedFixed64 - * @param array $requiredMap - * @param array $optionalArgs { - * Optional. - * @type int $optionalSingularInt32 - * @type int $optionalSingularInt64 - * @type float $optionalSingularFloat - * @type float $optionalSingularDouble - * @type bool $optionalSingularBool - * @type int $optionalSingularEnum - * For allowed values, use constants defined on {@see \Google\Example\Library\V1\TestOptionalRequiredFlatteningParamsRequest_InnerEnum} - * @type string $optionalSingularString - * @type string $optionalSingularBytes - * @type InnerMessage $optionalSingularMessage - * @type string $optionalSingularResourceName - * @type string $optionalSingularResourceNameOneof - * @type int $optionalSingularFixed32 - * @type int $optionalSingularFixed64 - * @type int[] $optionalRepeatedInt32 - * @type int[] $optionalRepeatedInt64 - * @type float[] $optionalRepeatedFloat - * @type float[] $optionalRepeatedDouble - * @type bool[] $optionalRepeatedBool - * @type int[] $optionalRepeatedEnum - * For allowed values, use constants defined on {@see \Google\Example\Library\V1\TestOptionalRequiredFlatteningParamsRequest_InnerEnum} - * @type string[] $optionalRepeatedString - * @type string[] $optionalRepeatedBytes - * @type InnerMessage[] $optionalRepeatedMessage - * @type string[] $optionalRepeatedResourceName - * @type string[] $optionalRepeatedResourceNameOneof - * @type int[] $optionalRepeatedFixed32 - * @type int[] $optionalRepeatedFixed64 - * @type array $optionalMap - * @type \Google\GAX\RetrySettings $retrySettings - * Retry settings to use for this call. If present, then - * $timeoutMillis is ignored. - * @type int $timeoutMillis - * Timeout to use for this call. Only used if $retrySettings - * is not set. - * } - * - * @return \Google\Example\Library\V1\TestOptionalRequiredFlatteningParamsResponse - * - * @throws \Google\GAX\ApiException if the remote call fails - * @experimental - */ - public function testOptionalRequiredFlatteningParams($requiredSingularInt32, $requiredSingularInt64, $requiredSingularFloat, $requiredSingularDouble, $requiredSingularBool, $requiredSingularEnum, $requiredSingularString, $requiredSingularBytes, $requiredSingularMessage, $requiredSingularResourceName, $requiredSingularResourceNameOneof, $requiredSingularFixed32, $requiredSingularFixed64, $requiredRepeatedInt32, $requiredRepeatedInt64, $requiredRepeatedFloat, $requiredRepeatedDouble, $requiredRepeatedBool, $requiredRepeatedEnum, $requiredRepeatedString, $requiredRepeatedBytes, $requiredRepeatedMessage, $requiredRepeatedResourceName, $requiredRepeatedResourceNameOneof, $requiredRepeatedFixed32, $requiredRepeatedFixed64, $requiredMap, $optionalArgs = []) - { - $request = new TestOptionalRequiredFlatteningParamsRequest(); - $request->setRequiredSingularInt32($requiredSingularInt32); - $request->setRequiredSingularInt64($requiredSingularInt64); - $request->setRequiredSingularFloat($requiredSingularFloat); - $request->setRequiredSingularDouble($requiredSingularDouble); - $request->setRequiredSingularBool($requiredSingularBool); - $request->setRequiredSingularEnum($requiredSingularEnum); - $request->setRequiredSingularString($requiredSingularString); - $request->setRequiredSingularBytes($requiredSingularBytes); - $request->setRequiredSingularMessage($requiredSingularMessage); - $request->setRequiredSingularResourceName($requiredSingularResourceName); - $request->setRequiredSingularResourceNameOneof($requiredSingularResourceNameOneof); - $request->setRequiredSingularFixed32($requiredSingularFixed32); - $request->setRequiredSingularFixed64($requiredSingularFixed64); - $request->setRequiredRepeatedInt32($requiredRepeatedInt32); - $request->setRequiredRepeatedInt64($requiredRepeatedInt64); - $request->setRequiredRepeatedFloat($requiredRepeatedFloat); - $request->setRequiredRepeatedDouble($requiredRepeatedDouble); - $request->setRequiredRepeatedBool($requiredRepeatedBool); - $request->setRequiredRepeatedEnum($requiredRepeatedEnum); - $request->setRequiredRepeatedString($requiredRepeatedString); - $request->setRequiredRepeatedBytes($requiredRepeatedBytes); - $request->setRequiredRepeatedMessage($requiredRepeatedMessage); - $request->setRequiredRepeatedResourceName($requiredRepeatedResourceName); - $request->setRequiredRepeatedResourceNameOneof($requiredRepeatedResourceNameOneof); - $request->setRequiredRepeatedFixed32($requiredRepeatedFixed32); - $request->setRequiredRepeatedFixed64($requiredRepeatedFixed64); - $request->setRequiredMap($requiredMap); - if (isset($optionalArgs['optionalSingularInt32'])) { - $request->setOptionalSingularInt32($optionalArgs['optionalSingularInt32']); - } - if (isset($optionalArgs['optionalSingularInt64'])) { - $request->setOptionalSingularInt64($optionalArgs['optionalSingularInt64']); - } - if (isset($optionalArgs['optionalSingularFloat'])) { - $request->setOptionalSingularFloat($optionalArgs['optionalSingularFloat']); - } - if (isset($optionalArgs['optionalSingularDouble'])) { - $request->setOptionalSingularDouble($optionalArgs['optionalSingularDouble']); - } - if (isset($optionalArgs['optionalSingularBool'])) { - $request->setOptionalSingularBool($optionalArgs['optionalSingularBool']); - } - if (isset($optionalArgs['optionalSingularEnum'])) { - $request->setOptionalSingularEnum($optionalArgs['optionalSingularEnum']); - } - if (isset($optionalArgs['optionalSingularString'])) { - $request->setOptionalSingularString($optionalArgs['optionalSingularString']); - } - if (isset($optionalArgs['optionalSingularBytes'])) { - $request->setOptionalSingularBytes($optionalArgs['optionalSingularBytes']); - } - if (isset($optionalArgs['optionalSingularMessage'])) { - $request->setOptionalSingularMessage($optionalArgs['optionalSingularMessage']); - } - if (isset($optionalArgs['optionalSingularResourceName'])) { - $request->setOptionalSingularResourceName($optionalArgs['optionalSingularResourceName']); - } - if (isset($optionalArgs['optionalSingularResourceNameOneof'])) { - $request->setOptionalSingularResourceNameOneof($optionalArgs['optionalSingularResourceNameOneof']); - } - if (isset($optionalArgs['optionalSingularFixed32'])) { - $request->setOptionalSingularFixed32($optionalArgs['optionalSingularFixed32']); - } - if (isset($optionalArgs['optionalSingularFixed64'])) { - $request->setOptionalSingularFixed64($optionalArgs['optionalSingularFixed64']); - } - if (isset($optionalArgs['optionalRepeatedInt32'])) { - $request->setOptionalRepeatedInt32($optionalArgs['optionalRepeatedInt32']); - } - if (isset($optionalArgs['optionalRepeatedInt64'])) { - $request->setOptionalRepeatedInt64($optionalArgs['optionalRepeatedInt64']); - } - if (isset($optionalArgs['optionalRepeatedFloat'])) { - $request->setOptionalRepeatedFloat($optionalArgs['optionalRepeatedFloat']); - } - if (isset($optionalArgs['optionalRepeatedDouble'])) { - $request->setOptionalRepeatedDouble($optionalArgs['optionalRepeatedDouble']); - } - if (isset($optionalArgs['optionalRepeatedBool'])) { - $request->setOptionalRepeatedBool($optionalArgs['optionalRepeatedBool']); - } - if (isset($optionalArgs['optionalRepeatedEnum'])) { - $request->setOptionalRepeatedEnum($optionalArgs['optionalRepeatedEnum']); - } - if (isset($optionalArgs['optionalRepeatedString'])) { - $request->setOptionalRepeatedString($optionalArgs['optionalRepeatedString']); - } - if (isset($optionalArgs['optionalRepeatedBytes'])) { - $request->setOptionalRepeatedBytes($optionalArgs['optionalRepeatedBytes']); - } - if (isset($optionalArgs['optionalRepeatedMessage'])) { - $request->setOptionalRepeatedMessage($optionalArgs['optionalRepeatedMessage']); - } - if (isset($optionalArgs['optionalRepeatedResourceName'])) { - $request->setOptionalRepeatedResourceName($optionalArgs['optionalRepeatedResourceName']); - } - if (isset($optionalArgs['optionalRepeatedResourceNameOneof'])) { - $request->setOptionalRepeatedResourceNameOneof($optionalArgs['optionalRepeatedResourceNameOneof']); - } - if (isset($optionalArgs['optionalRepeatedFixed32'])) { - $request->setOptionalRepeatedFixed32($optionalArgs['optionalRepeatedFixed32']); - } - if (isset($optionalArgs['optionalRepeatedFixed64'])) { - $request->setOptionalRepeatedFixed64($optionalArgs['optionalRepeatedFixed64']); - } - if (isset($optionalArgs['optionalMap'])) { - $request->setOptionalMap($optionalArgs['optionalMap']); - } - - $mergedSettings = $this->defaultCallSettings['testOptionalRequiredFlatteningParams']->merge( - new CallSettings($optionalArgs)); - $callable = ApiCallable::createApiCall( - $this->libraryServiceStub, 'TestOptionalRequiredFlatteningParams', $mergedSettings, $this->descriptors['testOptionalRequiredFlatteningParams']); - - return $callable( - $request, - [], - ['call_credentials_callback' => $this->createCredentialsCallback()]); - } - - /** - * Initiates an orderly shutdown in which preexisting calls continue but new - * calls are immediately cancelled. - * @experimental - */ - public function close() - { - $this->libraryServiceStub->close(); - $this->labelerStub->close(); - } - - private function createCredentialsCallback() - { - return $this->grpcCredentialsHelper->createCallCredentialsCallback(); - } + // This class is intentionally empty, and is intended to hold manual additions to the generated {@see LibraryServiceClientImpl} class. } diff --git a/src/test/java/com/google/api/codegen/testdata/php_partial_veneer_client_library.baseline b/src/test/java/com/google/api/codegen/testdata/php_partial_veneer_client_library.baseline new file mode 100644 index 0000000000..cc0845ca54 --- /dev/null +++ b/src/test/java/com/google/api/codegen/testdata/php_partial_veneer_client_library.baseline @@ -0,0 +1,92 @@ +============== file: src/Example/Library/V1/LibraryServiceClient.php ============== +