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
@@ -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
- # === Parameters
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
- # +project+::
29
- # Project identifier for the Pub/Sub service you are connecting to.
30
- # (+String+)
31
- # +keyfile+::
32
- # Keyfile downloaded from Google Cloud. If file path the file must be
33
- # readable. (+String+ or +Hash+)
34
- # +scope+::
35
- # The OAuth 2.0 scopes controlling the set of resources and operations that
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
- # * +https://www.googleapis.com/auth/pubsub+
43
- #
44
- # === Returns
45
- #
46
- # Gcloud::Pubsub::Project
38
+ # * `https://www.googleapis.com/auth/pubsub`
47
39
  #
48
- # === Example
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
- # = Google Cloud Pub/Sub
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
- # require "gcloud"
76
+ # ```ruby
77
+ # require "gcloud"
84
78
  #
85
- # gcloud = Gcloud.new
86
- # pubsub = gcloud.pubsub
79
+ # gcloud = Gcloud.new
80
+ # pubsub = gcloud.pubsub
87
81
  #
88
- # topic = pubsub.topic "my-topic"
89
- # topic.publish "task completed"
82
+ # topic = pubsub.topic "my-topic"
83
+ # topic.publish "task completed"
84
+ # ```
90
85
  #
91
- # To learn more about Pub/Sub, read the {Google Cloud Pub/Sub Overview
92
- # }[https://cloud.google.com/pubsub/overview].
86
+ # To learn more about Pub/Sub, read the [Google Cloud Pub/Sub Overview
87
+ # ](https://cloud.google.com/pubsub/overview).
93
88
  #
94
- # == Retrieving Topics
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
- # require "gcloud"
94
+ # ```ruby
95
+ # require "gcloud"
100
96
  #
101
- # gcloud = Gcloud.new
102
- # pubsub = gcloud.pubsub
103
- # topic = pubsub.topic "my-topic"
97
+ # gcloud = Gcloud.new
98
+ # pubsub = gcloud.pubsub
99
+ # topic = pubsub.topic "my-topic"
100
+ # ```
104
101
  #
105
- # == Creating a Topic
102
+ # ## Creating a Topic
106
103
  #
107
- # A Topic is created from a Project. (See Project#create_topic)
104
+ # A Topic is created from a Project. (See
105
+ # {Gcloud::Pubsub::Project#create_topic})
108
106
  #
109
- # require "gcloud"
107
+ # ```ruby
108
+ # require "gcloud"
110
109
  #
111
- # gcloud = Gcloud.new
112
- # pubsub = gcloud.pubsub
113
- # topic = pubsub.create_topic "my-topic"
110
+ # gcloud = Gcloud.new
111
+ # pubsub = gcloud.pubsub
112
+ # topic = pubsub.create_topic "my-topic"
113
+ # ```
114
114
  #
115
- # == Retrieving Subscriptions
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
- # A Subscription is found by its name. (See Topic#subscription)
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
- # require "gcloud"
122
+ # ```ruby
123
+ # require "gcloud"
122
124
  #
123
- # gcloud = Gcloud.new
124
- # pubsub = gcloud.pubsub
125
+ # gcloud = Gcloud.new
126
+ # pubsub = gcloud.pubsub
125
127
  #
126
- # topic = pubsub.topic "my-topic"
127
- # subscription = topic.subscription "my-topic-subscription"
128
- # puts subscription.name
128
+ # topic = pubsub.topic "my-topic"
129
+ # subscription = topic.subscription "my-topic-subscription"
130
+ # puts subscription.name
131
+ # ```
129
132
  #
130
- # == Creating a Subscription
133
+ # ## Creating a Subscription
131
134
  #
132
- # A Subscription is created from a Topic. (See Topic#subscribe and
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
- # require "gcloud"
138
+ # ```ruby
139
+ # require "gcloud"
136
140
  #
137
- # gcloud = Gcloud.new
138
- # pubsub = gcloud.pubsub
141
+ # gcloud = Gcloud.new
142
+ # pubsub = gcloud.pubsub
139
143
  #
140
- # topic = pubsub.topic "my-topic"
141
- # sub = topic.subscribe "my-topic-sub"
142
- # puts sub.name # => "my-topic-sub"
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
- # require "gcloud"
152
+ # ```ruby
153
+ # require "gcloud"
148
154
  #
149
- # gcloud = Gcloud.new
150
- # pubsub = gcloud.pubsub
155
+ # gcloud = Gcloud.new
156
+ # pubsub = gcloud.pubsub
151
157
  #
152
- # topic = pubsub.topic "my-topic"
153
- # sub = topic.subscribe "my-topic-sub",
154
- # deadline: 120,
155
- # endpoint: "https://example.com/push"
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
- # == Publishing Messages
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 Project#publish)
168
+ # publishing. (See {Gcloud::Pubsub::Topic#publish} and
169
+ # {Gcloud::Pubsub::Project#publish})
162
170
  #
163
- # require "gcloud"
171
+ # ```ruby
172
+ # require "gcloud"
164
173
  #
165
- # gcloud = Gcloud.new
166
- # pubsub = gcloud.pubsub
174
+ # gcloud = Gcloud.new
175
+ # pubsub = gcloud.pubsub
167
176
  #
168
- # topic = pubsub.topic "my-topic"
169
- # msg = topic.publish "new-message"
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
- # require "gcloud"
183
+ # ```ruby
184
+ # require "gcloud"
174
185
  #
175
- # gcloud = Gcloud.new
176
- # pubsub = gcloud.pubsub
186
+ # gcloud = Gcloud.new
187
+ # pubsub = gcloud.pubsub
177
188
  #
178
- # topic = pubsub.topic "my-topic"
179
- # msg = topic.publish "new-message",
180
- # foo: :bar,
181
- # this: :that
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
- # require "gcloud"
197
+ # ```ruby
198
+ # require "gcloud"
186
199
  #
187
- # gcloud = Gcloud.new
188
- # pubsub = gcloud.pubsub
200
+ # gcloud = Gcloud.new
201
+ # pubsub = gcloud.pubsub
189
202
  #
190
- # topic = pubsub.topic "my-topic"
191
- # msgs = topic.publish do |batch|
192
- # batch.publish "new-message-1", foo: :bar
193
- # batch.publish "new-message-2", foo: :baz
194
- # batch.publish "new-message-3", foo: :bif
195
- # end
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
- # == Pulling Messages
211
+ # ## Pulling Messages
198
212
  #
199
- # Messages are pulled from a Subscription. (See Subscription#pull)
213
+ # Messages are pulled from a Subscription. (See
214
+ # {Gcloud::Pubsub::Subscription#pull})
200
215
  #
201
- # require "gcloud"
216
+ # ```ruby
217
+ # require "gcloud"
202
218
  #
203
- # gcloud = Gcloud.new
204
- # pubsub = gcloud.pubsub
219
+ # gcloud = Gcloud.new
220
+ # pubsub = gcloud.pubsub
205
221
  #
206
- # sub = pubsub.subscription "my-topic-sub"
207
- # msgs = sub.pull
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
- # require "gcloud"
228
+ # ```ruby
229
+ # require "gcloud"
212
230
  #
213
- # gcloud = Gcloud.new
214
- # pubsub = gcloud.pubsub
231
+ # gcloud = Gcloud.new
232
+ # pubsub = gcloud.pubsub
215
233
  #
216
- # sub = pubsub.subscription "my-topic-sub", max: 10
217
- # msgs = sub.pull
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
- # require "gcloud"
241
+ # ```ruby
242
+ # require "gcloud"
223
243
  #
224
- # gcloud = Gcloud.new
225
- # pubsub = gcloud.pubsub
244
+ # gcloud = Gcloud.new
245
+ # pubsub = gcloud.pubsub
226
246
  #
227
- # sub = pubsub.subscription "my-topic-sub"
228
- # msgs = sub.wait_for_messages
247
+ # sub = pubsub.subscription "my-topic-sub"
248
+ # msgs = sub.wait_for_messages
249
+ # ```
229
250
  #
230
- # == Acknowledging a Message
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
- # require "gcloud"
260
+ # ```ruby
261
+ # require "gcloud"
240
262
  #
241
- # gcloud = Gcloud.new
242
- # pubsub = gcloud.pubsub
263
+ # gcloud = Gcloud.new
264
+ # pubsub = gcloud.pubsub
243
265
  #
244
- # sub = pubsub.subscription "my-topic-sub"
245
- # sub.pull.each { |msg| msg.acknowledge! }
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
- # require "gcloud"
273
+ # ```ruby
274
+ # require "gcloud"
251
275
  #
252
- # gcloud = Gcloud.new
253
- # pubsub = gcloud.pubsub
276
+ # gcloud = Gcloud.new
277
+ # pubsub = gcloud.pubsub
254
278
  #
255
- # sub = pubsub.subscription "my-topic-sub"
256
- # received_messages = sub.pull
257
- # sub.acknowledge received_messages
279
+ # sub = pubsub.subscription "my-topic-sub"
280
+ # received_messages = sub.pull
281
+ # sub.acknowledge received_messages
282
+ # ```
258
283
  #
259
- # == Modifying a Deadline
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 ReceivedMessage#delay!)
289
+ # the message is marked for redelivery. (See
290
+ # {Gcloud::Pubsub::ReceivedMessage#delay!})
265
291
  #
266
- # require "gcloud"
292
+ # ```ruby
293
+ # require "gcloud"
267
294
  #
268
- # gcloud = Gcloud.new
269
- # pubsub = gcloud.pubsub
295
+ # gcloud = Gcloud.new
296
+ # pubsub = gcloud.pubsub
270
297
  #
271
- # sub = pubsub.subscription "my-topic-sub"
272
- # received_message = sub.pull.first
273
- # if received_message
274
- # puts received_message.message.data
275
- # # Delay for 2 minutes
276
- # received_message.delay! 120
277
- # end
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
- # require "gcloud"
309
+ # ```ruby
310
+ # require "gcloud"
282
311
  #
283
- # gcloud = Gcloud.new
284
- # pubsub = gcloud.pubsub
312
+ # gcloud = Gcloud.new
313
+ # pubsub = gcloud.pubsub
285
314
  #
286
- # sub = pubsub.subscription "my-topic-sub"
287
- # received_message = sub.pull.first
288
- # if received_message
289
- # puts received_message.message.data
290
- # # Mark for redelivery by setting the deadline to now
291
- # received_message.delay! 0
292
- # end
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
- # require "gcloud"
327
+ # ```ruby
328
+ # require "gcloud"
298
329
  #
299
- # gcloud = Gcloud.new
300
- # pubsub = gcloud.pubsub
330
+ # gcloud = Gcloud.new
331
+ # pubsub = gcloud.pubsub
301
332
  #
302
- # sub = pubsub.subscription "my-topic-sub"
303
- # received_messages = sub.pull
304
- # sub.delay 120, received_messages
333
+ # sub = pubsub.subscription "my-topic-sub"
334
+ # received_messages = sub.pull
335
+ # sub.delay 120, received_messages
336
+ # ```
305
337
  #
306
- # == Listening for Messages
338
+ # ## Listening for Messages
307
339
  #
308
- # Long running workers are easy to create with +listen+, which runs an
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
- # require "gcloud"
344
+ # ```ruby
345
+ # require "gcloud"
313
346
  #
314
- # gcloud = Gcloud.new
315
- # pubsub = gcloud.pubsub
347
+ # gcloud = Gcloud.new
348
+ # pubsub = gcloud.pubsub
316
349
  #
317
- # sub = pubsub.subscription "my-topic-sub"
318
- # sub.listen do |msg|
319
- # # process msg
320
- # end
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 +max+ option:
357
+ # pulled per batch can be limited with the `max` option:
324
358
  #
325
- # require "gcloud"
359
+ # ```ruby
360
+ # require "gcloud"
326
361
  #
327
- # gcloud = Gcloud.new
328
- # pubsub = gcloud.pubsub
362
+ # gcloud = Gcloud.new
363
+ # pubsub = gcloud.pubsub
329
364
  #
330
- # sub = pubsub.subscription "my-topic-sub"
331
- # sub.listen max: 20 do |msg|
332
- # # process msg
333
- # end
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
- # +autoack+ option:
373
+ # `autoack` option:
338
374
  #
339
- # require "gcloud"
375
+ # ```ruby
376
+ # require "gcloud"
340
377
  #
341
- # gcloud = Gcloud.new
342
- # pubsub = gcloud.pubsub
378
+ # gcloud = Gcloud.new
379
+ # pubsub = gcloud.pubsub
343
380
  #
344
- # sub = pubsub.subscription "my-topic-sub"
345
- # sub.listen autoack: true do |msg|
346
- # # process msg
347
- # end
381
+ # sub = pubsub.subscription "my-topic-sub"
382
+ # sub.listen autoack: true do |msg|
383
+ # # process msg
384
+ # end
385
+ # ```
348
386
  #
349
- # == Working Across Projects
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 +project+ option. The main credentials must have permissions to the
392
+ # the `project` option. The main credentials must have permissions to the
355
393
  # topics and subscriptions in other projects.
356
394
  #
357
- # require "gcloud"
395
+ # ```ruby
396
+ # require "gcloud"
358
397
  #
359
- # gcloud = Gcloud.new # my-project-id
360
- # pubsub = gcloud.pubsub
398
+ # gcloud = Gcloud.new # my-project-id
399
+ # pubsub = gcloud.pubsub
361
400
  #
362
- # # Get a topic in the current project
363
- # my_topic = pubsub.topic "my-topic"
364
- # my_topic.name #=> "projects/my-project-id/topics/my-topic"
365
- # # Get a topic in another project
366
- # other_topic = pubsub.topic "other-topic", project: "other-project-id"
367
- # other_topic.name #=> "projects/other-project-id/topics/other-topic"
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
- # require "gcloud"
412
+ # ```ruby
413
+ # require "gcloud"
373
414
  #
374
- # gcloud = Gcloud.new # my-project-id
375
- # pubsub = gcloud.pubsub
415
+ # gcloud = Gcloud.new # my-project-id
416
+ # pubsub = gcloud.pubsub
376
417
  #
377
- # # Get a topic in another project
378
- # topic = pubsub.topic "other-topic", project: "other-project-id"
379
- # # Create a subscription in the current project that pulls from
380
- # # the topic in another project
381
- # sub = topic.subscribe "my-sub"
382
- # sub.name #=> "projects/my-project-id/subscriptions/my-sub"
383
- # sub.topic.name #=> "projects/other-project-id/topics/other-topic"
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