google-gax 0.8.5 → 0.8.6

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: 798b058e269c1439eae63e4902b7558b5be005c0
4
- data.tar.gz: 3ee51d01d9addb3d2edb034efb196478fcf0c4ae
3
+ metadata.gz: f71e32189b1fb624d4eea6c700022151e4e94134
4
+ data.tar.gz: 5885fdf6ce17d16932c891b3677cf60a6b30f574
5
5
  SHA512:
6
- metadata.gz: 84f4d99c7830db006033237c1f92f3de3b7d8dc4a43e4357b182f0cfabc52df76e6c7d3f0863ce6b89307221c31c3a50cf39573d116e8b4e78d28e42e4a11fb3
7
- data.tar.gz: 95ab0e0670ba6eeb51cc6a2a98ba93f4beda3246be5ac43a9e6b3b344aedb9a369d6d01ccb32710f56ac34797a1f22d2d7ecb28f9beb221753f2af8d636c3835
6
+ metadata.gz: 251e5b49190d51b23dca1350d45300687ec8b41c632df5f62198385223f25f7391f828cc5475d7ccd15847b0245128cab5b919494bb9fc6a5cbfc6671eb63a16
7
+ data.tar.gz: f8a733a59af40210710c1e1661fc5ef88692178799b37fe5d8f404e120159a461e8cf68a28fb69877dced9190a4cd8c07e965b11707083530574563bbcf0c063
@@ -90,7 +90,7 @@ module Google
90
90
  #
91
91
  # @return [Object] The coerced version of the given value.
92
92
  def coerce_submessage(val, field_descriptor)
93
- if field_descriptor.label == :repeated
93
+ if (field_descriptor.label == :repeated) && !(map_field? field_descriptor)
94
94
  coerce_array(val, field_descriptor)
95
95
  else
96
96
  coerce(val, field_descriptor)
@@ -108,12 +108,24 @@ module Google
108
108
  #
109
109
  # @return [Array<Object>] The coerced version of the given values.
110
110
  def coerce_array(array, field_descriptor)
111
- raise ArgumentError unless array.is_a? Array
111
+ unless array.is_a? Array
112
+ raise ArgumentError, 'Value ' + array.to_s + ' must be an array'
113
+ end
112
114
  array.map do |val|
113
115
  coerce(val, field_descriptor)
114
116
  end
115
117
  end
116
118
 
119
+ # Hack to determine if field_descriptor is for a map.
120
+ #
121
+ # TODO(geigerj): Remove this once protobuf Ruby supports an official way
122
+ # to determine if a FieldDescriptor represents a map.
123
+ # See: https://github.com/google/protobuf/issues/3425
124
+ def map_field?(field_descriptor)
125
+ (field_descriptor.label == :repeated) &&
126
+ (field_descriptor.subtype.name.include? '_MapEntry_')
127
+ end
128
+
117
129
  # Coerces the value of a field to be acceptable by the instantiation method
118
130
  # of the wrapping message.
119
131
  #
@@ -125,13 +137,13 @@ module Google
125
137
  #
126
138
  # @return [Object] The coerced version of the given value.
127
139
  def coerce(val, field_descriptor)
128
- return val unless val.is_a? Hash
140
+ return val unless (val.is_a? Hash) && !(map_field? field_descriptor)
129
141
  to_proto(val, field_descriptor.subtype.msgclass)
130
142
  end
131
143
 
132
144
  module_function :to_proto, :coerce_submessages, :coerce_submessage,
133
- :coerce_array, :coerce
145
+ :coerce_array, :coerce, :map_field?
134
146
  private_class_method :coerce_submessages, :coerce_submessage, :coerce_array,
135
- :coerce
147
+ :coerce, :map_field?
136
148
  end
137
149
  end
@@ -29,6 +29,6 @@
29
29
 
30
30
  module Google
31
31
  module Gax
32
- VERSION = '0.8.5'.freeze
32
+ VERSION = '0.8.6'.freeze
33
33
  end
34
34
  end
@@ -48,7 +48,7 @@ module Google
48
48
  # Manages long-running operations with an API service.
49
49
  #
50
50
  # When an API method normally takes long time to complete, it can be designed
51
- # to return Operation to the client, and the client can use this
51
+ # to return {Google::Longrunning::Operation Operation} to the client, and the client can use this
52
52
  # interface to receive the real response asynchronously by polling the
53
53
  # operation resource, or pass the operation resource to another API (such as
54
54
  # Google Cloud Pub/Sub API) to receive the response. Any API service that
@@ -86,13 +86,21 @@ module Google
86
86
  # The domain name of the API remote host.
87
87
  # @param port [Integer]
88
88
  # The port on which to connect to the remote host.
89
- # @param channel [Channel]
90
- # A Channel object through which to make calls.
91
- # @param chan_creds [Grpc::ChannelCredentials]
92
- # A ChannelCredentials for the setting up the RPC client.
93
- # @param updater_proc [Proc]
94
- # A function that transforms the metadata for requests, e.g., to give
95
- # OAuth credentials.
89
+ # @param credentials
90
+ # [Google::Gax::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
91
+ # Provides the means for authenticating requests made by the client. This parameter can
92
+ # be many types.
93
+ # A `Google::Gax::Credentials` uses a the properties of its represented keyfile for
94
+ # authenticating requests made by this client.
95
+ # A `String` will be treated as the path to the keyfile to be used for the construction of
96
+ # credentials for this client.
97
+ # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
98
+ # credentials for this client.
99
+ # A `GRPC::Core::Channel` will be used to make calls through.
100
+ # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
101
+ # should already be composed with a `GRPC::Core::CallCredentials` object.
102
+ # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
103
+ # metadata for requests, generally, to give OAuth credentials.
96
104
  # @param scopes [Array<String>]
97
105
  # The OAuth scopes for this service. This parameter is ignored if
98
106
  # an updater_proc is supplied.
@@ -109,6 +117,7 @@ module Google
109
117
  channel: nil,
110
118
  chan_creds: nil,
111
119
  updater_proc: nil,
120
+ credentials: nil,
112
121
  scopes: ALL_SCOPES,
113
122
  client_config: {},
114
123
  timeout: DEFAULT_TIMEOUT,
@@ -122,11 +131,35 @@ module Google
122
131
  require "google/gax/grpc"
123
132
  require "google/longrunning/operations_services_pb"
124
133
 
125
-
134
+ if channel || chan_creds || updater_proc
135
+ warn "The `channel`, `chan_creds`, and `updater_proc` parameters will be removed " \
136
+ "on 2017/09/08"
137
+ credentials ||= channel
138
+ credentials ||= chan_creds
139
+ credentials ||= updater_proc
140
+ end
126
141
  if app_name || app_version
127
142
  warn "`app_name` and `app_version` are no longer being used in the request headers."
128
143
  end
129
144
 
145
+ credentials ||= Google::Gax::Credentials.default
146
+
147
+ if credentials.is_a?(String) || credentials.is_a?(Hash)
148
+ updater_proc = Google::Gax::Credentials.new(credentials).updater_proc
149
+ end
150
+ if credentials.is_a?(GRPC::Core::Channel)
151
+ channel = credentials
152
+ end
153
+ if credentials.is_a?(GRPC::Core::ChannelCredentials)
154
+ chan_creds = credentials
155
+ end
156
+ if credentials.is_a?(Proc)
157
+ updater_proc = credentials
158
+ end
159
+ if credentials.is_a?(Google::Gax::Credentials)
160
+ updater_proc = credentials.updater_proc
161
+ end
162
+
130
163
  google_api_client = "gl-ruby/#{RUBY_VERSION}"
131
164
  google_api_client << " #{lib_name}/#{lib_version}" if lib_name
132
165
  google_api_client << " gapic/0.6.8 gax/#{Google::Gax::VERSION}"
@@ -193,16 +226,17 @@ module Google
193
226
  # @example
194
227
  # require "google/longrunning"
195
228
  #
196
- # operations_client = Google::Longrunning::OperationsClient.new
229
+ # operations_client = Google::Longrunning.new
197
230
  # name = ''
198
231
  # response = operations_client.get_operation(name)
199
232
 
200
233
  def get_operation \
201
234
  name,
202
235
  options: nil
203
- req = Google::Longrunning::GetOperationRequest.new({
236
+ req = {
204
237
  name: name
205
- }.delete_if { |_, v| v.nil? })
238
+ }.delete_if { |_, v| v.nil? }
239
+ req = Google::Gax::to_proto(req, Google::Longrunning::GetOperationRequest)
206
240
  @get_operation.call(req, options)
207
241
  end
208
242
 
@@ -234,7 +268,7 @@ module Google
234
268
  # @example
235
269
  # require "google/longrunning"
236
270
  #
237
- # operations_client = Google::Longrunning::OperationsClient.new
271
+ # operations_client = Google::Longrunning.new
238
272
  # name = ''
239
273
  # filter = ''
240
274
  #
@@ -256,11 +290,12 @@ module Google
256
290
  filter,
257
291
  page_size: nil,
258
292
  options: nil
259
- req = Google::Longrunning::ListOperationsRequest.new({
293
+ req = {
260
294
  name: name,
261
295
  filter: filter,
262
296
  page_size: page_size
263
- }.delete_if { |_, v| v.nil? })
297
+ }.delete_if { |_, v| v.nil? }
298
+ req = Google::Gax::to_proto(req, Google::Longrunning::ListOperationsRequest)
264
299
  @list_operations.call(req, options)
265
300
  end
266
301
 
@@ -268,11 +303,11 @@ module Google
268
303
  # makes a best effort to cancel the operation, but success is not
269
304
  # guaranteed. If the server doesn't support this method, it returns
270
305
  # +google.rpc.Code.UNIMPLEMENTED+. Clients can use
271
- # Operations::GetOperation or
306
+ # {Google::Longrunning::Operations::GetOperation Operations::GetOperation} or
272
307
  # other methods to check whether the cancellation succeeded or whether the
273
308
  # operation completed despite cancellation. On successful cancellation,
274
309
  # the operation is not deleted; instead, it becomes an operation with
275
- # an Operation#error value with a Google::Rpc::Status#code of 1,
310
+ # an {Google::Longrunning::Operation#error Operation#error} value with a {Google::Rpc::Status#code} of 1,
276
311
  # corresponding to +Code.CANCELLED+.
277
312
  #
278
313
  # @param name [String]
@@ -284,16 +319,17 @@ module Google
284
319
  # @example
285
320
  # require "google/longrunning"
286
321
  #
287
- # operations_client = Google::Longrunning::OperationsClient.new
322
+ # operations_client = Google::Longrunning.new
288
323
  # name = ''
289
324
  # operations_client.cancel_operation(name)
290
325
 
291
326
  def cancel_operation \
292
327
  name,
293
328
  options: nil
294
- req = Google::Longrunning::CancelOperationRequest.new({
329
+ req = {
295
330
  name: name
296
- }.delete_if { |_, v| v.nil? })
331
+ }.delete_if { |_, v| v.nil? }
332
+ req = Google::Gax::to_proto(req, Google::Longrunning::CancelOperationRequest)
297
333
  @cancel_operation.call(req, options)
298
334
  nil
299
335
  end
@@ -312,16 +348,17 @@ module Google
312
348
  # @example
313
349
  # require "google/longrunning"
314
350
  #
315
- # operations_client = Google::Longrunning::OperationsClient.new
351
+ # operations_client = Google::Longrunning.new
316
352
  # name = ''
317
353
  # operations_client.delete_operation(name)
318
354
 
319
355
  def delete_operation \
320
356
  name,
321
357
  options: nil
322
- req = Google::Longrunning::DeleteOperationRequest.new({
358
+ req = {
323
359
  name: name
324
- }.delete_if { |_, v| v.nil? })
360
+ }.delete_if { |_, v| v.nil? }
361
+ req = Google::Gax::to_proto(req, Google::Longrunning::DeleteOperationRequest)
325
362
  @delete_operation.call(req, options)
326
363
  nil
327
364
  end
@@ -6,9 +6,7 @@
6
6
  "DEADLINE_EXCEEDED",
7
7
  "UNAVAILABLE"
8
8
  ],
9
- "non_idempotent": [
10
- "UNAVAILABLE"
11
- ]
9
+ "non_idempotent": []
12
10
  },
13
11
  "retry_params": {
14
12
  "default": {
@@ -28,6 +28,7 @@ message User {
28
28
  string name = 1;
29
29
  UserType type = 2;
30
30
  repeated Post posts = 3;
31
+ map<string, string> map_field = 4;
31
32
  }
32
33
 
33
34
  message Post {
@@ -12,6 +12,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
12
12
  optional :name, :string, 1
13
13
  optional :type, :enum, 2, "google.protobuf.User.UserType"
14
14
  repeated :posts, :message, 3, "google.protobuf.Post"
15
+ map :map_field, :string, :string, 4
15
16
  end
16
17
  add_enum "google.protobuf.User.UserType" do
17
18
  value :UNSPECIFIED, 0
@@ -36,6 +36,10 @@ describe Google::Gax do
36
36
  USER_NAME = 'Ernest'.freeze
37
37
  USER_TYPE = :ADMINISTRATOR
38
38
  POST_TEXT = 'This is a test post.'.freeze
39
+ MAP = {
40
+ 'key1' => 'val1',
41
+ 'key2' => 'val2'
42
+ }.freeze
39
43
 
40
44
  it 'creates a protobuf message from a simple hash' do
41
45
  hash = { name: USER_NAME, type: USER_TYPE }
@@ -91,6 +95,20 @@ describe Google::Gax do
91
95
  end
92
96
  end
93
97
 
98
+ it 'handles maps' do
99
+ request_hash = {
100
+ name: USER_NAME,
101
+ map_field: MAP
102
+ }
103
+ user = Google::Gax.to_proto(request_hash, Google::Protobuf::User)
104
+ expect(user).to be_an_instance_of(Google::Protobuf::User)
105
+ expect(user.name).to eq(USER_NAME)
106
+ expect(user.map_field).to be_an_instance_of(Google::Protobuf::Map)
107
+ user.map_field.each do |k, v|
108
+ expect(MAP[k]).to eq v
109
+ end
110
+ end
111
+
94
112
  it 'fails if a key does not exist in the target message type' do
95
113
  user_hash = {
96
114
  name: USER_NAME,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-gax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Google API Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-21 00:00:00.000000000 Z
11
+ date: 2017-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: googleauth