google-cloud-translate 1.3.1 → 1.4.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: fce4c949921261a8c75ba0850348861e4868d1f8a3a78f3b314f7743342e6939
4
- data.tar.gz: 171c017925040b13631358a5e1c347f6188ccad4bb4656300efd8c8c2d58eaec
3
+ metadata.gz: 446be46e3daa8f7a75ccacfe05f26725697c67fe4f84607f4926df2fe4f9e909
4
+ data.tar.gz: a29473454843607b347d16cbffe1c9a27e152e2589e9a1294fa4f0c89b959fd9
5
5
  SHA512:
6
- metadata.gz: 5cc1b16bdaca4f0aacb52fd897efb6da493828bb9ee3c46e5ec7fcafc643c1a47be7503edd5da6734d45840fdaf00da52dbb5937f0e6bae03985fb33c041834e
7
- data.tar.gz: 21c94ae85e2a7dc332e641bc3245046a90707c2e2a8f85da51f34b96fa0baa64d74aed2150e2f5404425b64ccb25d39673666abc4586e255ee7ccb58a9de3bc4
6
+ metadata.gz: 076d7957b5fd21f68e4e7b7dafbdf1bf0e08b4da8c5ee876f008eec7c728f587bb63a26a58e6bbc6cffdf9df7369a48a87d0f01a00bed3b5b84bc807828392fc
7
+ data.tar.gz: 7ef9781612d55d99564dc1691b0c689ea0d242d30804b54c48f37b1a08f44e7b33560b1ac856f42483f00e57cb6062e8f3cb7c8fcf3ea60c9c9f07b107494393
@@ -1,5 +1,11 @@
1
1
  # Release History
2
2
 
3
+ ### 1.4.0 / 2019-10-01
4
+
5
+ #### Features
6
+
7
+ * Support overriding of service endpoint
8
+
3
9
  ### 1.3.1 / 2019-08-23
4
10
 
5
11
  #### Documentation
@@ -168,4 +168,5 @@ Google::Cloud.configure.add_config! :translate do |config|
168
168
  config.add_field! :scope, nil, match: [String, Array]
169
169
  config.add_field! :retries, nil, match: Integer
170
170
  config.add_field! :timeout, nil, match: Integer
171
+ config.add_field! :endpoint, nil, match: String
171
172
  end
@@ -68,6 +68,8 @@ module Google
68
68
  # @param [Integer] retries Number of times to retry requests on server
69
69
  # error. The default value is `3`. Optional.
70
70
  # @param [Integer] timeout Default timeout to use in requests. Optional.
71
+ # @param [String] endpoint Override of the endpoint host name. Optional.
72
+ # If the param is nil, uses the default endpoint.
71
73
  # @param [String] project Alias for the `project_id` argument. Deprecated.
72
74
  # @param [String] keyfile Alias for the `credentials` argument.
73
75
  # Deprecated.
@@ -106,34 +108,37 @@ module Google
106
108
  # translation.text #=> "Salve mundi!"
107
109
  #
108
110
  def self.new project_id: nil, credentials: nil, key: nil, scope: nil,
109
- retries: nil, timeout: nil, project: nil, keyfile: nil
111
+ retries: nil, timeout: nil, endpoint: nil, project: nil,
112
+ keyfile: nil
110
113
  project_id ||= (project || default_project_id)
111
114
  key ||= configure.key
115
+ retries ||= configure.retries
116
+ timeout ||= configure.timeout
117
+ endpoint ||= configure.endpoint
112
118
 
113
119
  if key
114
120
  return Google::Cloud::Translate::Api.new(
115
121
  Google::Cloud::Translate::Service.new(
116
- project_id.to_s, nil, retries: retries, timeout: timeout, key: key
122
+ project_id.to_s, nil,
123
+ retries: retries, timeout: timeout, key: key, host: endpoint
117
124
  )
118
125
  )
119
126
  end
120
127
 
121
128
  scope ||= configure.scope
122
- retries ||= configure.retries
123
- timeout ||= configure.timeout
124
129
  credentials ||= keyfile || default_credentials(scope: scope)
125
130
 
126
131
  unless credentials.is_a? Google::Auth::Credentials
127
132
  credentials = Translate::Credentials.new credentials, scope: scope
128
133
  end
129
134
 
130
- project_id ||= credentials.project_id if credentials.respond_to? :project_id
131
- project_id = project_id.to_s # Always cast to a string
135
+ project_id = resolve_project_id project_id, credentials
132
136
  raise ArgumentError, "project_id is missing" if project_id.empty?
133
137
 
134
138
  Translate::Api.new(
135
139
  Translate::Service.new(
136
- project_id, credentials, retries: retries, timeout: timeout
140
+ project_id, credentials,
141
+ retries: retries, timeout: timeout, host: endpoint
137
142
  )
138
143
  )
139
144
  end
@@ -154,6 +159,8 @@ module Google
154
159
  # * `retries` - (Integer) Number of times to retry requests on server
155
160
  # error.
156
161
  # * `timeout` - (Integer) Default timeout to use in requests.
162
+ # * `endpoint` - (String) Override of the endpoint host name, or `nil`
163
+ # to use the default endpoint.
157
164
  #
158
165
  # @return [Google::Cloud::Config] The configuration object the
159
166
  # Google::Cloud::Translate library uses.
@@ -179,6 +186,16 @@ module Google
179
186
  Google::Cloud.configure.credentials ||
180
187
  Translate::Credentials.default(scope: scope)
181
188
  end
189
+
190
+ ##
191
+ # @private Resolve project.
192
+ def self.resolve_project_id project_id, credentials
193
+ # Always cast to a string
194
+ return project_id.to_s unless credentials.respond_to? :project_id
195
+
196
+ # Always cast to a string
197
+ project_id || credentials.project_id.to_s
198
+ end
182
199
  end
183
200
  end
184
201
  end
@@ -17,6 +17,7 @@ require "google/cloud/errors"
17
17
  require "google/cloud/translate/credentials"
18
18
  require "google/cloud/translate/version"
19
19
  require "faraday"
20
+ require "uri"
20
21
 
21
22
  module Google
22
23
  module Cloud
@@ -34,12 +35,13 @@ module Google
34
35
  ##
35
36
  # Creates a new Service instance.
36
37
  def initialize project, credentials, retries: nil, timeout: nil,
37
- key: nil
38
+ key: nil, host: nil
38
39
  @project = project
39
40
  @credentials = credentials
40
41
  @retries = retries
41
42
  @timeout = timeout
42
43
  @key = key
44
+ @host = host || API_URL
43
45
  end
44
46
 
45
47
  ##
@@ -101,7 +103,7 @@ module Google
101
103
  # The HTTP object that makes calls to API.
102
104
  # This must be a Faraday object.
103
105
  def http
104
- @http ||= Faraday.new url: API_URL, request: {
106
+ @http ||= Faraday.new url: @host, request: {
105
107
  open_timeout: @timeout, timeout: @timeout
106
108
  }.delete_if { |_k, v| v.nil? }
107
109
  end
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Translate
19
- VERSION = "1.3.1".freeze
19
+ VERSION = "1.4.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.3.1
4
+ version: 1.4.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: 2019-08-23 00:00:00.000000000 Z
12
+ date: 2019-10-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core