gcloud 0.12.2 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +5 -13
  2. data/lib/gcloud.rb +27 -456
  3. data/lib/gcloud/bigquery.rb +2 -382
  4. data/lib/gcloud/datastore.rb +2 -576
  5. data/lib/gcloud/dns.rb +2 -321
  6. data/lib/gcloud/logging.rb +1 -322
  7. data/lib/gcloud/pubsub.rb +2 -476
  8. data/lib/gcloud/resource_manager.rb +2 -273
  9. data/lib/gcloud/storage.rb +2 -440
  10. data/lib/gcloud/translate.rb +1 -250
  11. data/lib/gcloud/version.rb +2 -2
  12. data/lib/gcloud/vision.rb +1 -501
  13. metadata +36 -332
  14. data/AUTHENTICATION.md +0 -75
  15. data/CHANGELOG.md +0 -382
  16. data/OVERVIEW.md +0 -259
  17. data/lib/gcloud/backoff.rb +0 -150
  18. data/lib/gcloud/bigquery/copy_job.rb +0 -97
  19. data/lib/gcloud/bigquery/credentials.rb +0 -29
  20. data/lib/gcloud/bigquery/data.rb +0 -239
  21. data/lib/gcloud/bigquery/dataset.rb +0 -753
  22. data/lib/gcloud/bigquery/dataset/access.rb +0 -507
  23. data/lib/gcloud/bigquery/dataset/list.rb +0 -169
  24. data/lib/gcloud/bigquery/extract_job.rb +0 -117
  25. data/lib/gcloud/bigquery/insert_response.rb +0 -81
  26. data/lib/gcloud/bigquery/job.rb +0 -299
  27. data/lib/gcloud/bigquery/job/list.rb +0 -172
  28. data/lib/gcloud/bigquery/load_job.rb +0 -202
  29. data/lib/gcloud/bigquery/project.rb +0 -475
  30. data/lib/gcloud/bigquery/query_data.rb +0 -234
  31. data/lib/gcloud/bigquery/query_job.rb +0 -137
  32. data/lib/gcloud/bigquery/schema.rb +0 -359
  33. data/lib/gcloud/bigquery/service.rb +0 -506
  34. data/lib/gcloud/bigquery/table.rb +0 -1141
  35. data/lib/gcloud/bigquery/table/list.rb +0 -180
  36. data/lib/gcloud/bigquery/view.rb +0 -475
  37. data/lib/gcloud/credentials.rb +0 -129
  38. data/lib/gcloud/datastore/commit.rb +0 -148
  39. data/lib/gcloud/datastore/credentials.rb +0 -35
  40. data/lib/gcloud/datastore/cursor.rb +0 -76
  41. data/lib/gcloud/datastore/dataset.rb +0 -660
  42. data/lib/gcloud/datastore/dataset/lookup_results.rb +0 -219
  43. data/lib/gcloud/datastore/dataset/query_results.rb +0 -386
  44. data/lib/gcloud/datastore/entity.rb +0 -449
  45. data/lib/gcloud/datastore/errors.rb +0 -41
  46. data/lib/gcloud/datastore/gql_query.rb +0 -211
  47. data/lib/gcloud/datastore/grpc_utils.rb +0 -132
  48. data/lib/gcloud/datastore/key.rb +0 -281
  49. data/lib/gcloud/datastore/properties.rb +0 -128
  50. data/lib/gcloud/datastore/query.rb +0 -348
  51. data/lib/gcloud/datastore/service.rb +0 -167
  52. data/lib/gcloud/datastore/transaction.rb +0 -362
  53. data/lib/gcloud/dns/change.rb +0 -158
  54. data/lib/gcloud/dns/change/list.rb +0 -173
  55. data/lib/gcloud/dns/credentials.rb +0 -29
  56. data/lib/gcloud/dns/importer.rb +0 -183
  57. data/lib/gcloud/dns/project.rb +0 -247
  58. data/lib/gcloud/dns/record.rb +0 -170
  59. data/lib/gcloud/dns/record/list.rb +0 -174
  60. data/lib/gcloud/dns/service.rb +0 -167
  61. data/lib/gcloud/dns/zone.rb +0 -759
  62. data/lib/gcloud/dns/zone/list.rb +0 -168
  63. data/lib/gcloud/dns/zone/transaction.rb +0 -176
  64. data/lib/gcloud/errors.rb +0 -206
  65. data/lib/gcloud/gce.rb +0 -56
  66. data/lib/gcloud/grpc_utils.rb +0 -87
  67. data/lib/gcloud/logging/credentials.rb +0 -29
  68. data/lib/gcloud/logging/entry.rb +0 -465
  69. data/lib/gcloud/logging/entry/http_request.rb +0 -141
  70. data/lib/gcloud/logging/entry/list.rb +0 -177
  71. data/lib/gcloud/logging/entry/operation.rb +0 -90
  72. data/lib/gcloud/logging/logger.rb +0 -307
  73. data/lib/gcloud/logging/metric.rb +0 -169
  74. data/lib/gcloud/logging/metric/list.rb +0 -172
  75. data/lib/gcloud/logging/project.rb +0 -642
  76. data/lib/gcloud/logging/resource.rb +0 -84
  77. data/lib/gcloud/logging/resource_descriptor.rb +0 -137
  78. data/lib/gcloud/logging/resource_descriptor/list.rb +0 -174
  79. data/lib/gcloud/logging/service.rb +0 -267
  80. data/lib/gcloud/logging/sink.rb +0 -227
  81. data/lib/gcloud/logging/sink/list.rb +0 -171
  82. data/lib/gcloud/pubsub/credentials.rb +0 -29
  83. data/lib/gcloud/pubsub/message.rb +0 -94
  84. data/lib/gcloud/pubsub/policy.rb +0 -204
  85. data/lib/gcloud/pubsub/project.rb +0 -482
  86. data/lib/gcloud/pubsub/received_message.rb +0 -160
  87. data/lib/gcloud/pubsub/service.rb +0 -334
  88. data/lib/gcloud/pubsub/subscription.rb +0 -565
  89. data/lib/gcloud/pubsub/subscription/list.rb +0 -208
  90. data/lib/gcloud/pubsub/topic.rb +0 -511
  91. data/lib/gcloud/pubsub/topic/list.rb +0 -174
  92. data/lib/gcloud/pubsub/topic/publisher.rb +0 -85
  93. data/lib/gcloud/resource_manager/credentials.rb +0 -30
  94. data/lib/gcloud/resource_manager/manager.rb +0 -266
  95. data/lib/gcloud/resource_manager/policy.rb +0 -211
  96. data/lib/gcloud/resource_manager/project.rb +0 -484
  97. data/lib/gcloud/resource_manager/project/list.rb +0 -167
  98. data/lib/gcloud/resource_manager/project/updater.rb +0 -130
  99. data/lib/gcloud/resource_manager/service.rb +0 -127
  100. data/lib/gcloud/storage/bucket.rb +0 -775
  101. data/lib/gcloud/storage/bucket/acl.rb +0 -810
  102. data/lib/gcloud/storage/bucket/cors.rb +0 -153
  103. data/lib/gcloud/storage/bucket/list.rb +0 -172
  104. data/lib/gcloud/storage/credentials.rb +0 -29
  105. data/lib/gcloud/storage/errors.rb +0 -65
  106. data/lib/gcloud/storage/file.rb +0 -842
  107. data/lib/gcloud/storage/file/acl.rb +0 -425
  108. data/lib/gcloud/storage/file/list.rb +0 -191
  109. data/lib/gcloud/storage/file/verifier.rb +0 -67
  110. data/lib/gcloud/storage/project.rb +0 -316
  111. data/lib/gcloud/storage/service.rb +0 -347
  112. data/lib/gcloud/translate/api.rb +0 -241
  113. data/lib/gcloud/translate/detection.rb +0 -137
  114. data/lib/gcloud/translate/language.rb +0 -69
  115. data/lib/gcloud/translate/service.rb +0 -80
  116. data/lib/gcloud/translate/translation.rb +0 -112
  117. data/lib/gcloud/vision/annotate.rb +0 -224
  118. data/lib/gcloud/vision/annotation.rb +0 -455
  119. data/lib/gcloud/vision/annotation/entity.rb +0 -234
  120. data/lib/gcloud/vision/annotation/face.rb +0 -1750
  121. data/lib/gcloud/vision/annotation/properties.rb +0 -245
  122. data/lib/gcloud/vision/annotation/safe_search.rb +0 -161
  123. data/lib/gcloud/vision/annotation/text.rb +0 -236
  124. data/lib/gcloud/vision/annotation/vertex.rb +0 -108
  125. data/lib/gcloud/vision/credentials.rb +0 -29
  126. data/lib/gcloud/vision/image.rb +0 -590
  127. data/lib/gcloud/vision/location.rb +0 -115
  128. data/lib/gcloud/vision/project.rb +0 -278
  129. data/lib/gcloud/vision/service.rb +0 -66
  130. data/lib/google/api/annotations.rb +0 -14
  131. data/lib/google/api/http.rb +0 -30
  132. data/lib/google/api/label.rb +0 -24
  133. data/lib/google/api/monitored_resource.rb +0 -25
  134. data/lib/google/datastore/v1beta3/datastore.rb +0 -115
  135. data/lib/google/datastore/v1beta3/datastore_services.rb +0 -33
  136. data/lib/google/datastore/v1beta3/entity.rb +0 -63
  137. data/lib/google/datastore/v1beta3/query.rb +0 -128
  138. data/lib/google/devtools/cloudtrace/v1/trace.rb +0 -78
  139. data/lib/google/devtools/cloudtrace/v1/trace_services.rb +0 -32
  140. data/lib/google/example/library/v1/library.rb +0 -91
  141. data/lib/google/example/library/v1/library_services.rb +0 -40
  142. data/lib/google/iam/v1/iam_policy.rb +0 -33
  143. data/lib/google/iam/v1/iam_policy_services.rb +0 -30
  144. data/lib/google/iam/v1/policy.rb +0 -25
  145. data/lib/google/logging/type/http_request.rb +0 -28
  146. data/lib/google/logging/type/log_severity.rb +0 -27
  147. data/lib/google/logging/v2/log_entry.rb +0 -44
  148. data/lib/google/logging/v2/logging.rb +0 -56
  149. data/lib/google/logging/v2/logging_config.rb +0 -59
  150. data/lib/google/logging/v2/logging_config_services.rb +0 -32
  151. data/lib/google/logging/v2/logging_metrics.rb +0 -51
  152. data/lib/google/logging/v2/logging_metrics_services.rb +0 -32
  153. data/lib/google/logging/v2/logging_services.rb +0 -31
  154. data/lib/google/longrunning/operations.rb +0 -50
  155. data/lib/google/longrunning/operations_services.rb +0 -29
  156. data/lib/google/protobuf/descriptor.rb +0 -0
  157. data/lib/google/pubsub/v1/pubsub.rb +0 -129
  158. data/lib/google/pubsub/v1/pubsub_services.rb +0 -56
  159. data/lib/google/pubsub/v1beta2/pubsub.rb +0 -126
  160. data/lib/google/pubsub/v1beta2/pubsub_services.rb +0 -56
  161. data/lib/google/rpc/code.rb +0 -32
  162. data/lib/google/rpc/error_details.rb +0 -61
  163. data/lib/google/rpc/status.rb +0 -19
  164. data/lib/google/type/color.rb +0 -20
  165. data/lib/google/type/date.rb +0 -18
  166. data/lib/google/type/dayofweek.rb +0 -23
  167. data/lib/google/type/latlng.rb +0 -17
  168. data/lib/google/type/money.rb +0 -18
  169. data/lib/google/type/timeofday.rb +0 -19
@@ -1,208 +0,0 @@
1
- # Copyright 2015 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 Pubsub
20
- class Subscription
21
- ##
22
- # Subscription::List is a special case Array with additional values.
23
- class List < DelegateClass(::Array)
24
- ##
25
- # If not empty, indicates that there are more subscriptions
26
- # that match the request and this value should be passed to
27
- # the next {Gcloud::Pubsub::Topic#subscriptions} to continue.
28
- attr_accessor :token
29
-
30
- ##
31
- # @private Create a new Subscription::List with an array of values.
32
- def initialize arr = []
33
- @topic = nil
34
- @prefix = nil
35
- @token = nil
36
- @max = nil
37
- super arr
38
- end
39
-
40
- ##
41
- # Whether there a next page of subscriptions.
42
- #
43
- # @return [Boolean]
44
- #
45
- # @example
46
- # require "gcloud"
47
- #
48
- # gcloud = Gcloud.new
49
- # pubsub = gcloud.pubsub
50
- #
51
- # subscriptions = pubsub.subscriptions
52
- # if subscriptions.next?
53
- # next_subscriptions = subscriptions.next
54
- # end
55
- #
56
- def next?
57
- !token.nil?
58
- end
59
-
60
- ##
61
- # Retrieve the next page of subscriptions.
62
- #
63
- # @return [Subscription::List]
64
- #
65
- # @example
66
- # require "gcloud"
67
- #
68
- # gcloud = Gcloud.new
69
- # pubsub = gcloud.pubsub
70
- #
71
- # subscriptions = pubsub.subscriptions
72
- # if subscriptions.next?
73
- # next_subscriptions = subscriptions.next
74
- # end
75
- #
76
- def next
77
- return nil unless next?
78
- ensure_service!
79
- if @topic
80
- next_topic_subscriptions
81
- else
82
- next_subscriptions
83
- end
84
- end
85
-
86
- ##
87
- # Retrieves all subscriptions by repeatedly loading {#next} until
88
- # {#next?} returns `false`. Calls the given block once for each
89
- # subscription, which is passed as the parameter.
90
- #
91
- # An Enumerator is returned if no block is given.
92
- #
93
- # This method may make several API calls until all subscriptions are
94
- # retrieved. Be sure to use as narrow a search criteria as possible.
95
- # Please use with caution.
96
- #
97
- # @param [Integer] request_limit The upper limit of API requests to make
98
- # to load all subscriptions. Default is no limit.
99
- # @yield [subscription] The block for accessing each subscription.
100
- # @yieldparam [Subscription] subscription The subscription object.
101
- #
102
- # @return [Enumerator]
103
- #
104
- # @example Iterating each subscription by passing a block:
105
- # require "gcloud"
106
- #
107
- # gcloud = Gcloud.new
108
- # pubsub = gcloud.pubsub
109
- #
110
- # subscriptions = pubsub.subscriptions
111
- # subscriptions.all do |subscription|
112
- # puts subscription.name
113
- # end
114
- #
115
- # @example Using the enumerator by not passing a block:
116
- # require "gcloud"
117
- #
118
- # gcloud = Gcloud.new
119
- # pubsub = gcloud.pubsub
120
- #
121
- # subscriptions = pubsub.subscriptions
122
- # all_names = subscriptions.all.map do |subscription|
123
- # subscription.name
124
- # end
125
- #
126
- # @example Limit the number of API calls made:
127
- # require "gcloud"
128
- #
129
- # gcloud = Gcloud.new
130
- # pubsub = gcloud.pubsub
131
- #
132
- # subscriptions = pubsub.subscriptions
133
- # subscriptions.all(request_limit: 10) do |subscription|
134
- # puts subscription.name
135
- # end
136
- #
137
- def all request_limit: nil
138
- request_limit = request_limit.to_i if request_limit
139
- unless block_given?
140
- return enum_for(:all, request_limit: request_limit)
141
- end
142
- results = self
143
- loop do
144
- results.each { |r| yield r }
145
- if request_limit
146
- request_limit -= 1
147
- break if request_limit < 0
148
- end
149
- break unless results.next?
150
- results = results.next
151
- end
152
- end
153
-
154
- ##
155
- # @private New Subscriptions::List from a
156
- # Google::Pubsub::V1::ListSubscriptionsRequest object.
157
- def self.from_grpc grpc_list, service, max = nil
158
- subs = new(Array(grpc_list.subscriptions).map do |grpc|
159
- Subscription.from_grpc grpc, service
160
- end)
161
- token = grpc_list.next_page_token
162
- token = nil if token == ""
163
- subs.instance_variable_set "@token", token
164
- subs.instance_variable_set "@service", service
165
- subs.instance_variable_set "@max", max
166
- subs
167
- end
168
-
169
- ##
170
- # @private New Subscriptions::List from a
171
- # Google::Pubsub::V1::ListTopicSubscriptionsResponse object.
172
- def self.from_topic_grpc grpc_list, service, topic, max = nil
173
- subs = new(Array(grpc_list.subscriptions).map do |grpc|
174
- Subscription.new_lazy grpc, service
175
- end)
176
- token = grpc_list.next_page_token
177
- token = nil if token == ""
178
- subs.instance_variable_set "@token", token
179
- subs.instance_variable_set "@service", service
180
- subs.instance_variable_set "@topic", topic
181
- subs.instance_variable_set "@max", max
182
- subs
183
- end
184
-
185
- protected
186
-
187
- ##
188
- # @private Raise an error unless an active connection to the service is
189
- # available.
190
- def ensure_service!
191
- fail "Must have active connection to service" unless @service
192
- end
193
-
194
- def next_subscriptions
195
- options = { prefix: @prefix, token: @token, max: @max }
196
- grpc = @service.list_subscriptions options
197
- self.class.from_grpc grpc, @service, @max
198
- end
199
-
200
- def next_topic_subscriptions
201
- options = { token: @token, max: @max }
202
- grpc = @service.list_topics_subscriptions @topic, options
203
- self.class.from_topic_grpc grpc, @service, @topic, @max
204
- end
205
- end
206
- end
207
- end
208
- end
@@ -1,511 +0,0 @@
1
- # Copyright 2015 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/errors"
17
- require "gcloud/pubsub/topic/publisher"
18
- require "gcloud/pubsub/topic/list"
19
- require "gcloud/pubsub/subscription"
20
- require "gcloud/pubsub/policy"
21
-
22
- module Gcloud
23
- module Pubsub
24
- ##
25
- # # Topic
26
- #
27
- # A named resource to which messages are published.
28
- #
29
- # @example
30
- # require "gcloud"
31
- #
32
- # gcloud = Gcloud.new
33
- # pubsub = gcloud.pubsub
34
- #
35
- # topic = pubsub.topic "my-topic"
36
- # topic.publish "task completed"
37
- #
38
- class Topic
39
- ##
40
- # @private The gRPC Service object.
41
- attr_accessor :service
42
-
43
- ##
44
- # @private The gRPC Google::Pubsub::V1::Topic object.
45
- attr_accessor :grpc
46
-
47
- ##
48
- # @private Create an empty {Topic} object.
49
- def initialize
50
- @service = nil
51
- @grpc = Google::Pubsub::V1::Topic.new
52
- @name = nil
53
- @exists = nil
54
- end
55
-
56
- ##
57
- # @private New lazy {Topic} object without making an HTTP request.
58
- def self.new_lazy name, service, options = {}
59
- new.tap do |t|
60
- t.grpc = nil
61
- t.service = service
62
- t.instance_variable_set "@name", service.topic_path(name, options)
63
- end
64
- end
65
-
66
- ##
67
- # The name of the topic in the form of
68
- # "/projects/project-identifier/topics/topic-name".
69
- def name
70
- @grpc ? @grpc.name : @name
71
- end
72
-
73
- ##
74
- # Permanently deletes the topic.
75
- #
76
- # @return [Boolean] Returns `true` if the topic was deleted.
77
- #
78
- # @example
79
- # require "gcloud"
80
- #
81
- # gcloud = Gcloud.new
82
- # pubsub = gcloud.pubsub
83
- #
84
- # topic = pubsub.topic "my-topic"
85
- # topic.delete
86
- #
87
- def delete
88
- ensure_service!
89
- service.delete_topic name
90
- true
91
- end
92
-
93
- ##
94
- # Creates a new {Subscription} object on the current Topic.
95
- #
96
- # @param [String] subscription_name Name of the new subscription. Must
97
- # start with a letter, and contain only letters ([A-Za-z]), numbers
98
- # ([0-9], dashes (-), underscores (_), periods (.), tildes (~), plus (+)
99
- # or percent signs (%). It must be between 3 and 255 characters in
100
- # length, and it must not start with "goog".
101
- # @param [Integer] deadline The maximum number of seconds after a
102
- # subscriber receives a message before the subscriber should acknowledge
103
- # the message.
104
- # @param [String] endpoint A URL locating the endpoint to which messages
105
- # should be pushed.
106
- #
107
- # @return [Gcloud::Pubsub::Subscription]
108
- #
109
- # @example
110
- # require "gcloud"
111
- #
112
- # gcloud = Gcloud.new
113
- # pubsub = gcloud.pubsub
114
- #
115
- # topic = pubsub.topic "my-topic"
116
- # sub = topic.subscribe "my-topic-sub"
117
- # puts sub.name # => "my-topic-sub"
118
- #
119
- # @example The name is optional, and will be generated if not given:
120
- # require "gcloud"
121
- #
122
- # gcloud = Gcloud.new
123
- # pubsub = gcloud.pubsub
124
- #
125
- # topic = pubsub.topic "my-topic"
126
- # sub = topic.subscribe "my-topic-sub"
127
- # puts sub.name # => "generated-sub-name"
128
- #
129
- # @example Wait 2 minutes for acknowledgement and push all to an endpoint:
130
- # require "gcloud"
131
- #
132
- # gcloud = Gcloud.new
133
- # pubsub = gcloud.pubsub
134
- #
135
- # topic = pubsub.topic "my-topic"
136
- # sub = topic.subscribe "my-topic-sub",
137
- # deadline: 120,
138
- # endpoint: "https://example.com/push"
139
- #
140
- def subscribe subscription_name, deadline: nil, endpoint: nil
141
- ensure_service!
142
- options = { deadline: deadline, endpoint: endpoint }
143
- grpc = service.create_subscription name, subscription_name, options
144
- Subscription.from_grpc grpc, service
145
- end
146
- alias_method :create_subscription, :subscribe
147
- alias_method :new_subscription, :subscribe
148
-
149
- ##
150
- # Retrieves subscription by name.
151
- #
152
- # @param [String] subscription_name Name of a subscription.
153
- # @param [Boolean] skip_lookup Optionally create a {Subscription} object
154
- # without verifying the subscription resource exists on the Pub/Sub
155
- # service. Calls made on this object will raise errors if the service
156
- # resource does not exist. Default is `false`.
157
- #
158
- # @return [Gcloud::Pubsub::Subscription, nil] Returns `nil` if
159
- # the subscription does not exist.
160
- #
161
- # @example
162
- # require "gcloud"
163
- #
164
- # gcloud = Gcloud.new
165
- # pubsub = gcloud.pubsub
166
- #
167
- # topic = pubsub.topic "my-topic"
168
- # subscription = topic.subscription "my-topic-subscription"
169
- # puts subscription.name
170
- #
171
- # @example Skip the lookup against the service with `skip_lookup`:
172
- # require "gcloud"
173
- #
174
- # gcloud = Gcloud.new
175
- # pubsub = gcloud.pubsub
176
- #
177
- # # No API call is made to retrieve the subscription information.
178
- # subscription = pubsub.subscription "my-sub", skip_lookup: true
179
- # puts subscription.name
180
- #
181
- def subscription subscription_name, skip_lookup: nil
182
- ensure_service!
183
- return Subscription.new_lazy subscription_name, service if skip_lookup
184
- grpc = service.get_subscription subscription_name
185
- Subscription.from_grpc grpc, service
186
- rescue Gcloud::NotFoundError
187
- nil
188
- end
189
- alias_method :get_subscription, :subscription
190
- alias_method :find_subscription, :subscription
191
-
192
- ##
193
- # Retrieves a list of subscription names for the given project.
194
- #
195
- # @param [String] token The `token` value returned by the last call to
196
- # `subscriptions`; indicates that this is a continuation of a call, and
197
- # that the system should return the next page of data.
198
- # @param [Integer] max Maximum number of subscriptions to return.
199
- #
200
- # @return [Array<Subscription>] (See {Subscription::List})
201
- #
202
- # @example
203
- # require "gcloud"
204
- #
205
- # gcloud = Gcloud.new
206
- # pubsub = gcloud.pubsub
207
- #
208
- # topic = pubsub.topic "my-topic"
209
- # subscription = topic.subscriptions
210
- # subscriptions.each do |subscription|
211
- # puts subscription.name
212
- # end
213
- #
214
- # @example Retrieve all subscriptions: (See {Subscription::List#all})
215
- # require "gcloud"
216
- #
217
- # gcloud = Gcloud.new
218
- # pubsub = gcloud.pubsub
219
- #
220
- # topic = pubsub.topic "my-topic"
221
- # subscription = topic.subscriptions
222
- # subscriptions.all do |subscription|
223
- # puts subscription.name
224
- # end
225
- #
226
- def subscriptions token: nil, max: nil
227
- ensure_service!
228
- options = { token: token, max: max }
229
- grpc = service.list_topics_subscriptions name, options
230
- Subscription::List.from_topic_grpc grpc, service, name, max
231
- end
232
- alias_method :find_subscriptions, :subscriptions
233
- alias_method :list_subscriptions, :subscriptions
234
-
235
- ##
236
- # Publishes one or more messages to the topic.
237
- #
238
- # @param [String, File] data The message data.
239
- # @param [Hash] attributes Optional attributes for the message.
240
- # @yield [publisher] a block for publishing multiple messages in one
241
- # request
242
- # @yieldparam [Topic::Publisher] publisher the topic publisher object
243
- #
244
- # @return [Message, Array<Message>] Returns the published message when
245
- # called without a block, or an array of messages when called with a
246
- # block.
247
- #
248
- # @example
249
- # require "gcloud"
250
- #
251
- # gcloud = Gcloud.new
252
- # pubsub = gcloud.pubsub
253
- #
254
- # topic = pubsub.topic "my-topic"
255
- # msg = topic.publish "new-message"
256
- #
257
- # @example A message can be published using a File object:
258
- # require "gcloud"
259
- #
260
- # gcloud = Gcloud.new
261
- # pubsub = gcloud.pubsub
262
- #
263
- # topic = pubsub.topic "my-topic"
264
- # msg = topic.publish File.open("message.txt")
265
- #
266
- # @example Additionally, a message can be published with attributes:
267
- # require "gcloud"
268
- #
269
- # gcloud = Gcloud.new
270
- # pubsub = gcloud.pubsub
271
- #
272
- # topic = pubsub.topic "my-topic"
273
- # msg = topic.publish "new-message",
274
- # foo: :bar,
275
- # this: :that
276
- #
277
- # @example Multiple messages can be sent at the same time using a block:
278
- # require "gcloud"
279
- #
280
- # gcloud = Gcloud.new
281
- # pubsub = gcloud.pubsub
282
- #
283
- # topic = pubsub.topic "my-topic"
284
- # msgs = topic.publish do |t|
285
- # t.publish "new-message-1", foo: :bar
286
- # t.publish "new-message-2", foo: :baz
287
- # t.publish "new-message-3", foo: :bif
288
- # end
289
- #
290
- def publish data = nil, attributes = {}
291
- ensure_service!
292
- publisher = Publisher.new data, attributes
293
- yield publisher if block_given?
294
- return nil if publisher.messages.count.zero?
295
- publish_batch_messages publisher
296
- end
297
-
298
- ##
299
- # Gets the [Cloud IAM](https://cloud.google.com/iam/) access control
300
- # policy for this topic.
301
- #
302
- # @see https://cloud.google.com/pubsub/reference/rpc/google.iam.v1#iampolicy
303
- # google.iam.v1.IAMPolicy
304
- #
305
- # @param [Boolean] force Force the latest policy to be retrieved from the
306
- # Pub/Sub service when `true`. Otherwise the policy will be memoized to
307
- # reduce the number of API calls made to the Pub/Sub service. The
308
- # default is `false`.
309
- #
310
- # @yield [policy] A block for updating the policy. The latest policy will
311
- # be read from the Pub/Sub service and passed to the block. After the
312
- # block completes, the modified policy will be written to the service.
313
- # @yieldparam [Policy] policy the current Cloud IAM Policy for this topic
314
- #
315
- # @return [Policy] the current Cloud IAM Policy for this topic
316
- #
317
- # @example Policy values are memoized to reduce the number of API calls:
318
- # require "gcloud"
319
- #
320
- # gcloud = Gcloud.new
321
- # pubsub = gcloud.pubsub
322
- # topic = pubsub.topic "my-topic"
323
- #
324
- # policy = topic.policy # API call
325
- # policy_2 = topic.policy # No API call
326
- #
327
- # @example Use `force` to retrieve the latest policy from the service:
328
- # require "gcloud"
329
- #
330
- # gcloud = Gcloud.new
331
- # pubsub = gcloud.pubsub
332
- # topic = pubsub.topic "my-topic"
333
- #
334
- # policy = topic.policy force: true # API call
335
- # policy_2 = topic.policy force: true # API call
336
- #
337
- # @example Update the policy by passing a block:
338
- # require "gcloud"
339
- #
340
- # gcloud = Gcloud.new
341
- # pubsub = gcloud.pubsub
342
- # topic = pubsub.topic "my-topic"
343
- #
344
- # policy = topic.policy do |p|
345
- # p.add "roles/owner", "user:owner@example.com"
346
- # end # 2 API calls
347
- #
348
- def policy force: nil
349
- @policy = nil if force || block_given?
350
- @policy ||= begin
351
- ensure_service!
352
- grpc = service.get_topic_policy name
353
- Policy.from_grpc grpc
354
- end
355
- return @policy unless block_given?
356
- p = @policy.deep_dup
357
- yield p
358
- self.policy = p
359
- end
360
-
361
- ##
362
- # Updates the [Cloud IAM](https://cloud.google.com/iam/) access control
363
- # policy for this topic. The policy should be read from {#policy}. See
364
- # {Gcloud::Pubsub::Policy} for an explanation of the policy `etag`
365
- # property and how to modify policies.
366
- #
367
- # You can also update the policy by passing a block to {#policy}, which
368
- # will call this method internally after the block completes.
369
- #
370
- # @see https://cloud.google.com/pubsub/reference/rpc/google.iam.v1#iampolicy
371
- # google.iam.v1.IAMPolicy
372
- #
373
- # @param [Policy] new_policy a new or modified Cloud IAM Policy for this
374
- # topic
375
- #
376
- # @example
377
- # require "gcloud"
378
- #
379
- # gcloud = Gcloud.new
380
- # pubsub = gcloud.pubsub
381
- # topic = pubsub.topic "my-topic"
382
- #
383
- # policy = topic.policy # API call
384
- #
385
- # policy.add "roles/owner", "user:owner@example.com"
386
- #
387
- # topic.policy = policy # API call
388
- #
389
- def policy= new_policy
390
- ensure_service!
391
- grpc = service.set_topic_policy name, new_policy.to_grpc
392
- @policy = Policy.from_grpc grpc
393
- end
394
-
395
- ##
396
- # Tests the specified permissions against the [Cloud
397
- # IAM](https://cloud.google.com/iam/) access control policy.
398
- #
399
- # @see https://cloud.google.com/iam/docs/managing-policies Managing
400
- # Policies
401
- #
402
- # @param [String, Array<String>] permissions The set of permissions to
403
- # check access for. Permissions with wildcards (such as `*` or
404
- # `storage.*`) are not allowed.
405
- #
406
- # The permissions that can be checked on a topic are:
407
- #
408
- # * pubsub.topics.publish
409
- # * pubsub.topics.attachSubscription
410
- # * pubsub.topics.get
411
- # * pubsub.topics.delete
412
- # * pubsub.topics.update
413
- # * pubsub.topics.getIamPolicy
414
- # * pubsub.topics.setIamPolicy
415
- #
416
- # @return [Array<Strings>] The permissions that have access.
417
- #
418
- # @example
419
- # require "gcloud"
420
- #
421
- # gcloud = Gcloud.new
422
- # pubsub = gcloud.pubsub
423
- # topic = pubsub.topic "my-topic"
424
- # perms = topic.test_permissions "pubsub.topics.get",
425
- # "pubsub.topics.publish"
426
- # perms.include? "pubsub.topics.get" #=> true
427
- # perms.include? "pubsub.topics.publish" #=> false
428
- #
429
- def test_permissions *permissions
430
- permissions = Array(permissions).flatten
431
- permissions = Array(permissions).flatten
432
- ensure_service!
433
- grpc = service.test_topic_permissions name, permissions
434
- grpc.permissions
435
- end
436
-
437
- ##
438
- # Determines whether the topic exists in the Pub/Sub service.
439
- #
440
- # @example
441
- # require "gcloud"
442
- #
443
- # gcloud = Gcloud.new
444
- # pubsub = gcloud.pubsub
445
- #
446
- # topic = pubsub.topic "my-topic"
447
- # topic.exists? #=> true
448
- #
449
- def exists?
450
- # Always true if we have a grpc object
451
- return true unless @grpc.nil?
452
- # If we have a value, return it
453
- return @exists unless @exists.nil?
454
- ensure_grpc!
455
- @exists = !@grpc.nil?
456
- end
457
-
458
- ##
459
- # @private
460
- # Determines whether the topic object was created with an HTTP call.
461
- #
462
- # @example
463
- # require "gcloud"
464
- #
465
- # gcloud = Gcloud.new
466
- # pubsub = gcloud.pubsub
467
- #
468
- # topic = pubsub.topic "my-topic"
469
- # topic.lazy? #=> false
470
- #
471
- def lazy?
472
- @grpc.nil?
473
- end
474
-
475
- ##
476
- # @private New Topic from a Google::Pubsub::V1::Topic object.
477
- def self.from_grpc grpc, service
478
- new.tap do |f|
479
- f.grpc = grpc
480
- f.service = service
481
- end
482
- end
483
-
484
- protected
485
-
486
- ##
487
- # @private Raise an error unless an active connection to the service is
488
- # available.
489
- def ensure_service!
490
- fail "Must have active connection to service" unless service
491
- end
492
-
493
- ##
494
- # Ensures a Google::Pubsub::V1::Topic object exists.
495
- def ensure_grpc!
496
- ensure_service!
497
- return @grpc if @grpc
498
- @grpc = service.get_topic @name
499
- rescue Gcloud::NotFoundError
500
- nil
501
- end
502
-
503
- ##
504
- # Call the publish API with arrays of data data and attrs.
505
- def publish_batch_messages batch
506
- grpc = service.publish name, batch.messages
507
- batch.to_gcloud_messages Array(grpc.message_ids)
508
- end
509
- end
510
- end
511
- end