google-cloud-storage 0.20.2 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,10 +37,9 @@ module Google
37
37
  # and Techniques
38
38
  #
39
39
  # @example
40
- # require "google/cloud"
40
+ # require "google/cloud/storage"
41
41
  #
42
- # gcloud = Google::Cloud.new
43
- # storage = gcloud.storage
42
+ # storage = Google::Cloud::Storage.new
44
43
  #
45
44
  # bucket = storage.bucket "my-bucket"
46
45
  #
@@ -276,10 +275,9 @@ module Google
276
275
  # @yield [file] a block yielding a delegate object for updating the file
277
276
  #
278
277
  # @example
279
- # require "google/cloud"
278
+ # require "google/cloud/storage"
280
279
  #
281
- # gcloud = Google::Cloud.new
282
- # storage = gcloud.storage
280
+ # storage = Google::Cloud::Storage.new
283
281
  #
284
282
  # bucket = storage.bucket "my-bucket"
285
283
  #
@@ -336,10 +334,9 @@ module Google
336
334
  # @return [File] Returns a `::File` object on the local file system
337
335
  #
338
336
  # @example
339
- # require "google/cloud"
337
+ # require "google/cloud/storage"
340
338
  #
341
- # gcloud = Google::Cloud.new
342
- # storage = gcloud.storage
339
+ # storage = Google::Cloud::Storage.new
343
340
  #
344
341
  # bucket = storage.bucket "my-bucket"
345
342
  #
@@ -347,10 +344,9 @@ module Google
347
344
  # file.download "path/to/downloaded/file.ext"
348
345
  #
349
346
  # @example Use the CRC32c digest by passing :crc32c.
350
- # require "google/cloud"
347
+ # require "google/cloud/storage"
351
348
  #
352
- # gcloud = Google::Cloud.new
353
- # storage = gcloud.storage
349
+ # storage = Google::Cloud::Storage.new
354
350
  #
355
351
  # bucket = storage.bucket "my-bucket"
356
352
  #
@@ -358,10 +354,9 @@ module Google
358
354
  # file.download "path/to/downloaded/file.ext", verify: :crc32c
359
355
  #
360
356
  # @example Use the MD5 and CRC32c digests by passing :all.
361
- # require "google/cloud"
357
+ # require "google/cloud/storage"
362
358
  #
363
- # gcloud = Google::Cloud.new
364
- # storage = gcloud.storage
359
+ # storage = Google::Cloud::Storage.new
365
360
  #
366
361
  # bucket = storage.bucket "my-bucket"
367
362
  #
@@ -369,10 +364,9 @@ module Google
369
364
  # file.download "path/to/downloaded/file.ext", verify: :all
370
365
  #
371
366
  # @example Disable the download verification by passing :none.
372
- # require "google/cloud"
367
+ # require "google/cloud/storage"
373
368
  #
374
- # gcloud = Google::Cloud.new
375
- # storage = gcloud.storage
369
+ # storage = Google::Cloud::Storage.new
376
370
  #
377
371
  # bucket = storage.bucket "my-bucket"
378
372
  #
@@ -433,10 +427,9 @@ module Google
433
427
  # @return [Google::Cloud::Storage::File]
434
428
  #
435
429
  # @example The file can be copied to a new path in the current bucket:
436
- # require "google/cloud"
430
+ # require "google/cloud/storage"
437
431
  #
438
- # gcloud = Google::Cloud.new
439
- # storage = gcloud.storage
432
+ # storage = Google::Cloud::Storage.new
440
433
  #
441
434
  # bucket = storage.bucket "my-bucket"
442
435
  #
@@ -444,10 +437,9 @@ module Google
444
437
  # file.copy "path/to/destination/file.ext"
445
438
  #
446
439
  # @example The file can also be copied to a different bucket:
447
- # require "google/cloud"
440
+ # require "google/cloud/storage"
448
441
  #
449
- # gcloud = Google::Cloud.new
450
- # storage = gcloud.storage
442
+ # storage = Google::Cloud::Storage.new
451
443
  #
452
444
  # bucket = storage.bucket "my-bucket"
453
445
  #
@@ -479,10 +471,9 @@ module Google
479
471
  # @return [Boolean] Returns `true` if the file was deleted.
480
472
  #
481
473
  # @example
482
- # require "google/cloud"
474
+ # require "google/cloud/storage"
483
475
  #
484
- # gcloud = Google::Cloud.new
485
- # storage = gcloud.storage
476
+ # storage = Google::Cloud::Storage.new
486
477
  #
487
478
  # bucket = storage.bucket "my-bucket"
488
479
  #
@@ -508,20 +499,18 @@ module Google
508
499
  # `HTTPS`.
509
500
  #
510
501
  # @example
511
- # require "google/cloud"
502
+ # require "google/cloud/storage"
512
503
  #
513
- # gcloud = Google::Cloud.new
514
- # storage = gcloud.storage
504
+ # storage = Google::Cloud::Storage.new
515
505
  #
516
506
  # bucket = storage.bucket "my-todo-app"
517
507
  # file = bucket.file "avatars/heidi/400x400.png"
518
508
  # public_url = file.public_url
519
509
  #
520
510
  # @example Generate the URL with a protocol other than HTTPS:
521
- # require "google/cloud"
511
+ # require "google/cloud/storage"
522
512
  #
523
- # gcloud = Google::Cloud.new
524
- # storage = gcloud.storage
513
+ # storage = Google::Cloud::Storage.new
525
514
  #
526
515
  # bucket = storage.bucket "my-todo-app"
527
516
  # file = bucket.file "avatars/heidi/400x400.png"
@@ -571,20 +560,18 @@ module Google
571
560
  # Private Key.
572
561
  #
573
562
  # @example
574
- # require "google/cloud"
563
+ # require "google/cloud/storage"
575
564
  #
576
- # gcloud = Google::Cloud.new
577
- # storage = gcloud.storage
565
+ # storage = Google::Cloud::Storage.new
578
566
  #
579
567
  # bucket = storage.bucket "my-todo-app"
580
568
  # file = bucket.file "avatars/heidi/400x400.png"
581
569
  # shared_url = file.signed_url
582
570
  #
583
571
  # @example Any of the option parameters may be specified:
584
- # require "google/cloud"
572
+ # require "google/cloud/storage"
585
573
  #
586
- # gcloud = Google::Cloud.new
587
- # storage = gcloud.storage
574
+ # storage = Google::Cloud::Storage.new
588
575
  #
589
576
  # bucket = storage.bucket "my-todo-app"
590
577
  # file = bucket.file "avatars/heidi/400x400.png"
@@ -610,7 +597,7 @@ module Google
610
597
  content_type: content_type, content_md5: content_md5,
611
598
  issuer: issuer, client_email: client_email,
612
599
  signing_key: signing_key, private_key: private_key }
613
- signer = File::Signer.new self
600
+ signer = File::Signer.from_file self
614
601
  signer.signed_url options
615
602
  end
616
603
 
@@ -625,10 +612,9 @@ module Google
625
612
  # Control guide
626
613
  #
627
614
  # @example Grant access to a user by prepending `"user-"` to an email:
628
- # require "google/cloud"
615
+ # require "google/cloud/storage"
629
616
  #
630
- # gcloud = Google::Cloud.new
631
- # storage = gcloud.storage
617
+ # storage = Google::Cloud::Storage.new
632
618
  #
633
619
  # bucket = storage.bucket "my-todo-app"
634
620
  # file = bucket.file "avatars/heidi/400x400.png"
@@ -637,10 +623,9 @@ module Google
637
623
  # file.acl.add_reader "user-#{email}"
638
624
  #
639
625
  # @example Grant access to a group by prepending `"group-"` to an email:
640
- # require "google/cloud"
626
+ # require "google/cloud/storage"
641
627
  #
642
- # gcloud = Google::Cloud.new
643
- # storage = gcloud.storage
628
+ # storage = Google::Cloud::Storage.new
644
629
  #
645
630
  # bucket = storage.bucket "my-todo-app"
646
631
  # file = bucket.file "avatars/heidi/400x400.png"
@@ -649,10 +634,9 @@ module Google
649
634
  # file.acl.add_reader "group-#{email}"
650
635
  #
651
636
  # @example Or, grant access via a predefined permissions list:
652
- # require "google/cloud"
637
+ # require "google/cloud/storage"
653
638
  #
654
- # gcloud = Google::Cloud.new
655
- # storage = gcloud.storage
639
+ # storage = Google::Cloud::Storage.new
656
640
  #
657
641
  # bucket = storage.bucket "my-todo-app"
658
642
  # file = bucket.file "avatars/heidi/400x400.png"
@@ -731,14 +715,24 @@ module Google
731
715
  ##
732
716
  # @private Create a signed_url for a file.
733
717
  class Signer
734
- def initialize file
735
- @file = file
718
+ def initialize bucket, path, service
719
+ @bucket = bucket
720
+ @path = path
721
+ @service = service
722
+ end
723
+
724
+ def self.from_file file
725
+ new file.bucket, file.name, file.service
726
+ end
727
+
728
+ def self.from_bucket bucket, path
729
+ new bucket.name, path, bucket.service
736
730
  end
737
731
 
738
732
  ##
739
733
  # The external path to the file.
740
734
  def ext_path
741
- URI.escape "/#{@file.bucket}/#{@file.name}"
735
+ URI.escape "/#{@bucket}/#{@path}"
742
736
  end
743
737
 
744
738
  ##
@@ -762,12 +756,12 @@ module Google
762
756
 
763
757
  def determine_signing_key options = {}
764
758
  options[:signing_key] || options[:private_key] ||
765
- @file.service.credentials.signing_key
759
+ @service.credentials.signing_key
766
760
  end
767
761
 
768
762
  def determine_issuer options = {}
769
763
  options[:issuer] || options[:client_email] ||
770
- @file.service.credentials.issuer
764
+ @service.credentials.issuer
771
765
  end
772
766
 
773
767
  def signed_url options
@@ -23,10 +23,9 @@ module Google
23
23
  # Represents a File's Access Control List.
24
24
  #
25
25
  # @example
26
- # require "google/cloud"
26
+ # require "google/cloud/storage"
27
27
  #
28
- # gcloud = Google::Cloud.new
29
- # storage = gcloud.storage
28
+ # storage = Google::Cloud::Storage.new
30
29
  #
31
30
  # bucket = storage.bucket "my-bucket"
32
31
  #
@@ -66,10 +65,9 @@ module Google
66
65
  # Reloads all Access Control List data for the file.
67
66
  #
68
67
  # @example
69
- # require "google/cloud"
68
+ # require "google/cloud/storage"
70
69
  #
71
- # gcloud = Google::Cloud.new
72
- # storage = gcloud.storage
70
+ # storage = Google::Cloud::Storage.new
73
71
  #
74
72
  # bucket = storage.bucket "my-bucket"
75
73
  #
@@ -79,9 +77,7 @@ module Google
79
77
  def reload!
80
78
  gapi = @service.list_file_acls @bucket, @file
81
79
  acls = Array(gapi.items).map do |acl|
82
- if acl.is_a? Google::Apis::StorageV1::ObjectAccessControl
83
- return acl
84
- end
80
+ next acl if acl.is_a? Google::Apis::StorageV1::ObjectAccessControl
85
81
  fail "Unknown ACL format: #{acl.class}" unless acl.is_a? Hash
86
82
  Google::Apis::StorageV1::ObjectAccessControl.from_json acl.to_json
87
83
  end
@@ -96,10 +92,9 @@ module Google
96
92
  # @return [Array<String>]
97
93
  #
98
94
  # @example
99
- # require "google/cloud"
95
+ # require "google/cloud/storage"
100
96
  #
101
- # gcloud = Google::Cloud.new
102
- # storage = gcloud.storage
97
+ # storage = Google::Cloud::Storage.new
103
98
  #
104
99
  # bucket = storage.bucket "my-bucket"
105
100
  #
@@ -117,10 +112,9 @@ module Google
117
112
  # @return [Array<String>]
118
113
  #
119
114
  # @example
120
- # require "google/cloud"
115
+ # require "google/cloud/storage"
121
116
  #
122
- # gcloud = Google::Cloud.new
123
- # storage = gcloud.storage
117
+ # storage = Google::Cloud::Storage.new
124
118
  #
125
119
  # bucket = storage.bucket "my-bucket"
126
120
  #
@@ -151,10 +145,9 @@ module Google
151
145
  # revision of this object. Default is the latest version.
152
146
  #
153
147
  # @example Grant access to a user by prepending `"user-"` to an email:
154
- # require "google/cloud"
148
+ # require "google/cloud/storage"
155
149
  #
156
- # gcloud = Google::Cloud.new
157
- # storage = gcloud.storage
150
+ # storage = Google::Cloud::Storage.new
158
151
  #
159
152
  # bucket = storage.bucket "my-bucket"
160
153
  #
@@ -163,10 +156,9 @@ module Google
163
156
  # file.acl.add_owner "user-#{email}"
164
157
  #
165
158
  # @example Grant access to a group by prepending `"group-"` to email:
166
- # require "google/cloud"
159
+ # require "google/cloud/storage"
167
160
  #
168
- # gcloud = Google::Cloud.new
169
- # storage = gcloud.storage
161
+ # storage = Google::Cloud::Storage.new
170
162
  #
171
163
  # bucket = storage.bucket "my-bucket"
172
164
  #
@@ -202,10 +194,9 @@ module Google
202
194
  # revision of this object. Default is the latest version.
203
195
  #
204
196
  # @example Grant access to a user by prepending `"user-"` to an email:
205
- # require "google/cloud"
197
+ # require "google/cloud/storage"
206
198
  #
207
- # gcloud = Google::Cloud.new
208
- # storage = gcloud.storage
199
+ # storage = Google::Cloud::Storage.new
209
200
  #
210
201
  # bucket = storage.bucket "my-bucket"
211
202
  #
@@ -214,10 +205,9 @@ module Google
214
205
  # file.acl.add_reader "user-#{email}"
215
206
  #
216
207
  # @example Grant access to a group by prepending `"group-"` to email:
217
- # require "google/cloud"
208
+ # require "google/cloud/storage"
218
209
  #
219
- # gcloud = Google::Cloud.new
220
- # storage = gcloud.storage
210
+ # storage = Google::Cloud::Storage.new
221
211
  #
222
212
  # bucket = storage.bucket "my-bucket"
223
213
  #
@@ -253,10 +243,9 @@ module Google
253
243
  # revision of this object. Default is the latest version.
254
244
  #
255
245
  # @example
256
- # require "google/cloud"
246
+ # require "google/cloud/storage"
257
247
  #
258
- # gcloud = Google::Cloud.new
259
- # storage = gcloud.storage
248
+ # storage = Google::Cloud::Storage.new
260
249
  #
261
250
  # bucket = storage.bucket "my-bucket"
262
251
  #
@@ -284,10 +273,9 @@ module Google
284
273
  # rule to the file.
285
274
  #
286
275
  # @example
287
- # require "google/cloud"
276
+ # require "google/cloud/storage"
288
277
  #
289
- # gcloud = Google::Cloud.new
290
- # storage = gcloud.storage
278
+ # storage = Google::Cloud::Storage.new
291
279
  #
292
280
  # bucket = storage.bucket "my-bucket"
293
281
  #
@@ -307,10 +295,9 @@ module Google
307
295
  # ACL rule to the file.
308
296
  #
309
297
  # @example
310
- # require "google/cloud"
298
+ # require "google/cloud/storage"
311
299
  #
312
- # gcloud = Google::Cloud.new
313
- # storage = gcloud.storage
300
+ # storage = Google::Cloud::Storage.new
314
301
  #
315
302
  # bucket = storage.bucket "my-bucket"
316
303
  #
@@ -327,10 +314,9 @@ module Google
327
314
  # rule to the file.
328
315
  #
329
316
  # @example
330
- # require "google/cloud"
317
+ # require "google/cloud/storage"
331
318
  #
332
- # gcloud = Google::Cloud.new
333
- # storage = gcloud.storage
319
+ # storage = Google::Cloud::Storage.new
334
320
  #
335
321
  # bucket = storage.bucket "my-bucket"
336
322
  #
@@ -347,10 +333,9 @@ module Google
347
333
  # rule to the file.
348
334
  #
349
335
  # @example
350
- # require "google/cloud"
336
+ # require "google/cloud/storage"
351
337
  #
352
- # gcloud = Google::Cloud.new
353
- # storage = gcloud.storage
338
+ # storage = Google::Cloud::Storage.new
354
339
  #
355
340
  # bucket = storage.bucket "my-bucket"
356
341
  #
@@ -366,10 +351,9 @@ module Google
366
351
  # rule to the file.
367
352
  #
368
353
  # @example
369
- # require "google/cloud"
354
+ # require "google/cloud/storage"
370
355
  #
371
- # gcloud = Google::Cloud.new
372
- # storage = gcloud.storage
356
+ # storage = Google::Cloud::Storage.new
373
357
  #
374
358
  # bucket = storage.bucket "my-bucket"
375
359
  #
@@ -386,10 +370,9 @@ module Google
386
370
  # rule to the file.
387
371
  #
388
372
  # @example
389
- # require "google/cloud"
373
+ # require "google/cloud/storage"
390
374
  #
391
- # gcloud = Google::Cloud.new
392
- # storage = gcloud.storage
375
+ # storage = Google::Cloud::Storage.new
393
376
  #
394
377
  # bucket = storage.bucket "my-bucket"
395
378
  #
@@ -44,10 +44,9 @@ module Google
44
44
  # @return [Boolean]
45
45
  #
46
46
  # @example
47
- # require "google/cloud"
47
+ # require "google/cloud/storage"
48
48
  #
49
- # gcloud = Google::Cloud.new
50
- # storage = gcloud.storage
49
+ # storage = Google::Cloud::Storage.new
51
50
  #
52
51
  # bucket = storage.bucket "my-bucket"
53
52
  # files = bucket.files
@@ -65,10 +64,9 @@ module Google
65
64
  # @return [File::List]
66
65
  #
67
66
  # @example
68
- # require "google/cloud"
67
+ # require "google/cloud/storage"
69
68
  #
70
- # gcloud = Google::Cloud.new
71
- # storage = gcloud.storage
69
+ # storage = Google::Cloud::Storage.new
72
70
  #
73
71
  # bucket = storage.bucket "my-bucket"
74
72
  # files = bucket.files
@@ -107,10 +105,9 @@ module Google
107
105
  # @return [Enumerator]
108
106
  #
109
107
  # @example Iterating each file by passing a block:
110
- # require "google/cloud"
108
+ # require "google/cloud/storage"
111
109
  #
112
- # gcloud = Google::Cloud.new
113
- # storage = gcloud.storage
110
+ # storage = Google::Cloud::Storage.new
114
111
  #
115
112
  # bucket = storage.bucket "my-bucket"
116
113
  # files = bucket.files
@@ -119,10 +116,9 @@ module Google
119
116
  # end
120
117
  #
121
118
  # @example Using the enumerator by not passing a block:
122
- # require "google/cloud"
119
+ # require "google/cloud/storage"
123
120
  #
124
- # gcloud = Google::Cloud.new
125
- # storage = gcloud.storage
121
+ # storage = Google::Cloud::Storage.new
126
122
  #
127
123
  # bucket = storage.bucket "my-bucket"
128
124
  # files = bucket.files
@@ -132,10 +128,9 @@ module Google
132
128
  # end
133
129
  #
134
130
  # @example Limit the number of API calls made:
135
- # require "google/cloud"
131
+ # require "google/cloud/storage"
136
132
  #
137
- # gcloud = Google::Cloud.new
138
- # storage = gcloud.storage
133
+ # storage = Google::Cloud::Storage.new
139
134
  #
140
135
  # bucket = storage.bucket "my-bucket"
141
136
  # files = bucket.files