gcloud 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +8 -8
  2. data/CHANGELOG.md +15 -0
  3. data/OVERVIEW.md +38 -5
  4. data/lib/gcloud.rb +55 -4
  5. data/lib/gcloud/bigquery/data.rb +2 -0
  6. data/lib/gcloud/bigquery/dataset.rb +1 -1
  7. data/lib/gcloud/bigquery/dataset/list.rb +2 -0
  8. data/lib/gcloud/bigquery/job/list.rb +2 -0
  9. data/lib/gcloud/bigquery/project.rb +2 -9
  10. data/lib/gcloud/bigquery/table/list.rb +2 -0
  11. data/lib/gcloud/datastore.rb +23 -28
  12. data/lib/gcloud/datastore/connection.rb +3 -1
  13. data/lib/gcloud/datastore/dataset.rb +167 -22
  14. data/lib/gcloud/datastore/dataset/lookup_results.rb +2 -0
  15. data/lib/gcloud/datastore/dataset/query_results.rb +2 -0
  16. data/lib/gcloud/datastore/entity.rb +11 -11
  17. data/lib/gcloud/datastore/key.rb +33 -16
  18. data/lib/gcloud/dns/change/list.rb +2 -0
  19. data/lib/gcloud/dns/project.rb +1 -1
  20. data/lib/gcloud/dns/record/list.rb +2 -0
  21. data/lib/gcloud/dns/zone.rb +2 -2
  22. data/lib/gcloud/dns/zone/list.rb +2 -0
  23. data/lib/gcloud/gce.rb +0 -5
  24. data/lib/gcloud/pubsub.rb +65 -62
  25. data/lib/gcloud/pubsub/connection.rb +20 -2
  26. data/lib/gcloud/pubsub/project.rb +233 -72
  27. data/lib/gcloud/pubsub/subscription.rb +45 -13
  28. data/lib/gcloud/pubsub/subscription/list.rb +2 -0
  29. data/lib/gcloud/pubsub/topic.rb +66 -85
  30. data/lib/gcloud/pubsub/topic/list.rb +2 -0
  31. data/lib/gcloud/resource_manager.rb +244 -0
  32. data/lib/gcloud/resource_manager/connection.rb +124 -0
  33. data/lib/gcloud/resource_manager/credentials.rb +30 -0
  34. data/lib/gcloud/resource_manager/errors.rb +64 -0
  35. data/lib/gcloud/resource_manager/manager.rb +319 -0
  36. data/lib/gcloud/resource_manager/project.rb +529 -0
  37. data/lib/gcloud/resource_manager/project/list.rb +91 -0
  38. data/lib/gcloud/resource_manager/project/updater.rb +137 -0
  39. data/lib/gcloud/storage/bucket.rb +1 -1
  40. data/lib/gcloud/storage/bucket/cors.rb +2 -0
  41. data/lib/gcloud/storage/bucket/list.rb +2 -0
  42. data/lib/gcloud/storage/file/list.rb +2 -0
  43. data/lib/gcloud/storage/project.rb +1 -1
  44. data/lib/gcloud/version.rb +1 -1
  45. metadata +10 -2
@@ -13,6 +13,8 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ require "delegate"
17
+
16
18
  module Gcloud
17
19
  module Datastore
18
20
  class Dataset
@@ -13,6 +13,8 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ require "delegate"
17
+
16
18
  module Gcloud
17
19
  module Datastore
18
20
  class Dataset
@@ -26,9 +26,9 @@ module Gcloud
26
26
  # Every Entity has a Key, and a list of properties.
27
27
  #
28
28
  # entity = Gcloud::Datastore::Entity.new
29
- # entity.key = Gcloud::Datastore::Key.new "User", "username"
30
- # entity["name"] = "User McUser"
31
- # entity["email"] = "user@example.net"
29
+ # entity.key = Gcloud::Datastore::Key.new "User", "heidi@example.com"
30
+ # entity["name"] = "Heidi Henderson"
31
+ #
32
32
  class Entity
33
33
  ##
34
34
  # The Key that identifies the entity.
@@ -62,7 +62,7 @@ module Gcloud
62
62
  #
63
63
  # gcloud = Gcloud.new
64
64
  # dataset = gcloud.datastore
65
- # user = dataset.find "User", "heidi"
65
+ # user = dataset.find "User", "heidi@example.com"
66
66
  # user["name"] #=> "Heidi Henderson"
67
67
  #
68
68
  # Or with a symbol name:
@@ -71,7 +71,7 @@ module Gcloud
71
71
  #
72
72
  # gcloud = Gcloud.new
73
73
  # dataset = gcloud.datastore
74
- # user = dataset.find "User", "heidi"
74
+ # user = dataset.find "User", "heidi@example.com"
75
75
  # user[:name] #=> "Heidi Henderson"
76
76
  #
77
77
  def [] prop_name
@@ -96,7 +96,7 @@ module Gcloud
96
96
  #
97
97
  # gcloud = Gcloud.new
98
98
  # dataset = gcloud.datastore
99
- # user = dataset.find "User", "heidi"
99
+ # user = dataset.find "User", "heidi@example.com"
100
100
  # user["name"] = "Heidi H. Henderson"
101
101
  #
102
102
  # Or with a symbol name:
@@ -105,7 +105,7 @@ module Gcloud
105
105
  #
106
106
  # gcloud = Gcloud.new
107
107
  # dataset = gcloud.datastore
108
- # user = dataset.find "User", "heidi"
108
+ # user = dataset.find "User", "heidi@example.com"
109
109
  # user[:name] = "Heidi H. Henderson"
110
110
  #
111
111
  def []= prop_name, prop_value
@@ -122,8 +122,8 @@ module Gcloud
122
122
  #
123
123
  # === Example
124
124
  #
125
- # entity.properties[:name] = "User McUser"
126
- # entity.properties["name"] #=> "User McUser"
125
+ # entity.properties[:name] = "Heidi H. Henderson"
126
+ # entity.properties["name"] #=> "Heidi H. Henderson"
127
127
  #
128
128
  # entity.properties.each do |name, value|
129
129
  # puts "property #{name} has a value of #{value}"
@@ -168,7 +168,7 @@ module Gcloud
168
168
  #
169
169
  # gcloud = Gcloud.new
170
170
  # dataset = gcloud.datastore
171
- # entity = dataset.find "User", "heidi"
171
+ # entity = dataset.find "User", "heidi@example.com"
172
172
  # entity.persisted? #=> true
173
173
  # entity.key = Gcloud::Datastore::Key.new "User" #=> RuntimeError
174
174
  # entity.key.frozen? #=> true
@@ -192,7 +192,7 @@ module Gcloud
192
192
  # new_entity = Gcloud::Datastore::Entity.new
193
193
  # new_entity.persisted? #=> false
194
194
  #
195
- # found_entity = dataset.find "User", "heidi"
195
+ # found_entity = dataset.find "User", "heidi@example.com"
196
196
  # found_entity.persisted? #=> true
197
197
  #
198
198
  def persisted?
@@ -25,7 +25,7 @@ module Gcloud
25
25
  # name string, assigned explicitly by the application, or an integer numeric
26
26
  # ID, assigned automatically by Datastore.
27
27
  #
28
- # key = Gcloud::Datastore::Key.new "User", "username"
28
+ # key = Gcloud::Datastore::Key.new "User", "heidi@example.com"
29
29
  class Key
30
30
  ##
31
31
  # The kind of the Key.
@@ -57,7 +57,7 @@ module Gcloud
57
57
  # "/path/to/keyfile.json"
58
58
  #
59
59
  # dataset = gcloud.datastore
60
- # entity = dataset.find "User", "heidi"
60
+ # entity = dataset.find "User", "heidi@example.com"
61
61
  # entity.key.dataset_id #=> "my-todo-project"
62
62
  #
63
63
  attr_accessor :dataset_id
@@ -77,11 +77,29 @@ module Gcloud
77
77
  # "/path/to/keyfile.json"
78
78
  #
79
79
  # dataset = gcloud.datastore
80
- # entity = dataset.find "User", "heidi"
80
+ # entity = dataset.find "User", "heidi@example.com"
81
81
  # entity.key.namespace #=> "ns~todo-project"
82
82
  #
83
83
  attr_accessor :namespace
84
84
 
85
+ ##
86
+ # Create a new Key instance.
87
+ #
88
+ # === Parameters
89
+ #
90
+ # +kind+::
91
+ # The kind of the Key. This is optional. (+String+)
92
+ # +id_or_name+::
93
+ # The id or name of the Key. This is optional. (+Integer+ or +String+)
94
+ #
95
+ # === Returns
96
+ #
97
+ # Gcloud::Datastore::Dataset::Key
98
+ #
99
+ # === Example
100
+ #
101
+ # key = Gcloud::Datastore::Key.new "User", "heidi@example.com"
102
+ #
85
103
  def initialize kind = nil, id_or_name = nil
86
104
  @kind = kind
87
105
  if id_or_name.is_a? Integer
@@ -101,9 +119,9 @@ module Gcloud
101
119
  #
102
120
  # === Example
103
121
  #
104
- # key = Gcloud::Datastore::Key.new "User", "heidi"
122
+ # key = Gcloud::Datastore::Key.new "User", "heidi@example.com"
105
123
  # key.id #=> nil
106
- # key.name #=> "heidi"
124
+ # key.name #=> "heidi@example.com"
107
125
  # key.id = 654321
108
126
  # key.id #=> 654321
109
127
  # key.name #=> nil
@@ -140,9 +158,9 @@ module Gcloud
140
158
  # key = Gcloud::Datastore::Key.new "User", 123456
141
159
  # key.id #=> 123456
142
160
  # key.name #=> nil
143
- # key.name = "heidi"
161
+ # key.name = "heidi@example.com"
144
162
  # key.id #=> nil
145
- # key.name #=> "heidi"
163
+ # key.name #=> "heidi@example.com"
146
164
  #
147
165
  def name= new_name #:nodoc:
148
166
  @id = nil if new_name
@@ -158,8 +176,8 @@ module Gcloud
158
176
  #
159
177
  # === Example
160
178
  #
161
- # key = Gcloud::Datastore::Key.new "User", "heidi"
162
- # key.name #=> "heidi"
179
+ # key = Gcloud::Datastore::Key.new "User", "heidi@example.com"
180
+ # key.name #=> "heidi@example.com"
163
181
  #
164
182
  attr_reader :name
165
183
 
@@ -173,7 +191,7 @@ module Gcloud
173
191
  # === Example
174
192
  #
175
193
  # key = Gcloud::Datastore::Key.new "List", "todos"
176
- # key.parent = Gcloud::Datastore::Key.new "User", "heidi"
194
+ # key.parent = Gcloud::Datastore::Key.new "User", "heidi@example.com"
177
195
  #
178
196
  def parent= new_parent #:nodoc:
179
197
  # store key if given an entity
@@ -195,12 +213,11 @@ module Gcloud
195
213
  # gcloud = Gcloud.new
196
214
  # dataset = gcloud.datastore
197
215
  #
198
- # user = dataset.find "User", "heidi"
199
- # query = Gcloud::Datastore::Query.new
200
- # query.kind("List").
216
+ # user = dataset.find "User", "heidi@example.com"
217
+ # query = dataset.query("List").
201
218
  # ancestor(user.key)
202
219
  # lists = dataset.run query
203
- # lists.first.key.parent #=> Key("User", "heidi")
220
+ # lists.first.key.parent #=> Key("User", "heidi@example.com")
204
221
  #
205
222
  attr_reader :parent
206
223
 
@@ -216,8 +233,8 @@ module Gcloud
216
233
  # === Example
217
234
  #
218
235
  # key = Gcloud::Datastore::Key.new "List", "todos"
219
- # key.parent = Gcloud::Datastore::Key.new "User", "heidi"
220
- # key.path #=> [["User", "heidi"], ["List", "todos"]]
236
+ # key.parent = Gcloud::Datastore::Key.new "User", "heidi@example.com"
237
+ # key.path #=> [["User", "heidi@example.com"], ["List", "todos"]]
221
238
  #
222
239
  def path
223
240
  new_path = parent ? parent.path : []
@@ -13,6 +13,8 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ require "delegate"
17
+
16
18
  module Gcloud
17
19
  module Dns
18
20
  class Change
@@ -181,7 +181,7 @@ module Gcloud
181
181
  #
182
182
  # === Returns
183
183
  #
184
- # Array of Gcloud::Dns::Zone (Gcloud::Dns::Zone::List)
184
+ # Array of Gcloud::Dns::Zone (See Gcloud::Dns::Zone::List)
185
185
  #
186
186
  # === Examples
187
187
  #
@@ -13,6 +13,8 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ require "delegate"
17
+
16
18
  module Gcloud
17
19
  module Dns
18
20
  class Record
@@ -238,7 +238,7 @@ module Gcloud
238
238
  #
239
239
  # === Returns
240
240
  #
241
- # Array of Gcloud::Dns::Change (Gcloud::Dns::Change::List)
241
+ # Array of Gcloud::Dns::Change (See Gcloud::Dns::Change::List)
242
242
  #
243
243
  # === Examples
244
244
  #
@@ -314,7 +314,7 @@ module Gcloud
314
314
  #
315
315
  # === Returns
316
316
  #
317
- # Array of Gcloud::Dns::Record (Gcloud::Dns::Record::List)
317
+ # Array of Gcloud::Dns::Record (See Gcloud::Dns::Record::List)
318
318
  #
319
319
  # === Examples
320
320
  #
@@ -13,6 +13,8 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ require "delegate"
17
+
16
18
  module Gcloud
17
19
  module Dns
18
20
  class Zone
data/lib/gcloud/gce.rb CHANGED
@@ -24,9 +24,6 @@ module Gcloud
24
24
  CHECK_URI = "http://169.254.169.254"
25
25
  PROJECT_URI = "#{CHECK_URI}/computeMetadata/v1/project/project-id"
26
26
 
27
- # rubocop:disable all
28
- # Disabled rubocop because this is private and we don't need more methods.
29
-
30
27
  def self.gce? options = {}
31
28
  conn = options[:connection] || Faraday.default_connection
32
29
  resp = conn.get CHECK_URI do |req|
@@ -56,7 +53,5 @@ module Gcloud
56
53
  @gce ||= {}
57
54
  @gce[:project_id] = nil
58
55
  end
59
-
60
- # rubocop:enable all
61
56
  end
62
57
  end
data/lib/gcloud/pubsub.rb CHANGED
@@ -114,44 +114,6 @@ module Gcloud
114
114
  # pubsub = gcloud.pubsub
115
115
  # topic = pubsub.create_topic "my-topic"
116
116
  #
117
- # == Publishing Messages
118
- #
119
- # Messages are published to a topic. (See Topic#publish)
120
- #
121
- # require "gcloud"
122
- #
123
- # gcloud = Gcloud.new
124
- # pubsub = gcloud.pubsub
125
- #
126
- # topic = pubsub.topic "my-topic"
127
- # msg = topic.publish "new-message"
128
- #
129
- # Messages can also be published with attributes:
130
- #
131
- # require "gcloud"
132
- #
133
- # gcloud = Gcloud.new
134
- # pubsub = gcloud.pubsub
135
- #
136
- # topic = pubsub.topic "my-topic"
137
- # msg = topic.publish "new-message",
138
- # foo: :bar,
139
- # this: :that
140
- #
141
- # Multiple messages can be published at the same time by passing a block:
142
- #
143
- # require "gcloud"
144
- #
145
- # gcloud = Gcloud.new
146
- # pubsub = gcloud.pubsub
147
- #
148
- # topic = pubsub.topic "my-topic"
149
- # msgs = topic.publish do |batch|
150
- # batch.publish "new-message-1", foo: :bar
151
- # batch.publish "new-message-2", foo: :baz
152
- # batch.publish "new-message-3", foo: :bif
153
- # end
154
- #
155
117
  # == Retrieving Subscriptions
156
118
  #
157
119
  # A Subscription is a named resource representing the stream of messages from
@@ -169,7 +131,8 @@ module Gcloud
169
131
  #
170
132
  # == Creating a Subscription
171
133
  #
172
- # A Subscription is created from a Topic. (See Topic#subscribe)
134
+ # A Subscription is created from a Topic. (See Topic#subscribe and
135
+ # Project#subscribe)
173
136
  #
174
137
  # require "gcloud"
175
138
  #
@@ -193,41 +156,45 @@ module Gcloud
193
156
  # deadline: 120,
194
157
  # endpoint: "https://example.com/push"
195
158
  #
196
- # == Working Across Projects
159
+ # == Publishing Messages
197
160
  #
198
- # All calls to the Pub/Sub service use the same project and credentials
199
- # provided to the Gcloud#pubsub method. However, it is common to reference
200
- # topics or subscriptions in other projects, which can be achieved by using
201
- # the +project+ option. The main credentials must have permissions to the
202
- # topics and subscriptions in other projects.
161
+ # Messages are published to a topic. Any message published to a topic without
162
+ # a subscription will be lost. Ensure the topic has a subscription before
163
+ # publishing. (See Topic#publish and Project#publish)
203
164
  #
204
165
  # require "gcloud"
205
166
  #
206
- # gcloud = Gcloud.new # my-project-id
167
+ # gcloud = Gcloud.new
207
168
  # pubsub = gcloud.pubsub
208
169
  #
209
- # # Get a topic in the current project
210
- # my_topic = pubsub.topic "my-topic"
211
- # my_topic.name #=> "projects/my-project-id/topics/my-topic"
212
- # # Get a topic in another project
213
- # other_topic = pubsub.topic "other-topic", project: "other-project-id"
214
- # other_topic.name #=> "projects/other-project-id/topics/other-topic"
170
+ # topic = pubsub.topic "my-topic"
171
+ # msg = topic.publish "new-message"
215
172
  #
216
- # It is possible to create a subscription in the current project that pulls
217
- # from a topic in another project:
173
+ # Messages can also be published with attributes:
218
174
  #
219
175
  # require "gcloud"
220
176
  #
221
- # gcloud = Gcloud.new # my-project-id
177
+ # gcloud = Gcloud.new
222
178
  # pubsub = gcloud.pubsub
223
179
  #
224
- # # Get a topic in another project
225
- # topic = pubsub.topic "other-topic", project: "other-project-id"
226
- # # Create a subscription in the current project that pulls from
227
- # # the topic in another project
228
- # sub = topic.subscribe "my-sub"
229
- # sub.name #=> "projects/my-project-id/subscriptions/my-sub"
230
- # sub.topic.name #=> "projects/other-project-id/topics/other-topic"
180
+ # topic = pubsub.topic "my-topic"
181
+ # msg = topic.publish "new-message",
182
+ # foo: :bar,
183
+ # this: :that
184
+ #
185
+ # Multiple messages can be published at the same time by passing a block:
186
+ #
187
+ # require "gcloud"
188
+ #
189
+ # gcloud = Gcloud.new
190
+ # pubsub = gcloud.pubsub
191
+ #
192
+ # topic = pubsub.topic "my-topic"
193
+ # msgs = topic.publish do |batch|
194
+ # batch.publish "new-message-1", foo: :bar
195
+ # batch.publish "new-message-2", foo: :baz
196
+ # batch.publish "new-message-3", foo: :bif
197
+ # end
231
198
  #
232
199
  # == Pulling Messages
233
200
  #
@@ -381,6 +348,42 @@ module Gcloud
381
348
  # # process msg
382
349
  # end
383
350
  #
351
+ # == Working Across Projects
352
+ #
353
+ # All calls to the Pub/Sub service use the same project and credentials
354
+ # provided to the Gcloud#pubsub method. However, it is common to reference
355
+ # topics or subscriptions in other projects, which can be achieved by using
356
+ # the +project+ option. The main credentials must have permissions to the
357
+ # topics and subscriptions in other projects.
358
+ #
359
+ # require "gcloud"
360
+ #
361
+ # gcloud = Gcloud.new # my-project-id
362
+ # pubsub = gcloud.pubsub
363
+ #
364
+ # # Get a topic in the current project
365
+ # my_topic = pubsub.topic "my-topic"
366
+ # my_topic.name #=> "projects/my-project-id/topics/my-topic"
367
+ # # Get a topic in another project
368
+ # other_topic = pubsub.topic "other-topic", project: "other-project-id"
369
+ # other_topic.name #=> "projects/other-project-id/topics/other-topic"
370
+ #
371
+ # It is possible to create a subscription in the current project that pulls
372
+ # from a topic in another project:
373
+ #
374
+ # require "gcloud"
375
+ #
376
+ # gcloud = Gcloud.new # my-project-id
377
+ # pubsub = gcloud.pubsub
378
+ #
379
+ # # Get a topic in another project
380
+ # topic = pubsub.topic "other-topic", project: "other-project-id"
381
+ # # Create a subscription in the current project that pulls from
382
+ # # the topic in another project
383
+ # sub = topic.subscribe "my-sub"
384
+ # sub.name #=> "projects/my-project-id/subscriptions/my-sub"
385
+ # sub.topic.name #=> "projects/other-project-id/topics/other-topic"
386
+ #
384
387
  module Pubsub
385
388
  end
386
389
  end