google-cloud-translate 1.1.0 → 1.2.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
  SHA256:
3
- metadata.gz: f57095104f31f5d2599e3e8581240c69e0ed606fd726cb382d2fda74f0547f85
4
- data.tar.gz: 834d192ac8e50111bebbf6c020301abcc6ed5f9f0b707adda84de0661ad79426
3
+ metadata.gz: 41ec37f5e02cac79d4901ad0538400bacbf4b6614042b9150165e6cbd415dae5
4
+ data.tar.gz: 7b337bce70d91e3d57ef0b7728a948b311322248776ca3517d45f3f8b0a942a1
5
5
  SHA512:
6
- metadata.gz: 3dacdd67988fc96e3560c492f3865af64ba0b9b47808031e50c94096619c55d5f0e4eff475ef95df7169ab99231b79e7be0bb7dd7af8ba2a8981ec029f01a194
7
- data.tar.gz: 60dcdf8e53fef429e271048fd7e07d8c3e0bfba4a2e95f74621f665d067e774436bfa6f57099eee50a0798abbf3ed9be9c9cd05263353a0dfdb36318a5a25db8
6
+ metadata.gz: 79da43c9637bc93f00de089075d484aa93971d6936d51d35605a409f3cf3d9ce43034fbd830770c34e6af13a3d409d980e193ab2982eb429d4dbd1f8063d3aab
7
+ data.tar.gz: 152b161306540e6cb2619b4d171de05376f2c43039f15dbdf52afa79930b88e482a131bffe3c2abe6f834675fb6d2c00038637deebaf949c858afaf8687e8d57
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  Apache License
2
2
  Version 2.0, January 2004
3
- http://www.apache.org/licenses/
3
+ https://www.apache.org/licenses/
4
4
 
5
5
  TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
6
 
@@ -192,7 +192,7 @@
192
192
  you may not use this file except in compliance with the License.
193
193
  You may obtain a copy of the License at
194
194
 
195
- http://www.apache.org/licenses/LICENSE-2.0
195
+ https://www.apache.org/licenses/LICENSE-2.0
196
196
 
197
197
  Unless required by applicable law or agreed to in writing, software
198
198
  distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,10 +1,10 @@
1
- # Copyright 2016 Google Inc. All rights reserved.
1
+ # Copyright 2016 Google LLC
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
5
5
  # You may obtain a copy of the License at
6
6
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
8
  #
9
9
  # Unless required by applicable law or agreed to in writing, software
10
10
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -20,6 +20,8 @@
20
20
 
21
21
  gem "google-cloud-core"
22
22
  require "google/cloud"
23
+ require "google/cloud/config"
24
+ require "googleauth"
23
25
 
24
26
  module Google
25
27
  module Cloud
@@ -140,3 +142,30 @@ module Google
140
142
  end
141
143
  end
142
144
  end
145
+
146
+ # Set the default translate configuration
147
+ Google::Cloud.configure.add_config! :translate do |config|
148
+ default_project = Google::Cloud::Config.deferred do
149
+ ENV["TRANSLATE_PROJECT"]
150
+ end
151
+ default_creds = Google::Cloud::Config.deferred do
152
+ Google::Cloud::Config.credentials_from_env(
153
+ "TRANSLATE_CREDENTIALS", "TRANSLATE_CREDENTIALS_JSON",
154
+ "TRANSLATE_KEYFILE", "TRANSLATE_KEYFILE_JSON"
155
+ )
156
+ end
157
+ default_key = Google::Cloud::Config.deferred do
158
+ ENV["TRANSLATE_KEY"] || ENV["GOOGLE_CLOUD_KEY"]
159
+ end
160
+
161
+ config.add_field! :project_id, default_project, match: String, allow_nil: true
162
+ config.add_alias! :project, :project_id
163
+ config.add_field! :credentials, default_creds,
164
+ match: [String, Hash, Google::Auth::Credentials],
165
+ allow_nil: true
166
+ config.add_alias! :keyfile, :credentials
167
+ config.add_field! :key, default_key, match: String, allow_nil: true
168
+ config.add_field! :scope, nil, match: [String, Array]
169
+ config.add_field! :retries, nil, match: Integer
170
+ config.add_field! :timeout, nil, match: Integer
171
+ end
@@ -1,10 +1,10 @@
1
- # Copyright 2016 Google Inc. All rights reserved.
1
+ # Copyright 2016 Google LLC
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
5
5
  # You may obtain a copy of the License at
6
6
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
8
  #
9
9
  # Unless required by applicable law or agreed to in writing, software
10
10
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,6 +15,8 @@
15
15
 
16
16
  require "google-cloud-translate"
17
17
  require "google/cloud/translate/api"
18
+ require "google/cloud/config"
19
+ require "google/cloud/env"
18
20
 
19
21
  module Google
20
22
  module Cloud
@@ -275,28 +277,75 @@ module Google
275
277
  #
276
278
  def self.new project_id: nil, credentials: nil, key: nil, scope: nil,
277
279
  retries: nil, timeout: nil, project: nil, keyfile: nil
278
- project_id ||= (project || Translate::Api.default_project_id)
280
+ project_id ||= (project || default_project_id)
279
281
  project_id = project_id.to_s # Always cast to a string
280
282
 
281
- key ||= ENV["TRANSLATE_KEY"]
282
- key ||= ENV["GOOGLE_CLOUD_KEY"]
283
+ key ||= configure.key
283
284
  if key
284
285
  return Google::Cloud::Translate::Api.new(
285
286
  Google::Cloud::Translate::Service.new(
286
- project_id, nil, retries: retries, timeout: timeout, key: key))
287
+ project_id, nil, retries: retries, timeout: timeout, key: key
288
+ )
289
+ )
287
290
  end
288
291
 
289
- fail ArgumentError, "project_id is missing" if project_id.empty?
292
+ raise ArgumentError, "project_id is missing" if project_id.empty?
290
293
 
291
- credentials ||= keyfile
292
- credentials ||= Translate::Credentials.default(scope: scope)
294
+ scope ||= configure.scope
295
+ retries ||= configure.retries
296
+ timeout ||= configure.timeout
297
+ credentials ||= keyfile || default_credentials(scope: scope)
293
298
  unless credentials.is_a? Google::Auth::Credentials
294
299
  credentials = Translate::Credentials.new credentials, scope: scope
295
300
  end
296
301
 
297
302
  Translate::Api.new(
298
303
  Translate::Service.new(
299
- project_id, credentials, retries: retries, timeout: timeout))
304
+ project_id, credentials, retries: retries, timeout: timeout
305
+ )
306
+ )
307
+ end
308
+
309
+ ##
310
+ # Configure the Google Cloud Translate library.
311
+ #
312
+ # The following Translate configuration parameters are supported:
313
+ #
314
+ # * `project_id` - (String) Identifier for a Translate project. (The
315
+ # parameter `project` is considered deprecated, but may also be used.)
316
+ # * `credentials` - (String, Hash, Google::Auth::Credentials) The path to
317
+ # the keyfile as a String, the contents of the keyfile as a Hash, or a
318
+ # Google::Auth::Credentials object. (See {Translate::Credentials}) (The
319
+ # parameter `keyfile` is considered deprecated, but may also be used.)
320
+ # * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
321
+ # the set of resources and operations that the connection can access.
322
+ # * `retries` - (Integer) Number of times to retry requests on server
323
+ # error.
324
+ # * `timeout` - (Integer) Default timeout to use in requests.
325
+ #
326
+ # @return [Google::Cloud::Config] The configuration object the
327
+ # Google::Cloud::Translate library uses.
328
+ #
329
+ def self.configure
330
+ yield Google::Cloud.configure.translate if block_given?
331
+
332
+ Google::Cloud.configure.translate
333
+ end
334
+
335
+ ##
336
+ # @private Default project.
337
+ def self.default_project_id
338
+ Google::Cloud.configure.translate.project_id ||
339
+ Google::Cloud.configure.project_id ||
340
+ Google::Cloud.env.project_id
341
+ end
342
+
343
+ ##
344
+ # @private Default credentials.
345
+ def self.default_credentials scope: nil
346
+ Google::Cloud.configure.translate.credentials ||
347
+ Google::Cloud.configure.credentials ||
348
+ Translate::Credentials.default(scope: scope)
300
349
  end
301
350
  end
302
351
  end
@@ -1,10 +1,10 @@
1
- # Copyright 2016 Google Inc. All rights reserved.
1
+ # Copyright 2016 Google LLC
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
5
5
  # You may obtain a copy of the License at
6
6
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
8
  #
9
9
  # Unless required by applicable law or agreed to in writing, software
10
10
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,7 +13,6 @@
13
13
  # limitations under the License.
14
14
 
15
15
 
16
- require "google/cloud/env"
17
16
  require "google/cloud/translate/service"
18
17
  require "google/cloud/translate/translation"
19
18
  require "google/cloud/translate/detection"
@@ -78,16 +77,7 @@ module Google
78
77
  def project_id
79
78
  service.project
80
79
  end
81
- alias_method :project, :project_id
82
-
83
- ##
84
- # @private Default project.
85
- def self.default_project_id
86
- ENV["TRANSLATE_PROJECT"] ||
87
- ENV["GOOGLE_CLOUD_PROJECT"] ||
88
- ENV["GCLOUD_PROJECT"] ||
89
- Google::Cloud.env.project_id
90
- end
80
+ alias project project_id
91
81
 
92
82
  ##
93
83
  # Returns text translations from one language to another.
@@ -184,7 +174,7 @@ module Google
184
174
  def translate *text, to: nil, from: nil, format: nil, model: nil,
185
175
  cid: nil
186
176
  return nil if text.empty?
187
- fail ArgumentError, "to is required" if to.nil?
177
+ raise ArgumentError, "to is required" if to.nil?
188
178
  to = to.to_s
189
179
  from = from.to_s if from
190
180
  format = format.to_s if format
@@ -1,10 +1,10 @@
1
- # Copyright 2016 Google Inc. All rights reserved.
1
+ # Copyright 2016 Google LLC
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
5
5
  # You may obtain a copy of the License at
6
6
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
8
  #
9
9
  # Unless required by applicable law or agreed to in writing, software
10
10
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -38,19 +38,19 @@ module Google
38
38
  # translate.project_id #=> "my-todo-project"
39
39
  #
40
40
  class Credentials < Google::Auth::Credentials
41
- SCOPE = ["https://www.googleapis.com/auth/cloud-platform"]
42
- PATH_ENV_VARS = %w(TRANSLATE_CREDENTIALS
41
+ SCOPE = ["https://www.googleapis.com/auth/cloud-platform"].freeze
42
+ PATH_ENV_VARS = %w[TRANSLATE_CREDENTIALS
43
43
  TRANSLATE_KEYFILE
44
44
  GOOGLE_CLOUD_CREDENTIALS
45
45
  GOOGLE_CLOUD_KEYFILE
46
- GCLOUD_KEYFILE)
47
- JSON_ENV_VARS = %w(TRANSLATE_CREDENTIALS_JSON
46
+ GCLOUD_KEYFILE].freeze
47
+ JSON_ENV_VARS = %w[TRANSLATE_CREDENTIALS_JSON
48
48
  TRANSLATE_KEYFILE_JSON
49
49
  GOOGLE_CLOUD_CREDENTIALS_JSON
50
50
  GOOGLE_CLOUD_KEYFILE_JSON
51
- GCLOUD_KEYFILE_JSON)
51
+ GCLOUD_KEYFILE_JSON].freeze
52
52
  DEFAULT_PATHS = \
53
- ["~/.config/gcloud/application_default_credentials.json"]
53
+ ["~/.config/gcloud/application_default_credentials.json"].freeze
54
54
  end
55
55
  end
56
56
  end
@@ -1,10 +1,10 @@
1
- # Copyright 2016 Google Inc. All rights reserved.
1
+ # Copyright 2016 Google LLC
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
5
5
  # You may obtain a copy of the License at
6
6
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
8
  #
9
9
  # Unless required by applicable law or agreed to in writing, software
10
10
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,10 +1,10 @@
1
- # Copyright 2016 Google Inc. All rights reserved.
1
+ # Copyright 2016 Google LLC
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
5
5
  # You may obtain a copy of the License at
6
6
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
8
  #
9
9
  # Unless required by applicable law or agreed to in writing, software
10
10
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -1,10 +1,10 @@
1
- # Copyright 2016 Google Inc. All rights reserved.
1
+ # Copyright 2016 Google LLC
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
5
5
  # You may obtain a copy of the License at
6
6
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
8
  #
9
9
  # Unless required by applicable law or agreed to in writing, software
10
10
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -25,8 +25,8 @@ module Google
25
25
  # @private
26
26
  # Represents the Translation API REST service, exposing the API calls.
27
27
  class Service #:nodoc:
28
- API_VERSION = "v2"
29
- API_URL = "https://translation.googleapis.com"
28
+ API_VERSION = "v2".freeze
29
+ API_URL = "https://translation.googleapis.com".freeze
30
30
 
31
31
  # @private
32
32
  attr_accessor :project, :credentials, :retries, :timeout, :key
@@ -71,7 +71,7 @@ module Google
71
71
  end
72
72
 
73
73
  def inspect
74
- "#{self.class}"
74
+ self.class.to_s
75
75
  end
76
76
 
77
77
  protected
@@ -92,7 +92,7 @@ module Google
92
92
 
93
93
  return JSON.parse(response.body)["data"] if response.success?
94
94
 
95
- fail Google::Cloud::Error.gapi_error_class_for(response.status)
95
+ raise Google::Cloud::Error.gapi_error_class_for(response.status)
96
96
  rescue Faraday::ConnectionFailed
97
97
  raise Google::Cloud::ResourceExhaustedError
98
98
  end
@@ -153,7 +153,7 @@ module Google
153
153
  # Set the default values
154
154
  self.retries = 3
155
155
  self.http_codes = [500, 503]
156
- self.reasons = %w(rateLimitExceeded userRateLimitExceeded)
156
+ self.reasons = %w[rateLimitExceeded userRateLimitExceeded]
157
157
  self.backoff = ->(retries) { sleep retries.to_i }
158
158
 
159
159
  def initialize options = {} #:nodoc:
@@ -1,10 +1,10 @@
1
- # Copyright 2016 Google Inc. All rights reserved.
1
+ # Copyright 2016 Google LLC
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
5
5
  # You may obtain a copy of the License at
6
6
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
8
  #
9
9
  # Unless required by applicable law or agreed to in writing, software
10
10
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -45,8 +45,8 @@ module Google
45
45
  #
46
46
  # @return [String]
47
47
  attr_reader :text
48
- alias_method :to_s, :text
49
- alias_method :to_str, :text
48
+ alias to_s text
49
+ alias to_str text
50
50
 
51
51
  ##
52
52
  # The original query text that was translated.
@@ -59,15 +59,15 @@ module Google
59
59
  #
60
60
  # @return [String]
61
61
  attr_reader :to
62
- alias_method :language, :to
63
- alias_method :target, :to
62
+ alias language to
63
+ alias target to
64
64
 
65
65
  ##
66
66
  # The source language from which the text was translated.
67
67
  #
68
68
  # @return [String]
69
69
  attr_reader :from
70
- alias_method :source, :from
70
+ alias source from
71
71
 
72
72
  ##
73
73
  # The translation model. Can be either `base` for the Phrase-Based
@@ -1,10 +1,10 @@
1
- # Copyright 2016 Google Inc. All rights reserved.
1
+ # Copyright 2016 Google LLC
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
5
5
  # You may obtain a copy of the License at
6
6
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
8
  #
9
9
  # Unless required by applicable law or agreed to in writing, software
10
10
  # distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Translate
19
- VERSION = "1.1.0"
19
+ VERSION = "1.2.0".freeze
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-translate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.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: 2017-11-15 00:00:00.000000000 Z
12
+ date: 2018-02-28 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: '1.1'
20
+ version: '1.2'
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: '1.1'
27
+ version: '1.2'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: faraday
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -127,16 +127,16 @@ dependencies:
127
127
  name: rubocop
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  requirements:
130
- - - "<="
130
+ - - "~>"
131
131
  - !ruby/object:Gem::Version
132
- version: 0.35.1
132
+ version: 0.50.0
133
133
  type: :development
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
136
136
  requirements:
137
- - - "<="
137
+ - - "~>"
138
138
  - !ruby/object:Gem::Version
139
- version: 0.35.1
139
+ version: 0.50.0
140
140
  - !ruby/object:Gem::Dependency
141
141
  name: simplecov
142
142
  requirement: !ruby/object:Gem::Requirement
@@ -220,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
220
  version: '0'
221
221
  requirements: []
222
222
  rubyforge_project:
223
- rubygems_version: 2.7.2
223
+ rubygems_version: 2.7.6
224
224
  signing_key:
225
225
  specification_version: 4
226
226
  summary: API Client library for Google Cloud Translation API