google-cloud-language 0.20.2 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4c7e8d3f85410dfae128039b0eca4d5a3a64757
4
- data.tar.gz: 636b67a4a34c6b2e6b9e497c4e91d56a12890bab
3
+ metadata.gz: 6536bd82a69982cc8b9da419acc3eeb883bdb739
4
+ data.tar.gz: 84831608d0fbb373ee9bfe869b47dfa7b7690275
5
5
  SHA512:
6
- metadata.gz: 50f34170360cca7eff01a4809ee8d027910912e9e9ec4fb4aafb36b2d7fc05dfe7b586057561a800fbc1c0678da0e69041ed139aca79cd00b5c1fc2cb1aca337
7
- data.tar.gz: a7dd8f7731b4d69d5cc575422f64fc88f8dae027ce96193c35f855ad5fcff1cc67712dc214fc256042c4d7dd32ae8aa660729086f7e9bc2bdc050b1a7cd876e1
6
+ metadata.gz: 6513aeb70c77930f49d4b5e1b73c3f254349f31f860d1ac899d8a6eccae98dc50ac776b089a7a0a65d41307801592983137acaf2cb3a5da4a43bfd20b30b1183
7
+ data.tar.gz: 537a9e4a4726b33a875d09ed4960985a4ed1f6d0dc3d2af36875dd631175555925d1bf232a8f475911770279d8da064a5916dbbdfc5fe1494cbf5abd6ba2630a
@@ -38,8 +38,9 @@ module Google
38
38
  # The default scope is:
39
39
  #
40
40
  # * `"https://www.googleapis.com/auth/cloud-platform"`
41
- # @param [Integer] retries This option is not currently supported.
42
41
  # @param [Integer] timeout Default timeout to use in requests. Optional.
42
+ # @param [Hash] client_config A hash of values to override the default
43
+ # behavior of the API client. Optional.
43
44
  #
44
45
  # @return [Google::Cloud::Language::Project]
45
46
  #
@@ -60,10 +61,10 @@ module Google
60
61
  # platform_scope = "https://www.googleapis.com/auth/cloud-platform"
61
62
  # language = gcloud.language scope: platform_scope
62
63
  #
63
- def language scope: nil, retries: nil, timeout: nil
64
- Google::Cloud.language @project, @keyfile, scope: scope,
65
- retries: (retries || @retries),
66
- timeout: (timeout || @timeout)
64
+ def language scope: nil, timeout: nil, client_config: nil
65
+ Google::Cloud.language @project, @keyfile,
66
+ scope: scope, timeout: (timeout || @timeout),
67
+ client_config: client_config
67
68
  end
68
69
 
69
70
  ##
@@ -85,13 +86,14 @@ module Google
85
86
  # The default scope is:
86
87
  #
87
88
  # * `"https://www.googleapis.com/auth/cloud-platform"`
88
- # @param [Integer] retries This option is not currently supported.
89
89
  # @param [Integer] timeout Default timeout to use in requests. Optional.
90
+ # @param [Hash] client_config A hash of values to override the default
91
+ # behavior of the API client. Optional.
90
92
  #
91
93
  # @return [Google::Cloud::Language::Project]
92
94
  #
93
95
  # @example
94
- # require "google/cloud/language"
96
+ # require "google/cloud"
95
97
  #
96
98
  # language = Google::Cloud.language
97
99
  #
@@ -99,19 +101,12 @@ module Google
99
101
  # document = language.document content
100
102
  # annotation = document.annotate
101
103
  #
102
- def self.language project = nil, keyfile = nil, scope: nil, retries: nil,
103
- timeout: nil
104
+ def self.language project = nil, keyfile = nil, scope: nil, timeout: nil,
105
+ client_config: nil
104
106
  require "google/cloud/language"
105
- project ||= Google::Cloud::Language::Project.default_project
106
- if keyfile.nil?
107
- credentials = Google::Cloud::Language::Credentials.default scope: scope
108
- else
109
- credentials = Google::Cloud::Language::Credentials.new(
110
- keyfile, scope: scope)
111
- end
112
- Google::Cloud::Language::Project.new(
113
- Google::Cloud::Language::Service.new(
114
- project, credentials, retries: retries, timeout: timeout))
107
+ Google::Cloud::Language.new project: project, keyfile: keyfile,
108
+ scope: scope, timeout: timeout,
109
+ client_config: client_config
115
110
  end
116
111
  end
117
112
  end
@@ -64,10 +64,9 @@ module Google
64
64
  # Language service. You can provide text or HTML content as a string:
65
65
  #
66
66
  # ```ruby
67
- # require "google/cloud"
67
+ # require "google/cloud/language"
68
68
  #
69
- # gcloud = Google::Cloud.new
70
- # language = gcloud.language
69
+ # language = Google::Cloud::Language.new
71
70
  #
72
71
  # document = language.document "It was the best of times, it was..."
73
72
  # ```
@@ -75,10 +74,9 @@ module Google
75
74
  # Or, you can pass a Google Cloud Storage URI for a text or HTML file:
76
75
  #
77
76
  # ```ruby
78
- # require "google/cloud"
77
+ # require "google/cloud/language"
79
78
  #
80
- # gcloud = Google::Cloud.new
81
- # language = gcloud.language
79
+ # language = Google::Cloud::Language.new
82
80
  #
83
81
  # document = language.document "gs://bucket-name/path/to/document"
84
82
  # ```
@@ -86,15 +84,16 @@ module Google
86
84
  # Or, you can initialize it with a Google Cloud Storage File object:
87
85
  #
88
86
  # ```ruby
89
- # require "google/cloud"
87
+ # require "google/cloud/storage"
90
88
  #
91
- # gcloud = Google::Cloud.new
92
- # storage = gcloud.storage
89
+ # storage = Google::Cloud::Storage.new
93
90
  #
94
91
  # bucket = storage.bucket "bucket-name"
95
92
  # file = bucket.file "path/to/document"
96
93
  #
97
- # language = gcloud.language
94
+ # require "google/cloud/language"
95
+ #
96
+ # language = Google::Cloud::Language.new
98
97
  #
99
98
  # document = language.document file
100
99
  # ```
@@ -102,10 +101,9 @@ module Google
102
101
  # You can specify the format and language of the content:
103
102
  #
104
103
  # ```ruby
105
- # require "google/cloud"
104
+ # require "google/cloud/language"
106
105
  #
107
- # gcloud = Google::Cloud.new
108
- # language = gcloud.language
106
+ # language = Google::Cloud::Language.new
109
107
  #
110
108
  # document = language.document "<p>El viejo y el mar</p>",
111
109
  # format: :html, language: "es"
@@ -130,10 +128,9 @@ module Google
130
128
  # English is supported for sentiment analysis.
131
129
  #
132
130
  # ```ruby
133
- # require "google/cloud"
131
+ # require "google/cloud/language"
134
132
  #
135
- # gcloud = Google::Cloud.new
136
- # language = gcloud.language
133
+ # language = Google::Cloud::Language.new
137
134
  #
138
135
  # content = "Darth Vader is the best villain in Star Wars."
139
136
  # document = language.document content
@@ -149,10 +146,9 @@ module Google
149
146
  # {Language::Document#entities} method.
150
147
  #
151
148
  # ```ruby
152
- # require "google/cloud"
149
+ # require "google/cloud/language"
153
150
  #
154
- # gcloud = Google::Cloud.new
155
- # language = gcloud.language
151
+ # language = Google::Cloud::Language.new
156
152
  #
157
153
  # content = "Darth Vader is the best villain in Star Wars."
158
154
  # document = language.document content
@@ -171,10 +167,9 @@ module Google
171
167
  # performed with the {Language::Document#syntax} method.
172
168
  #
173
169
  # ```ruby
174
- # require "google/cloud"
170
+ # require "google/cloud/language"
175
171
  #
176
- # gcloud = Google::Cloud.new
177
- # language = gcloud.language
172
+ # language = Google::Cloud::Language.new
178
173
  #
179
174
  # content = "Darth Vader is the best villain in Star Wars."
180
175
  # document = language.document content
@@ -188,10 +183,9 @@ module Google
188
183
  # for each desired feature to {Language::Document#annotate}:
189
184
  #
190
185
  # ```ruby
191
- # require "google/cloud"
186
+ # require "google/cloud/language"
192
187
  #
193
- # gcloud = Google::Cloud.new
194
- # language = gcloud.language
188
+ # language = Google::Cloud::Language.new
195
189
  #
196
190
  # content = "Darth Vader is the best villain in Star Wars."
197
191
  # document = language.document content
@@ -207,10 +201,9 @@ module Google
207
201
  # the document with **all** features:
208
202
  #
209
203
  # ```ruby
210
- # require "google/cloud"
204
+ # require "google/cloud/language"
211
205
  #
212
- # gcloud = Google::Cloud.new
213
- # language = gcloud.language
206
+ # language = Google::Cloud::Language.new
214
207
  #
215
208
  # content = "Darth Vader is the best villain in Star Wars."
216
209
  # document = language.document content
@@ -224,6 +217,57 @@ module Google
224
217
  # ```
225
218
  #
226
219
  module Language
220
+ ##
221
+ # Creates a new object for connecting to the Language service.
222
+ # Each call creates a new connection.
223
+ #
224
+ # For more information on connecting to Google Cloud see the
225
+ # [Authentication
226
+ # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
227
+ #
228
+ # @param [String] project Project identifier for the Language service you
229
+ # are connecting to.
230
+ # @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If
231
+ # file path the file must be readable.
232
+ # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
233
+ # the set of resources and operations that the connection can access.
234
+ # See [Using OAuth 2.0 to Access Google
235
+ # APIs](https://developers.goorequire
236
+ # "google/cloud"gle.com/identity/protocols/OAuth2).
237
+ #
238
+ # The default scope is:
239
+ #
240
+ # * `"https://www.googleapis.com/auth/cloud-platform"`
241
+ # @param [Integer] timeout Default timeout to use in requests. Optional.
242
+ # @param [Hash] client_config A hash of values to override the default
243
+ # behavior of the API client. Optional.
244
+ #
245
+ # @return [Google::Cloud::Language::Project]
246
+ #
247
+ # @example
248
+ # require "google/cloud/language"
249
+ #
250
+ # language = Google::Cloud::Language.new
251
+ #
252
+ # content = "Darth Vader is the best villain in Star Wars."
253
+ # document = language.document content
254
+ # annotation = document.annotate
255
+ #
256
+ def self.new project: nil, keyfile: nil, scope: nil, timeout: nil,
257
+ client_config: nil
258
+ project ||= Google::Cloud::Language::Project.default_project
259
+ if keyfile.nil?
260
+ credentials = Google::Cloud::Language::Credentials.default(
261
+ scope: scope)
262
+ else
263
+ credentials = Google::Cloud::Language::Credentials.new(
264
+ keyfile, scope: scope)
265
+ end
266
+ Google::Cloud::Language::Project.new(
267
+ Google::Cloud::Language::Service.new(
268
+ project, credentials, timeout: timeout,
269
+ client_config: client_config))
270
+ end
227
271
  end
228
272
  end
229
273
  end
@@ -26,10 +26,9 @@ module Google
26
26
  # See {Project#annotate} and {Document#annotate}.
27
27
  #
28
28
  # @example
29
- # require "google/cloud"
29
+ # require "google/cloud/language"
30
30
  #
31
- # gcloud = Google::Cloud.new
32
- # language = gcloud.language
31
+ # language = Google::Cloud::Language.new
33
32
  #
34
33
  # content = "Darth Vader is the best villain in Star Wars."
35
34
  # document = language.document content
@@ -59,10 +58,9 @@ module Google
59
58
  # relative location
60
59
  #
61
60
  # @example
62
- # require "google/cloud"
61
+ # require "google/cloud/language"
63
62
  #
64
- # gcloud = Google::Cloud.new
65
- # language = gcloud.language
63
+ # language = Google::Cloud::Language.new
66
64
  #
67
65
  # content = "I love dogs. I hate cats."
68
66
  # document = language.document content
@@ -85,10 +83,9 @@ module Google
85
83
  # blocks of the text
86
84
  #
87
85
  # @example
88
- # require "google/cloud"
86
+ # require "google/cloud/language"
89
87
  #
90
- # gcloud = Google::Cloud.new
91
- # language = gcloud.language
88
+ # language = Google::Cloud::Language.new
92
89
  #
93
90
  # content = "Darth Vader is the best villain in Star Wars."
94
91
  # document = language.document content
@@ -114,10 +111,9 @@ module Google
114
111
  # @return [Entities]
115
112
  #
116
113
  # @example
117
- # require "google/cloud"
114
+ # require "google/cloud/language"
118
115
  #
119
- # gcloud = Google::Cloud.new
120
- # language = gcloud.language
116
+ # language = Google::Cloud::Language.new
121
117
  #
122
118
  # content = "Darth Vader is the best villain in Star Wars."
123
119
  # document = language.document content
@@ -145,10 +141,9 @@ module Google
145
141
  # @return [Sentiment]
146
142
  #
147
143
  # @example
148
- # require "google/cloud"
144
+ # require "google/cloud/language"
149
145
  #
150
- # gcloud = Google::Cloud.new
151
- # language = gcloud.language
146
+ # language = Google::Cloud::Language.new
152
147
  #
153
148
  # content = "Darth Vader is the best villain in Star Wars."
154
149
  # document = language.document content
@@ -172,10 +167,9 @@ module Google
172
167
  # @return [String] the language code
173
168
  #
174
169
  # @example
175
- # require "google/cloud"
170
+ # require "google/cloud/language"
176
171
  #
177
- # gcloud = Google::Cloud.new
178
- # language = gcloud.language
172
+ # language = Google::Cloud::Language.new
179
173
  #
180
174
  # content = "Darth Vader is the best villain in Star Wars."
181
175
  # document = language.document content
@@ -214,10 +208,9 @@ module Google
214
208
  # specified in the API request.
215
209
  #
216
210
  # @example
217
- # require "google/cloud"
211
+ # require "google/cloud/language"
218
212
  #
219
- # gcloud = Google::Cloud.new
220
- # language = gcloud.language
213
+ # language = Google::Cloud::Language.new
221
214
  #
222
215
  # content = "I love dogs. I hate cats."
223
216
  # document = language.document content
@@ -263,10 +256,9 @@ module Google
263
256
  # of the token.
264
257
  #
265
258
  # @example
266
- # require "google/cloud"
259
+ # require "google/cloud/language"
267
260
  #
268
- # gcloud = Google::Cloud.new
269
- # language = gcloud.language
261
+ # language = Google::Cloud::Language.new
270
262
  #
271
263
  # content = "Darth Vader is the best villain in Star Wars."
272
264
  # document = language.document content
@@ -325,10 +317,9 @@ module Google
325
317
  # BCP-47 language codes are supported.
326
318
  #
327
319
  # @example
328
- # require "google/cloud"
320
+ # require "google/cloud/language"
329
321
  #
330
- # gcloud = Google::Cloud.new
331
- # language = gcloud.language
322
+ # language = Google::Cloud::Language.new
332
323
  #
333
324
  # content = "Darth Vader is the best villain in Star Wars."
334
325
  # document = language.document content
@@ -450,10 +441,9 @@ module Google
450
441
  # the input document. The API currently supports proper noun mentions.
451
442
  #
452
443
  # @example
453
- # require "google/cloud"
444
+ # require "google/cloud/language"
454
445
  #
455
- # gcloud = Google::Cloud.new
456
- # language = gcloud.language
446
+ # language = Google::Cloud::Language.new
457
447
  #
458
448
  # content = "Darth Vader is the best villain in Star Wars."
459
449
  # document = language.document content
@@ -591,10 +581,9 @@ module Google
591
581
  # BCP-47 language codes are supported.
592
582
  #
593
583
  # @example
594
- # require "google/cloud"
584
+ # require "google/cloud/language"
595
585
  #
596
- # gcloud = Google::Cloud.new
597
- # language = gcloud.language
586
+ # language = Google::Cloud::Language.new
598
587
  #
599
588
  # content = "Darth Vader is the best villain in Star Wars."
600
589
  # document = language.document content
@@ -34,10 +34,9 @@ module Google
34
34
  # See {Project#document}.
35
35
  #
36
36
  # @example
37
- # require "google/cloud"
37
+ # require "google/cloud/language"
38
38
  #
39
- # gcloud = Google::Cloud.new
40
- # language = gcloud.language
39
+ # language = Google::Cloud::Language.new
41
40
  #
42
41
  # content = "Darth Vader is the best villain in Star Wars."
43
42
  # document = language.document content
@@ -186,10 +185,9 @@ module Google
186
185
  # @return [Annotation>] The results of the content analysis.
187
186
  #
188
187
  # @example
189
- # require "google/cloud"
188
+ # require "google/cloud/language"
190
189
  #
191
- # gcloud = Google::Cloud.new
192
- # language = gcloud.language
190
+ # language = Google::Cloud::Language.new
193
191
  #
194
192
  # content = "Darth Vader is the best villain in Star Wars."
195
193
  # document = language.document content
@@ -202,10 +200,9 @@ module Google
202
200
  # annotation.tokens.count #=> 10
203
201
  #
204
202
  # @example With feature flags:
205
- # require "google/cloud"
203
+ # require "google/cloud/language"
206
204
  #
207
- # gcloud = Google::Cloud.new
208
- # language = gcloud.language
205
+ # language = Google::Cloud::Language.new
209
206
  #
210
207
  # content = "Darth Vader is the best villain in Star Wars."
211
208
  # document = language.document content
@@ -239,10 +236,9 @@ module Google
239
236
  # @return [Annotation>] The results for the content analysis.
240
237
  #
241
238
  # @example
242
- # require "google/cloud"
239
+ # require "google/cloud/language"
243
240
  #
244
- # gcloud = Google::Cloud.new
245
- # language = gcloud.language
241
+ # language = Google::Cloud::Language.new
246
242
  #
247
243
  # document = language.document "Hello world!"
248
244
  #
@@ -264,10 +260,9 @@ module Google
264
260
  # @return [Annotation::Entities>] The results for the entities analysis.
265
261
  #
266
262
  # @example
267
- # require "google/cloud"
263
+ # require "google/cloud/language"
268
264
  #
269
- # gcloud = Google::Cloud.new
270
- # language = gcloud.language
265
+ # language = Google::Cloud::Language.new
271
266
  #
272
267
  # content = "Darth Vader is the best villain in Star Wars."
273
268
  # document = language.document content
@@ -295,10 +290,9 @@ module Google
295
290
  # analysis.
296
291
  #
297
292
  # @example
298
- # require "google/cloud"
293
+ # require "google/cloud/language"
299
294
  #
300
- # gcloud = Google::Cloud.new
301
- # language = gcloud.language
295
+ # language = Google::Cloud::Language.new
302
296
  #
303
297
  # content = "Darth Vader is the best villain in Star Wars."
304
298
  # document = language.document content
@@ -14,7 +14,7 @@
14
14
 
15
15
 
16
16
  require "google/cloud/errors"
17
- require "google/cloud/core/gce"
17
+ require "google/cloud/core/environment"
18
18
  require "google/cloud/language/service"
19
19
  require "google/cloud/language/document"
20
20
  require "google/cloud/language/annotation"
@@ -33,10 +33,9 @@ module Google
33
33
  # See {Google::Cloud#language}
34
34
  #
35
35
  # @example
36
- # require "google/cloud"
36
+ # require "google/cloud/language"
37
37
  #
38
- # gcloud = Google::Cloud.new
39
- # language = gcloud.language
38
+ # language = Google::Cloud::Language.new
40
39
  #
41
40
  # content = "Darth Vader is the best villain in Star Wars."
42
41
  # annotation = language.annotate content
@@ -61,11 +60,12 @@ module Google
61
60
  # The Language project connected to.
62
61
  #
63
62
  # @example
64
- # require "google/cloud"
63
+ # require "google/cloud/language"
65
64
  #
66
- # gcloud = Google::Cloud.new "my-project-id",
67
- # "/path/to/keyfile.json"
68
- # language = gcloud.language
65
+ # language = Google::Cloud::Language.new(
66
+ # project: "my-project-id",
67
+ # keyfile: "/path/to/keyfile.json"
68
+ # )
69
69
  #
70
70
  # language.project #=> "my-project-id"
71
71
  #
@@ -79,7 +79,7 @@ module Google
79
79
  ENV["LANGUAGE_PROJECT"] ||
80
80
  ENV["GOOGLE_CLOUD_PROJECT"] ||
81
81
  ENV["GCLOUD_PROJECT"] ||
82
- Google::Cloud::Core::GCE.project_id
82
+ Google::Cloud::Core::Environment.project_id
83
83
  end
84
84
 
85
85
  ##
@@ -98,39 +98,35 @@ module Google
98
98
  # @return [Document] An document for the Language service.
99
99
  #
100
100
  # @example
101
- # require "google/cloud"
101
+ # require "google/cloud/language"
102
102
  #
103
- # gcloud = Google::Cloud.new
104
- # language = gcloud.language
103
+ # language = Google::Cloud::Language.new
105
104
  #
106
105
  # document = language.document "It was the best of times, it was..."
107
106
  #
108
107
  # @example With a Google Cloud Storage URI:
109
- # require "google/cloud"
108
+ # require "google/cloud/language"
110
109
  #
111
- # gcloud = Google::Cloud.new
112
- # language = gcloud.language
110
+ # language = Google::Cloud::Language.new
113
111
  #
114
112
  # document = language.document "gs://bucket-name/path/to/document"
115
113
  #
116
114
  # @example With a Google Cloud Storage File object:
117
- # require "google/cloud"
118
- #
119
- # gcloud = Google::Cloud.new
120
- # storage = gcloud.storage
115
+ # require "google/cloud/storage"
116
+ # storage = Google::Cloud::Storage.new
121
117
  #
122
118
  # bucket = storage.bucket "bucket-name"
123
119
  # file = bucket.file "path/to/document"
124
120
  #
125
- # language = gcloud.language
121
+ # require "google/cloud/language"
122
+ # language = Google::Cloud::Language.new
126
123
  #
127
124
  # document = language.document file
128
125
  #
129
126
  # @example With `format` and `language` options:
130
- # require "google/cloud"
127
+ # require "google/cloud/language"
131
128
  #
132
- # gcloud = Google::Cloud.new
133
- # language = gcloud.language
129
+ # language = Google::Cloud::Language.new
134
130
  #
135
131
  # document = language.document "<p>El viejo y el mar</p>",
136
132
  # format: :html, language: "es"
@@ -216,10 +212,9 @@ module Google
216
212
  # @return [Annotation>] The results for the content analysis.
217
213
  #
218
214
  # @example
219
- # require "google/cloud"
215
+ # require "google/cloud/language"
220
216
  #
221
- # gcloud = Google::Cloud.new
222
- # language = gcloud.language
217
+ # language = Google::Cloud::Language.new
223
218
  #
224
219
  # content = "Darth Vader is the best villain in Star Wars."
225
220
  # annotation = language.annotate content
@@ -263,10 +258,9 @@ module Google
263
258
  # @return [Annotation>] The results for the content syntax analysis.
264
259
  #
265
260
  # @example
266
- # require "google/cloud"
261
+ # require "google/cloud/language"
267
262
  #
268
- # gcloud = Google::Cloud.new
269
- # language = gcloud.language
263
+ # language = Google::Cloud::Language.new
270
264
  #
271
265
  # document = language.document "Hello world!"
272
266
  #
@@ -297,10 +291,9 @@ module Google
297
291
  # @return [Annotation::Entities>] The results for the entities analysis.
298
292
  #
299
293
  # @example
300
- # require "google/cloud"
294
+ # require "google/cloud/language"
301
295
  #
302
- # gcloud = Google::Cloud.new
303
- # language = gcloud.language
296
+ # language = Google::Cloud::Language.new
304
297
  #
305
298
  # document = language.document "Hello Chris and Mike!"
306
299
  #
@@ -333,10 +326,9 @@ module Google
333
326
  # analysis.
334
327
  #
335
328
  # @example
336
- # require "google/cloud"
329
+ # require "google/cloud/language"
337
330
  #
338
- # gcloud = Google::Cloud.new
339
- # language = gcloud.language
331
+ # language = Google::Cloud::Language.new
340
332
  #
341
333
  # document = language.document "Hello Chris and Mike!"
342
334
  #
@@ -16,7 +16,8 @@
16
16
  require "google/cloud/errors"
17
17
  require "google/cloud/language/credentials"
18
18
  require "google/cloud/language/version"
19
- require "google/cloud/language/v1beta1/language_service_pb"
19
+ require "google/cloud/language/v1beta1/language_service_services_pb"
20
+ require "google/cloud/language/v1beta1/language_service_api"
20
21
 
21
22
  module Google
22
23
  module Cloud
@@ -25,42 +26,40 @@ module Google
25
26
  # @private Represents the gRPC Language service, including all the API
26
27
  # methods.
27
28
  class Service
28
- attr_accessor :project, :credentials, :host, :retries, :timeout
29
+ attr_accessor :project, :credentials, :host, :client_config, :timeout
29
30
 
30
31
  ##
31
32
  # Creates a new Service instance.
32
- def initialize project, credentials, host: nil, retries: nil,
33
+ def initialize project, credentials, host: nil, client_config: nil,
33
34
  timeout: nil
34
35
  @project = project
35
36
  @credentials = credentials
36
37
  @host = host || V1beta1::LanguageServiceApi::SERVICE_ADDRESS
37
- @retries = retries
38
+ @client_config = client_config || {}
38
39
  @timeout = timeout
39
40
  end
40
41
 
41
42
  def channel
43
+ require "grpc"
42
44
  GRPC::Core::Channel.new host, nil, chan_creds
43
45
  end
44
46
 
45
47
  def chan_creds
46
48
  return credentials if insecure?
49
+ require "grpc"
47
50
  GRPC::Core::ChannelCredentials.new.compose \
48
51
  GRPC::Core::CallCredentials.new credentials.client.updater_proc
49
52
  end
50
53
 
51
54
  def service
52
55
  return mocked_service if mocked_service
53
- @service ||= begin
54
- require "google/cloud/language/v1beta1/language_service_api"
55
-
56
- V1beta1::LanguageServiceApi.new(
57
- service_path: host,
58
- channel: channel,
59
- timeout: timeout,
60
- app_name: "google-cloud-language",
61
- app_version: Google::Cloud::Language::VERSION)
62
- # TODO: Get retries configured
63
- end
56
+ @service ||= V1beta1::LanguageServiceApi.new(
57
+ service_path: host,
58
+ channel: channel,
59
+ timeout: timeout,
60
+ client_config: client_config,
61
+ app_name: "gcloud-ruby",
62
+ app_version: Google::Cloud::Language::VERSION)
64
63
  end
65
64
  attr_accessor :mocked_service
66
65
 
@@ -81,16 +80,24 @@ module Google
81
80
  extract_syntax: syntax, extract_entities: entities,
82
81
  extract_document_sentiment: sentiment)
83
82
  encoding = verify_encoding! encoding
84
- execute { service.annotate_text doc_grpc, features, encoding }
83
+ execute do
84
+ service.annotate_text doc_grpc, features, encoding,
85
+ options: default_options
86
+ end
85
87
  end
86
88
 
87
89
  def entities doc_grpc, encoding: nil
88
90
  encoding = verify_encoding! encoding
89
- execute { service.analyze_entities doc_grpc, encoding }
91
+ execute do
92
+ service.analyze_entities doc_grpc, encoding,
93
+ options: default_options
94
+ end
90
95
  end
91
96
 
92
97
  def sentiment doc_grpc
93
- execute { service.analyze_sentiment doc_grpc }
98
+ execute do
99
+ service.analyze_sentiment doc_grpc, options: default_options
100
+ end
94
101
  end
95
102
 
96
103
  def inspect
@@ -105,10 +112,19 @@ module Google
105
112
  encoding
106
113
  end
107
114
 
115
+ def default_headers
116
+ { "google-cloud-resource-prefix" => "projects/#{@project}" }
117
+ end
118
+
119
+ def default_options
120
+ Google::Gax::CallOptions.new kwargs: default_headers
121
+ end
122
+
108
123
  def execute
109
124
  yield
110
- rescue GRPC::BadStatus => e
111
- raise Google::Cloud::Error.from_error(e)
125
+ rescue Google::Gax::GaxError => e
126
+ # GaxError wraps BadStatus, but exposes it as #cause
127
+ raise Google::Cloud::Error.from_error(e.cause)
112
128
  end
113
129
  end
114
130
  end
@@ -26,7 +26,7 @@ require "json"
26
26
  require "pathname"
27
27
 
28
28
  require "google/gax"
29
- require "google/cloud/language/v1beta1/language_service_services_pb"
29
+ require "google/cloud/language/v1beta1/language_service_pb"
30
30
 
31
31
  module Google
32
32
  module Cloud
@@ -35,10 +35,10 @@ module Google
35
35
  # Provides text analysis operations such as sentiment analysis and entity
36
36
  # recognition.
37
37
  #
38
- # @!attribute [r] stub
38
+ # @!attribute [r] language_service_stub
39
39
  # @return [Google::Cloud::Language::V1beta1::LanguageService::Stub]
40
40
  class LanguageServiceApi
41
- attr_reader :stub
41
+ attr_reader :language_service_stub
42
42
 
43
43
  # The default address of the service.
44
44
  SERVICE_ADDRESS = "language.googleapis.com".freeze
@@ -85,8 +85,15 @@ module Google
85
85
  timeout: DEFAULT_TIMEOUT,
86
86
  app_name: "gax",
87
87
  app_version: Google::Gax::VERSION
88
+ # These require statements are intentionally placed here to initialize
89
+ # the gRPC module only when it's required.
90
+ # See https://github.com/googleapis/toolkit/issues/446
91
+ require "google/gax/grpc"
92
+ require "google/cloud/language/v1beta1/language_service_services_pb"
93
+
88
94
  google_api_client = "#{app_name}/#{app_version} " \
89
- "#{CODE_GEN_NAME_VERSION} ruby/#{RUBY_VERSION}".freeze
95
+ "#{CODE_GEN_NAME_VERSION} gax/#{Google::Gax::VERSION} " \
96
+ "ruby/#{RUBY_VERSION}".freeze
90
97
  headers = { :"x-goog-api-client" => google_api_client }
91
98
  client_config_file = Pathname.new(__dir__).join(
92
99
  "language_service_client_config.json"
@@ -102,7 +109,7 @@ module Google
102
109
  kwargs: headers
103
110
  )
104
111
  end
105
- @stub = Google::Gax::Grpc.create_stub(
112
+ @language_service_stub = Google::Gax::Grpc.create_stub(
106
113
  service_path,
107
114
  port,
108
115
  chan_creds: chan_creds,
@@ -112,15 +119,15 @@ module Google
112
119
  )
113
120
 
114
121
  @analyze_sentiment = Google::Gax.create_api_call(
115
- @stub.method(:analyze_sentiment),
122
+ @language_service_stub.method(:analyze_sentiment),
116
123
  defaults["analyze_sentiment"]
117
124
  )
118
125
  @analyze_entities = Google::Gax.create_api_call(
119
- @stub.method(:analyze_entities),
126
+ @language_service_stub.method(:analyze_entities),
120
127
  defaults["analyze_entities"]
121
128
  )
122
129
  @annotate_text = Google::Gax.create_api_call(
123
- @stub.method(:annotate_text),
130
+ @language_service_stub.method(:annotate_text),
124
131
  defaults["annotate_text"]
125
132
  )
126
133
  end
@@ -137,6 +144,16 @@ module Google
137
144
  # retries, etc.
138
145
  # @return [Google::Cloud::Language::V1beta1::AnalyzeSentimentResponse]
139
146
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
147
+ # @example
148
+ # require "google/cloud/language/v1beta1/language_service_api"
149
+ #
150
+ # Document = Google::Cloud::Language::V1beta1::Document
151
+ # LanguageServiceApi = Google::Cloud::Language::V1beta1::LanguageServiceApi
152
+ #
153
+ # language_service_api = LanguageServiceApi.new
154
+ # document = Document.new
155
+ # response = language_service_api.analyze_sentiment(document)
156
+
140
157
  def analyze_sentiment \
141
158
  document,
142
159
  options: nil
@@ -158,6 +175,18 @@ module Google
158
175
  # retries, etc.
159
176
  # @return [Google::Cloud::Language::V1beta1::AnalyzeEntitiesResponse]
160
177
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
178
+ # @example
179
+ # require "google/cloud/language/v1beta1/language_service_api"
180
+ #
181
+ # Document = Google::Cloud::Language::V1beta1::Document
182
+ # EncodingType = Google::Cloud::Language::V1beta1::EncodingType
183
+ # LanguageServiceApi = Google::Cloud::Language::V1beta1::LanguageServiceApi
184
+ #
185
+ # language_service_api = LanguageServiceApi.new
186
+ # document = Document.new
187
+ # encoding_type = EncodingType::NONE
188
+ # response = language_service_api.analyze_entities(document, encoding_type)
189
+
161
190
  def analyze_entities \
162
191
  document,
163
192
  encoding_type,
@@ -185,6 +214,20 @@ module Google
185
214
  # retries, etc.
186
215
  # @return [Google::Cloud::Language::V1beta1::AnnotateTextResponse]
187
216
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
217
+ # @example
218
+ # require "google/cloud/language/v1beta1/language_service_api"
219
+ #
220
+ # Document = Google::Cloud::Language::V1beta1::Document
221
+ # EncodingType = Google::Cloud::Language::V1beta1::EncodingType
222
+ # Features = Google::Cloud::Language::V1beta1::AnnotateTextRequest::Features
223
+ # LanguageServiceApi = Google::Cloud::Language::V1beta1::LanguageServiceApi
224
+ #
225
+ # language_service_api = LanguageServiceApi.new
226
+ # document = Document.new
227
+ # features = Features.new
228
+ # encoding_type = EncodingType::NONE
229
+ # response = language_service_api.annotate_text(document, features, encoding_type)
230
+
188
231
  def annotate_text \
189
232
  document,
190
233
  features,
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Language
19
- VERSION = "0.20.2"
19
+ VERSION = "0.21.0"
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-language
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.2
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-09-02 00:00:00.000000000 Z
12
+ date: 2016-10-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 0.20.0
20
+ version: 0.21.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 0.20.0
27
+ version: 0.21.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: grpc
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: 0.4.4
48
+ version: 0.6.0
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: 0.4.4
55
+ version: 0.6.0
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: google-protobuf
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -73,14 +73,14 @@ dependencies:
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '1.2'
76
+ version: '1.3'
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '1.2'
83
+ version: '1.3'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: minitest
86
86
  requirement: !ruby/object:Gem::Requirement
@@ -193,6 +193,20 @@ dependencies:
193
193
  - - "~>"
194
194
  - !ruby/object:Gem::Version
195
195
  version: '0.9'
196
+ - !ruby/object:Gem::Dependency
197
+ name: yard-doctest
198
+ requirement: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - "~>"
201
+ - !ruby/object:Gem::Version
202
+ version: 0.1.6
203
+ type: :development
204
+ prerelease: false
205
+ version_requirements: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - "~>"
208
+ - !ruby/object:Gem::Version
209
+ version: 0.1.6
196
210
  description: google-cloud-language is the official library for Google Cloud Natural
197
211
  Language API.
198
212
  email: