oss 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +160 -12
- data/lib/oss/service.rb +1 -1
- data/lib/oss/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b6ac21fd62a512f849f4479d6ee4e00fc905cac
|
4
|
+
data.tar.gz: 86d458df9b9f4fdb76ddf236e397a4dce01546b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8eb1642cba5e9abbe9db0b344d596764a926803e7fdf3bcf16d27b34dec8530940f8c219d020730d1eef80b5552641b7fcd68410032f38a7085d7d9e6a88f7ba
|
7
|
+
data.tar.gz: 2dbb6f7ca282587052d6f3c28f031e704c0e101ddd87c31c9f19c65a17546fe016b18021ac5868539d602df7649249efdf8f025aabf5c662ac0e6bb7cfee218d
|
data/README.md
CHANGED
@@ -28,19 +28,9 @@ Go to OSS website, create a new account for new user.
|
|
28
28
|
|
29
29
|
After account created, you can create the OSS instance and get the `accessKeyId` and `accessKeySecret`.
|
30
30
|
|
31
|
-
###
|
32
|
-
|
33
|
-
#### 1. Initialize OSS API
|
34
|
-
|
35
|
-
```ruby
|
36
|
-
# require the gem if you not set in Gemfile
|
37
|
-
require 'oss'
|
31
|
+
### Rails Application
|
38
32
|
|
39
|
-
|
40
|
-
@api = Oss::Api.new(endpoint, access_key_id, access_key_secret)
|
41
|
-
```
|
42
|
-
|
43
|
-
Rails Application Config:
|
33
|
+
Config:
|
44
34
|
|
45
35
|
create `oss.yml` file in your rails application `config` path:
|
46
36
|
|
@@ -64,6 +54,22 @@ test:
|
|
64
54
|
<<: *default
|
65
55
|
```
|
66
56
|
|
57
|
+
Rails Application Usage Demo:
|
58
|
+
|
59
|
+
[http://git.oschina.net/raymond/oss-rails-demo](http://git.oschina.net/raymond/oss-rails-demo)
|
60
|
+
|
61
|
+
### Quick Start
|
62
|
+
|
63
|
+
#### 1. Initialize OSS API
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
# require the gem if you not set in Gemfile
|
67
|
+
require 'oss'
|
68
|
+
|
69
|
+
endpoint = 'oss-cn-hangzhou.aliyuncs.com'
|
70
|
+
@api = Oss::Api.new(endpoint, access_key_id, access_key_secret)
|
71
|
+
```
|
72
|
+
|
67
73
|
#### 2. Create New Bucket
|
68
74
|
|
69
75
|
```ruby
|
@@ -355,6 +361,10 @@ Success will return Hash:
|
|
355
361
|
- `allow_empty_referer` {Bool} allow empty request referer or not
|
356
362
|
- `referers` {Array} Referer white list
|
357
363
|
|
364
|
+
```ruby
|
365
|
+
puts @api.get_bucket_referer('bucket_name')
|
366
|
+
```
|
367
|
+
|
358
368
|
#### .get_bucket_website(bucket_name)
|
359
369
|
|
360
370
|
Get the bucket website config.
|
@@ -367,6 +377,10 @@ Success will return Hash:
|
|
367
377
|
- `index_doc` {String} index page
|
368
378
|
- `error_doc` {String} error page, maybe nil
|
369
379
|
|
380
|
+
```ruby
|
381
|
+
puts @api.get_bucket_website('bucket_name')
|
382
|
+
```
|
383
|
+
|
370
384
|
#### .get_bucket_lifecycle(bucket_name)
|
371
385
|
|
372
386
|
Get the bucket object lifecycle.
|
@@ -381,6 +395,10 @@ Success will return lifecycle rules Array:
|
|
381
395
|
- `[days]` {Number} expire after the days
|
382
396
|
- `[date]` {String} expire date, e.g.: `2022-10-11T00:00:00.000Z` date and days only has one.
|
383
397
|
|
398
|
+
```ruby
|
399
|
+
puts @api.get_bucket_lifecycle('bucket_name')
|
400
|
+
```
|
401
|
+
|
384
402
|
#### .delete_bucket_logging(bucket_name)
|
385
403
|
|
386
404
|
Delete the bucket logging settings.
|
@@ -390,6 +408,10 @@ parameters:
|
|
390
408
|
|
391
409
|
Success will return true
|
392
410
|
|
411
|
+
```ruby
|
412
|
+
puts @api.delete_bucket_logging('bucket_name')
|
413
|
+
```
|
414
|
+
|
393
415
|
#### .delete_bucket_website(bucket_name)
|
394
416
|
|
395
417
|
Delete the bucket website config.
|
@@ -399,6 +421,10 @@ parameters:
|
|
399
421
|
|
400
422
|
Success will return true
|
401
423
|
|
424
|
+
```ruby
|
425
|
+
puts @api.delete_bucket_website('bucket_name')
|
426
|
+
```
|
427
|
+
|
402
428
|
#### .delete_bucket_lifecycle(bucket_name)
|
403
429
|
|
404
430
|
Delete the bucket object lifecycle.
|
@@ -408,6 +434,10 @@ parameters:
|
|
408
434
|
|
409
435
|
Success will return true
|
410
436
|
|
437
|
+
```ruby
|
438
|
+
puts @api.delete_bucket_lifecycle('bucket_name')
|
439
|
+
```
|
440
|
+
|
411
441
|
#### .delete_bucket(bucket_name)
|
412
442
|
|
413
443
|
Delete an empty bucket.
|
@@ -416,6 +446,10 @@ Delete an empty bucket.
|
|
416
446
|
|
417
447
|
Success will return true
|
418
448
|
|
449
|
+
```ruby
|
450
|
+
puts @api.delete_bucket('bucket_name')
|
451
|
+
```
|
452
|
+
|
419
453
|
### Object Operations
|
420
454
|
Class `Oss::Object`
|
421
455
|
|
@@ -438,6 +472,11 @@ parameters:
|
|
438
472
|
|
439
473
|
Success will return true
|
440
474
|
|
475
|
+
```ruby
|
476
|
+
file = File.read('/path/to/your/file')
|
477
|
+
puts @api.put_object('bucket_name', 'object_name', file)
|
478
|
+
```
|
479
|
+
|
441
480
|
#### .copy_object(bucket_name, object, old_bucket, old_object, options)
|
442
481
|
|
443
482
|
To copy an existing object on OSS to form another object.
|
@@ -461,6 +500,12 @@ Success will return Hash:
|
|
461
500
|
- `last_modify` the object last modify time
|
462
501
|
- `etag` the object etag
|
463
502
|
|
503
|
+
```ruby
|
504
|
+
result = @api.copy_object('bucket_name', 'object_name', 'old_bucket', 'old_object')
|
505
|
+
puts result[:last_modify]
|
506
|
+
puts result[:etag]
|
507
|
+
```
|
508
|
+
|
464
509
|
#### .get_object(bucket_name, object, options)
|
465
510
|
|
466
511
|
Get an object from the bucket.
|
@@ -504,6 +549,13 @@ Success will return Hash:
|
|
504
549
|
- `hash_crc64ecma` {String} append object hash crc64
|
505
550
|
- `next_append_position` {String} next append position
|
506
551
|
|
552
|
+
```ruby
|
553
|
+
file = File.read('/path/to/your/file')
|
554
|
+
result = @api.append_object('bucket_name', 'object_name', file, 'old_object', 0)
|
555
|
+
puts result[:hash_crc64ecma]
|
556
|
+
puts result[:next_append_position]
|
557
|
+
```
|
558
|
+
|
507
559
|
#### .delete_object(bucket_name, object_name)
|
508
560
|
|
509
561
|
Delete the object.
|
@@ -514,6 +566,10 @@ parameters:
|
|
514
566
|
|
515
567
|
Success will return true
|
516
568
|
|
569
|
+
```ruby
|
570
|
+
puts @api.delete_object('bucket_name', 'object_name')
|
571
|
+
```
|
572
|
+
|
517
573
|
#### .delete_multiple_objects(bucket_name, objects)
|
518
574
|
|
519
575
|
Delete multiple objects.
|
@@ -524,6 +580,10 @@ parameters:
|
|
524
580
|
|
525
581
|
Success will return success deleted object names
|
526
582
|
|
583
|
+
```ruby
|
584
|
+
puts @api.delete_multiple_objects('bucket_name', ['object_name1', 'object_name2'])
|
585
|
+
```
|
586
|
+
|
527
587
|
#### .head_object(bucket_name, object_name, options)
|
528
588
|
|
529
589
|
Head an object and get the meta info.
|
@@ -539,6 +599,10 @@ parameters:
|
|
539
599
|
|
540
600
|
Success will return response headers
|
541
601
|
|
602
|
+
```ruby
|
603
|
+
puts @api.head_object('bucket_name', 'object_name')
|
604
|
+
```
|
605
|
+
|
542
606
|
#### .put_object_acl(bucket_name, object_name, acl)
|
543
607
|
|
544
608
|
Set the object ACL.
|
@@ -550,6 +614,10 @@ parameters:
|
|
550
614
|
|
551
615
|
Success will return true
|
552
616
|
|
617
|
+
```ruby
|
618
|
+
puts @api.put_object_acl('bucket_name', 'object_name', 'public-read')
|
619
|
+
```
|
620
|
+
|
553
621
|
#### .get_object_acl(bucket_name, object_name)
|
554
622
|
|
555
623
|
Get the object ACL.
|
@@ -563,6 +631,10 @@ Success will return Hash:
|
|
563
631
|
- `grant` {String} acl settings string
|
564
632
|
- `owner` {Hash} object owner, including `id` and `display_name`
|
565
633
|
|
634
|
+
```ruby
|
635
|
+
puts @api.get_object_acl('bucket_name', 'object_name')
|
636
|
+
```
|
637
|
+
|
566
638
|
#### .post_object(bucket_name, key, options)
|
567
639
|
|
568
640
|
Create form post upload parameters.
|
@@ -574,6 +646,11 @@ parameters:
|
|
574
646
|
|
575
647
|
return form post need parameters including `OSSAccessKeyId` `Signature`
|
576
648
|
|
649
|
+
```ruby
|
650
|
+
@form_info = @api.post_object('bucket_name', 'object_name', options)
|
651
|
+
# render @form_info in views
|
652
|
+
```
|
653
|
+
|
577
654
|
### Multipart Upload Operations
|
578
655
|
Class `Oss::Multipart`
|
579
656
|
|
@@ -596,6 +673,13 @@ Success will return Hash:
|
|
596
673
|
- `key` {String} key
|
597
674
|
- `upload_id` {String} upload_id
|
598
675
|
|
676
|
+
```ruby
|
677
|
+
result = @api.initiate_multipart_upload('bucket_name', 'object_name')
|
678
|
+
put result[:bucket]
|
679
|
+
put result[:key]
|
680
|
+
put result[:upload_id]
|
681
|
+
```
|
682
|
+
|
599
683
|
#### .upload_part(bucket_name, object_name, upload_id, file, part_number, options)
|
600
684
|
|
601
685
|
After a Multipart Upload is initialized, data can be uploaded by part according to the specified Object name and Upload ID. Each part uploaded has an identification number (Part number, range: 1-10,000).
|
@@ -612,6 +696,13 @@ Success will return Hash:
|
|
612
696
|
- `etag` {String} part etag
|
613
697
|
- `part_number` {String} part_number
|
614
698
|
|
699
|
+
```ruby
|
700
|
+
file = File.read('/file/to/path')
|
701
|
+
result = @api.upload_part('bucket_name', 'object_name', upload_id, 1, file)
|
702
|
+
put result[:etag]
|
703
|
+
put result[:part_number]
|
704
|
+
```
|
705
|
+
|
615
706
|
#### .upload_part_copy(bucket_name, object_name, upload_id, old_bucket, old_object, part_number, options)
|
616
707
|
|
617
708
|
The interface Upload Part Copy is used to upload a Part data by copying the data from an existing Object.
|
@@ -634,6 +725,13 @@ Success will return Hash:
|
|
634
725
|
- `etag` {String} part etag
|
635
726
|
- `last_modify` {String} object last modify time
|
636
727
|
|
728
|
+
```ruby
|
729
|
+
options = {copy_source_begin: 0, copy_source_end: 1024}
|
730
|
+
result = @api.upload_part_copy('bucket_name', 'object_name', upload_id, 'old_bucket', 'old_object', 1, options)
|
731
|
+
put result[:etag]
|
732
|
+
put result[:last_modify]
|
733
|
+
```
|
734
|
+
|
637
735
|
#### .complete_multipart_upload(bucket_name, object_name, upload_id, parts)
|
638
736
|
|
639
737
|
After all the Part data are uploaded, the API of Complete Multipart Upload must be called to complete the Multipart Upload of the entire file.
|
@@ -650,6 +748,15 @@ Success will return Hash:
|
|
650
748
|
- `key` {String} object key
|
651
749
|
- `etag` {String} object etag
|
652
750
|
|
751
|
+
```ruby
|
752
|
+
parts = [{etag: 'etag1', part_number: 1}, {etag: 'etag2', part_number: 2}]
|
753
|
+
result = @api.complete_multipart_upload('bucket_name', 'object_name', upload_id, parts)
|
754
|
+
put result[:location]
|
755
|
+
put result[:bucket]
|
756
|
+
put result[:key]
|
757
|
+
put result[:etag]
|
758
|
+
```
|
759
|
+
|
653
760
|
#### .abort_multipart_upload(bucket_name, object_name, upload_id)
|
654
761
|
|
655
762
|
This interface can be used to abort a Multipart Upload event according to the corresponding Upload ID offered by the user.
|
@@ -661,6 +768,10 @@ parameters:
|
|
661
768
|
|
662
769
|
Success will return true
|
663
770
|
|
771
|
+
```ruby
|
772
|
+
puts @api.abort_multipart_upload('bucket_name', 'object_name', upload_id)
|
773
|
+
```
|
774
|
+
|
664
775
|
#### .list_multipart_upload(bucket_name, options)
|
665
776
|
|
666
777
|
This interface can list all Multipart Upload events under execution, which means all the events initialized but neither completed nor aborted.
|
@@ -683,6 +794,15 @@ return uploads Array including Hash:
|
|
683
794
|
- `upload_id` {String} upload id
|
684
795
|
- `initiated` {String} initiated time
|
685
796
|
|
797
|
+
```ruby
|
798
|
+
list = @api.list_multipart_upload('bucket_name', upload_id)
|
799
|
+
list.uploads.each do |object|
|
800
|
+
puts object[:key]
|
801
|
+
puts object[:upload_id]
|
802
|
+
puts object[:initiated]
|
803
|
+
end
|
804
|
+
```
|
805
|
+
|
686
806
|
#### .list_parts(bucket_name, object_name, options)
|
687
807
|
|
688
808
|
The interface List Parts can be used to list all Parts corresponding to a specified Upload ID which have been successfully uploaded.
|
@@ -704,6 +824,16 @@ return parts Array including Hash:
|
|
704
824
|
- `etag` {String} part etag
|
705
825
|
- `size` {String} part size
|
706
826
|
|
827
|
+
```ruby
|
828
|
+
list = @api.list_parts('bucket_name', 'object_name')
|
829
|
+
list.parts.each do |part|
|
830
|
+
puts part[:part_number]
|
831
|
+
puts part[:last_modified]
|
832
|
+
puts part[:etag]
|
833
|
+
puts part[:size]
|
834
|
+
end
|
835
|
+
```
|
836
|
+
|
707
837
|
### CORS (Cross-Origin Resource Sharing) Operations
|
708
838
|
Class `Oss::Cors`
|
709
839
|
|
@@ -717,6 +847,11 @@ parameters:
|
|
717
847
|
|
718
848
|
Success will return true
|
719
849
|
|
850
|
+
```ruby
|
851
|
+
rules = [[{key: 'AllowedOrigin', value: '*'}, {key: 'AllowedMethod', value: 'GET'}], [{key: 'AllowedOrigin', value: 'http://www.a.com'}, {key: 'AllowedMethod', value: 'PUT'}]]
|
852
|
+
puts @api.put_bucket_cors('bucket_name', rules)
|
853
|
+
```
|
854
|
+
|
720
855
|
#### .get_bucket_cors(bucket_name)
|
721
856
|
|
722
857
|
The operation of Get Bucket cors operation is used to get the current CORS rules in the specified Bucket.
|
@@ -726,6 +861,10 @@ parameters:
|
|
726
861
|
|
727
862
|
Success will return rules Array
|
728
863
|
|
864
|
+
```ruby
|
865
|
+
puts @api.get_bucket_cors('bucket_name')
|
866
|
+
```
|
867
|
+
|
729
868
|
#### .delete_bucket_cors(bucket_name)
|
730
869
|
|
731
870
|
The Delete Bucket cors operation is used to disable the CORS function corresponding to the specified Bucket and remove all the rules.
|
@@ -735,6 +874,10 @@ parameters:
|
|
735
874
|
|
736
875
|
Success will return true
|
737
876
|
|
877
|
+
```ruby
|
878
|
+
puts @api.delete_bucket_cors('bucket_name')
|
879
|
+
```
|
880
|
+
|
738
881
|
#### .option_object(bucket_name, object_name, origin, request_method, request_headers)
|
739
882
|
|
740
883
|
Before sending the cross-origin request, the browser will first send a preflight request (OPTIONS) with specific source origin, HTTP method, and header information to OSS so that it can decide whether to send the real request.
|
@@ -748,6 +891,11 @@ parameters:
|
|
748
891
|
|
749
892
|
Success will return response headers
|
750
893
|
|
894
|
+
```ruby
|
895
|
+
result = @api.option_object('bucket_name', 'object_name', 'Origin', 'GET', request_headers)
|
896
|
+
puts result.headers
|
897
|
+
```
|
898
|
+
|
751
899
|
## Run Rake Unit Test
|
752
900
|
|
753
901
|
`id=accessKeyId secret=accessKeyIdSecret rake test -I --order=a`
|
data/lib/oss/service.rb
CHANGED
data/lib/oss/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RaymondChou
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|