google-cloud-translate 1.0.1 → 1.1.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
- SHA1:
3
- metadata.gz: baa4ef9d4e57fa267c4a87b3dc644a845f18f576
4
- data.tar.gz: bbc46f7fe1a421d614cec10f86feed394e3de2b3
2
+ SHA256:
3
+ metadata.gz: f57095104f31f5d2599e3e8581240c69e0ed606fd726cb382d2fda74f0547f85
4
+ data.tar.gz: 834d192ac8e50111bebbf6c020301abcc6ed5f9f0b707adda84de0661ad79426
5
5
  SHA512:
6
- metadata.gz: b604d808b98dbf4c6dbbdb2a6b73ddeacfa288f04a19cb4d17ec7acd7822950a74906169329108f08f5c077a11461dd0fab381ce14e43c60c66ef72be68b044e
7
- data.tar.gz: eae5a477536f242613f890a04eab7952792104b08932ee0758170d4a76bed6c2653fe12dd160e9de39f67edb334810eec76a1506e2b0469d88a41efd0eff58c0
6
+ metadata.gz: 3dacdd67988fc96e3560c492f3865af64ba0b9b47808031e50c94096619c55d5f0e4eff475ef95df7169ab99231b79e7be0bb7dd7af8ba2a8981ec029f01a194
7
+ data.tar.gz: 60dcdf8e53fef429e271048fd7e07d8c3e0bfba4a2e95f74621f665d067e774436bfa6f57099eee50a0798abbf3ed9be9c9cd05263353a0dfdb36318a5a25db8
data/README.md CHANGED
@@ -48,8 +48,6 @@ This library is supported on Ruby 2.0+.
48
48
 
49
49
  This library follows [Semantic Versioning](http://semver.org/).
50
50
 
51
- It is currently in major version zero (0.y.z), which means that anything may change at any time and the public API should not be considered stable.
52
-
53
51
  ## Contributing
54
52
 
55
53
  Contributions to this library are always welcome and highly encouraged.
@@ -13,9 +13,9 @@
13
13
  # limitations under the License.
14
14
 
15
15
  ##
16
- # This file is here to be autorequired by bundler, so that the .bigquery and
17
- # #bigquery methods can be available, but the library and all dependencies won't
18
- # be loaded until required and used.
16
+ # This file is here to be autorequired by bundler, so that the
17
+ # Google::Cloud.translate and Google::Cloud#translate methods can be available,
18
+ # but the library and all dependencies won't be loaded until required and used.
19
19
 
20
20
 
21
21
  gem "google-cloud-core"
@@ -70,7 +70,7 @@ module Google
70
70
  # translation.text #=> "Salve mundi!"
71
71
  #
72
72
  def translate key = nil, scope: nil, retries: nil, timeout: nil
73
- Google::Cloud.translate key, project: @project, keyfile: @keyfile,
73
+ Google::Cloud.translate key, project_id: @project, credentials: @keyfile,
74
74
  scope: scope,
75
75
  retries: (retries || @retries),
76
76
  timeout: (timeout || @timeout)
@@ -88,10 +88,12 @@ module Google
88
88
  # [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-translate/guides/authentication).
89
89
  #
90
90
  # @param [String] key a public API access key (not an OAuth 2.0 token)
91
- # @param [String] project Identifier for the Cloud Translation API project
92
- # to which you are connecting.
93
- # @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If
94
- # file path the file must be readable.
91
+ # @param [String] project_id Project identifier for the Cloud Translation
92
+ # service you are connecting to. If not present, the default project for
93
+ # the credentials is used.
94
+ # @param [String, Hash, Google::Auth::Credentials] credentials The path to
95
+ # the keyfile as a String, the contents of the keyfile as a Hash, or a
96
+ # Google::Auth::Credentials object. (See {Translate::Credentials})
95
97
  # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
96
98
  # set of resources and operations that the connection can access. See
97
99
  # [Using OAuth 2.0 to Access Google
@@ -103,6 +105,9 @@ module Google
103
105
  # @param [Integer] retries Number of times to retry requests on server
104
106
  # error. The default value is `3`. Optional.
105
107
  # @param [Integer] timeout Default timeout to use in requests. Optional.
108
+ # @param [String] project Alias for the `project_id` argument. Deprecated.
109
+ # @param [String] keyfile Alias for the `credentials` argument.
110
+ # Deprecated.
106
111
  #
107
112
  # @return [Google::Cloud::Translate::Api]
108
113
  #
@@ -124,12 +129,14 @@ module Google
124
129
  # translation = translate.translate "Hello world!", to: "la"
125
130
  # translation.text #=> "Salve mundi!"
126
131
  #
127
- def self.translate key = nil, project: nil, keyfile: nil, scope: nil,
128
- retries: nil, timeout: nil
132
+ def self.translate key = nil, project_id: nil, credentials: nil, scope: nil,
133
+ retries: nil, timeout: nil, project: nil, keyfile: nil
129
134
  require "google/cloud/translate"
130
- Google::Cloud::Translate.new key: key, project: project, keyfile: keyfile,
135
+ Google::Cloud::Translate.new key: key, project_id: project_id,
136
+ credentials: credentials,
131
137
  scope: scope, retries: retries,
132
- timeout: timeout
138
+ timeout: timeout,
139
+ project: project, keyfile: keyfile
133
140
  end
134
141
  end
135
142
  end
@@ -218,10 +218,13 @@ module Google
218
218
  # covered in the [Authentication
219
219
  # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-translate/guides/authentication).
220
220
  #
221
- # @param [String] project Identifier for the Cloud Translation API project
222
- # to which you are connecting.
223
- # @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If
224
- # file path the file must be readable.
221
+ # @param [String] project_id Project identifier for the Cloud Translation
222
+ # service you are connecting to. If not present, the default project for
223
+ # the credentials is used.
224
+ # @param [String, Hash, Google::Auth::Credentials] credentials The path to
225
+ # the keyfile as a String, the contents of the keyfile as a Hash, or a
226
+ # Google::Auth::Credentials object. (See {Translate::Credentials})
227
+ # @param [String] key a public API access key (not an OAuth 2.0 token)
225
228
  # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
226
229
  # the set of resources and operations that the connection can access.
227
230
  # See [Using OAuth 2.0 to Access Google
@@ -230,10 +233,12 @@ module Google
230
233
  # The default scope is:
231
234
  #
232
235
  # * `https://www.googleapis.com/auth/cloud-platform`
233
- # @param [String] key a public API access key (not an OAuth 2.0 token)
234
236
  # @param [Integer] retries Number of times to retry requests on server
235
237
  # error. The default value is `3`. Optional.
236
238
  # @param [Integer] timeout Default timeout to use in requests. Optional.
239
+ # @param [String] project Alias for the `project_id` argument. Deprecated.
240
+ # @param [String] keyfile Alias for the `credentials` argument.
241
+ # Deprecated.
237
242
  #
238
243
  # @return [Google::Cloud::Translate::Api]
239
244
  #
@@ -241,8 +246,8 @@ module Google
241
246
  # require "google/cloud/translate"
242
247
  #
243
248
  # translate = Google::Cloud::Translate.new(
244
- # project: "my-todo-project",
245
- # keyfile: "/path/to/keyfile.json"
249
+ # project_id: "my-todo-project",
250
+ # credentials: "/path/to/keyfile.json"
246
251
  # )
247
252
  #
248
253
  # translation = translate.translate "Hello world!", to: "la"
@@ -268,30 +273,30 @@ module Google
268
273
  # translation = translate.translate "Hello world!", to: "la"
269
274
  # translation.text #=> "Salve mundi!"
270
275
  #
271
- def self.new project: nil, keyfile: nil, scope: nil, key: nil,
272
- retries: nil, timeout: nil
273
- project ||= Google::Cloud::Translate::Api.default_project
274
- project = project.to_s # Always cast to a string
276
+ def self.new project_id: nil, credentials: nil, key: nil, scope: nil,
277
+ retries: nil, timeout: nil, project: nil, keyfile: nil
278
+ project_id ||= (project || Translate::Api.default_project_id)
279
+ project_id = project_id.to_s # Always cast to a string
275
280
 
276
281
  key ||= ENV["TRANSLATE_KEY"]
277
282
  key ||= ENV["GOOGLE_CLOUD_KEY"]
278
283
  if key
279
284
  return Google::Cloud::Translate::Api.new(
280
285
  Google::Cloud::Translate::Service.new(
281
- project, nil, retries: retries, timeout: timeout, key: key))
286
+ project_id, nil, retries: retries, timeout: timeout, key: key))
282
287
  end
283
288
 
284
- if keyfile.nil?
285
- credentials = Google::Cloud::Translate::Credentials.default(
286
- scope: scope)
287
- else
288
- credentials = Google::Cloud::Translate::Credentials.new(
289
- keyfile, scope: scope)
289
+ fail ArgumentError, "project_id is missing" if project_id.empty?
290
+
291
+ credentials ||= keyfile
292
+ credentials ||= Translate::Credentials.default(scope: scope)
293
+ unless credentials.is_a? Google::Auth::Credentials
294
+ credentials = Translate::Credentials.new credentials, scope: scope
290
295
  end
291
296
 
292
- Google::Cloud::Translate::Api.new(
293
- Google::Cloud::Translate::Service.new(
294
- project, credentials, retries: retries, timeout: timeout))
297
+ Translate::Api.new(
298
+ Translate::Service.new(
299
+ project_id, credentials, retries: retries, timeout: timeout))
295
300
  end
296
301
  end
297
302
  end
@@ -69,19 +69,20 @@ module Google
69
69
  # require "google/cloud/translate"
70
70
  #
71
71
  # translate = Google::Cloud::Translate.new(
72
- # project: "my-todo-project",
73
- # keyfile: "/path/to/keyfile.json"
72
+ # project_id: "my-todo-project",
73
+ # credentials: "/path/to/keyfile.json"
74
74
  # )
75
75
  #
76
- # translate.project #=> "my-todo-project"
76
+ # translate.project_id #=> "my-todo-project"
77
77
  #
78
- def project
78
+ def project_id
79
79
  service.project
80
80
  end
81
+ alias_method :project, :project_id
81
82
 
82
83
  ##
83
84
  # @private Default project.
84
- def self.default_project
85
+ def self.default_project_id
85
86
  ENV["TRANSLATE_PROJECT"] ||
86
87
  ENV["GOOGLE_CLOUD_PROJECT"] ||
87
88
  ENV["GCLOUD_PROJECT"] ||
@@ -13,29 +13,44 @@
13
13
  # limitations under the License.
14
14
 
15
15
 
16
- require "google/cloud/credentials"
16
+ require "googleauth"
17
17
 
18
18
  module Google
19
19
  module Cloud
20
20
  module Translate
21
21
  ##
22
- # @private Represents the OAuth 2.0 signing logic for Translation API.
23
- class Credentials < Google::Cloud::Credentials
22
+ # # Credentials
23
+ #
24
+ # Represents the authentication and authorization used to connect to the
25
+ # Cloud Translation API.
26
+ #
27
+ # @example
28
+ # require "google/cloud/translate"
29
+ #
30
+ # keyfile = "/path/to/keyfile.json"
31
+ # creds = Google::Cloud::Translate::Credentials.new keyfile
32
+ #
33
+ # translate = Google::Cloud::Translate.new(
34
+ # project_id: "my-todo-project",
35
+ # credentials: creds
36
+ # )
37
+ #
38
+ # translate.project_id #=> "my-todo-project"
39
+ #
40
+ class Credentials < Google::Auth::Credentials
24
41
  SCOPE = ["https://www.googleapis.com/auth/cloud-platform"]
25
- PATH_ENV_VARS = %w(TRANSLATE_KEYFILE GOOGLE_CLOUD_KEYFILE
42
+ PATH_ENV_VARS = %w(TRANSLATE_CREDENTIALS
43
+ TRANSLATE_KEYFILE
44
+ GOOGLE_CLOUD_CREDENTIALS
45
+ GOOGLE_CLOUD_KEYFILE
26
46
  GCLOUD_KEYFILE)
27
- JSON_ENV_VARS = %w(TRANSLATE_KEYFILE_JSON GOOGLE_CLOUD_KEYFILE_JSON
47
+ JSON_ENV_VARS = %w(TRANSLATE_CREDENTIALS_JSON
48
+ TRANSLATE_KEYFILE_JSON
49
+ GOOGLE_CLOUD_CREDENTIALS_JSON
50
+ GOOGLE_CLOUD_KEYFILE_JSON
28
51
  GCLOUD_KEYFILE_JSON)
29
-
30
- ##
31
- # @private Sign Oauth2 API calls.
32
- def sign_http_request request #:nodoc:
33
- if @client
34
- @client.fetch_access_token! if @client.expires_within? 30
35
- @client.generate_authenticated_request request: request
36
- end
37
- request
38
- end
52
+ DEFAULT_PATHS = \
53
+ ["~/.config/gcloud/application_default_credentials.json"]
39
54
  end
40
55
  end
41
56
  end
@@ -16,7 +16,7 @@
16
16
  require "google/cloud/errors"
17
17
  require "google/cloud/translate/credentials"
18
18
  require "google/cloud/translate/version"
19
- require "faraday" # comes from googleauth, comes from google-cloud-core
19
+ require "faraday"
20
20
 
21
21
  module Google
22
22
  module Cloud
@@ -85,7 +85,7 @@ module Google
85
85
  if @key
86
86
  req.params = { key: @key }
87
87
  else
88
- @credentials.sign_http_request req
88
+ sign_http_request! req
89
89
  end
90
90
  end
91
91
  end
@@ -129,6 +129,17 @@ module Google
129
129
  raise Google::Cloud::ResourceExhaustedError
130
130
  end
131
131
 
132
+ ##
133
+ # Sign Oauth2 API calls.
134
+ def sign_http_request! request
135
+ client = credentials.client
136
+ return if client.nil?
137
+
138
+ client.fetch_access_token! if client.expires_within? 30
139
+ client.generate_authenticated_request request: request
140
+ request
141
+ end
142
+
132
143
  ##
133
144
  # @private Backoff
134
145
  class Backoff
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Translate
19
- VERSION = "1.0.1"
19
+ VERSION = "1.1.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-translate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.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-07-11 00:00:00.000000000 Z
12
+ date: 2017-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core
@@ -17,28 +17,42 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '1.0'
20
+ version: '1.1'
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.0'
27
+ version: '1.1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: faraday
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '0.13'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '0.13'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: googleauth
30
44
  requirement: !ruby/object:Gem::Requirement
31
45
  requirements:
32
46
  - - "~>"
33
47
  - !ruby/object:Gem::Version
34
- version: 0.5.1
48
+ version: 0.6.2
35
49
  type: :runtime
36
50
  prerelease: false
37
51
  version_requirements: !ruby/object:Gem::Requirement
38
52
  requirements:
39
53
  - - "~>"
40
54
  - !ruby/object:Gem::Version
41
- version: 0.5.1
55
+ version: 0.6.2
42
56
  - !ruby/object:Gem::Dependency
43
57
  name: minitest
44
58
  requirement: !ruby/object:Gem::Requirement
@@ -206,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
220
  version: '0'
207
221
  requirements: []
208
222
  rubyforge_project:
209
- rubygems_version: 2.6.12
223
+ rubygems_version: 2.7.2
210
224
  signing_key:
211
225
  specification_version: 4
212
226
  summary: API Client library for Google Cloud Translation API