google-cloud-pubsub 2.15.5 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +12 -1
  3. data/CHANGELOG.md +129 -0
  4. data/OVERVIEW.md +189 -145
  5. data/lib/google/cloud/pubsub/admin_clients.rb +116 -0
  6. data/lib/google/cloud/pubsub/async_publisher.rb +20 -19
  7. data/lib/google/cloud/pubsub/batch_publisher.rb +7 -5
  8. data/lib/google/cloud/pubsub/convert.rb +1 -1
  9. data/lib/google/cloud/pubsub/errors.rb +3 -3
  10. data/lib/google/cloud/pubsub/flow_controller.rb +0 -2
  11. data/lib/google/cloud/pubsub/internal_logger.rb +76 -0
  12. data/lib/google/cloud/pubsub/message.rb +10 -11
  13. data/lib/google/cloud/pubsub/{subscriber → message_listener}/enumerator_queue.rb +1 -1
  14. data/lib/google/cloud/pubsub/{subscriber → message_listener}/inventory.rb +13 -10
  15. data/lib/google/cloud/pubsub/{subscriber → message_listener}/sequencer.rb +1 -1
  16. data/lib/google/cloud/pubsub/{subscriber → message_listener}/stream.rb +58 -17
  17. data/lib/google/cloud/pubsub/{subscriber → message_listener}/timed_unary_buffer.rb +29 -9
  18. data/lib/google/cloud/pubsub/message_listener.rb +413 -0
  19. data/lib/google/cloud/pubsub/project.rb +108 -523
  20. data/lib/google/cloud/pubsub/publisher.rb +424 -0
  21. data/lib/google/cloud/pubsub/received_message.rb +50 -45
  22. data/lib/google/cloud/pubsub/service.rb +48 -349
  23. data/lib/google/cloud/pubsub/subscriber.rb +442 -279
  24. data/lib/google/cloud/pubsub/version.rb +1 -1
  25. data/lib/google/cloud/pubsub.rb +51 -30
  26. data/lib/google-cloud-pubsub.rb +30 -10
  27. metadata +19 -183
  28. data/lib/google/cloud/pubsub/policy.rb +0 -188
  29. data/lib/google/cloud/pubsub/retry_policy.rb +0 -88
  30. data/lib/google/cloud/pubsub/schema/list.rb +0 -180
  31. data/lib/google/cloud/pubsub/schema.rb +0 -310
  32. data/lib/google/cloud/pubsub/snapshot/list.rb +0 -178
  33. data/lib/google/cloud/pubsub/snapshot.rb +0 -205
  34. data/lib/google/cloud/pubsub/subscription/list.rb +0 -205
  35. data/lib/google/cloud/pubsub/subscription/push_config.rb +0 -268
  36. data/lib/google/cloud/pubsub/subscription.rb +0 -1467
  37. data/lib/google/cloud/pubsub/topic/list.rb +0 -171
  38. data/lib/google/cloud/pubsub/topic.rb +0 -1100
@@ -1,310 +0,0 @@
1
- # Copyright 2021 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- require "google/cloud/pubsub/schema/list"
17
- require "google/cloud/pubsub/v1"
18
-
19
- module Google
20
- module Cloud
21
- module PubSub
22
- ##
23
- # # Schema
24
- #
25
- # A schema resource.
26
- #
27
- # @example
28
- # require "google/cloud/pubsub"
29
- #
30
- # pubsub = Google::Cloud::PubSub.new
31
- #
32
- # schema = pubsub.schema "my-schema"
33
- # schema.name #=> "projects/my-project/schemas/my-schema"
34
- # schema.type #=> :PROTOCOL_BUFFER
35
- #
36
- class Schema
37
- ##
38
- # @private The Service object.
39
- attr_accessor :service
40
-
41
- ##
42
- # @private The gRPC Google::Cloud::PubSub::V1::Schema object.
43
- attr_accessor :grpc
44
-
45
- ##
46
- # @private Create a new Schema instance.
47
- def initialize grpc, service, view: nil
48
- @grpc = grpc
49
- @service = service
50
- @exists = nil
51
- @view = view || :FULL
52
- end
53
-
54
- ##
55
- # The name of the schema.
56
- #
57
- # @return [String] A fully-qualified schema name in the form `projects/{project_id}/schemas/{schema_id}`.
58
- #
59
- def name
60
- @grpc.name
61
- end
62
-
63
- ##
64
- # The type of the schema. Possible values include:
65
- #
66
- # * `PROTOCOL_BUFFER` - A Protocol Buffer schema definition.
67
- # * `AVRO` - An Avro schema definition.
68
- #
69
- # @return [String, nil] The upper-case type name.
70
- #
71
- def type
72
- return nil if reference?
73
- @grpc.type
74
- end
75
-
76
- ##
77
- # The definition of the schema. This should be a string representing the full definition of the schema that is a
78
- # valid schema definition of the type specified in {#type}.
79
- #
80
- # @return [String, nil] The schema definition.
81
- #
82
- def definition
83
- return nil if reference?
84
- @grpc.definition if @grpc.definition && !@grpc.definition.empty?
85
- end
86
-
87
- ##
88
- # Validates a message against a schema.
89
- #
90
- # @param message_data [String] Message to validate against the provided `schema_spec`.
91
- # @param message_encoding [Symbol, String] The encoding of the message validated against the schema. Values
92
- # include:
93
- #
94
- # * `JSON` - JSON encoding.
95
- # * `BINARY` - Binary encoding, as defined by the schema type. For some schema types, binary encoding may not
96
- # be available.
97
- #
98
- # @return [Boolean] Returns `true` if the message validiation succeeds, `false` otherwise.
99
- #
100
- # @example
101
- # require "google/cloud/pubsub"
102
- #
103
- # pubsub = Google::Cloud::PubSub.new
104
- # schema = pubsub.schema "my-schema"
105
- #
106
- # message_data = { "name" => "Alaska", "post_abbr" => "AK" }.to_json
107
- # schema.validate_message message_data, :json
108
- #
109
- def validate_message message_data, message_encoding
110
- message_encoding = message_encoding.to_s.upcase
111
- service.validate_message message_data, message_encoding, schema_name: name
112
- true
113
- rescue Google::Cloud::InvalidArgumentError
114
- false
115
- end
116
-
117
- ##
118
- # Removes the schema, if it exists.
119
- #
120
- # @return [Boolean] Returns `true` if the schema was deleted.
121
- #
122
- # @example
123
- # require "google/cloud/pubsub"
124
- #
125
- # pubsub = Google::Cloud::PubSub.new
126
- # schema = pubsub.schema "my-schema"
127
- #
128
- # schema.delete
129
- #
130
- def delete
131
- ensure_service!
132
- service.delete_schema name
133
- true
134
- end
135
-
136
- ##
137
- # Reloads the schema with current data from the Pub/Sub service.
138
- #
139
- # @param view [Symbol, String, nil] The set of fields to return in the response. Possible values:
140
- # * `BASIC` - Include the `name` and `type` of the schema, but not the `definition`.
141
- # * `FULL` - Include all Schema object fields.
142
- #
143
- # Optional. If not provided or `nil`, the last non-nil `view` argument to this method will be used if one has
144
- # been given, othewise `FULL` will be used.
145
- #
146
- # @return [Google::Cloud::PubSub::Schema] Returns the reloaded schema.
147
- #
148
- # @example Skip retrieving the schema from the service, then load it:
149
- # require "google/cloud/pubsub"
150
- #
151
- # pubsub = Google::Cloud::PubSub.new
152
- # schema = pubsub.schema "my-schema", skip_lookup: true
153
- #
154
- # schema.reload!
155
- #
156
- # @example Use the `view` option to load the basic or full resource:
157
- # require "google/cloud/pubsub"
158
- #
159
- # pubsub = Google::Cloud::PubSub.new
160
- # schema = pubsub.schema "my-schema", view: :basic
161
- # schema.resource_partial? #=> true
162
- #
163
- # schema.reload! view: :full
164
- # schema.resource_partial? #=> false
165
- #
166
- # @!group Lifecycle
167
- #
168
- def reload! view: nil
169
- ensure_service!
170
- @view = view || @view
171
- @grpc = service.get_schema name, @view
172
- @reference = nil
173
- @exists = nil
174
- self
175
- end
176
- alias refresh! reload!
177
-
178
- ##
179
- # Determines whether the schema exists in the Pub/Sub service.
180
- #
181
- # @example
182
- # require "google/cloud/pubsub"
183
- #
184
- # pubsub = Google::Cloud::PubSub.new
185
- #
186
- # schema = pubsub.schema "my-schema"
187
- # schema.exists? #=> true
188
- #
189
- def exists?
190
- # Always true if the object is not set as reference
191
- return true unless reference?
192
- # If we have a value, return it
193
- return @exists unless @exists.nil?
194
- ensure_grpc!
195
- @exists = true
196
- rescue Google::Cloud::NotFoundError
197
- @exists = false
198
- end
199
-
200
- ##
201
- # Determines whether the schema object was created without retrieving the
202
- # resource representation from the Pub/Sub service.
203
- #
204
- # @return [Boolean] `true` when the schema was created without a resource
205
- # representation, `false` otherwise.
206
- #
207
- # @example
208
- # require "google/cloud/pubsub"
209
- #
210
- # pubsub = Google::Cloud::PubSub.new
211
- #
212
- # schema = pubsub.schema "my-schema", skip_lookup: true
213
- # schema.reference? #=> true
214
- #
215
- def reference?
216
- @grpc.type.nil? || @grpc.type == :TYPE_UNSPECIFIED
217
- end
218
-
219
- ##
220
- # Determines whether the schema object was created with a resource
221
- # representation from the Pub/Sub service.
222
- #
223
- # @return [Boolean] `true` when the schema was created with a resource
224
- # representation, `false` otherwise.
225
- #
226
- # @example
227
- # require "google/cloud/pubsub"
228
- #
229
- # pubsub = Google::Cloud::PubSub.new
230
- #
231
- # schema = pubsub.schema "my-schema"
232
- # schema.resource? #=> true
233
- #
234
- def resource?
235
- !reference?
236
- end
237
-
238
- ##
239
- # Whether the schema was created with a partial resource representation
240
- # from the Pub/Sub service.
241
- #
242
- # @return [Boolean] `true` when the schema was created with a partial
243
- # resource representation, `false` otherwise.
244
- #
245
- # @example
246
- # require "google/cloud/pubsub"
247
- #
248
- # pubsub = Google::Cloud::PubSub.new
249
- # schema = pubsub.schema "my-schema", view: :basic
250
- #
251
- # schema.resource_partial? #=> true
252
- # schema.reload! view: :full # Loads the full resource.
253
- # schema.resource_partial? #=> false
254
- #
255
- def resource_partial?
256
- resource? && !resource_full?
257
- end
258
-
259
- ##
260
- # Whether the schema was created with a full resource representation
261
- # from the Pub/Sub service.
262
- #
263
- # @return [Boolean] `true` when the schema was created with a full
264
- # resource representation, `false` otherwise.
265
- #
266
- # @example
267
- # require "google/cloud/pubsub"
268
- #
269
- # pubsub = Google::Cloud::PubSub.new
270
- # schema = pubsub.schema "my-schema"
271
- #
272
- # schema.resource_full? #=> true
273
- #
274
- def resource_full?
275
- resource? && @grpc.definition && !@grpc.definition.empty?
276
- end
277
-
278
- ##
279
- # @private New Schema from a Google::Cloud::PubSub::V1::Schema object.
280
- def self.from_grpc grpc, service, view: nil
281
- new grpc, service, view: view
282
- end
283
-
284
- ##
285
- # @private New reference Schema object without making an HTTP request.
286
- def self.from_name name, view, service, options = {}
287
- grpc = Google::Cloud::PubSub::V1::Schema.new name: service.schema_path(name, options)
288
- from_grpc grpc, service, view: view
289
- end
290
-
291
- protected
292
-
293
- ##
294
- # @private Raise an error unless an active connection to the service is available.
295
- def ensure_service!
296
- raise "Must have active connection to service" unless service
297
- end
298
-
299
- ##
300
- # Ensures a Google::Cloud::PubSub::V1::Schema object exists.
301
- def ensure_grpc!
302
- ensure_service!
303
- reload! if reference?
304
- end
305
- end
306
- end
307
-
308
- Pubsub = PubSub unless const_defined? :Pubsub
309
- end
310
- end
@@ -1,178 +0,0 @@
1
- # Copyright 2017 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- require "delegate"
17
-
18
- module Google
19
- module Cloud
20
- module PubSub
21
- class Snapshot
22
- ##
23
- # Snapshot::List is a special case Array with additional values.
24
- class List < DelegateClass(::Array)
25
- ##
26
- # If not empty, indicates that there are more snapshots
27
- # that match the request and this value should be passed to
28
- # the next {Google::Cloud::PubSub::Project#snapshots} to continue.
29
- attr_accessor :token
30
-
31
- ##
32
- # @private Create a new Snapshot::List with an array of values.
33
- def initialize arr = []
34
- @prefix = nil
35
- @token = nil
36
- @max = nil
37
- super arr
38
- end
39
-
40
- ##
41
- # Whether there a next page of snapshots.
42
- #
43
- # @return [Boolean]
44
- #
45
- # @example
46
- # require "google/cloud/pubsub"
47
- #
48
- # pubsub = Google::Cloud::PubSub.new
49
- #
50
- # snapshots = pubsub.snapshots
51
- # if snapshots.next?
52
- # next_snapshots = snapshots.next
53
- # end
54
- #
55
- def next?
56
- !token.nil?
57
- end
58
-
59
- ##
60
- # Retrieve the next page of snapshots.
61
- #
62
- # @return [Snapshot::List]
63
- #
64
- # @example
65
- # require "google/cloud/pubsub"
66
- #
67
- # pubsub = Google::Cloud::PubSub.new
68
- #
69
- # snapshots = pubsub.snapshots
70
- # if snapshots.next?
71
- # next_snapshots = snapshots.next
72
- # end
73
- #
74
- def next
75
- return nil unless next?
76
- ensure_service!
77
- next_snapshots
78
- end
79
-
80
- ##
81
- # Retrieves remaining results by repeatedly invoking {#next} until
82
- # {#next?} returns `false`. Calls the given block once for each
83
- # result, which is passed as the argument to the block.
84
- #
85
- # An Enumerator is returned if no block is given.
86
- #
87
- # This method will make repeated API calls until all remaining results
88
- # are retrieved. (Unlike `#each`, for example, which merely iterates
89
- # over the results returned by a single API call.) Use with caution.
90
- #
91
- # @param [Integer] request_limit The upper limit of API requests to
92
- # make to load all snapshots. Default is no limit.
93
- # @yield [snapshot] The block for accessing each snapshot.
94
- # @yieldparam [Snapshot] snapshot The snapshot object.
95
- #
96
- # @return [Enumerator]
97
- #
98
- # @example Iterating each snapshot by passing a block:
99
- # require "google/cloud/pubsub"
100
- #
101
- # pubsub = Google::Cloud::PubSub.new
102
- #
103
- # snapshots = pubsub.snapshots
104
- # snapshots.all do |snapshot|
105
- # puts snapshot.name
106
- # end
107
- #
108
- # @example Using the enumerator by not passing a block:
109
- # require "google/cloud/pubsub"
110
- #
111
- # pubsub = Google::Cloud::PubSub.new
112
- #
113
- # snapshots = pubsub.snapshots
114
- # all_names = snapshots.all.map do |snapshot|
115
- # snapshot.name
116
- # end
117
- #
118
- # @example Limit the number of API calls made:
119
- # require "google/cloud/pubsub"
120
- #
121
- # pubsub = Google::Cloud::PubSub.new
122
- #
123
- # snapshots = pubsub.snapshots
124
- # snapshots.all(request_limit: 10) do |snapshot|
125
- # puts snapshot.name
126
- # end
127
- #
128
- def all request_limit: nil, &block
129
- request_limit = request_limit.to_i if request_limit
130
- return enum_for :all, request_limit: request_limit unless block_given?
131
- results = self
132
- loop do
133
- results.each(&block)
134
- if request_limit
135
- request_limit -= 1
136
- break if request_limit.negative?
137
- end
138
- break unless results.next?
139
- results = results.next
140
- end
141
- end
142
-
143
- ##
144
- # @private New Snapshots::List from a
145
- # Google::Cloud::PubSub::V1::ListSnapshotsRequest object.
146
- def self.from_grpc grpc_list, service, max = nil
147
- subs = new(Array(grpc_list.snapshots).map do |grpc|
148
- Snapshot.from_grpc grpc, service
149
- end)
150
- token = grpc_list.next_page_token
151
- token = nil if token == "".freeze
152
- subs.instance_variable_set :@token, token
153
- subs.instance_variable_set :@service, service
154
- subs.instance_variable_set :@max, max
155
- subs
156
- end
157
-
158
- protected
159
-
160
- ##
161
- # @private Raise an error unless an active connection to the service
162
- # is available.
163
- def ensure_service!
164
- raise "Must have active connection to service" unless @service
165
- end
166
-
167
- def next_snapshots
168
- options = { prefix: @prefix, token: @token, max: @max }
169
- grpc = @service.list_snapshots options
170
- self.class.from_grpc grpc, @service, @max
171
- end
172
- end
173
- end
174
- end
175
-
176
- Pubsub = PubSub unless const_defined? :Pubsub
177
- end
178
- end
@@ -1,205 +0,0 @@
1
- # Copyright 2017 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- require "google/cloud/errors"
17
- require "google/cloud/pubsub/snapshot/list"
18
- require "google/cloud/pubsub/v1"
19
-
20
- module Google
21
- module Cloud
22
- module PubSub
23
- ##
24
- # # Snapshot
25
- #
26
- # A named resource created from a subscription to retain a stream of
27
- # messages from a topic. A snapshot is guaranteed to retain:
28
- #
29
- # * The existing backlog on the subscription. More precisely, this is
30
- # defined as the messages in the subscription's backlog that are
31
- # unacknowledged upon the successful completion of the
32
- # `create_snapshot` operation; as well as:
33
- # * Any messages published to the subscription's topic following the
34
- # successful completion of the `create_snapshot` operation.
35
- #
36
- # @example
37
- # require "google/cloud/pubsub"
38
- #
39
- # pubsub = Google::Cloud::PubSub.new
40
- # sub = pubsub.subscription "my-sub"
41
- #
42
- # snapshot = sub.create_snapshot "my-snapshot"
43
- # snapshot.name #=> "projects/my-project/snapshots/my-snapshot"
44
- #
45
- class Snapshot
46
- ##
47
- # @private The Service object.
48
- attr_accessor :service
49
-
50
- ##
51
- # @private The gRPC Google::Cloud::PubSub::V1::Snapshot object.
52
- attr_accessor :grpc
53
-
54
- ##
55
- # @private Create an empty {Snapshot} object.
56
- def initialize
57
- @service = nil
58
- @grpc = Google::Cloud::PubSub::V1::Snapshot.new
59
- end
60
-
61
- ##
62
- # The name of the snapshot.
63
- #
64
- # @return [String] A fully-qualified snapshot name in the form
65
- # `projects/{project_id}/snapshots/{snapshot_id}`.
66
- def name
67
- @grpc.name
68
- end
69
-
70
- ##
71
- # The {Topic} from which this snapshot is retaining messages.
72
- #
73
- # @return [Topic]
74
- #
75
- # @example
76
- # require "google/cloud/pubsub"
77
- #
78
- # pubsub = Google::Cloud::PubSub.new
79
- # sub = pubsub.subscription "my-sub"
80
- #
81
- # snapshot = sub.create_snapshot "my-snapshot"
82
- # snapshot.topic.name #=> "projects/my-project/topics/my-topic"
83
- #
84
- def topic
85
- Topic.from_name @grpc.topic, service
86
- end
87
-
88
- ##
89
- # The snapshot is guaranteed to exist up until this time.
90
- # A newly-created snapshot expires no later than 7 days from the time of
91
- # its creation. Its exact lifetime is determined at creation by the
92
- # existing backlog in the source subscription. Specifically, the
93
- # lifetime of the snapshot is 7 days - (age of oldest unacked message in
94
- # the subscription). For example, consider a subscription whose oldest
95
- # unacked message is 3 days old. If a snapshot is created from this
96
- # subscription, the snapshot -- which will always capture this 3-day-old
97
- # backlog as long as the snapshot exists -- will expire in 4 days.
98
- #
99
- # @return [Time] The time until which the snapshot is guaranteed to
100
- # exist.
101
- #
102
- # @example
103
- # require "google/cloud/pubsub"
104
- #
105
- # pubsub = Google::Cloud::PubSub.new
106
- # sub = pubsub.subscription "my-sub"
107
- #
108
- # snapshot = sub.create_snapshot "my-snapshot"
109
- # snapshot.topic.name #=> "projects/my-project/topics/my-topic"
110
- # snapshot.expiration_time
111
- #
112
- def expiration_time
113
- self.class.timestamp_from_grpc @grpc.expire_time
114
- end
115
-
116
- ##
117
- # A hash of user-provided labels associated with this snapshot.
118
- # Labels can be used to organize and group snapshots.See [Creating and
119
- # Managing Labels](https://cloud.google.com/pubsub/docs/labels).
120
- #
121
- # The returned hash is frozen and changes are not allowed. Use
122
- # {#labels=} to update the labels for this snapshot.
123
- #
124
- # @return [Hash] The frozen labels hash.
125
- #
126
- def labels
127
- @grpc.labels.to_h.freeze
128
- end
129
-
130
- ##
131
- # Sets the hash of user-provided labels associated with this
132
- # snapshot. Labels can be used to organize and group snapshots.
133
- # Label keys and values can be no longer than 63 characters, can only
134
- # contain lowercase letters, numeric characters, underscores and dashes.
135
- # International characters are allowed. Label values are optional. Label
136
- # keys must start with a letter and each label in the list must have a
137
- # different key. See [Creating and Managing
138
- # Labels](https://cloud.google.com/pubsub/docs/labels).
139
- #
140
- # @param [Hash] new_labels The new labels hash.
141
- #
142
- def labels= new_labels
143
- raise ArgumentError, "Value must be a Hash" if new_labels.nil?
144
- labels_map = Google::Protobuf::Map.new :string, :string
145
- Hash(new_labels).each { |k, v| labels_map[String(k)] = String(v) }
146
- update_grpc = @grpc.dup
147
- update_grpc.labels = labels_map
148
- @grpc = service.update_snapshot update_grpc, :labels
149
- end
150
-
151
- ##
152
- # Removes an existing snapshot. All messages retained in the snapshot
153
- # are immediately dropped. After a snapshot is deleted, a new one may be
154
- # created with the same name, but the new one has no association with
155
- # the old snapshot or its subscription, unless the same subscription is
156
- # specified.
157
- #
158
- # @return [Boolean] Returns `true` if the snapshot was deleted.
159
- #
160
- # @example
161
- # require "google/cloud/pubsub"
162
- #
163
- # pubsub = Google::Cloud::PubSub.new
164
- #
165
- # pubsub.snapshots.each do |snapshot|
166
- # snapshot.delete
167
- # end
168
- #
169
- def delete
170
- ensure_service!
171
- service.delete_snapshot name
172
- true
173
- end
174
-
175
- ##
176
- # @private New Snapshot from a Google::Cloud::PubSub::V1::Snapshot
177
- # object.
178
- def self.from_grpc grpc, service
179
- new.tap do |f|
180
- f.grpc = grpc
181
- f.service = service
182
- end
183
- end
184
-
185
- ##
186
- # @private Get a Time object from a Google::Protobuf::Timestamp object.
187
- def self.timestamp_from_grpc grpc_timestamp
188
- return nil if grpc_timestamp.nil?
189
- Time.at grpc_timestamp.seconds, Rational(grpc_timestamp.nanos, 1000)
190
- end
191
-
192
- protected
193
-
194
- ##
195
- # @private Raise an error unless an active connection to the service is
196
- # available.
197
- def ensure_service!
198
- raise "Must have active connection to service" unless service
199
- end
200
- end
201
- end
202
-
203
- Pubsub = PubSub unless const_defined? :Pubsub
204
- end
205
- end