gcloud 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +8 -8
  2. data/CHANGELOG.md +21 -0
  3. data/lib/gcloud.rb +0 -5
  4. data/lib/gcloud/bigquery.rb +31 -62
  5. data/lib/gcloud/bigquery/connection.rb +58 -35
  6. data/lib/gcloud/bigquery/dataset.rb +147 -18
  7. data/lib/gcloud/bigquery/dataset/access.rb +477 -0
  8. data/lib/gcloud/bigquery/dataset/list.rb +1 -1
  9. data/lib/gcloud/bigquery/errors.rb +2 -0
  10. data/lib/gcloud/bigquery/job.rb +30 -6
  11. data/lib/gcloud/bigquery/job/list.rb +1 -1
  12. data/lib/gcloud/bigquery/project.rb +47 -8
  13. data/lib/gcloud/bigquery/query_job.rb +1 -5
  14. data/lib/gcloud/bigquery/table.rb +185 -47
  15. data/lib/gcloud/bigquery/table/list.rb +1 -1
  16. data/lib/gcloud/bigquery/table/schema.rb +252 -0
  17. data/lib/gcloud/bigquery/view.rb +25 -0
  18. data/lib/gcloud/datastore/connection.rb +4 -0
  19. data/lib/gcloud/datastore/dataset.rb +5 -2
  20. data/lib/gcloud/datastore/errors.rb +1 -1
  21. data/lib/gcloud/datastore/properties.rb +1 -0
  22. data/lib/gcloud/datastore/proto.rb +3 -0
  23. data/lib/gcloud/errors.rb +23 -0
  24. data/lib/gcloud/gce.rb +62 -0
  25. data/lib/gcloud/pubsub/connection.rb +4 -0
  26. data/lib/gcloud/pubsub/errors.rb +2 -0
  27. data/lib/gcloud/pubsub/project.rb +5 -3
  28. data/lib/gcloud/pubsub/subscription/list.rb +1 -1
  29. data/lib/gcloud/pubsub/topic.rb +1 -1
  30. data/lib/gcloud/pubsub/topic/list.rb +1 -1
  31. data/lib/gcloud/storage.rb +16 -0
  32. data/lib/gcloud/storage/bucket.rb +31 -1
  33. data/lib/gcloud/storage/bucket/acl.rb +12 -10
  34. data/lib/gcloud/storage/bucket/list.rb +1 -1
  35. data/lib/gcloud/storage/connection.rb +4 -0
  36. data/lib/gcloud/storage/errors.rb +2 -0
  37. data/lib/gcloud/storage/file.rb +13 -0
  38. data/lib/gcloud/storage/file/acl.rb +6 -5
  39. data/lib/gcloud/storage/file/list.rb +1 -1
  40. data/lib/gcloud/storage/project.rb +4 -2
  41. data/lib/gcloud/version.rb +1 -1
  42. metadata +6 -2
@@ -253,6 +253,10 @@ module Gcloud
253
253
  "#{project_path(options)}/subscriptions/#{subscription_name}"
254
254
  end
255
255
 
256
+ def inspect #:nodoc:
257
+ "#{self.class}(#{@project})"
258
+ end
259
+
256
260
  protected
257
261
 
258
262
  def subscription_data topic, options = {}
@@ -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 "gcloud/errors"
17
+
16
18
  module Gcloud
17
19
  module Pubsub
18
20
  ##
@@ -13,6 +13,7 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ require "gcloud/gce"
16
17
  require "gcloud/pubsub/connection"
17
18
  require "gcloud/pubsub/credentials"
18
19
  require "gcloud/pubsub/errors"
@@ -73,7 +74,8 @@ module Gcloud
73
74
  def self.default_project #:nodoc:
74
75
  ENV["PUBSUB_PROJECT"] ||
75
76
  ENV["GCLOUD_PROJECT"] ||
76
- ENV["GOOGLE_CLOUD_PROJECT"]
77
+ ENV["GOOGLE_CLOUD_PROJECT"] ||
78
+ Gcloud::GCE.project_id
77
79
  end
78
80
 
79
81
  ##
@@ -260,7 +262,7 @@ module Gcloud
260
262
  ensure_connection!
261
263
  resp = connection.list_topics options
262
264
  if resp.success?
263
- Topic::List.from_resp resp, connection
265
+ Topic::List.from_response resp, connection
264
266
  else
265
267
  fail ApiError.from_response(resp)
266
268
  end
@@ -392,7 +394,7 @@ module Gcloud
392
394
  ensure_connection!
393
395
  resp = connection.list_subscriptions options
394
396
  if resp.success?
395
- Subscription::List.from_resp resp, connection
397
+ Subscription::List.from_response resp, connection
396
398
  else
397
399
  fail ApiError.from_response(resp)
398
400
  end
@@ -34,7 +34,7 @@ module Gcloud
34
34
 
35
35
  ##
36
36
  # New Subscription::List from a response object.
37
- def self.from_resp resp, conn #:nodoc:
37
+ def self.from_response resp, conn #:nodoc:
38
38
  subs = Array(resp.data["subscriptions"]).map do |gapi_object|
39
39
  if gapi_object.is_a? String
40
40
  Subscription.new_lazy gapi_object, conn
@@ -299,7 +299,7 @@ module Gcloud
299
299
  ensure_connection!
300
300
  resp = connection.list_topics_subscriptions name, options
301
301
  if resp.success?
302
- Subscription::List.from_resp resp, connection
302
+ Subscription::List.from_response resp, connection
303
303
  else
304
304
  fail ApiError.from_response(resp)
305
305
  end
@@ -34,7 +34,7 @@ module Gcloud
34
34
 
35
35
  ##
36
36
  # New Topic::List from a response object.
37
- def self.from_resp resp, conn #:nodoc:
37
+ def self.from_response resp, conn #:nodoc:
38
38
  topics = Array(resp.data["topics"]).map do |gapi_object|
39
39
  Topic.from_gapi gapi_object, conn
40
40
  end
@@ -227,6 +227,22 @@ module Gcloud
227
227
  # bucket.create_file "/var/todo-app/avatars/heidi/400x400.png",
228
228
  # "avatars/heidi/400x400.png"
229
229
  #
230
+ # === A note about large uploads
231
+ #
232
+ # You may encounter a broken pipe error while attempting to upload large
233
+ # files. To avoid this problem, add
234
+ # {httpclient}[https://rubygems.org/gems/httpclient] as a dependency to your
235
+ # project, and configure {Faraday}[https://rubygems.org/gems/faraday] to use
236
+ # it, after requiring Gcloud, but before initiating your Gcloud connection.
237
+ #
238
+ # require "gcloud"
239
+ #
240
+ # Faraday.default_adapter = :httpclient
241
+ #
242
+ # gcloud = Gcloud.new
243
+ # storage = gcloud.storage
244
+ # bucket = storage.bucket "my-todo-app"
245
+ #
230
246
  # == Downloading a File
231
247
  #
232
248
  # Files can be downloaded to the local file system. (See File#download)
@@ -208,7 +208,7 @@ module Gcloud
208
208
  ensure_connection!
209
209
  resp = connection.list_files name, options
210
210
  if resp.success?
211
- File::List.from_resp resp, connection
211
+ File::List.from_response resp, connection
212
212
  else
213
213
  fail ApiError.from_response(resp)
214
214
  end
@@ -324,6 +324,23 @@ module Gcloud
324
324
  # "destination/path/file.ext",
325
325
  # chunk_size: 1024*1024 # 1 MB chunk
326
326
  #
327
+ # ==== A note about large uploads
328
+ #
329
+ # You may encounter a broken pipe error while attempting to upload large
330
+ # files. To avoid this problem, add
331
+ # {httpclient}[https://rubygems.org/gems/httpclient] as a dependency to
332
+ # your project, and configure {Faraday}[https://rubygems.org/gems/faraday]
333
+ # to use it, after requiring Gcloud, but before initiating your Gcloud
334
+ # connection.
335
+ #
336
+ # require "gcloud"
337
+ #
338
+ # Faraday.default_adapter = :httpclient
339
+ #
340
+ # gcloud = Gcloud.new
341
+ # storage = gcloud.storage
342
+ # bucket = storage.bucket "my-todo-app"
343
+ #
327
344
  def create_file file, path = nil, options = {}
328
345
  ensure_connection!
329
346
  ensure_file_exists! file
@@ -447,6 +464,19 @@ module Gcloud
447
464
  @default_acl ||= Bucket::DefaultAcl.new self
448
465
  end
449
466
 
467
+ ##
468
+ # Reloads the bucket with current data from the Storage service.
469
+ def reload!
470
+ ensure_connection!
471
+ resp = connection.get_bucket name
472
+ if resp.success?
473
+ @gapi = resp.data
474
+ else
475
+ fail ApiError.from_response(resp)
476
+ end
477
+ end
478
+ alias_method :refresh!, :reload!
479
+
450
480
  ##
451
481
  # New Bucket from a Google API Client object.
452
482
  def self.from_gapi gapi, conn #:nodoc:
@@ -69,15 +69,16 @@ module Gcloud
69
69
  #
70
70
  # bucket = storage.bucket "my-bucket"
71
71
  #
72
- # bucket.acl.refresh!
72
+ # bucket.acl.reload!
73
73
  #
74
- def refresh!
74
+ def reload!
75
75
  resp = @connection.list_bucket_acls @bucket
76
76
  acls = resp.data["items"]
77
77
  @owners = entities_from_acls acls, "OWNER"
78
78
  @writers = entities_from_acls acls, "WRITER"
79
79
  @readers = entities_from_acls acls, "READER"
80
80
  end
81
+ alias_method :refresh!, :reload!
81
82
 
82
83
  ##
83
84
  # Lists the owners of the bucket.
@@ -98,7 +99,7 @@ module Gcloud
98
99
  # bucket.acl.owners.each { |owner| puts owner }
99
100
  #
100
101
  def owners
101
- refresh! if @owners.nil?
102
+ reload! if @owners.nil?
102
103
  @owners
103
104
  end
104
105
 
@@ -121,7 +122,7 @@ module Gcloud
121
122
  # bucket.acl.writers.each { |writer| puts writer }
122
123
  #
123
124
  def writers
124
- refresh! if @writers.nil?
125
+ reload! if @writers.nil?
125
126
  @writers
126
127
  end
127
128
 
@@ -144,7 +145,7 @@ module Gcloud
144
145
  # bucket.acl.readers.each { |reader| puts reader }
145
146
  #
146
147
  def readers
147
- refresh! if @readers.nil?
148
+ reload! if @readers.nil?
148
149
  @readers
149
150
  end
150
151
 
@@ -535,15 +536,16 @@ module Gcloud
535
536
  #
536
537
  # bucket = storage.bucket "my-bucket"
537
538
  #
538
- # bucket.default_acl.refresh!
539
+ # bucket.default_acl.reload!
539
540
  #
540
- def refresh!
541
+ def reload!
541
542
  resp = @connection.list_default_acls @bucket
542
543
  acls = resp.data["items"]
543
544
  @owners = entities_from_acls acls, "OWNER"
544
545
  @writers = entities_from_acls acls, "WRITER"
545
546
  @readers = entities_from_acls acls, "READER"
546
547
  end
548
+ alias_method :refresh!, :reload!
547
549
 
548
550
  ##
549
551
  # Lists the default owners for files in the bucket.
@@ -564,7 +566,7 @@ module Gcloud
564
566
  # bucket.default_acl.owners.each { |owner| puts owner }
565
567
  #
566
568
  def owners
567
- refresh! if @owners.nil?
569
+ reload! if @owners.nil?
568
570
  @owners
569
571
  end
570
572
 
@@ -587,7 +589,7 @@ module Gcloud
587
589
  # bucket.default_acl.writers.each { |writer| puts writer }
588
590
  #
589
591
  def writers
590
- refresh! if @writers.nil?
592
+ reload! if @writers.nil?
591
593
  @writers
592
594
  end
593
595
 
@@ -610,7 +612,7 @@ module Gcloud
610
612
  # bucket.default_acl.readers.each { |reader| puts reader }
611
613
  #
612
614
  def readers
613
- refresh! if @readers.nil?
615
+ reload! if @readers.nil?
614
616
  @readers
615
617
  end
616
618
 
@@ -34,7 +34,7 @@ module Gcloud
34
34
 
35
35
  ##
36
36
  # New Bucket::List from a response object.
37
- def self.from_resp resp, conn #:nodoc:
37
+ def self.from_response resp, conn #:nodoc:
38
38
  buckets = Array(resp.data["items"]).map do |gapi_object|
39
39
  Bucket.from_gapi gapi_object, conn
40
40
  end
@@ -347,6 +347,10 @@ module Gcloud
347
347
  MIME::Types.of(path).first.to_s
348
348
  end
349
349
 
350
+ def inspect #:nodoc:
351
+ "#{self.class}(#{@project})"
352
+ end
353
+
350
354
  protected
351
355
 
352
356
  def incremental_backoff options = {}
@@ -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 "gcloud/errors"
17
+
16
18
  module Gcloud
17
19
  module Storage
18
20
  ##
@@ -463,6 +463,19 @@ module Gcloud
463
463
  @acl ||= File::Acl.new self
464
464
  end
465
465
 
466
+ ##
467
+ # Reloads the file with current data from the Storage service.
468
+ def reload!
469
+ ensure_connection!
470
+ resp = connection.get_file bucket, name
471
+ if resp.success?
472
+ @gapi = resp.data
473
+ else
474
+ fail ApiError.from_response(resp)
475
+ end
476
+ end
477
+ alias_method :refresh!, :reload!
478
+
466
479
  ##
467
480
  # URI of the location and file name in the format of
468
481
  # <code>gs://my-bucket/file-name.json</code>.
@@ -73,15 +73,16 @@ module Gcloud
73
73
  # bucket = storage.bucket "my-bucket"
74
74
  #
75
75
  # file = bucket.file "path/to/my-file.ext"
76
- # file.acl.refresh!
76
+ # file.acl.reload!
77
77
  #
78
- def refresh!
78
+ def reload!
79
79
  resp = @connection.list_file_acls @bucket, @file
80
80
  acls = resp.data["items"]
81
81
  @owners = entities_from_acls acls, "OWNER"
82
82
  @writers = entities_from_acls acls, "WRITER"
83
83
  @readers = entities_from_acls acls, "READER"
84
84
  end
85
+ alias_method :refresh!, :reload!
85
86
 
86
87
  ##
87
88
  # Lists the owners of the file.
@@ -103,7 +104,7 @@ module Gcloud
103
104
  # file.acl.owners.each { |owner| puts owner }
104
105
  #
105
106
  def owners
106
- refresh! if @owners.nil?
107
+ reload! if @owners.nil?
107
108
  @owners
108
109
  end
109
110
 
@@ -127,7 +128,7 @@ module Gcloud
127
128
  # file.acl.writers.each { |writer| puts writer }
128
129
  #
129
130
  def writers
130
- refresh! if @writers.nil?
131
+ reload! if @writers.nil?
131
132
  @writers
132
133
  end
133
134
 
@@ -151,7 +152,7 @@ module Gcloud
151
152
  # file.acl.readers.each { |reader| puts reader }
152
153
  #
153
154
  def readers
154
- refresh! if @readers.nil?
155
+ reload! if @readers.nil?
155
156
  @readers
156
157
  end
157
158
 
@@ -39,7 +39,7 @@ module Gcloud
39
39
 
40
40
  ##
41
41
  # New File::List from a response object.
42
- def self.from_resp resp, conn #:nodoc:
42
+ def self.from_response resp, conn #:nodoc:
43
43
  buckets = Array(resp.data["items"]).map do |gapi_object|
44
44
  File.from_gapi gapi_object, conn
45
45
  end
@@ -13,6 +13,7 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ require "gcloud/gce"
16
17
  require "gcloud/storage/errors"
17
18
  require "gcloud/storage/connection"
18
19
  require "gcloud/storage/credentials"
@@ -79,7 +80,8 @@ module Gcloud
79
80
  def self.default_project #:nodoc:
80
81
  ENV["STORAGE_PROJECT"] ||
81
82
  ENV["GCLOUD_PROJECT"] ||
82
- ENV["GOOGLE_CLOUD_PROJECT"]
83
+ ENV["GOOGLE_CLOUD_PROJECT"] ||
84
+ Gcloud::GCE.project_id
83
85
  end
84
86
 
85
87
  ##
@@ -147,7 +149,7 @@ module Gcloud
147
149
  def buckets options = {}
148
150
  resp = connection.list_buckets options
149
151
  if resp.success?
150
- Bucket::List.from_resp resp, connection
152
+ Bucket::List.from_response resp, connection
151
153
  else
152
154
  fail ApiError.from_response(resp)
153
155
  end
@@ -16,5 +16,5 @@
16
16
  #--
17
17
  # Google Cloud Version
18
18
  module Gcloud
19
- VERSION = "0.3.0"
19
+ VERSION = "0.3.1"
20
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gcloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Silvano Luciani
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-08-21 00:00:00.000000000 Z
12
+ date: 2015-09-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: beefcake
@@ -229,6 +229,7 @@ files:
229
229
  - lib/gcloud/bigquery/credentials.rb
230
230
  - lib/gcloud/bigquery/data.rb
231
231
  - lib/gcloud/bigquery/dataset.rb
232
+ - lib/gcloud/bigquery/dataset/access.rb
232
233
  - lib/gcloud/bigquery/dataset/list.rb
233
234
  - lib/gcloud/bigquery/errors.rb
234
235
  - lib/gcloud/bigquery/extract_job.rb
@@ -241,6 +242,7 @@ files:
241
242
  - lib/gcloud/bigquery/query_job.rb
242
243
  - lib/gcloud/bigquery/table.rb
243
244
  - lib/gcloud/bigquery/table/list.rb
245
+ - lib/gcloud/bigquery/table/schema.rb
244
246
  - lib/gcloud/bigquery/view.rb
245
247
  - lib/gcloud/credentials.rb
246
248
  - lib/gcloud/datastore.rb
@@ -256,6 +258,8 @@ files:
256
258
  - lib/gcloud/datastore/proto.rb
257
259
  - lib/gcloud/datastore/query.rb
258
260
  - lib/gcloud/datastore/transaction.rb
261
+ - lib/gcloud/errors.rb
262
+ - lib/gcloud/gce.rb
259
263
  - lib/gcloud/proto/datastore_v1.pb.rb
260
264
  - lib/gcloud/pubsub.rb
261
265
  - lib/gcloud/pubsub/connection.rb