lib/google/cloud/dialogflow/v2/documents/client.rb in google-cloud-dialogflow-v2-0.13.0 vs lib/google/cloud/dialogflow/v2/documents/client.rb in google-cloud-dialogflow-v2-0.14.0

- old
+ new

@@ -473,10 +473,126 @@ rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end ## + # Creates documents by importing data from external sources. + # Dialogflow supports up to 350 documents in each request. If you try to + # import more, Dialogflow will return an error. + # + # This method is a [long-running + # operation](https://cloud.google.com/dialogflow/cx/docs/how/long-running-operation). + # The returned `Operation` type has the following method-specific fields: + # + # - `metadata`: {::Google::Cloud::Dialogflow::V2::KnowledgeOperationMetadata KnowledgeOperationMetadata} + # - `response`: {::Google::Cloud::Dialogflow::V2::ImportDocumentsResponse ImportDocumentsResponse} + # + # @overload import_documents(request, options = nil) + # Pass arguments to `import_documents` via a request object, either of type + # {::Google::Cloud::Dialogflow::V2::ImportDocumentsRequest} or an equivalent Hash. + # + # @param request [::Google::Cloud::Dialogflow::V2::ImportDocumentsRequest, ::Hash] + # A request object representing the call parameters. Required. To specify no + # parameters, or to keep all the default parameter values, pass an empty Hash. + # @param options [::Gapic::CallOptions, ::Hash] + # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional. + # + # @overload import_documents(parent: nil, gcs_source: nil, document_template: nil, import_gcs_custom_metadata: nil) + # Pass arguments to `import_documents` via keyword arguments. Note that at + # least one keyword argument is required. To specify no parameters, or to keep all + # the default parameter values, pass an empty Hash as a request object (see above). + # + # @param parent [::String] + # Required. The knowledge base to import documents into. + # Format: `projects/<Project ID>/locations/<Location + # ID>/knowledgeBases/<Knowledge Base ID>`. + # @param gcs_source [::Google::Cloud::Dialogflow::V2::GcsSources, ::Hash] + # The Google Cloud Storage location for the documents. + # The path can include a wildcard. + # + # These URIs may have the forms + # `gs://<bucket-name>/<object-name>`. + # `gs://<bucket-name>/<object-path>/*.<extension>`. + # @param document_template [::Google::Cloud::Dialogflow::V2::ImportDocumentTemplate, ::Hash] + # Required. Document template used for importing all the documents. + # @param import_gcs_custom_metadata [::Boolean] + # Whether to import custom metadata from Google Cloud Storage. + # Only valid when the document source is Google Cloud Storage URI. + # + # @yield [response, operation] Access the result along with the RPC operation + # @yieldparam response [::Gapic::Operation] + # @yieldparam operation [::GRPC::ActiveCall::Operation] + # + # @return [::Gapic::Operation] + # + # @raise [::Google::Cloud::Error] if the RPC is aborted. + # + # @example Basic example + # require "google/cloud/dialogflow/v2" + # + # # Create a client object. The client can be reused for multiple calls. + # client = Google::Cloud::Dialogflow::V2::Documents::Client.new + # + # # Create a request. To set request fields, pass in keyword arguments. + # request = Google::Cloud::Dialogflow::V2::ImportDocumentsRequest.new + # + # # Call the import_documents method. + # result = client.import_documents request + # + # # The returned object is of type Gapic::Operation. You can use this + # # object to check the status of an operation, cancel it, or wait + # # for results. Here is how to block until completion: + # result.wait_until_done! timeout: 60 + # if result.response? + # p result.response + # else + # puts "Error!" + # end + # + def import_documents request, options = nil + raise ::ArgumentError, "request must be provided" if request.nil? + + request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Dialogflow::V2::ImportDocumentsRequest + + # Converts hash and nil to an options object + options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h + + # Customize the options with defaults + metadata = @config.rpcs.import_documents.metadata.to_h + + # Set x-goog-api-client and x-goog-user-project headers + metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ + lib_name: @config.lib_name, lib_version: @config.lib_version, + gapic_version: ::Google::Cloud::Dialogflow::V2::VERSION + metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id + + header_params = {} + if request.parent + header_params["parent"] = request.parent + end + + request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") + metadata[:"x-goog-request-params"] ||= request_params_header + + options.apply_defaults timeout: @config.rpcs.import_documents.timeout, + metadata: metadata, + retry_policy: @config.rpcs.import_documents.retry_policy + + options.apply_defaults timeout: @config.timeout, + metadata: @config.metadata, + retry_policy: @config.retry_policy + + @documents_stub.call_rpc :import_documents, request, options: options do |response, operation| + response = ::Gapic::Operation.new response, @operations_client, options: options + yield response, operation if block_given? + return response + end + rescue ::GRPC::BadStatus => e + raise ::Google::Cloud::Error.from_error(e) + end + + ## # Deletes the specified document. # # This method is a [long-running # operation](https://cloud.google.com/dialogflow/cx/docs/how/long-running-operation). # The returned `Operation` type has the following method-specific fields: @@ -1061,10 +1177,15 @@ # RPC-specific configuration for `create_document` # @return [::Gapic::Config::Method] # attr_reader :create_document ## + # RPC-specific configuration for `import_documents` + # @return [::Gapic::Config::Method] + # + attr_reader :import_documents + ## # RPC-specific configuration for `delete_document` # @return [::Gapic::Config::Method] # attr_reader :delete_document ## @@ -1089,9 +1210,11 @@ @list_documents = ::Gapic::Config::Method.new list_documents_config get_document_config = parent_rpcs.get_document if parent_rpcs.respond_to? :get_document @get_document = ::Gapic::Config::Method.new get_document_config create_document_config = parent_rpcs.create_document if parent_rpcs.respond_to? :create_document @create_document = ::Gapic::Config::Method.new create_document_config + import_documents_config = parent_rpcs.import_documents if parent_rpcs.respond_to? :import_documents + @import_documents = ::Gapic::Config::Method.new import_documents_config delete_document_config = parent_rpcs.delete_document if parent_rpcs.respond_to? :delete_document @delete_document = ::Gapic::Config::Method.new delete_document_config update_document_config = parent_rpcs.update_document if parent_rpcs.respond_to? :update_document @update_document = ::Gapic::Config::Method.new update_document_config reload_document_config = parent_rpcs.reload_document if parent_rpcs.respond_to? :reload_document