google-cloud-dialogflow 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,7 +25,7 @@ require "pathname"
25
25
  require "google/gax"
26
26
 
27
27
  require "google/cloud/dialogflow/v2/context_pb"
28
- require "google/cloud/dialogflow/credentials"
28
+ require "google/cloud/dialogflow/v2/credentials"
29
29
 
30
30
  module Google
31
31
  module Cloud
@@ -60,6 +60,9 @@ module Google
60
60
  # The default port of the service.
61
61
  DEFAULT_SERVICE_PORT = 443
62
62
 
63
+ # The default set of gRPC interceptors.
64
+ GRPC_INTERCEPTORS = []
65
+
63
66
  DEFAULT_TIMEOUT = 30
64
67
 
65
68
  PAGE_DESCRIPTORS = {
@@ -138,11 +141,18 @@ module Google
138
141
  # or the specified config is missing data points.
139
142
  # @param timeout [Numeric]
140
143
  # The default timeout, in seconds, for calls made through this client.
144
+ # @param metadata [Hash]
145
+ # Default metadata to be sent with each request. This can be overridden on a per call basis.
146
+ # @param exception_transformer [Proc]
147
+ # An optional proc that intercepts any exceptions raised during an API call to inject
148
+ # custom error handling.
141
149
  def initialize \
142
150
  credentials: nil,
143
151
  scopes: ALL_SCOPES,
144
152
  client_config: {},
145
153
  timeout: DEFAULT_TIMEOUT,
154
+ metadata: nil,
155
+ exception_transformer: nil,
146
156
  lib_name: nil,
147
157
  lib_version: ""
148
158
  # These require statements are intentionally placed here to initialize
@@ -151,10 +161,10 @@ module Google
151
161
  require "google/gax/grpc"
152
162
  require "google/cloud/dialogflow/v2/context_services_pb"
153
163
 
154
- credentials ||= Google::Cloud::Dialogflow::Credentials.default
164
+ credentials ||= Google::Cloud::Dialogflow::V2::Credentials.default
155
165
 
156
166
  if credentials.is_a?(String) || credentials.is_a?(Hash)
157
- updater_proc = Google::Cloud::Dialogflow::Credentials.new(credentials).updater_proc
167
+ updater_proc = Google::Cloud::Dialogflow::V2::Credentials.new(credentials).updater_proc
158
168
  end
159
169
  if credentials.is_a?(GRPC::Core::Channel)
160
170
  channel = credentials
@@ -178,6 +188,7 @@ module Google
178
188
  google_api_client.freeze
179
189
 
180
190
  headers = { :"x-goog-api-client" => google_api_client }
191
+ headers.merge!(metadata) unless metadata.nil?
181
192
  client_config_file = Pathname.new(__dir__).join(
182
193
  "contexts_client_config.json"
183
194
  )
@@ -190,13 +201,14 @@ module Google
190
201
  timeout,
191
202
  page_descriptors: PAGE_DESCRIPTORS,
192
203
  errors: Google::Gax::Grpc::API_ERRORS,
193
- kwargs: headers
204
+ metadata: headers
194
205
  )
195
206
  end
196
207
 
197
208
  # Allow overriding the service path/port in subclasses.
198
209
  service_path = self.class::SERVICE_ADDRESS
199
210
  port = self.class::DEFAULT_SERVICE_PORT
211
+ interceptors = self.class::GRPC_INTERCEPTORS
200
212
  @contexts_stub = Google::Gax::Grpc.create_stub(
201
213
  service_path,
202
214
  port,
@@ -204,32 +216,39 @@ module Google
204
216
  channel: channel,
205
217
  updater_proc: updater_proc,
206
218
  scopes: scopes,
219
+ interceptors: interceptors,
207
220
  &Google::Cloud::Dialogflow::V2::Contexts::Stub.method(:new)
208
221
  )
209
222
 
210
223
  @list_contexts = Google::Gax.create_api_call(
211
224
  @contexts_stub.method(:list_contexts),
212
- defaults["list_contexts"]
225
+ defaults["list_contexts"],
226
+ exception_transformer: exception_transformer
213
227
  )
214
228
  @get_context = Google::Gax.create_api_call(
215
229
  @contexts_stub.method(:get_context),
216
- defaults["get_context"]
230
+ defaults["get_context"],
231
+ exception_transformer: exception_transformer
217
232
  )
218
233
  @create_context = Google::Gax.create_api_call(
219
234
  @contexts_stub.method(:create_context),
220
- defaults["create_context"]
235
+ defaults["create_context"],
236
+ exception_transformer: exception_transformer
221
237
  )
222
238
  @update_context = Google::Gax.create_api_call(
223
239
  @contexts_stub.method(:update_context),
224
- defaults["update_context"]
240
+ defaults["update_context"],
241
+ exception_transformer: exception_transformer
225
242
  )
226
243
  @delete_context = Google::Gax.create_api_call(
227
244
  @contexts_stub.method(:delete_context),
228
- defaults["delete_context"]
245
+ defaults["delete_context"],
246
+ exception_transformer: exception_transformer
229
247
  )
230
248
  @delete_all_contexts = Google::Gax.create_api_call(
231
249
  @contexts_stub.method(:delete_all_contexts),
232
- defaults["delete_all_contexts"]
250
+ defaults["delete_all_contexts"],
251
+ exception_transformer: exception_transformer
233
252
  )
234
253
  end
235
254
 
@@ -249,6 +268,9 @@ module Google
249
268
  # @param options [Google::Gax::CallOptions]
250
269
  # Overrides the default settings for this call, e.g, timeout,
251
270
  # retries, etc.
271
+ # @yield [result, operation] Access the result along with the RPC operation
272
+ # @yieldparam result [Google::Gax::PagedEnumerable<Google::Cloud::Dialogflow::V2::Context>]
273
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
252
274
  # @return [Google::Gax::PagedEnumerable<Google::Cloud::Dialogflow::V2::Context>]
253
275
  # An enumerable of Google::Cloud::Dialogflow::V2::Context instances.
254
276
  # See Google::Gax::PagedEnumerable documentation for other
@@ -256,9 +278,9 @@ module Google
256
278
  # object.
257
279
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
258
280
  # @example
259
- # require "google/cloud/dialogflow/v2"
281
+ # require "google/cloud/dialogflow"
260
282
  #
261
- # contexts_client = Google::Cloud::Dialogflow::V2::Contexts.new
283
+ # contexts_client = Google::Cloud::Dialogflow::Contexts.new(version: :v2)
262
284
  # formatted_parent = Google::Cloud::Dialogflow::V2::ContextsClient.session_path("[PROJECT]", "[SESSION]")
263
285
  #
264
286
  # # Iterate over all results.
@@ -277,13 +299,14 @@ module Google
277
299
  def list_contexts \
278
300
  parent,
279
301
  page_size: nil,
280
- options: nil
302
+ options: nil,
303
+ &block
281
304
  req = {
282
305
  parent: parent,
283
306
  page_size: page_size
284
307
  }.delete_if { |_, v| v.nil? }
285
308
  req = Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::ListContextsRequest)
286
- @list_contexts.call(req, options)
309
+ @list_contexts.call(req, options, &block)
287
310
  end
288
311
 
289
312
  # Retrieves the specified context.
@@ -294,23 +317,27 @@ module Google
294
317
  # @param options [Google::Gax::CallOptions]
295
318
  # Overrides the default settings for this call, e.g, timeout,
296
319
  # retries, etc.
320
+ # @yield [result, operation] Access the result along with the RPC operation
321
+ # @yieldparam result [Google::Cloud::Dialogflow::V2::Context]
322
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
297
323
  # @return [Google::Cloud::Dialogflow::V2::Context]
298
324
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
299
325
  # @example
300
- # require "google/cloud/dialogflow/v2"
326
+ # require "google/cloud/dialogflow"
301
327
  #
302
- # contexts_client = Google::Cloud::Dialogflow::V2::Contexts.new
328
+ # contexts_client = Google::Cloud::Dialogflow::Contexts.new(version: :v2)
303
329
  # formatted_name = Google::Cloud::Dialogflow::V2::ContextsClient.context_path("[PROJECT]", "[SESSION]", "[CONTEXT]")
304
330
  # response = contexts_client.get_context(formatted_name)
305
331
 
306
332
  def get_context \
307
333
  name,
308
- options: nil
334
+ options: nil,
335
+ &block
309
336
  req = {
310
337
  name: name
311
338
  }.delete_if { |_, v| v.nil? }
312
339
  req = Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::GetContextRequest)
313
- @get_context.call(req, options)
340
+ @get_context.call(req, options, &block)
314
341
  end
315
342
 
316
343
  # Creates a context.
@@ -325,12 +352,15 @@ module Google
325
352
  # @param options [Google::Gax::CallOptions]
326
353
  # Overrides the default settings for this call, e.g, timeout,
327
354
  # retries, etc.
355
+ # @yield [result, operation] Access the result along with the RPC operation
356
+ # @yieldparam result [Google::Cloud::Dialogflow::V2::Context]
357
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
328
358
  # @return [Google::Cloud::Dialogflow::V2::Context]
329
359
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
330
360
  # @example
331
- # require "google/cloud/dialogflow/v2"
361
+ # require "google/cloud/dialogflow"
332
362
  #
333
- # contexts_client = Google::Cloud::Dialogflow::V2::Contexts.new
363
+ # contexts_client = Google::Cloud::Dialogflow::Contexts.new(version: :v2)
334
364
  # formatted_parent = Google::Cloud::Dialogflow::V2::ContextsClient.session_path("[PROJECT]", "[SESSION]")
335
365
  #
336
366
  # # TODO: Initialize +context+:
@@ -340,13 +370,14 @@ module Google
340
370
  def create_context \
341
371
  parent,
342
372
  context,
343
- options: nil
373
+ options: nil,
374
+ &block
344
375
  req = {
345
376
  parent: parent,
346
377
  context: context
347
378
  }.delete_if { |_, v| v.nil? }
348
379
  req = Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::CreateContextRequest)
349
- @create_context.call(req, options)
380
+ @create_context.call(req, options, &block)
350
381
  end
351
382
 
352
383
  # Updates the specified context.
@@ -362,12 +393,15 @@ module Google
362
393
  # @param options [Google::Gax::CallOptions]
363
394
  # Overrides the default settings for this call, e.g, timeout,
364
395
  # retries, etc.
396
+ # @yield [result, operation] Access the result along with the RPC operation
397
+ # @yieldparam result [Google::Cloud::Dialogflow::V2::Context]
398
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
365
399
  # @return [Google::Cloud::Dialogflow::V2::Context]
366
400
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
367
401
  # @example
368
- # require "google/cloud/dialogflow/v2"
402
+ # require "google/cloud/dialogflow"
369
403
  #
370
- # contexts_client = Google::Cloud::Dialogflow::V2::Contexts.new
404
+ # contexts_client = Google::Cloud::Dialogflow::Contexts.new(version: :v2)
371
405
  #
372
406
  # # TODO: Initialize +context+:
373
407
  # context = {}
@@ -376,13 +410,14 @@ module Google
376
410
  def update_context \
377
411
  context,
378
412
  update_mask: nil,
379
- options: nil
413
+ options: nil,
414
+ &block
380
415
  req = {
381
416
  context: context,
382
417
  update_mask: update_mask
383
418
  }.delete_if { |_, v| v.nil? }
384
419
  req = Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::UpdateContextRequest)
385
- @update_context.call(req, options)
420
+ @update_context.call(req, options, &block)
386
421
  end
387
422
 
388
423
  # Deletes the specified context.
@@ -393,22 +428,26 @@ module Google
393
428
  # @param options [Google::Gax::CallOptions]
394
429
  # Overrides the default settings for this call, e.g, timeout,
395
430
  # retries, etc.
431
+ # @yield [result, operation] Access the result along with the RPC operation
432
+ # @yieldparam result []
433
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
396
434
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
397
435
  # @example
398
- # require "google/cloud/dialogflow/v2"
436
+ # require "google/cloud/dialogflow"
399
437
  #
400
- # contexts_client = Google::Cloud::Dialogflow::V2::Contexts.new
438
+ # contexts_client = Google::Cloud::Dialogflow::Contexts.new(version: :v2)
401
439
  # formatted_name = Google::Cloud::Dialogflow::V2::ContextsClient.context_path("[PROJECT]", "[SESSION]", "[CONTEXT]")
402
440
  # contexts_client.delete_context(formatted_name)
403
441
 
404
442
  def delete_context \
405
443
  name,
406
- options: nil
444
+ options: nil,
445
+ &block
407
446
  req = {
408
447
  name: name
409
448
  }.delete_if { |_, v| v.nil? }
410
449
  req = Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::DeleteContextRequest)
411
- @delete_context.call(req, options)
450
+ @delete_context.call(req, options, &block)
412
451
  nil
413
452
  end
414
453
 
@@ -420,22 +459,26 @@ module Google
420
459
  # @param options [Google::Gax::CallOptions]
421
460
  # Overrides the default settings for this call, e.g, timeout,
422
461
  # retries, etc.
462
+ # @yield [result, operation] Access the result along with the RPC operation
463
+ # @yieldparam result []
464
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
423
465
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
424
466
  # @example
425
- # require "google/cloud/dialogflow/v2"
467
+ # require "google/cloud/dialogflow"
426
468
  #
427
- # contexts_client = Google::Cloud::Dialogflow::V2::Contexts.new
469
+ # contexts_client = Google::Cloud::Dialogflow::Contexts.new(version: :v2)
428
470
  # formatted_parent = Google::Cloud::Dialogflow::V2::ContextsClient.session_path("[PROJECT]", "[SESSION]")
429
471
  # contexts_client.delete_all_contexts(formatted_parent)
430
472
 
431
473
  def delete_all_contexts \
432
474
  parent,
433
- options: nil
475
+ options: nil,
476
+ &block
434
477
  req = {
435
478
  parent: parent
436
479
  }.delete_if { |_, v| v.nil? }
437
480
  req = Google::Gax::to_proto(req, Google::Cloud::Dialogflow::V2::DeleteAllContextsRequest)
438
- @delete_all_contexts.call(req, options)
481
+ @delete_all_contexts.call(req, options, &block)
439
482
  nil
440
483
  end
441
484
  end
@@ -0,0 +1,40 @@
1
+ # Copyright 2018 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require "googleauth"
16
+
17
+ module Google
18
+ module Cloud
19
+ module Dialogflow
20
+ module V2
21
+ class Credentials < Google::Auth::Credentials
22
+ SCOPE = [
23
+ "https://www.googleapis.com/auth/cloud-platform"
24
+ ].freeze
25
+ PATH_ENV_VARS = %w(DIALOGFLOW_CREDENTIALS
26
+ DIALOGFLOW_KEYFILE
27
+ GOOGLE_CLOUD_CREDENTIALS
28
+ GOOGLE_CLOUD_KEYFILE
29
+ GCLOUD_KEYFILE)
30
+ JSON_ENV_VARS = %w(DIALOGFLOW_CREDENTIALS_JSON
31
+ DIALOGFLOW_KEYFILE_JSON
32
+ GOOGLE_CLOUD_CREDENTIALS_JSON
33
+ GOOGLE_CLOUD_KEYFILE_JSON
34
+ GCLOUD_KEYFILE_JSON)
35
+ DEFAULT_PATHS = ["~/.config/gcloud/application_default_credentials.json"]
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -15,17 +15,6 @@
15
15
  module Google
16
16
  module Cloud
17
17
  module Dialogflow
18
- ##
19
- # # Dialogflow API Contents
20
- #
21
- # | Class | Description |
22
- # | ----- | ----------- |
23
- # | [AgentsClient][] | Agents are best described as Natural Language Understanding (NLU) modules that transform user requests into actionable data. |
24
- # | [Data Types][] | Data types for Google::Cloud::Dialogflow::V2 |
25
- #
26
- # [AgentsClient]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-dialogflow/latest/google/cloud/dialogflow/v2/agentsclient
27
- # [Data Types]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-dialogflow/latest/google/cloud/dialogflow/v2/datatypes
28
- #
29
18
  module V2
30
19
  # Represents a conversational agent.
31
20
  # @!attribute [rw] parent
@@ -15,17 +15,6 @@
15
15
  module Google
16
16
  module Cloud
17
17
  module Dialogflow
18
- ##
19
- # # Dialogflow API Contents
20
- #
21
- # | Class | Description |
22
- # | ----- | ----------- |
23
- # | [ContextsClient][] | A context represents additional information included with user input or with an intent returned by the Dialogflow API. |
24
- # | [Data Types][] | Data types for Google::Cloud::Dialogflow::V2 |
25
- #
26
- # [ContextsClient]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-dialogflow/latest/google/cloud/dialogflow/v2/contextsclient
27
- # [Data Types]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-dialogflow/latest/google/cloud/dialogflow/v2/datatypes
28
- #
29
18
  module V2
30
19
  # Represents a context.
31
20
  # @!attribute [rw] name
@@ -15,17 +15,6 @@
15
15
  module Google
16
16
  module Cloud
17
17
  module Dialogflow
18
- ##
19
- # # Dialogflow API Contents
20
- #
21
- # | Class | Description |
22
- # | ----- | ----------- |
23
- # | [EntityTypesClient][] | Entities are extracted from user input and represent parameters that are meaningful to your application. |
24
- # | [Data Types][] | Data types for Google::Cloud::Dialogflow::V2 |
25
- #
26
- # [EntityTypesClient]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-dialogflow/latest/google/cloud/dialogflow/v2/entitytypesclient
27
- # [Data Types]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-dialogflow/latest/google/cloud/dialogflow/v2/datatypes
28
- #
29
18
  module V2
30
19
  # Represents an entity type.
31
20
  # Entity types serve as a tool for extracting parameter values from natural
@@ -15,17 +15,6 @@
15
15
  module Google
16
16
  module Cloud
17
17
  module Dialogflow
18
- ##
19
- # # Dialogflow API Contents
20
- #
21
- # | Class | Description |
22
- # | ----- | ----------- |
23
- # | [IntentsClient][] | An intent represents a mapping between input from a user and an action to be taken by your application. |
24
- # | [Data Types][] | Data types for Google::Cloud::Dialogflow::V2 |
25
- #
26
- # [IntentsClient]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-dialogflow/latest/google/cloud/dialogflow/v2/intentsclient
27
- # [Data Types]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-dialogflow/latest/google/cloud/dialogflow/v2/datatypes
28
- #
29
18
  module V2
30
19
  # Represents an intent.
31
20
  # Intents convert a number of user expressions or patterns into an action. An
@@ -15,17 +15,6 @@
15
15
  module Google
16
16
  module Cloud
17
17
  module Dialogflow
18
- ##
19
- # # Dialogflow API Contents
20
- #
21
- # | Class | Description |
22
- # | ----- | ----------- |
23
- # | [SessionsClient][] | A session represents an interaction with a user. |
24
- # | [Data Types][] | Data types for Google::Cloud::Dialogflow::V2 |
25
- #
26
- # [SessionsClient]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-dialogflow/latest/google/cloud/dialogflow/v2/sessionsclient
27
- # [Data Types]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-dialogflow/latest/google/cloud/dialogflow/v2/datatypes
28
- #
29
18
  module V2
30
19
  # The request to detect user's intent.
31
20
  # @!attribute [rw] session