gcloud 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/AUTHENTICATION.md +13 -9
- data/CHANGELOG.md +8 -3
- data/OVERVIEW.md +46 -8
- data/lib/gcloud.rb +123 -117
- data/lib/gcloud/backoff.rb +43 -15
- data/lib/gcloud/bigquery.rb +211 -195
- data/lib/gcloud/bigquery/connection.rb +9 -9
- data/lib/gcloud/bigquery/copy_job.rb +15 -16
- data/lib/gcloud/bigquery/credentials.rb +3 -3
- data/lib/gcloud/bigquery/data.rb +12 -11
- data/lib/gcloud/bigquery/dataset.rb +162 -216
- data/lib/gcloud/bigquery/dataset/access.rb +59 -43
- data/lib/gcloud/bigquery/dataset/list.rb +3 -3
- data/lib/gcloud/bigquery/errors.rb +9 -5
- data/lib/gcloud/bigquery/extract_job.rb +18 -18
- data/lib/gcloud/bigquery/insert_response.rb +7 -4
- data/lib/gcloud/bigquery/job.rb +48 -44
- data/lib/gcloud/bigquery/job/list.rb +3 -3
- data/lib/gcloud/bigquery/load_job.rb +24 -25
- data/lib/gcloud/bigquery/project.rb +145 -204
- data/lib/gcloud/bigquery/query_data.rb +10 -9
- data/lib/gcloud/bigquery/query_job.rb +23 -32
- data/lib/gcloud/bigquery/table.rb +238 -280
- data/lib/gcloud/bigquery/table/list.rb +3 -3
- data/lib/gcloud/bigquery/table/schema.rb +79 -87
- data/lib/gcloud/bigquery/view.rb +69 -82
- data/lib/gcloud/credentials.rb +3 -9
- data/lib/gcloud/datastore.rb +194 -170
- data/lib/gcloud/datastore/connection.rb +12 -8
- data/lib/gcloud/datastore/credentials.rb +6 -4
- data/lib/gcloud/datastore/dataset.rb +74 -141
- data/lib/gcloud/datastore/dataset/lookup_results.rb +6 -4
- data/lib/gcloud/datastore/dataset/query_results.rb +6 -4
- data/lib/gcloud/datastore/entity.rb +81 -76
- data/lib/gcloud/datastore/errors.rb +10 -8
- data/lib/gcloud/datastore/key.rb +41 -77
- data/lib/gcloud/datastore/properties.rb +3 -3
- data/lib/gcloud/datastore/proto.rb +7 -4
- data/lib/gcloud/datastore/query.rb +26 -3
- data/lib/gcloud/datastore/transaction.rb +12 -8
- data/lib/gcloud/dns.rb +180 -152
- data/lib/gcloud/dns/change.rb +16 -16
- data/lib/gcloud/dns/change/list.rb +3 -3
- data/lib/gcloud/dns/connection.rb +9 -10
- data/lib/gcloud/dns/credentials.rb +3 -3
- data/lib/gcloud/dns/errors.rb +9 -5
- data/lib/gcloud/dns/importer.rb +17 -23
- data/lib/gcloud/dns/project.rb +42 -64
- data/lib/gcloud/dns/record.rb +58 -46
- data/lib/gcloud/dns/record/list.rb +6 -7
- data/lib/gcloud/dns/zone.rb +198 -289
- data/lib/gcloud/dns/zone/list.rb +3 -3
- data/lib/gcloud/dns/zone/transaction.rb +56 -72
- data/lib/gcloud/errors.rb +174 -3
- data/lib/gcloud/gce.rb +3 -4
- data/lib/gcloud/grpc_utils.rb +76 -0
- data/lib/gcloud/logging.rb +308 -0
- data/lib/gcloud/logging/credentials.rb +29 -0
- data/lib/gcloud/logging/entry.rb +303 -0
- data/lib/gcloud/logging/entry/http_request.rb +141 -0
- data/lib/gcloud/logging/entry/list.rb +111 -0
- data/lib/gcloud/logging/entry/operation.rb +90 -0
- data/lib/gcloud/logging/logger.rb +307 -0
- data/lib/gcloud/logging/metric.rb +175 -0
- data/lib/gcloud/logging/metric/list.rb +98 -0
- data/lib/gcloud/logging/project.rb +650 -0
- data/lib/gcloud/logging/resource.rb +95 -0
- data/lib/gcloud/logging/resource_descriptor.rb +140 -0
- data/lib/gcloud/logging/resource_descriptor/list.rb +78 -0
- data/lib/gcloud/logging/service.rb +258 -0
- data/lib/gcloud/logging/sink.rb +233 -0
- data/lib/gcloud/logging/sink/list.rb +97 -0
- data/lib/gcloud/pubsub.rb +241 -199
- data/lib/gcloud/pubsub/credentials.rb +3 -3
- data/lib/gcloud/pubsub/message.rb +26 -20
- data/lib/gcloud/pubsub/project.rb +166 -233
- data/lib/gcloud/pubsub/received_message.rb +28 -38
- data/lib/gcloud/pubsub/service.rb +323 -0
- data/lib/gcloud/pubsub/subscription.rb +172 -242
- data/lib/gcloud/pubsub/subscription/list.rb +11 -9
- data/lib/gcloud/pubsub/topic.rb +152 -271
- data/lib/gcloud/pubsub/topic/batch.rb +66 -0
- data/lib/gcloud/pubsub/topic/list.rb +9 -7
- data/lib/gcloud/resource_manager.rb +158 -138
- data/lib/gcloud/resource_manager/connection.rb +6 -5
- data/lib/gcloud/resource_manager/credentials.rb +3 -3
- data/lib/gcloud/resource_manager/errors.rb +9 -5
- data/lib/gcloud/resource_manager/manager.rb +54 -86
- data/lib/gcloud/resource_manager/project.rb +69 -88
- data/lib/gcloud/resource_manager/project/list.rb +4 -5
- data/lib/gcloud/resource_manager/project/updater.rb +12 -14
- data/lib/gcloud/search.rb +158 -135
- data/lib/gcloud/search/api_client.rb +7 -7
- data/lib/gcloud/search/connection.rb +8 -8
- data/lib/gcloud/search/credentials.rb +3 -3
- data/lib/gcloud/search/document.rb +64 -87
- data/lib/gcloud/search/document/list.rb +5 -5
- data/lib/gcloud/search/errors.rb +9 -5
- data/lib/gcloud/search/field_value.rb +32 -38
- data/lib/gcloud/search/field_values.rb +50 -80
- data/lib/gcloud/search/fields.rb +44 -65
- data/lib/gcloud/search/index.rb +163 -204
- data/lib/gcloud/search/index/list.rb +5 -5
- data/lib/gcloud/search/project.rb +31 -47
- data/lib/gcloud/search/result.rb +27 -31
- data/lib/gcloud/search/result/list.rb +6 -6
- data/lib/gcloud/storage.rb +224 -190
- data/lib/gcloud/storage/bucket.rb +202 -227
- data/lib/gcloud/storage/bucket/acl.rb +83 -170
- data/lib/gcloud/storage/bucket/cors.rb +31 -34
- data/lib/gcloud/storage/bucket/list.rb +3 -3
- data/lib/gcloud/storage/connection.rb +11 -7
- data/lib/gcloud/storage/credentials.rb +3 -3
- data/lib/gcloud/storage/errors.rb +11 -8
- data/lib/gcloud/storage/file.rb +129 -171
- data/lib/gcloud/storage/file/acl.rb +51 -99
- data/lib/gcloud/storage/file/list.rb +3 -3
- data/lib/gcloud/storage/file/verifier.rb +3 -2
- data/lib/gcloud/storage/project.rb +111 -132
- data/lib/gcloud/upload.rb +4 -7
- data/lib/gcloud/version.rb +2 -4
- data/lib/google/api/annotations.rb +14 -0
- data/lib/google/api/http.rb +30 -0
- data/lib/google/api/label.rb +24 -0
- data/lib/google/api/monitored_resource.rb +25 -0
- data/lib/google/datastore/v1beta3/datastore.rb +115 -0
- data/lib/google/datastore/v1beta3/datastore_services.rb +33 -0
- data/lib/google/datastore/v1beta3/entity.rb +63 -0
- data/lib/google/datastore/v1beta3/query.rb +128 -0
- data/lib/google/devtools/cloudtrace/v1/trace.rb +78 -0
- data/lib/google/devtools/cloudtrace/v1/trace_services.rb +32 -0
- data/lib/google/example/library/v1/library.rb +91 -0
- data/lib/google/example/library/v1/library_services.rb +40 -0
- data/lib/google/iam/v1/iam_policy.rb +33 -0
- data/lib/google/iam/v1/iam_policy_services.rb +30 -0
- data/lib/google/iam/v1/policy.rb +25 -0
- data/lib/google/logging/type/http_request.rb +28 -0
- data/lib/google/logging/type/log_severity.rb +27 -0
- data/lib/google/logging/v2/log_entry.rb +44 -0
- data/lib/google/logging/v2/logging.rb +56 -0
- data/lib/google/logging/v2/logging_config.rb +59 -0
- data/lib/google/logging/v2/logging_config_services.rb +32 -0
- data/lib/google/logging/v2/logging_metrics.rb +51 -0
- data/lib/google/logging/v2/logging_metrics_services.rb +32 -0
- data/lib/google/logging/v2/logging_services.rb +31 -0
- data/lib/google/longrunning/operations.rb +50 -0
- data/lib/google/longrunning/operations_services.rb +29 -0
- data/lib/google/protobuf/any.rb +17 -0
- data/lib/google/protobuf/api.rb +31 -0
- data/lib/google/protobuf/descriptor.rb +0 -0
- data/lib/google/protobuf/duration.rb +17 -0
- data/lib/google/protobuf/empty.rb +15 -0
- data/lib/google/protobuf/field_mask.rb +16 -0
- data/lib/google/protobuf/source_context.rb +16 -0
- data/lib/google/protobuf/struct.rb +35 -0
- data/lib/google/protobuf/timestamp.rb +17 -0
- data/lib/google/protobuf/type.rb +79 -0
- data/lib/google/protobuf/wrappers.rb +48 -0
- data/lib/google/pubsub/v1/pubsub.rb +129 -0
- data/lib/google/pubsub/v1/pubsub_services.rb +56 -0
- data/lib/google/pubsub/v1beta2/pubsub.rb +126 -0
- data/lib/google/pubsub/v1beta2/pubsub_services.rb +56 -0
- data/lib/google/rpc/code.rb +32 -0
- data/lib/google/rpc/error_details.rb +61 -0
- data/lib/google/rpc/status.rb +19 -0
- data/lib/google/type/color.rb +20 -0
- data/lib/google/type/date.rb +18 -0
- data/lib/google/type/dayofweek.rb +23 -0
- data/lib/google/type/latlng.rb +17 -0
- data/lib/google/type/money.rb +18 -0
- data/lib/google/type/timeofday.rb +19 -0
- metadata +101 -4
- data/lib/gcloud/pubsub/connection.rb +0 -295
- data/lib/gcloud/pubsub/errors.rb +0 -93
@@ -0,0 +1,233 @@
|
|
1
|
+
# Copyright 2016 Google Inc. All rights reserved.
|
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
|
+
# http://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 "gcloud/logging/sink/list"
|
17
|
+
|
18
|
+
module Gcloud
|
19
|
+
module Logging
|
20
|
+
##
|
21
|
+
# # Sink
|
22
|
+
#
|
23
|
+
# Used to export log entries outside Cloud Logging. When you create a sink,
|
24
|
+
# new log entries are exported. Cloud Logging does not send
|
25
|
+
# previously-ingested log entries to the sink's destination.
|
26
|
+
#
|
27
|
+
# Before creating the sink, ensure that you have granted
|
28
|
+
# `cloud-logs@google.com` permission to write logs to the destination. See
|
29
|
+
# [Permissions for writing exported
|
30
|
+
# logs](https://cloud.google.com/logging/docs/export/configure_export#setting_product_name_short_permissions_for_writing_exported_logs).
|
31
|
+
#
|
32
|
+
# You can retrieve an existing sink with {Project#sink}.
|
33
|
+
#
|
34
|
+
# @see https://cloud.google.com/logging/docs/api/tasks/exporting-logs
|
35
|
+
# Exporting Logs With Sinks
|
36
|
+
# @see https://cloud.google.com/logging/docs/api/introduction_v2#kinds_of_log_sinks
|
37
|
+
# Kinds of log sinks (API V2)
|
38
|
+
# @see https://cloud.google.com/logging/docs/api/#sinks Sinks (API V1)
|
39
|
+
# @see https://cloud.google.com/logging/docs/export/configure_export#setting_product_name_short_permissions_for_writing_exported_logs
|
40
|
+
# Permissions for writing exported logs
|
41
|
+
#
|
42
|
+
# @example
|
43
|
+
# require "gcloud"
|
44
|
+
#
|
45
|
+
# gcloud = Gcloud.new
|
46
|
+
# logging = gcloud.logging
|
47
|
+
# storage = gcloud.storage
|
48
|
+
#
|
49
|
+
# bucket = storage.create_bucket "my-logs-bucket"
|
50
|
+
#
|
51
|
+
# # Grant owner permission to Cloud Logging service
|
52
|
+
# email = "cloud-logs@google.com"
|
53
|
+
# bucket.acl.add_owner "group-#{email}"
|
54
|
+
#
|
55
|
+
# sink = logging.create_sink "my-sink",
|
56
|
+
# "storage.googleapis.com/#{bucket.id}"
|
57
|
+
#
|
58
|
+
class Sink
|
59
|
+
##
|
60
|
+
# @private The gRPC Service object.
|
61
|
+
attr_accessor :service
|
62
|
+
|
63
|
+
##
|
64
|
+
# @private The Google API Client object.
|
65
|
+
attr_accessor :grpc
|
66
|
+
|
67
|
+
##
|
68
|
+
# @private Create an empty Sink object.
|
69
|
+
def initialize
|
70
|
+
@service = nil
|
71
|
+
@grpc = Google::Logging::V2::LogSink.new
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# The client-assigned sink identifier. Sink identifiers are limited to
|
76
|
+
# 1000 characters and can include only the following characters: `A-Z`,
|
77
|
+
# `a-z`, `0-9`, and the special characters `_-.`.
|
78
|
+
def name
|
79
|
+
@grpc.name
|
80
|
+
end
|
81
|
+
|
82
|
+
##
|
83
|
+
# The export destination. See [Exporting Logs With
|
84
|
+
# Sinks](https://cloud.google.com/logging/docs/api/tasks/exporting-logs).
|
85
|
+
def destination
|
86
|
+
@grpc.destination
|
87
|
+
end
|
88
|
+
|
89
|
+
##
|
90
|
+
# Updates the export destination. See [Exporting Logs With
|
91
|
+
# Sinks](https://cloud.google.com/logging/docs/api/tasks/exporting-logs).
|
92
|
+
def destination= destination
|
93
|
+
@grpc.destination = destination
|
94
|
+
end
|
95
|
+
|
96
|
+
##
|
97
|
+
# An [advanced logs
|
98
|
+
# filter](https://cloud.google.com/logging/docs/view/advanced_filters)
|
99
|
+
# that defines the log entries to be exported. The filter must be
|
100
|
+
# consistent with the log entry format designed by the `version`
|
101
|
+
# parameter, regardless of the format of the log entry that was originally
|
102
|
+
# written to Cloud Logging.
|
103
|
+
def filter
|
104
|
+
@grpc.filter
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# Updates the [advanced logs
|
109
|
+
# filter](https://cloud.google.com/logging/docs/view/advanced_filters)
|
110
|
+
# that defines the log entries to be exported. The filter must be
|
111
|
+
# consistent with the log entry format designed by the `version`
|
112
|
+
# parameter, regardless of the format of the log entry that was originally
|
113
|
+
# written to Cloud Logging.
|
114
|
+
def filter= filter
|
115
|
+
@grpc.filter = filter
|
116
|
+
end
|
117
|
+
|
118
|
+
##
|
119
|
+
# The log entry version used when exporting log entries from this sink.
|
120
|
+
# This version does not have to correspond to the version of the log entry
|
121
|
+
# when it was written to Cloud Logging.
|
122
|
+
def version
|
123
|
+
@grpc.output_version_format
|
124
|
+
end
|
125
|
+
|
126
|
+
##
|
127
|
+
# Updates the log entry version used when exporting log entries from this
|
128
|
+
# sink. This version does not have to correspond to the version of the log
|
129
|
+
# entry when it was written to Cloud Logging. Accepted values are
|
130
|
+
# `:VERSION_FORMAT_UNSPECIFIED`, `:V2`, and `:V1`.
|
131
|
+
def version= version
|
132
|
+
@grpc.output_version_format = self.class.resolve_version(version)
|
133
|
+
end
|
134
|
+
|
135
|
+
##
|
136
|
+
# Helper to determine if the sink's version is
|
137
|
+
# `VERSION_FORMAT_UNSPECIFIED`.
|
138
|
+
def unspecified?
|
139
|
+
!(v1? || v2?)
|
140
|
+
end
|
141
|
+
|
142
|
+
##
|
143
|
+
# Helper to determine if the sink's version is `V2`.
|
144
|
+
def v2?
|
145
|
+
version == :V2
|
146
|
+
end
|
147
|
+
|
148
|
+
##
|
149
|
+
# Helper to determine if the sink's version is `V1`.
|
150
|
+
def v1?
|
151
|
+
version == :V1
|
152
|
+
end
|
153
|
+
|
154
|
+
##
|
155
|
+
# Updates the logs-based sink.
|
156
|
+
#
|
157
|
+
# @example
|
158
|
+
# require "gcloud"
|
159
|
+
#
|
160
|
+
# gcloud = Gcloud.new
|
161
|
+
# logging = gcloud.logging
|
162
|
+
# sink = logging.sink "severe_errors"
|
163
|
+
# sink.filter = "logName:syslog AND severity>=ERROR"
|
164
|
+
# sink.save
|
165
|
+
#
|
166
|
+
def save
|
167
|
+
ensure_service!
|
168
|
+
@grpc = service.update_sink name, destination, filter, version
|
169
|
+
rescue GRPC::BadStatus => e
|
170
|
+
raise Gcloud::Error.from_error(e)
|
171
|
+
end
|
172
|
+
|
173
|
+
##
|
174
|
+
# Reloads the logs-based sink with current data from the Logging
|
175
|
+
# service.
|
176
|
+
def reload!
|
177
|
+
ensure_service!
|
178
|
+
@grpc = service.get_sink name
|
179
|
+
rescue GRPC::BadStatus => e
|
180
|
+
raise Gcloud::Error.from_error(e)
|
181
|
+
end
|
182
|
+
alias_method :refresh!, :reload!
|
183
|
+
|
184
|
+
##
|
185
|
+
# Permanently deletes the logs-based sink.
|
186
|
+
#
|
187
|
+
# @return [Boolean] Returns `true` if the sink was deleted.
|
188
|
+
#
|
189
|
+
# @example
|
190
|
+
# require "gcloud"
|
191
|
+
#
|
192
|
+
# gcloud = Gcloud.new
|
193
|
+
# logging = gcloud.logging
|
194
|
+
# sink = logging.sink "severe_errors"
|
195
|
+
# sink.delete
|
196
|
+
#
|
197
|
+
def delete
|
198
|
+
ensure_service!
|
199
|
+
service.delete_sink name
|
200
|
+
return true
|
201
|
+
rescue GRPC::BadStatus => e
|
202
|
+
raise Gcloud::Error.from_error(e)
|
203
|
+
end
|
204
|
+
|
205
|
+
##
|
206
|
+
# @private New Sink from a Google::Logging::V2::LogSink object.
|
207
|
+
def self.from_grpc grpc, service
|
208
|
+
new.tap do |f|
|
209
|
+
f.grpc = grpc
|
210
|
+
f.service = service
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
##
|
215
|
+
# @private Convert a version value to the gRPC enum value.
|
216
|
+
def self.resolve_version version
|
217
|
+
ver = version.to_s.upcase.to_sym
|
218
|
+
ver = Google::Logging::V2::LogSink::VersionFormat.resolve ver
|
219
|
+
return ver if ver
|
220
|
+
Google::Logging::V2::LogSink::VersionFormat::VERSION_FORMAT_UNSPECIFIED
|
221
|
+
end
|
222
|
+
|
223
|
+
protected
|
224
|
+
|
225
|
+
##
|
226
|
+
# @private Raise an error unless an active connection to the service is
|
227
|
+
# available.
|
228
|
+
def ensure_service!
|
229
|
+
fail "Must have active connection to service" unless service
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# Copyright 2016 Google Inc. All rights reserved.
|
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
|
+
# http://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 Gcloud
|
19
|
+
module Logging
|
20
|
+
class Sink
|
21
|
+
##
|
22
|
+
# Sink::List is a special case Array with additional values.
|
23
|
+
class List < DelegateClass(::Array)
|
24
|
+
##
|
25
|
+
# If not empty, indicates that there are more records that match
|
26
|
+
# the request and this value should be passed to continue.
|
27
|
+
attr_accessor :token
|
28
|
+
|
29
|
+
##
|
30
|
+
# @private Create a new Sink::List with an array of Sink instances.
|
31
|
+
def initialize arr = []
|
32
|
+
super arr
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Whether there is a next page of sinks.
|
37
|
+
def next?
|
38
|
+
!token.nil?
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Retrieve the next page of sinks.
|
43
|
+
def next
|
44
|
+
return nil unless next?
|
45
|
+
ensure_service!
|
46
|
+
list_grpc = @service.list_sinks token: token
|
47
|
+
self.class.from_grpc list_grpc, @service
|
48
|
+
rescue GRPC::BadStatus => e
|
49
|
+
raise Gcloud::Error.from_error(e)
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# Retrieves all sinks by repeatedly loading {#next?} until {#next?}
|
54
|
+
# returns `false`. Returns the list instance for method chaining.
|
55
|
+
#
|
56
|
+
# @example
|
57
|
+
# require "gcloud"
|
58
|
+
#
|
59
|
+
# gcloud = Gcloud.new
|
60
|
+
# logging = gcloud.logging
|
61
|
+
# all_sinks = logging.sinks.all # Load all pages of sinks
|
62
|
+
#
|
63
|
+
def all
|
64
|
+
while next?
|
65
|
+
next_records = self.next
|
66
|
+
push(*next_records)
|
67
|
+
self.token = next_records.token
|
68
|
+
end
|
69
|
+
self
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
# @private New Sink::List from a Google::Logging::V2::ListSinksResponse
|
74
|
+
# object.
|
75
|
+
def self.from_grpc grpc_list, service
|
76
|
+
sinks = new(Array(grpc_list.sinks).map do |grpc|
|
77
|
+
Sink.from_grpc grpc, service
|
78
|
+
end)
|
79
|
+
sinks.instance_eval do
|
80
|
+
@token = grpc_list.next_page_token
|
81
|
+
@token = nil if @token == ""
|
82
|
+
@service = service
|
83
|
+
end
|
84
|
+
sinks
|
85
|
+
end
|
86
|
+
|
87
|
+
protected
|
88
|
+
|
89
|
+
##
|
90
|
+
# Raise an error unless an active service is available.
|
91
|
+
def ensure_service!
|
92
|
+
fail "Must have active service" unless @service
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/lib/gcloud/pubsub.rb
CHANGED
@@ -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,40 +12,34 @@
|
|
13
12
|
# See the License for the specific language governing permissions and
|
14
13
|
# limitations under the License.
|
15
14
|
|
15
|
+
|
16
16
|
require "gcloud"
|
17
17
|
require "gcloud/pubsub/project"
|
18
18
|
|
19
|
-
#--
|
20
|
-
# Google Cloud Pub/Sub
|
21
19
|
module Gcloud
|
22
20
|
##
|
23
21
|
# Creates a new object for connecting to the Pub/Sub service.
|
24
22
|
# Each call creates a new connection.
|
25
23
|
#
|
26
|
-
#
|
24
|
+
# For more information on connecting to Google Cloud see the [Authentication
|
25
|
+
# Guide](https://googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).
|
27
26
|
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
# the connection can access. See {Using OAuth 2.0 to Access Google
|
37
|
-
# APIs}[https://developers.google.com/identity/protocols/OAuth2]. (+String+
|
38
|
-
# or +Array+)
|
27
|
+
# @param [String] project Project identifier for the Pub/Sub service you are
|
28
|
+
# connecting to.
|
29
|
+
# @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If file
|
30
|
+
# path the file must be readable.
|
31
|
+
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
|
32
|
+
# set of resources and operations that the connection can access. See [Using
|
33
|
+
# OAuth 2.0 to Access Google
|
34
|
+
# APIs](https://developers.google.com/identity/protocols/OAuth2).
|
39
35
|
#
|
40
36
|
# The default scope is:
|
41
37
|
#
|
42
|
-
# *
|
43
|
-
#
|
44
|
-
# === Returns
|
45
|
-
#
|
46
|
-
# Gcloud::Pubsub::Project
|
38
|
+
# * `https://www.googleapis.com/auth/pubsub`
|
47
39
|
#
|
48
|
-
#
|
40
|
+
# @return [Gcloud::Pubsub::Project]
|
49
41
|
#
|
42
|
+
# @example
|
50
43
|
# require "gcloud/pubsub"
|
51
44
|
#
|
52
45
|
# pubsub = Gcloud.pubsub
|
@@ -65,7 +58,7 @@ module Gcloud
|
|
65
58
|
end
|
66
59
|
|
67
60
|
##
|
68
|
-
#
|
61
|
+
# # Google Cloud Pub/Sub
|
69
62
|
#
|
70
63
|
# Google Cloud Pub/Sub is designed to provide reliable, many-to-many,
|
71
64
|
# asynchronous messaging between applications. Publisher applications can
|
@@ -75,312 +68,361 @@ module Gcloud
|
|
75
68
|
# applications.
|
76
69
|
#
|
77
70
|
# Gcloud's goal is to provide a API that is familiar and comfortable to
|
78
|
-
# Rubyists. Authentication is handled by Gcloud#pubsub. You can provide the
|
71
|
+
# Rubyists. Authentication is handled by {Gcloud#pubsub}. You can provide the
|
79
72
|
# project and credential information to connect to the Pub/Sub service, or if
|
80
73
|
# you are running on Google Compute Engine this configuration is taken care
|
81
74
|
# of for you.
|
82
75
|
#
|
83
|
-
#
|
76
|
+
# ```ruby
|
77
|
+
# require "gcloud"
|
84
78
|
#
|
85
|
-
#
|
86
|
-
#
|
79
|
+
# gcloud = Gcloud.new
|
80
|
+
# pubsub = gcloud.pubsub
|
87
81
|
#
|
88
|
-
#
|
89
|
-
#
|
82
|
+
# topic = pubsub.topic "my-topic"
|
83
|
+
# topic.publish "task completed"
|
84
|
+
# ```
|
90
85
|
#
|
91
|
-
# To learn more about Pub/Sub, read the
|
92
|
-
#
|
86
|
+
# To learn more about Pub/Sub, read the [Google Cloud Pub/Sub Overview
|
87
|
+
# ](https://cloud.google.com/pubsub/overview).
|
93
88
|
#
|
94
|
-
#
|
89
|
+
# ## Retrieving Topics
|
95
90
|
#
|
96
91
|
# A Topic is a named resource to which messages are sent by publishers.
|
97
|
-
# A Topic is found by its name. (See Project#topic)
|
92
|
+
# A Topic is found by its name. (See {Gcloud::Pubsub::Project#topic})
|
98
93
|
#
|
99
|
-
#
|
94
|
+
# ```ruby
|
95
|
+
# require "gcloud"
|
100
96
|
#
|
101
|
-
#
|
102
|
-
#
|
103
|
-
#
|
97
|
+
# gcloud = Gcloud.new
|
98
|
+
# pubsub = gcloud.pubsub
|
99
|
+
# topic = pubsub.topic "my-topic"
|
100
|
+
# ```
|
104
101
|
#
|
105
|
-
#
|
102
|
+
# ## Creating a Topic
|
106
103
|
#
|
107
|
-
# A Topic is created from a Project. (See
|
104
|
+
# A Topic is created from a Project. (See
|
105
|
+
# {Gcloud::Pubsub::Project#create_topic})
|
108
106
|
#
|
109
|
-
#
|
107
|
+
# ```ruby
|
108
|
+
# require "gcloud"
|
110
109
|
#
|
111
|
-
#
|
112
|
-
#
|
113
|
-
#
|
110
|
+
# gcloud = Gcloud.new
|
111
|
+
# pubsub = gcloud.pubsub
|
112
|
+
# topic = pubsub.create_topic "my-topic"
|
113
|
+
# ```
|
114
114
|
#
|
115
|
-
#
|
115
|
+
# ## Retrieving Subscriptions
|
116
116
|
#
|
117
117
|
# A Subscription is a named resource representing the stream of messages from
|
118
|
-
# a single, specific Topic, to be delivered to the subscribing application.
|
119
|
-
#
|
118
|
+
# a single, specific Topic, to be delivered to the subscribing application. A
|
119
|
+
# Subscription is found by its name. (See
|
120
|
+
# {Gcloud::Pubsub::Topic#subscription})
|
120
121
|
#
|
121
|
-
#
|
122
|
+
# ```ruby
|
123
|
+
# require "gcloud"
|
122
124
|
#
|
123
|
-
#
|
124
|
-
#
|
125
|
+
# gcloud = Gcloud.new
|
126
|
+
# pubsub = gcloud.pubsub
|
125
127
|
#
|
126
|
-
#
|
127
|
-
#
|
128
|
-
#
|
128
|
+
# topic = pubsub.topic "my-topic"
|
129
|
+
# subscription = topic.subscription "my-topic-subscription"
|
130
|
+
# puts subscription.name
|
131
|
+
# ```
|
129
132
|
#
|
130
|
-
#
|
133
|
+
# ## Creating a Subscription
|
131
134
|
#
|
132
|
-
# A Subscription is created from a Topic. (See
|
133
|
-
# Project#subscribe)
|
135
|
+
# A Subscription is created from a Topic. (See
|
136
|
+
# {Gcloud::Pubsub::Topic#subscribe} and {Gcloud::Pubsub::Project#subscribe})
|
134
137
|
#
|
135
|
-
#
|
138
|
+
# ```ruby
|
139
|
+
# require "gcloud"
|
136
140
|
#
|
137
|
-
#
|
138
|
-
#
|
141
|
+
# gcloud = Gcloud.new
|
142
|
+
# pubsub = gcloud.pubsub
|
139
143
|
#
|
140
|
-
#
|
141
|
-
#
|
142
|
-
#
|
144
|
+
# topic = pubsub.topic "my-topic"
|
145
|
+
# sub = topic.subscribe "my-topic-sub"
|
146
|
+
# puts sub.name # => "my-topic-sub"
|
147
|
+
# ```
|
143
148
|
#
|
144
149
|
# The subscription can be created that specifies the number of seconds to
|
145
150
|
# wait to be acknowledged as well as an endpoint URL to push the messages to:
|
146
151
|
#
|
147
|
-
#
|
152
|
+
# ```ruby
|
153
|
+
# require "gcloud"
|
148
154
|
#
|
149
|
-
#
|
150
|
-
#
|
155
|
+
# gcloud = Gcloud.new
|
156
|
+
# pubsub = gcloud.pubsub
|
151
157
|
#
|
152
|
-
#
|
153
|
-
#
|
154
|
-
#
|
155
|
-
#
|
158
|
+
# topic = pubsub.topic "my-topic"
|
159
|
+
# sub = topic.subscribe "my-topic-sub",
|
160
|
+
# deadline: 120,
|
161
|
+
# endpoint: "https://example.com/push"
|
162
|
+
# ```
|
156
163
|
#
|
157
|
-
#
|
164
|
+
# ## Publishing Messages
|
158
165
|
#
|
159
166
|
# Messages are published to a topic. Any message published to a topic without
|
160
167
|
# a subscription will be lost. Ensure the topic has a subscription before
|
161
|
-
# publishing. (See Topic#publish and
|
168
|
+
# publishing. (See {Gcloud::Pubsub::Topic#publish} and
|
169
|
+
# {Gcloud::Pubsub::Project#publish})
|
162
170
|
#
|
163
|
-
#
|
171
|
+
# ```ruby
|
172
|
+
# require "gcloud"
|
164
173
|
#
|
165
|
-
#
|
166
|
-
#
|
174
|
+
# gcloud = Gcloud.new
|
175
|
+
# pubsub = gcloud.pubsub
|
167
176
|
#
|
168
|
-
#
|
169
|
-
#
|
177
|
+
# topic = pubsub.topic "my-topic"
|
178
|
+
# msg = topic.publish "new-message"
|
179
|
+
# ```
|
170
180
|
#
|
171
181
|
# Messages can also be published with attributes:
|
172
182
|
#
|
173
|
-
#
|
183
|
+
# ```ruby
|
184
|
+
# require "gcloud"
|
174
185
|
#
|
175
|
-
#
|
176
|
-
#
|
186
|
+
# gcloud = Gcloud.new
|
187
|
+
# pubsub = gcloud.pubsub
|
177
188
|
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
#
|
189
|
+
# topic = pubsub.topic "my-topic"
|
190
|
+
# msg = topic.publish "new-message",
|
191
|
+
# foo: :bar,
|
192
|
+
# this: :that
|
193
|
+
# ```
|
182
194
|
#
|
183
195
|
# Multiple messages can be published at the same time by passing a block:
|
184
196
|
#
|
185
|
-
#
|
197
|
+
# ```ruby
|
198
|
+
# require "gcloud"
|
186
199
|
#
|
187
|
-
#
|
188
|
-
#
|
200
|
+
# gcloud = Gcloud.new
|
201
|
+
# pubsub = gcloud.pubsub
|
189
202
|
#
|
190
|
-
#
|
191
|
-
#
|
192
|
-
#
|
193
|
-
#
|
194
|
-
#
|
195
|
-
#
|
203
|
+
# topic = pubsub.topic "my-topic"
|
204
|
+
# msgs = topic.publish do |batch|
|
205
|
+
# batch.publish "new-message-1", foo: :bar
|
206
|
+
# batch.publish "new-message-2", foo: :baz
|
207
|
+
# batch.publish "new-message-3", foo: :bif
|
208
|
+
# end
|
209
|
+
# ```
|
196
210
|
#
|
197
|
-
#
|
211
|
+
# ## Pulling Messages
|
198
212
|
#
|
199
|
-
# Messages are pulled from a Subscription. (See
|
213
|
+
# Messages are pulled from a Subscription. (See
|
214
|
+
# {Gcloud::Pubsub::Subscription#pull})
|
200
215
|
#
|
201
|
-
#
|
216
|
+
# ```ruby
|
217
|
+
# require "gcloud"
|
202
218
|
#
|
203
|
-
#
|
204
|
-
#
|
219
|
+
# gcloud = Gcloud.new
|
220
|
+
# pubsub = gcloud.pubsub
|
205
221
|
#
|
206
|
-
#
|
207
|
-
#
|
222
|
+
# sub = pubsub.subscription "my-topic-sub"
|
223
|
+
# msgs = sub.pull
|
224
|
+
# ```
|
208
225
|
#
|
209
226
|
# A maximum number of messages returned can also be specified:
|
210
227
|
#
|
211
|
-
#
|
228
|
+
# ```ruby
|
229
|
+
# require "gcloud"
|
212
230
|
#
|
213
|
-
#
|
214
|
-
#
|
231
|
+
# gcloud = Gcloud.new
|
232
|
+
# pubsub = gcloud.pubsub
|
215
233
|
#
|
216
|
-
#
|
217
|
-
#
|
234
|
+
# sub = pubsub.subscription "my-topic-sub", max: 10
|
235
|
+
# msgs = sub.pull
|
236
|
+
# ```
|
218
237
|
#
|
219
238
|
# The request for messages can also block until messages are available.
|
220
|
-
# (See Subscription#wait_for_messages)
|
239
|
+
# (See {Gcloud::Pubsub::Subscription#wait_for_messages})
|
221
240
|
#
|
222
|
-
#
|
241
|
+
# ```ruby
|
242
|
+
# require "gcloud"
|
223
243
|
#
|
224
|
-
#
|
225
|
-
#
|
244
|
+
# gcloud = Gcloud.new
|
245
|
+
# pubsub = gcloud.pubsub
|
226
246
|
#
|
227
|
-
#
|
228
|
-
#
|
247
|
+
# sub = pubsub.subscription "my-topic-sub"
|
248
|
+
# msgs = sub.wait_for_messages
|
249
|
+
# ```
|
229
250
|
#
|
230
|
-
#
|
251
|
+
# ## Acknowledging a Message
|
231
252
|
#
|
232
253
|
# Messages that are received can be acknowledged in Pub/Sub, marking the
|
233
254
|
# message to be removed so it cannot be pulled again.
|
234
255
|
#
|
235
256
|
# A Message that can be acknowledged is called a ReceivedMessage.
|
236
257
|
# ReceivedMessages can be acknowledged one at a time:
|
237
|
-
# (See ReceivedMessage#acknowledge!)
|
258
|
+
# (See {Gcloud::Pubsub::ReceivedMessage#acknowledge!})
|
238
259
|
#
|
239
|
-
#
|
260
|
+
# ```ruby
|
261
|
+
# require "gcloud"
|
240
262
|
#
|
241
|
-
#
|
242
|
-
#
|
263
|
+
# gcloud = Gcloud.new
|
264
|
+
# pubsub = gcloud.pubsub
|
243
265
|
#
|
244
|
-
#
|
245
|
-
#
|
266
|
+
# sub = pubsub.subscription "my-topic-sub"
|
267
|
+
# sub.pull.each { |msg| msg.acknowledge! }
|
268
|
+
# ```
|
246
269
|
#
|
247
270
|
# Or, multiple messages can be acknowledged in a single API call:
|
248
|
-
# (See Subscription#acknowledge)
|
271
|
+
# (See {Gcloud::Pubsub::Subscription#acknowledge})
|
249
272
|
#
|
250
|
-
#
|
273
|
+
# ```ruby
|
274
|
+
# require "gcloud"
|
251
275
|
#
|
252
|
-
#
|
253
|
-
#
|
276
|
+
# gcloud = Gcloud.new
|
277
|
+
# pubsub = gcloud.pubsub
|
254
278
|
#
|
255
|
-
#
|
256
|
-
#
|
257
|
-
#
|
279
|
+
# sub = pubsub.subscription "my-topic-sub"
|
280
|
+
# received_messages = sub.pull
|
281
|
+
# sub.acknowledge received_messages
|
282
|
+
# ```
|
258
283
|
#
|
259
|
-
#
|
284
|
+
# ## Modifying a Deadline
|
260
285
|
#
|
261
286
|
# A message must be acknowledged after it is pulled, or Pub/Sub will mark the
|
262
287
|
# message for redelivery. The message acknowledgement deadline can delayed if
|
263
288
|
# more time is needed. This will allow more time to process the message before
|
264
|
-
# the message is marked for redelivery. (See
|
289
|
+
# the message is marked for redelivery. (See
|
290
|
+
# {Gcloud::Pubsub::ReceivedMessage#delay!})
|
265
291
|
#
|
266
|
-
#
|
292
|
+
# ```ruby
|
293
|
+
# require "gcloud"
|
267
294
|
#
|
268
|
-
#
|
269
|
-
#
|
295
|
+
# gcloud = Gcloud.new
|
296
|
+
# pubsub = gcloud.pubsub
|
270
297
|
#
|
271
|
-
#
|
272
|
-
#
|
273
|
-
#
|
274
|
-
#
|
275
|
-
#
|
276
|
-
#
|
277
|
-
#
|
298
|
+
# sub = pubsub.subscription "my-topic-sub"
|
299
|
+
# received_message = sub.pull.first
|
300
|
+
# if received_message
|
301
|
+
# puts received_message.message.data
|
302
|
+
# # Delay for 2 minutes
|
303
|
+
# received_message.delay! 120
|
304
|
+
# end
|
305
|
+
# ```
|
278
306
|
#
|
279
307
|
# The message can also be made available for immediate redelivery:
|
280
308
|
#
|
281
|
-
#
|
309
|
+
# ```ruby
|
310
|
+
# require "gcloud"
|
282
311
|
#
|
283
|
-
#
|
284
|
-
#
|
312
|
+
# gcloud = Gcloud.new
|
313
|
+
# pubsub = gcloud.pubsub
|
285
314
|
#
|
286
|
-
#
|
287
|
-
#
|
288
|
-
#
|
289
|
-
#
|
290
|
-
#
|
291
|
-
#
|
292
|
-
#
|
315
|
+
# sub = pubsub.subscription "my-topic-sub"
|
316
|
+
# received_message = sub.pull.first
|
317
|
+
# if received_message
|
318
|
+
# puts received_message.message.data
|
319
|
+
# # Mark for redelivery by setting the deadline to now
|
320
|
+
# received_message.delay! 0
|
321
|
+
# end
|
322
|
+
# ```
|
293
323
|
#
|
294
324
|
# Multiple messages can be delayed or made available for immediate redelivery:
|
295
|
-
# (See Subscription#delay)
|
325
|
+
# (See {Gcloud::Pubsub::Subscription#delay})
|
296
326
|
#
|
297
|
-
#
|
327
|
+
# ```ruby
|
328
|
+
# require "gcloud"
|
298
329
|
#
|
299
|
-
#
|
300
|
-
#
|
330
|
+
# gcloud = Gcloud.new
|
331
|
+
# pubsub = gcloud.pubsub
|
301
332
|
#
|
302
|
-
#
|
303
|
-
#
|
304
|
-
#
|
333
|
+
# sub = pubsub.subscription "my-topic-sub"
|
334
|
+
# received_messages = sub.pull
|
335
|
+
# sub.delay 120, received_messages
|
336
|
+
# ```
|
305
337
|
#
|
306
|
-
#
|
338
|
+
# ## Listening for Messages
|
307
339
|
#
|
308
|
-
# Long running workers are easy to create with
|
340
|
+
# Long running workers are easy to create with `listen`, which runs an
|
309
341
|
# infinitely blocking loop to process messages as they are received. (See
|
310
|
-
# Subscription#listen)
|
342
|
+
# {Gcloud::Pubsub::Subscription#listen})
|
311
343
|
#
|
312
|
-
#
|
344
|
+
# ```ruby
|
345
|
+
# require "gcloud"
|
313
346
|
#
|
314
|
-
#
|
315
|
-
#
|
347
|
+
# gcloud = Gcloud.new
|
348
|
+
# pubsub = gcloud.pubsub
|
316
349
|
#
|
317
|
-
#
|
318
|
-
#
|
319
|
-
#
|
320
|
-
#
|
350
|
+
# sub = pubsub.subscription "my-topic-sub"
|
351
|
+
# sub.listen do |msg|
|
352
|
+
# # process msg
|
353
|
+
# end
|
354
|
+
# ```
|
321
355
|
#
|
322
356
|
# Messages are retrieved in batches for efficiency. The number of messages
|
323
|
-
# pulled per batch can be limited with the
|
357
|
+
# pulled per batch can be limited with the `max` option:
|
324
358
|
#
|
325
|
-
#
|
359
|
+
# ```ruby
|
360
|
+
# require "gcloud"
|
326
361
|
#
|
327
|
-
#
|
328
|
-
#
|
362
|
+
# gcloud = Gcloud.new
|
363
|
+
# pubsub = gcloud.pubsub
|
329
364
|
#
|
330
|
-
#
|
331
|
-
#
|
332
|
-
#
|
333
|
-
#
|
365
|
+
# sub = pubsub.subscription "my-topic-sub"
|
366
|
+
# sub.listen max: 20 do |msg|
|
367
|
+
# # process msg
|
368
|
+
# end
|
369
|
+
# ```
|
334
370
|
#
|
335
371
|
# When processing time and the acknowledgement deadline are a concern,
|
336
372
|
# messages can be automatically acknowledged as they are pulled with the
|
337
|
-
#
|
373
|
+
# `autoack` option:
|
338
374
|
#
|
339
|
-
#
|
375
|
+
# ```ruby
|
376
|
+
# require "gcloud"
|
340
377
|
#
|
341
|
-
#
|
342
|
-
#
|
378
|
+
# gcloud = Gcloud.new
|
379
|
+
# pubsub = gcloud.pubsub
|
343
380
|
#
|
344
|
-
#
|
345
|
-
#
|
346
|
-
#
|
347
|
-
#
|
381
|
+
# sub = pubsub.subscription "my-topic-sub"
|
382
|
+
# sub.listen autoack: true do |msg|
|
383
|
+
# # process msg
|
384
|
+
# end
|
385
|
+
# ```
|
348
386
|
#
|
349
|
-
#
|
387
|
+
# ## Working Across Projects
|
350
388
|
#
|
351
389
|
# All calls to the Pub/Sub service use the same project and credentials
|
352
|
-
# provided to the Gcloud#pubsub method. However, it is common to reference
|
390
|
+
# provided to the {Gcloud#pubsub} method. However, it is common to reference
|
353
391
|
# topics or subscriptions in other projects, which can be achieved by using
|
354
|
-
# the
|
392
|
+
# the `project` option. The main credentials must have permissions to the
|
355
393
|
# topics and subscriptions in other projects.
|
356
394
|
#
|
357
|
-
#
|
395
|
+
# ```ruby
|
396
|
+
# require "gcloud"
|
358
397
|
#
|
359
|
-
#
|
360
|
-
#
|
398
|
+
# gcloud = Gcloud.new # my-project-id
|
399
|
+
# pubsub = gcloud.pubsub
|
361
400
|
#
|
362
|
-
#
|
363
|
-
#
|
364
|
-
#
|
365
|
-
#
|
366
|
-
#
|
367
|
-
#
|
401
|
+
# # Get a topic in the current project
|
402
|
+
# my_topic = pubsub.topic "my-topic"
|
403
|
+
# my_topic.name #=> "projects/my-project-id/topics/my-topic"
|
404
|
+
# # Get a topic in another project
|
405
|
+
# other_topic = pubsub.topic "other-topic", project: "other-project-id"
|
406
|
+
# other_topic.name #=> "projects/other-project-id/topics/other-topic"
|
407
|
+
# ```
|
368
408
|
#
|
369
409
|
# It is possible to create a subscription in the current project that pulls
|
370
410
|
# from a topic in another project:
|
371
411
|
#
|
372
|
-
#
|
412
|
+
# ```ruby
|
413
|
+
# require "gcloud"
|
373
414
|
#
|
374
|
-
#
|
375
|
-
#
|
415
|
+
# gcloud = Gcloud.new # my-project-id
|
416
|
+
# pubsub = gcloud.pubsub
|
376
417
|
#
|
377
|
-
#
|
378
|
-
#
|
379
|
-
#
|
380
|
-
#
|
381
|
-
#
|
382
|
-
#
|
383
|
-
#
|
418
|
+
# # Get a topic in another project
|
419
|
+
# topic = pubsub.topic "other-topic", project: "other-project-id"
|
420
|
+
# # Create a subscription in the current project that pulls from
|
421
|
+
# # the topic in another project
|
422
|
+
# sub = topic.subscribe "my-sub"
|
423
|
+
# sub.name #=> "projects/my-project-id/subscriptions/my-sub"
|
424
|
+
# sub.topic.name #=> "projects/other-project-id/topics/other-topic"
|
425
|
+
# ```
|
384
426
|
#
|
385
427
|
module Pubsub
|
386
428
|
end
|