gcloud 0.6.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +8 -8
  2. data/AUTHENTICATION.md +13 -9
  3. data/CHANGELOG.md +8 -3
  4. data/OVERVIEW.md +46 -8
  5. data/lib/gcloud.rb +123 -117
  6. data/lib/gcloud/backoff.rb +43 -15
  7. data/lib/gcloud/bigquery.rb +211 -195
  8. data/lib/gcloud/bigquery/connection.rb +9 -9
  9. data/lib/gcloud/bigquery/copy_job.rb +15 -16
  10. data/lib/gcloud/bigquery/credentials.rb +3 -3
  11. data/lib/gcloud/bigquery/data.rb +12 -11
  12. data/lib/gcloud/bigquery/dataset.rb +162 -216
  13. data/lib/gcloud/bigquery/dataset/access.rb +59 -43
  14. data/lib/gcloud/bigquery/dataset/list.rb +3 -3
  15. data/lib/gcloud/bigquery/errors.rb +9 -5
  16. data/lib/gcloud/bigquery/extract_job.rb +18 -18
  17. data/lib/gcloud/bigquery/insert_response.rb +7 -4
  18. data/lib/gcloud/bigquery/job.rb +48 -44
  19. data/lib/gcloud/bigquery/job/list.rb +3 -3
  20. data/lib/gcloud/bigquery/load_job.rb +24 -25
  21. data/lib/gcloud/bigquery/project.rb +145 -204
  22. data/lib/gcloud/bigquery/query_data.rb +10 -9
  23. data/lib/gcloud/bigquery/query_job.rb +23 -32
  24. data/lib/gcloud/bigquery/table.rb +238 -280
  25. data/lib/gcloud/bigquery/table/list.rb +3 -3
  26. data/lib/gcloud/bigquery/table/schema.rb +79 -87
  27. data/lib/gcloud/bigquery/view.rb +69 -82
  28. data/lib/gcloud/credentials.rb +3 -9
  29. data/lib/gcloud/datastore.rb +194 -170
  30. data/lib/gcloud/datastore/connection.rb +12 -8
  31. data/lib/gcloud/datastore/credentials.rb +6 -4
  32. data/lib/gcloud/datastore/dataset.rb +74 -141
  33. data/lib/gcloud/datastore/dataset/lookup_results.rb +6 -4
  34. data/lib/gcloud/datastore/dataset/query_results.rb +6 -4
  35. data/lib/gcloud/datastore/entity.rb +81 -76
  36. data/lib/gcloud/datastore/errors.rb +10 -8
  37. data/lib/gcloud/datastore/key.rb +41 -77
  38. data/lib/gcloud/datastore/properties.rb +3 -3
  39. data/lib/gcloud/datastore/proto.rb +7 -4
  40. data/lib/gcloud/datastore/query.rb +26 -3
  41. data/lib/gcloud/datastore/transaction.rb +12 -8
  42. data/lib/gcloud/dns.rb +180 -152
  43. data/lib/gcloud/dns/change.rb +16 -16
  44. data/lib/gcloud/dns/change/list.rb +3 -3
  45. data/lib/gcloud/dns/connection.rb +9 -10
  46. data/lib/gcloud/dns/credentials.rb +3 -3
  47. data/lib/gcloud/dns/errors.rb +9 -5
  48. data/lib/gcloud/dns/importer.rb +17 -23
  49. data/lib/gcloud/dns/project.rb +42 -64
  50. data/lib/gcloud/dns/record.rb +58 -46
  51. data/lib/gcloud/dns/record/list.rb +6 -7
  52. data/lib/gcloud/dns/zone.rb +198 -289
  53. data/lib/gcloud/dns/zone/list.rb +3 -3
  54. data/lib/gcloud/dns/zone/transaction.rb +56 -72
  55. data/lib/gcloud/errors.rb +174 -3
  56. data/lib/gcloud/gce.rb +3 -4
  57. data/lib/gcloud/grpc_utils.rb +76 -0
  58. data/lib/gcloud/logging.rb +308 -0
  59. data/lib/gcloud/logging/credentials.rb +29 -0
  60. data/lib/gcloud/logging/entry.rb +303 -0
  61. data/lib/gcloud/logging/entry/http_request.rb +141 -0
  62. data/lib/gcloud/logging/entry/list.rb +111 -0
  63. data/lib/gcloud/logging/entry/operation.rb +90 -0
  64. data/lib/gcloud/logging/logger.rb +307 -0
  65. data/lib/gcloud/logging/metric.rb +175 -0
  66. data/lib/gcloud/logging/metric/list.rb +98 -0
  67. data/lib/gcloud/logging/project.rb +650 -0
  68. data/lib/gcloud/logging/resource.rb +95 -0
  69. data/lib/gcloud/logging/resource_descriptor.rb +140 -0
  70. data/lib/gcloud/logging/resource_descriptor/list.rb +78 -0
  71. data/lib/gcloud/logging/service.rb +258 -0
  72. data/lib/gcloud/logging/sink.rb +233 -0
  73. data/lib/gcloud/logging/sink/list.rb +97 -0
  74. data/lib/gcloud/pubsub.rb +241 -199
  75. data/lib/gcloud/pubsub/credentials.rb +3 -3
  76. data/lib/gcloud/pubsub/message.rb +26 -20
  77. data/lib/gcloud/pubsub/project.rb +166 -233
  78. data/lib/gcloud/pubsub/received_message.rb +28 -38
  79. data/lib/gcloud/pubsub/service.rb +323 -0
  80. data/lib/gcloud/pubsub/subscription.rb +172 -242
  81. data/lib/gcloud/pubsub/subscription/list.rb +11 -9
  82. data/lib/gcloud/pubsub/topic.rb +152 -271
  83. data/lib/gcloud/pubsub/topic/batch.rb +66 -0
  84. data/lib/gcloud/pubsub/topic/list.rb +9 -7
  85. data/lib/gcloud/resource_manager.rb +158 -138
  86. data/lib/gcloud/resource_manager/connection.rb +6 -5
  87. data/lib/gcloud/resource_manager/credentials.rb +3 -3
  88. data/lib/gcloud/resource_manager/errors.rb +9 -5
  89. data/lib/gcloud/resource_manager/manager.rb +54 -86
  90. data/lib/gcloud/resource_manager/project.rb +69 -88
  91. data/lib/gcloud/resource_manager/project/list.rb +4 -5
  92. data/lib/gcloud/resource_manager/project/updater.rb +12 -14
  93. data/lib/gcloud/search.rb +158 -135
  94. data/lib/gcloud/search/api_client.rb +7 -7
  95. data/lib/gcloud/search/connection.rb +8 -8
  96. data/lib/gcloud/search/credentials.rb +3 -3
  97. data/lib/gcloud/search/document.rb +64 -87
  98. data/lib/gcloud/search/document/list.rb +5 -5
  99. data/lib/gcloud/search/errors.rb +9 -5
  100. data/lib/gcloud/search/field_value.rb +32 -38
  101. data/lib/gcloud/search/field_values.rb +50 -80
  102. data/lib/gcloud/search/fields.rb +44 -65
  103. data/lib/gcloud/search/index.rb +163 -204
  104. data/lib/gcloud/search/index/list.rb +5 -5
  105. data/lib/gcloud/search/project.rb +31 -47
  106. data/lib/gcloud/search/result.rb +27 -31
  107. data/lib/gcloud/search/result/list.rb +6 -6
  108. data/lib/gcloud/storage.rb +224 -190
  109. data/lib/gcloud/storage/bucket.rb +202 -227
  110. data/lib/gcloud/storage/bucket/acl.rb +83 -170
  111. data/lib/gcloud/storage/bucket/cors.rb +31 -34
  112. data/lib/gcloud/storage/bucket/list.rb +3 -3
  113. data/lib/gcloud/storage/connection.rb +11 -7
  114. data/lib/gcloud/storage/credentials.rb +3 -3
  115. data/lib/gcloud/storage/errors.rb +11 -8
  116. data/lib/gcloud/storage/file.rb +129 -171
  117. data/lib/gcloud/storage/file/acl.rb +51 -99
  118. data/lib/gcloud/storage/file/list.rb +3 -3
  119. data/lib/gcloud/storage/file/verifier.rb +3 -2
  120. data/lib/gcloud/storage/project.rb +111 -132
  121. data/lib/gcloud/upload.rb +4 -7
  122. data/lib/gcloud/version.rb +2 -4
  123. data/lib/google/api/annotations.rb +14 -0
  124. data/lib/google/api/http.rb +30 -0
  125. data/lib/google/api/label.rb +24 -0
  126. data/lib/google/api/monitored_resource.rb +25 -0
  127. data/lib/google/datastore/v1beta3/datastore.rb +115 -0
  128. data/lib/google/datastore/v1beta3/datastore_services.rb +33 -0
  129. data/lib/google/datastore/v1beta3/entity.rb +63 -0
  130. data/lib/google/datastore/v1beta3/query.rb +128 -0
  131. data/lib/google/devtools/cloudtrace/v1/trace.rb +78 -0
  132. data/lib/google/devtools/cloudtrace/v1/trace_services.rb +32 -0
  133. data/lib/google/example/library/v1/library.rb +91 -0
  134. data/lib/google/example/library/v1/library_services.rb +40 -0
  135. data/lib/google/iam/v1/iam_policy.rb +33 -0
  136. data/lib/google/iam/v1/iam_policy_services.rb +30 -0
  137. data/lib/google/iam/v1/policy.rb +25 -0
  138. data/lib/google/logging/type/http_request.rb +28 -0
  139. data/lib/google/logging/type/log_severity.rb +27 -0
  140. data/lib/google/logging/v2/log_entry.rb +44 -0
  141. data/lib/google/logging/v2/logging.rb +56 -0
  142. data/lib/google/logging/v2/logging_config.rb +59 -0
  143. data/lib/google/logging/v2/logging_config_services.rb +32 -0
  144. data/lib/google/logging/v2/logging_metrics.rb +51 -0
  145. data/lib/google/logging/v2/logging_metrics_services.rb +32 -0
  146. data/lib/google/logging/v2/logging_services.rb +31 -0
  147. data/lib/google/longrunning/operations.rb +50 -0
  148. data/lib/google/longrunning/operations_services.rb +29 -0
  149. data/lib/google/protobuf/any.rb +17 -0
  150. data/lib/google/protobuf/api.rb +31 -0
  151. data/lib/google/protobuf/descriptor.rb +0 -0
  152. data/lib/google/protobuf/duration.rb +17 -0
  153. data/lib/google/protobuf/empty.rb +15 -0
  154. data/lib/google/protobuf/field_mask.rb +16 -0
  155. data/lib/google/protobuf/source_context.rb +16 -0
  156. data/lib/google/protobuf/struct.rb +35 -0
  157. data/lib/google/protobuf/timestamp.rb +17 -0
  158. data/lib/google/protobuf/type.rb +79 -0
  159. data/lib/google/protobuf/wrappers.rb +48 -0
  160. data/lib/google/pubsub/v1/pubsub.rb +129 -0
  161. data/lib/google/pubsub/v1/pubsub_services.rb +56 -0
  162. data/lib/google/pubsub/v1beta2/pubsub.rb +126 -0
  163. data/lib/google/pubsub/v1beta2/pubsub_services.rb +56 -0
  164. data/lib/google/rpc/code.rb +32 -0
  165. data/lib/google/rpc/error_details.rb +61 -0
  166. data/lib/google/rpc/status.rb +19 -0
  167. data/lib/google/type/color.rb +20 -0
  168. data/lib/google/type/date.rb +18 -0
  169. data/lib/google/type/dayofweek.rb +23 -0
  170. data/lib/google/type/latlng.rb +17 -0
  171. data/lib/google/type/money.rb +18 -0
  172. data/lib/google/type/timeofday.rb +19 -0
  173. metadata +101 -4
  174. data/lib/gcloud/pubsub/connection.rb +0 -295
  175. data/lib/gcloud/pubsub/errors.rb +0 -93
@@ -1,4 +1,3 @@
1
- #--
2
1
  # Copyright 2015 Google Inc. All rights reserved.
3
2
  #
4
3
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,18 +12,20 @@
13
12
  # See the License for the specific language governing permissions and
14
13
  # limitations under the License.
15
14
 
16
- require "gcloud/pubsub/errors"
15
+
16
+ require "gcloud/errors"
17
17
  require "gcloud/pubsub/subscription/list"
18
18
  require "gcloud/pubsub/received_message"
19
19
 
20
20
  module Gcloud
21
21
  module Pubsub
22
22
  ##
23
- # = Subscription
23
+ # # Subscription
24
24
  #
25
25
  # A named resource representing the stream of messages from a single,
26
- # specific topic, to be delivered to the subscribing application.
26
+ # specific {Topic}, to be delivered to the subscribing application.
27
27
  #
28
+ # @example
28
29
  # require "gcloud"
29
30
  #
30
31
  # gcloud = Gcloud.new
@@ -36,31 +37,31 @@ module Gcloud
36
37
  #
37
38
  class Subscription
38
39
  ##
39
- # The Connection object.
40
- attr_accessor :connection #:nodoc:
40
+ # @private The gRPC Service object.
41
+ attr_accessor :service
41
42
 
42
43
  ##
43
- # The Google API Client object.
44
- attr_accessor :gapi #:nodoc:
44
+ # @private The gRPC Google::Pubsub::V1::Subscription object.
45
+ attr_accessor :grpc
45
46
 
46
47
  ##
47
- # Create an empty Subscription object.
48
- def initialize #:nodoc:
49
- @connection = nil
50
- @gapi = {}
48
+ # @private Create an empty {Subscription} object.
49
+ def initialize
50
+ @service = nil
51
+ @grpc = Google::Pubsub::V1::Subscription.new
51
52
  @name = nil
52
53
  @exists = nil
53
54
  end
54
55
 
55
56
  ##
56
- # New lazy Topic object without making an HTTP request.
57
- def self.new_lazy name, conn, options = {} #:nodoc:
57
+ # @private New lazy {Topic} object without making an HTTP request.
58
+ def self.new_lazy name, service, options = {}
58
59
  sub = new.tap do |f|
59
- f.gapi = nil
60
- f.connection = conn
60
+ f.grpc = nil
61
+ f.service = service
61
62
  end
62
63
  sub.instance_eval do
63
- @name = conn.subscription_path(name, options)
64
+ @name = service.subscription_path(name, options)
64
65
  end
65
66
  sub
66
67
  end
@@ -68,18 +69,15 @@ module Gcloud
68
69
  ##
69
70
  # The name of the subscription.
70
71
  def name
71
- @gapi ? @gapi["name"] : @name
72
+ @grpc ? @grpc.name : @name
72
73
  end
73
74
 
74
75
  ##
75
- # The Topic from which this subscription receives messages.
76
- #
77
- # === Returns
78
- #
79
- # Topic
76
+ # The {Topic} from which this subscription receives messages.
80
77
  #
81
- # === Example
78
+ # @return [Topic]
82
79
  #
80
+ # @example
83
81
  # require "gcloud"
84
82
  #
85
83
  # gcloud = Gcloud.new
@@ -89,43 +87,43 @@ module Gcloud
89
87
  # sub.topic.name #=> "projects/my-project/topics/my-topic"
90
88
  #
91
89
  def topic
92
- ensure_gapi!
93
- Topic.new_lazy @gapi["topic"], connection
90
+ ensure_grpc!
91
+ Topic.new_lazy @grpc.topic, service
94
92
  end
95
93
 
96
94
  ##
97
95
  # This value is the maximum number of seconds after a subscriber receives
98
96
  # a message before the subscriber should acknowledge the message.
99
97
  def deadline
100
- ensure_gapi!
101
- @gapi["ackDeadlineSeconds"]
98
+ ensure_grpc!
99
+ @grpc.ack_deadline_seconds
102
100
  end
103
101
 
104
102
  ##
105
103
  # Returns the URL locating the endpoint to which messages should be
106
104
  # pushed.
107
105
  def endpoint
108
- ensure_gapi!
109
- @gapi["pushConfig"]["pushEndpoint"] if @gapi["pushConfig"]
106
+ ensure_grpc!
107
+ @grpc.push_config.push_endpoint if @grpc.push_config
110
108
  end
111
109
 
112
110
  ##
113
111
  # Sets the URL locating the endpoint to which messages should be pushed.
114
112
  def endpoint= new_endpoint
115
- ensure_connection!
116
- resp = connection.modify_push_config name, new_endpoint, {}
117
- if resp.success?
118
- @gapi["pushConfig"]["pushEndpoint"] = new_endpoint if @gapi
119
- else
120
- fail ApiError.from_response(resp)
121
- end
113
+ ensure_service!
114
+ service.modify_push_config name, new_endpoint, {}
115
+ @grpc.push_config = Google::Pubsub::V1::PushConfig.new(
116
+ push_endpoint: new_endpoint,
117
+ attributes: {}
118
+ ) if @grpc
119
+ rescue GRPC::BadStatus => e
120
+ raise Error.from_error(e)
122
121
  end
123
122
 
124
123
  ##
125
124
  # Determines whether the subscription exists in the Pub/Sub service.
126
125
  #
127
- # === Example
128
- #
126
+ # @example
129
127
  # require "gcloud"
130
128
  #
131
129
  # gcloud = Gcloud.new
@@ -135,22 +133,22 @@ module Gcloud
135
133
  # sub.exists? #=> true
136
134
  #
137
135
  def exists?
138
- # Always true if we have a gapi object
139
- return true unless @gapi.nil?
136
+ # Always true if we have a grpc object
137
+ return true unless @grpc.nil?
140
138
  # If we have a value, return it
141
139
  return @exists unless @exists.nil?
142
- ensure_gapi!
143
- @exists = !@gapi.nil?
144
- rescue NotFoundError
140
+ ensure_grpc!
141
+ @exists = !@grpc.nil?
142
+ rescue Gcloud::NotFoundError
145
143
  @exists = false
146
144
  end
147
145
 
148
146
  ##
147
+ # @private
149
148
  # Determines whether the subscription object was created with an
150
149
  # HTTP call.
151
150
  #
152
- # === Example
153
- #
151
+ # @example
154
152
  # require "gcloud"
155
153
  #
156
154
  # gcloud = Gcloud.new
@@ -159,20 +157,17 @@ module Gcloud
159
157
  # sub = pubsub.get_subscription "my-topic-sub"
160
158
  # sub.lazy? #=> false
161
159
  #
162
- def lazy? #:nodoc:
163
- @gapi.nil?
160
+ def lazy?
161
+ @grpc.nil?
164
162
  end
165
163
 
166
164
  ##
167
165
  # Deletes an existing subscription.
168
166
  # All pending messages in the subscription are immediately dropped.
169
167
  #
170
- # === Returns
171
- #
172
- # +true+ if the subscription was deleted.
173
- #
174
- # === Example
168
+ # @return [Boolean] Returns `true` if the subscription was deleted.
175
169
  #
170
+ # @example
176
171
  # require "gcloud"
177
172
  #
178
173
  # gcloud = Gcloud.new
@@ -182,42 +177,33 @@ module Gcloud
182
177
  # sub.delete
183
178
  #
184
179
  def delete
185
- ensure_connection!
186
- resp = connection.delete_subscription name
187
- if resp.success?
188
- true
189
- else
190
- fail ApiError.from_response(resp)
191
- end
180
+ ensure_service!
181
+ service.delete_subscription name
182
+ return true
183
+ rescue GRPC::BadStatus => e
184
+ raise Error.from_error(e)
192
185
  end
193
186
 
194
187
  ##
195
188
  # Pulls messages from the server. Returns an empty list if there are no
196
189
  # messages available in the backlog. Raises an ApiError with status
197
- # +UNAVAILABLE+ if there are too many concurrent pull requests pending
190
+ # `UNAVAILABLE` if there are too many concurrent pull requests pending
198
191
  # for the given subscription.
199
192
  #
200
- # === Parameters
201
- #
202
- # +immediate+::
203
- # When +true+ the system will respond immediately even if it is not able
204
- # to return messages. When +false+ the system is allowed to wait until
205
- # it can return least one message. No messages are returned when a
206
- # request times out. The default value is +true+. (+Boolean+)
207
- # +max+::
208
- # The maximum number of messages to return for this request. The Pub/Sub
209
- # system may return fewer than the number specified. The default value
210
- # is +100+, the maximum value is +1000+. (+Integer+)
211
- # +autoack+::
212
- # Automatically acknowledge the message as it is pulled. The default
213
- # value is +false+. (+Boolean+)
214
- #
215
- # === Returns
193
+ # @param [Boolean] immediate When `true` the system will respond
194
+ # immediately even if it is not able to return messages. When `false`
195
+ # the system is allowed to wait until it can return least one message.
196
+ # No messages are returned when a request times out. The default value
197
+ # is `true`.
198
+ # @param [Integer] max The maximum number of messages to return for this
199
+ # request. The Pub/Sub system may return fewer than the number
200
+ # specified. The default value is `100`, the maximum value is `1000`.
201
+ # @param [Boolean] autoack Automatically acknowledge the message as it is
202
+ # pulled. The default value is `false`.
216
203
  #
217
- # Array of Gcloud::Pubsub::ReceivedMessage
218
- #
219
- # === Examples
204
+ # @return [Array<Gcloud::Pubsub::ReceivedMessage>]
220
205
  #
206
+ # @example
221
207
  # require "gcloud"
222
208
  #
223
209
  # gcloud = Gcloud.new
@@ -226,8 +212,7 @@ module Gcloud
226
212
  # sub = pubsub.subscription "my-topic-sub"
227
213
  # sub.pull.each { |msg| msg.acknowledge! }
228
214
  #
229
- # A maximum number of messages returned can also be specified:
230
- #
215
+ # @example A maximum number of messages returned can also be specified:
231
216
  # require "gcloud"
232
217
  #
233
218
  # gcloud = Gcloud.new
@@ -236,9 +221,7 @@ module Gcloud
236
221
  # sub = pubsub.subscription "my-topic-sub", max: 10
237
222
  # sub.pull.each { |msg| msg.acknowledge! }
238
223
  #
239
- # The call can block until messages are available by setting the
240
- # +:immediate+ option to +false+:
241
- #
224
+ # @example The call can block until messages are available:
242
225
  # require "gcloud"
243
226
  #
244
227
  # gcloud = Gcloud.new
@@ -249,18 +232,16 @@ module Gcloud
249
232
  # msgs.each { |msg| msg.acknowledge! }
250
233
  #
251
234
  def pull immediate: true, max: 100, autoack: false
252
- ensure_connection!
235
+ ensure_service!
253
236
  options = { immediate: immediate, max: max }
254
- resp = connection.pull name, options
255
- if resp.success?
256
- messages = Array(resp.data["receivedMessages"]).map do |gapi|
257
- ReceivedMessage.from_gapi gapi, self
258
- end
259
- acknowledge messages if autoack
260
- messages
261
- else
262
- fail ApiError.from_response(resp)
237
+ list_grpc = service.pull name, options
238
+ messages = Array(list_grpc.received_messages).map do |msg_grpc|
239
+ ReceivedMessage.from_grpc msg_grpc, self
263
240
  end
241
+ acknowledge messages if autoack
242
+ messages
243
+ rescue GRPC::BadStatus => e
244
+ raise Error.from_error(e)
264
245
  rescue Faraday::TimeoutError
265
246
  []
266
247
  end
@@ -271,22 +252,15 @@ module Gcloud
271
252
  #
272
253
  # subscription.pull immediate: false
273
254
  #
274
- # === Parameters
275
- #
276
- # +max+::
277
- # The maximum number of messages to return for this request. The Pub/Sub
278
- # system may return fewer than the number specified. The default value
279
- # is +100+, the maximum value is +1000+. (+Integer+)
280
- # +autoack+::
281
- # Automatically acknowledge the message as it is pulled. The default
282
- # value is +false+. (+Boolean+)
283
- #
284
- # === Returns
255
+ # @param [Integer] max The maximum number of messages to return for this
256
+ # request. The Pub/Sub system may return fewer than the number
257
+ # specified. The default value is `100`, the maximum value is `1000`.
258
+ # @param [Boolean] autoack Automatically acknowledge the message as it is
259
+ # pulled. The default value is `false`.
285
260
  #
286
- # Array of Gcloud::Pubsub::ReceivedMessage
287
- #
288
- # === Example
261
+ # @return [Array<Gcloud::Pubsub::ReceivedMessage>]
289
262
  #
263
+ # @example
290
264
  # require "gcloud"
291
265
  #
292
266
  # gcloud = Gcloud.new
@@ -304,22 +278,18 @@ module Gcloud
304
278
  # Poll the backend for new messages. This runs a loop to ping the API,
305
279
  # blocking indefinitely, yielding retrieved messages as they are received.
306
280
  #
307
- # === Parameters
308
- #
309
- # +max+::
310
- # The maximum number of messages to return for this request. The Pub/Sub
311
- # system may return fewer than the number specified. The default value
312
- # is +100+, the maximum value is +1000+. (+Integer+)
313
- # +autoack+::
314
- # Automatically acknowledge the message as it is pulled. The default
315
- # value is +false+. (+Boolean+)
316
- # +delay+::
317
- # The number of seconds to pause between requests when the Google Cloud
318
- # service has no messages to return. The default value is +1+.
319
- # (+Number+)
320
- #
321
- # === Examples
322
- #
281
+ # @param [Integer] max The maximum number of messages to return for this
282
+ # request. The Pub/Sub system may return fewer than the number
283
+ # specified. The default value is `100`, the maximum value is `1000`.
284
+ # @param [Boolean] autoack Automatically acknowledge the message as it is
285
+ # pulled. The default value is `false`.
286
+ # @param [Number] delay The number of seconds to pause between requests
287
+ # when the Google Cloud service has no messages to return. The default
288
+ # value is `1`.
289
+ # @yield [msg] a block for processing new messages
290
+ # @yieldparam [ReceivedMessage] msg the newly received message
291
+ #
292
+ # @example
323
293
  # require "gcloud"
324
294
  #
325
295
  # gcloud = Gcloud.new
@@ -330,9 +300,7 @@ module Gcloud
330
300
  # # process msg
331
301
  # end
332
302
  #
333
- # The number of messages pulled per batch can be set with the +max+
334
- # option:
335
- #
303
+ # @example Limit the number of messages pulled per batch with `max`:
336
304
  # require "gcloud"
337
305
  #
338
306
  # gcloud = Gcloud.new
@@ -343,9 +311,7 @@ module Gcloud
343
311
  # # process msg
344
312
  # end
345
313
  #
346
- # Messages can be automatically acknowledged as they are pulled with the
347
- # +autoack+ option:
348
- #
314
+ # @example Automatically acknowledge messages with `autoack`:
349
315
  # require "gcloud"
350
316
  #
351
317
  # gcloud = Gcloud.new
@@ -375,14 +341,10 @@ module Gcloud
375
341
  # Acknowledging a message more than once will not result in an error.
376
342
  # This is only used for messages received via pull.
377
343
  #
378
- # === Parameters
379
- #
380
- # +messages+::
381
- # One or more ReceivedMessage objects or ack_id values.
382
- # (+ReceivedMessage+ or +ack_id+)
383
- #
384
- # === Example
344
+ # @param [ReceivedMessage, String] messages One or more {ReceivedMessage}
345
+ # objects or ack_id values.
385
346
  #
347
+ # @example
386
348
  # require "gcloud"
387
349
  #
388
350
  # gcloud = Gcloud.new
@@ -394,13 +356,11 @@ module Gcloud
394
356
  #
395
357
  def acknowledge *messages
396
358
  ack_ids = coerce_ack_ids messages
397
- ensure_connection!
398
- resp = connection.acknowledge name, *ack_ids
399
- if resp.success?
400
- true
401
- else
402
- fail ApiError.from_response(resp)
403
- end
359
+ ensure_service!
360
+ service.acknowledge name, *ack_ids
361
+ true
362
+ rescue GRPC::BadStatus => e
363
+ raise Error.from_error(e)
404
364
  end
405
365
  alias_method :ack, :acknowledge
406
366
 
@@ -411,20 +371,15 @@ module Gcloud
411
371
  # make the messages available for redelivery if the processing was
412
372
  # interrupted.
413
373
  #
414
- # === Parameters
415
- #
416
- # +new_deadline+::
417
- # The new ack deadline in seconds from the time this request is sent
418
- # to the Pub/Sub system. Must be >= 0. For example, if the value is
419
- # +10+, the new ack deadline will expire 10 seconds after the call is
420
- # made. Specifying +0+ may immediately make the messages available for
421
- # another pull request. (+Integer+)
422
- # +messages+::
423
- # One or more ReceivedMessage objects or ack_id values.
424
- # (+ReceivedMessage+ or +ack_id+)
425
- #
426
- # === Example
374
+ # @param [Integer] new_deadline The new ack deadline in seconds from the
375
+ # time this request is sent to the Pub/Sub system. Must be >= 0. For
376
+ # example, if the value is `10`, the new ack deadline will expire 10
377
+ # seconds after the call is made. Specifying `0` may immediately make
378
+ # the message available for another pull request.
379
+ # @param [ReceivedMessage, String] messages One or more {ReceivedMessage}
380
+ # objects or ack_id values.
427
381
  #
382
+ # @example
428
383
  # require "gcloud"
429
384
  #
430
385
  # gcloud = Gcloud.new
@@ -436,29 +391,25 @@ module Gcloud
436
391
  #
437
392
  def delay new_deadline, *messages
438
393
  ack_ids = coerce_ack_ids messages
439
- ensure_connection!
440
- resp = connection.modify_ack_deadline name, ack_ids, new_deadline
441
- if resp.success?
442
- true
443
- else
444
- fail ApiError.from_response(resp)
445
- end
394
+ ensure_service!
395
+ service.modify_ack_deadline name, ack_ids, new_deadline
396
+ return true
397
+ rescue GRPC::BadStatus => e
398
+ raise Error.from_error(e)
446
399
  end
447
400
 
448
401
  ##
449
402
  # Gets the access control policy.
450
403
  #
451
- # === Parameters
452
- #
453
- # +force+::
454
- # Force the latest policy to be retrieved from the Pub/Sub service when
455
- # +true. Otherwise the policy will be memoized to reduce the number of
456
- # API calls made to the Pub/Sub service. The default is +false+.
457
- # (+Boolean+)
404
+ # By default, the policy values are memoized to reduce the number of API
405
+ # calls to the Pub/Sub service.
458
406
  #
459
- # === Returns
407
+ # @param [Boolean] force Force the latest policy to be retrieved from the
408
+ # Pub/Sub service when `true`. Otherwise the policy will be memoized to
409
+ # reduce the number of API calls made to the Pub/Sub service. The
410
+ # default is `false`.
460
411
  #
461
- # A hash that conforms to the following structure:
412
+ # @return [Hash] Returns a hash that conforms to the following structure:
462
413
  #
463
414
  # {
464
415
  # "etag"=>"CAE=",
@@ -468,11 +419,7 @@ module Gcloud
468
419
  # }]
469
420
  # }
470
421
  #
471
- # === Examples
472
- #
473
- # By default, the policy values are memoized to reduce the number of API
474
- # calls to the Pub/Sub service.
475
- #
422
+ # @example Policy values are memoized to reduce the number of API calls:
476
423
  # require "gcloud"
477
424
  #
478
425
  # gcloud = Gcloud.new
@@ -482,9 +429,7 @@ module Gcloud
482
429
  # puts subscription.policy["bindings"]
483
430
  # puts subscription.policy["rules"]
484
431
  #
485
- # To retrieve the latest policy from the Pub/Sub service, use the +force+
486
- # flag.
487
- #
432
+ # @example Use `force` to retrieve the latest policy from the service:
488
433
  # require "gcloud"
489
434
  #
490
435
  # gcloud = Gcloud.new
@@ -496,22 +441,19 @@ module Gcloud
496
441
  def policy force: nil
497
442
  @policy = nil if force
498
443
  @policy ||= begin
499
- ensure_connection!
500
- resp = connection.get_subscription_policy name
501
- fail ApiError.from_response(resp) unless resp.success?
502
- policy = resp.data
503
- policy = policy.to_hash if policy.respond_to? :to_hash
504
- policy
444
+ ensure_service!
445
+ grpc = service.get_subscription_policy name
446
+ JSON.parse(Google::Iam::V1::Policy.encode_json(grpc))
447
+ rescue GRPC::BadStatus => e
448
+ raise Error.from_error(e)
505
449
  end
506
450
  end
507
451
 
508
452
  ##
509
453
  # Sets the access control policy.
510
454
  #
511
- # === Parameters
512
- #
513
- # +new_policy+::
514
- # A hash that conforms to the following structure:
455
+ # @param [String] new_policy A hash that conforms to the following
456
+ # structure:
515
457
  #
516
458
  # {
517
459
  # "bindings" => [{
@@ -520,8 +462,7 @@ module Gcloud
520
462
  # }]
521
463
  # }
522
464
  #
523
- # === Example
524
- #
465
+ # @example
525
466
  # require "gcloud"
526
467
  #
527
468
  # gcloud = Gcloud.new
@@ -537,28 +478,23 @@ module Gcloud
537
478
  # subscription.policy = viewer_policy
538
479
  #
539
480
  def policy= new_policy
540
- ensure_connection!
541
- resp = connection.set_subscription_policy name, new_policy
542
- if resp.success?
543
- @policy = resp.data["policy"]
544
- @policy = @policy.to_hash if @policy.respond_to? :to_hash
545
- else
546
- fail ApiError.from_response(resp)
547
- end
481
+ ensure_service!
482
+ grpc = service.set_subscription_policy name, new_policy
483
+ @policy = JSON.parse(Google::Iam::V1::Policy.encode_json(grpc))
484
+ rescue GRPC::BadStatus => e
485
+ raise Error.from_error(e)
548
486
  end
549
487
 
550
488
  ##
551
- # Tests the specified permissions against the {Cloud
552
- # IAM}[https://cloud.google.com/iam/] access control policy. See
553
- # {Managing Policies}[https://cloud.google.com/iam/docs/managing-policies]
554
- # for more information.
489
+ # Tests the specified permissions against the [Cloud
490
+ # IAM](https://cloud.google.com/iam/) access control policy.
555
491
  #
556
- # === Parameters
492
+ # @see https://cloud.google.com/iam/docs/managing-policies Managing
493
+ # Policies
557
494
  #
558
- # +permissions+::
559
- # The set of permissions to check access for. Permissions with wildcards
560
- # (such as +*+ or +storage.*+) are not allowed.
561
- # (String or Array of Strings)
495
+ # @param [String, Array<String>] permissions The set of permissions to
496
+ # check access for. Permissions with wildcards (such as `*` or
497
+ # `storage.*`) are not allowed.
562
498
  #
563
499
  # The permissions that can be checked on a subscription are:
564
500
  #
@@ -569,12 +505,9 @@ module Gcloud
569
505
  # * pubsub.subscriptions.getIamPolicy
570
506
  # * pubsub.subscriptions.setIamPolicy
571
507
  #
572
- # === Returns
573
- #
574
- # The permissions that have access. (Array of Strings)
575
- #
576
- # === Example
508
+ # @return [Array<String>] The permissions that have access.
577
509
  #
510
+ # @example
578
511
  # require "gcloud"
579
512
  #
580
513
  # gcloud = Gcloud.new
@@ -587,48 +520,45 @@ module Gcloud
587
520
  #
588
521
  def test_permissions *permissions
589
522
  permissions = Array(permissions).flatten
590
- ensure_connection!
591
- resp = connection.test_subscription_permissions name, permissions
592
- if resp.success?
593
- Array(resp.data["permissions"])
594
- else
595
- fail ApiError.from_response(resp)
596
- end
523
+ ensure_service!
524
+ grpc = service.test_subscription_permissions name, permissions
525
+ grpc.permissions
526
+ rescue GRPC::BadStatus => e
527
+ raise Error.from_error(e)
597
528
  end
598
529
 
599
530
  ##
600
- # New Subscription from a Google API Client object.
601
- def self.from_gapi gapi, conn #:nodoc:
531
+ # @private New Subscription from a Google::Pubsub::V1::Subscription
532
+ # object.
533
+ def self.from_grpc grpc, service
602
534
  new.tap do |f|
603
- f.gapi = gapi
604
- f.connection = conn
535
+ f.grpc = grpc
536
+ f.service = service
605
537
  end
606
538
  end
607
539
 
608
540
  protected
609
541
 
610
542
  ##
611
- # Raise an error unless an active connection is available.
612
- def ensure_connection!
613
- fail "Must have active connection" unless connection
543
+ # @private Raise an error unless an active connection to the service is
544
+ # available.
545
+ def ensure_service!
546
+ fail "Must have active connection to service" unless service
614
547
  end
615
548
 
616
549
  ##
617
- # Ensures a Google API object exists.
618
- def ensure_gapi!
619
- ensure_connection!
620
- return @gapi if @gapi
621
- resp = connection.get_subscription @name
622
- if resp.success?
623
- @gapi = resp.data
624
- else
625
- fail ApiError.from_response(resp)
626
- end
550
+ # Ensures a Google::Pubsub::V1::Subscription object exists.
551
+ def ensure_grpc!
552
+ ensure_service!
553
+ return @grpc if @grpc
554
+ @grpc = service.get_subscription @name
555
+ rescue GRPC::BadStatus => e
556
+ raise Error.from_error(e)
627
557
  end
628
558
 
629
559
  ##
630
- # Makes sure the values are the +ack_id+.
631
- # If given several ReceivedMessage objects extract the +ack_id+ values.
560
+ # Makes sure the values are the `ack_id`.
561
+ # If given several {ReceivedMessage} objects extract the `ack_id` values.
632
562
  def coerce_ack_ids messages
633
563
  Array(messages).flatten.map do |msg|
634
564
  msg.respond_to?(:ack_id) ? msg.ack_id : msg.to_s