lib/google/cloud/dialogflow/v2/contexts/client.rb in google-cloud-dialogflow-v2-0.6.4 vs lib/google/cloud/dialogflow/v2/contexts/client.rb in google-cloud-dialogflow-v2-0.7.0
- old
+ new
@@ -25,29 +25,12 @@
module V2
module Contexts
##
# Client for the Contexts service.
#
- # A context represents additional information included with user input or with
- # an intent returned by the Dialogflow API. Contexts are helpful for
- # differentiating user input which may be vague or have a different meaning
- # depending on additional details from your application such as user setting
- # and preferences, previous user input, where the user is in your application,
- # geographic location, and so on.
+ # Service for managing {::Google::Cloud::Dialogflow::V2::Context Contexts}.
#
- # You can include contexts as input parameters of a
- # {::Google::Cloud::Dialogflow::V2::Sessions::Client#detect_intent DetectIntent} (or
- # {::Google::Cloud::Dialogflow::V2::Sessions::Client#streaming_detect_intent StreamingDetectIntent}) request,
- # or as output contexts included in the returned intent.
- # Contexts expire when an intent is matched, after the number of `DetectIntent`
- # requests specified by the `lifespan_count` parameter, or after 20 minutes
- # if no intents are matched for a `DetectIntent` request.
- #
- # For more information about contexts, see the
- # [Dialogflow
- # documentation](https://cloud.google.com/dialogflow/docs/contexts-overview).
- #
class Client
include Paths
# @private
attr_reader :contexts_stub
@@ -75,21 +58,21 @@
@configure ||= begin
namespace = ["Google", "Cloud", "Dialogflow", "V2"]
parent_config = while namespace.any?
parent_name = namespace.join "::"
parent_const = const_get parent_name
- break parent_const.configure if parent_const&.respond_to? :configure
+ break parent_const.configure if parent_const.respond_to? :configure
namespace.pop
end
default_config = Client::Configuration.new parent_config
default_config.timeout = 60.0
default_config.retry_policy = {
initial_delay: 0.1,
- max_delay: 60.0,
- multiplier: 1.3,
- retry_codes: ["UNAVAILABLE"]
+ max_delay: 60.0,
+ multiplier: 1.3,
+ retry_codes: [14]
}
default_config
end
yield @configure if block_given?
@@ -149,11 +132,17 @@
# Yield the configuration if needed
yield @config if block_given?
# Create credentials
credentials = @config.credentials
- credentials ||= Credentials.default scope: @config.scope
+ # Use self-signed JWT if the scope and endpoint are unchanged from default,
+ # but only if the default endpoint does not have a region prefix.
+ enable_self_signed_jwt = @config.scope == Client.configure.scope &&
+ @config.endpoint == Client.configure.endpoint &&
+ !@config.endpoint.split(".").first.include?("-")
+ credentials ||= Credentials.default scope: @config.scope,
+ enable_self_signed_jwt: enable_self_signed_jwt
if credentials.is_a?(String) || credentials.is_a?(Hash)
credentials = Credentials.new credentials, scope: @config.scope
end
@quota_project_id = @config.quota_project
@quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id
@@ -685,18 +674,18 @@
class Configuration
extend ::Gapic::Config
config_attr :endpoint, "dialogflow.googleapis.com", ::String
config_attr :credentials, nil do |value|
- allowed = [::String, ::Hash, ::Proc, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
+ allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
allowed += [::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] if defined? ::GRPC
allowed.any? { |klass| klass === value }
end
config_attr :scope, nil, ::String, ::Array, nil
config_attr :lib_name, nil, ::String, nil
config_attr :lib_version, nil, ::String, nil
- config_attr(:channel_args, { "grpc.service_config_disable_resolution"=>1 }, ::Hash, nil)
+ config_attr(:channel_args, { "grpc.service_config_disable_resolution" => 1 }, ::Hash, nil)
config_attr :interceptors, nil, ::Array, nil
config_attr :timeout, nil, ::Numeric, nil
config_attr :metadata, nil, ::Hash, nil
config_attr :retry_policy, nil, ::Hash, ::Proc, nil
config_attr :quota_project, nil, ::String, nil
@@ -713,11 +702,11 @@
# @return [Rpcs]
#
def rpcs
@rpcs ||= begin
parent_rpcs = nil
- parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config&.respond_to?(:rpcs)
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs)
Rpcs.new parent_rpcs
end
end
##
@@ -725,11 +714,11 @@
#
# Includes fields providing the configuration for each RPC in this service.
# Each configuration object is of type `Gapic::Config::Method` and includes
# the following configuration fields:
#
- # * `timeout` (*type:* `Numeric`) - The call timeout in milliseconds
+ # * `timeout` (*type:* `Numeric`) - The call timeout in seconds
# * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional gRPC headers
# * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
# include the following keys:
# * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
# * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
@@ -769,20 +758,20 @@
#
attr_reader :delete_all_contexts
# @private
def initialize parent_rpcs = nil
- list_contexts_config = parent_rpcs&.list_contexts if parent_rpcs&.respond_to? :list_contexts
+ list_contexts_config = parent_rpcs.list_contexts if parent_rpcs.respond_to? :list_contexts
@list_contexts = ::Gapic::Config::Method.new list_contexts_config
- get_context_config = parent_rpcs&.get_context if parent_rpcs&.respond_to? :get_context
+ get_context_config = parent_rpcs.get_context if parent_rpcs.respond_to? :get_context
@get_context = ::Gapic::Config::Method.new get_context_config
- create_context_config = parent_rpcs&.create_context if parent_rpcs&.respond_to? :create_context
+ create_context_config = parent_rpcs.create_context if parent_rpcs.respond_to? :create_context
@create_context = ::Gapic::Config::Method.new create_context_config
- update_context_config = parent_rpcs&.update_context if parent_rpcs&.respond_to? :update_context
+ update_context_config = parent_rpcs.update_context if parent_rpcs.respond_to? :update_context
@update_context = ::Gapic::Config::Method.new update_context_config
- delete_context_config = parent_rpcs&.delete_context if parent_rpcs&.respond_to? :delete_context
+ delete_context_config = parent_rpcs.delete_context if parent_rpcs.respond_to? :delete_context
@delete_context = ::Gapic::Config::Method.new delete_context_config
- delete_all_contexts_config = parent_rpcs&.delete_all_contexts if parent_rpcs&.respond_to? :delete_all_contexts
+ delete_all_contexts_config = parent_rpcs.delete_all_contexts if parent_rpcs.respond_to? :delete_all_contexts
@delete_all_contexts = ::Gapic::Config::Method.new delete_all_contexts_config
yield self if block_given?
end
end