Class: Aliyun::Oss::Bucket
- Inherits:
-
Object
- Object
- Aliyun::Oss::Bucket
- Defined in:
- lib/aliyunoss/bucket.rb
Instance Attribute Summary collapse
-
#creation_date ⇒ Object
Returns the value of attribute creation_date.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#extranet_endpoint ⇒ Object
Returns the value of attribute extranet_endpoint.
-
#intranet_endpoint ⇒ Object
Returns the value of attribute intranet_endpoint.
-
#location ⇒ Object
Returns the value of attribute location.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
-
.all ⇒ Object
Class method - List all buckets in my account.
-
.create(name, location = 'oss-cn-hangzhou') ⇒ Object
Class method - Create a new bucket.
Instance Method Summary collapse
-
#delete(path) ⇒ Object
Delete remote file.
-
#delete! ⇒ Object
delete this bucket.
- #disable_logging ⇒ Object
- #disable_website_access ⇒ Object
-
#download(path, options = {}) ⇒ Object
Download file from remote server.
- #enable_logging(target_bucket_name, log_prefix) ⇒ Object
- #enable_website_access(index_page, error_page) ⇒ Object
- #get_acl ⇒ Object
-
#initialize(params = {}) ⇒ Bucket
constructor
A new instance of Bucket.
-
#list_files(options = {}) ⇒ Object
List all files in an bucket.
- #logging_status ⇒ Object
- #multipart_abort(path, upload_id) ⇒ Object
- #multipart_copy_from(source_bucket, source_path, size, range = nil) ⇒ Object
-
#multipart_pending ⇒ Object
Multipart upload and copy.
- #multipart_upload(data) ⇒ Object
- #multipart_upload_complete ⇒ Object
- #multipart_upload_initiate(path) ⇒ Object
- #set_acl(permission) ⇒ Object
-
#share(path, expires_in = 3600) ⇒ Object
Generate a url that can be shared to others.
-
#upload(data, path, options = {}) ⇒ Object
Upload data to bucket.
- #website_access_status ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Bucket
Returns a new instance of Bucket.
7 8 9 10 11 12 13 |
# File 'lib/aliyunoss/bucket.rb', line 7 def initialize(params = {}) params.each_pair {|k,v| send("#{k.to_s}=", v) } if String === @creation_date @creation_date =~ /(\d+) ([a-zA-Z]+) (\d+) (\d\d):(\d\d):(\d\d)/ @creation_date = Time.gm($3, $2, $1, $4, $5, $6) end end |
Instance Attribute Details
#creation_date ⇒ Object
Returns the value of attribute creation_date.
5 6 7 |
# File 'lib/aliyunoss/bucket.rb', line 5 def creation_date @creation_date end |
#domain ⇒ Object
Returns the value of attribute domain.
5 6 7 |
# File 'lib/aliyunoss/bucket.rb', line 5 def domain @domain end |
#extranet_endpoint ⇒ Object
Returns the value of attribute extranet_endpoint.
5 6 7 |
# File 'lib/aliyunoss/bucket.rb', line 5 def extranet_endpoint @extranet_endpoint end |
#intranet_endpoint ⇒ Object
Returns the value of attribute intranet_endpoint.
5 6 7 |
# File 'lib/aliyunoss/bucket.rb', line 5 def intranet_endpoint @intranet_endpoint end |
#location ⇒ Object
Returns the value of attribute location.
5 6 7 |
# File 'lib/aliyunoss/bucket.rb', line 5 def location @location end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/aliyunoss/bucket.rb', line 5 def name @name end |
Class Method Details
.all ⇒ Object
Class method - List all buckets in my account
18 19 20 |
# File 'lib/aliyunoss/bucket.rb', line 18 def self.all Aliyun::Oss::API.list_bucket.raise_unless(Net::HTTPOK).to_buckets end |
.create(name, location = 'oss-cn-hangzhou') ⇒ Object
Class method - Create a new bucket
25 26 27 28 |
# File 'lib/aliyunoss/bucket.rb', line 25 def self.create(name, location = 'oss-cn-hangzhou') Aliyun::Oss::API.put_bucket(name, location).raise_unless(Net::HTTPOK) Bucket.new(:name => name, :location=> location, :creation_date => Time.now) end |
Instance Method Details
#delete(path) ⇒ Object
Delete remote file
63 64 65 |
# File 'lib/aliyunoss/bucket.rb', line 63 def delete(path) Aliyun::Oss::API.delete_object(self, path).raise_unless(Net::HTTPNoContent) end |
#delete! ⇒ Object
delete this bucket
122 123 124 |
# File 'lib/aliyunoss/bucket.rb', line 122 def delete! Aliyun::Oss::API.delete_bucket(self).raise_unless(Net::HTTPNoContent) end |
#disable_logging ⇒ Object
126 127 128 |
# File 'lib/aliyunoss/bucket.rb', line 126 def disable_logging Aliyun::Oss::API.delete_logging(self).raise_unless(Net::HTTPNoContent) end |
#disable_website_access ⇒ Object
138 139 140 |
# File 'lib/aliyunoss/bucket.rb', line 138 def disable_website_access Aliyun::Oss::API.delete_website(self).raise_unless(Net::HTTPNoContent) end |
#download(path, options = {}) ⇒ Object
Download file from remote server
47 48 49 50 51 |
# File 'lib/aliyunoss/bucket.rb', line 47 def download(path, = {}) Aliyun::Oss::API.get_object(self, path, ) .raise_unless(Net::HTTPOK) .body end |
#enable_logging(target_bucket_name, log_prefix) ⇒ Object
130 131 132 |
# File 'lib/aliyunoss/bucket.rb', line 130 def enable_logging(target_bucket_name, log_prefix) Aliyun::Oss::API.enable_bucket_logging(self, target_bucket_name, log_prefix).raise_unless(Net::HTTPOK) end |
#enable_website_access(index_page, error_page) ⇒ Object
142 143 144 |
# File 'lib/aliyunoss/bucket.rb', line 142 def enable_website_access(index_page, error_page) Aliyun::Oss::API.put_bucket_website(self, index_page, error_page).raise_unless(Net::HTTPOK) end |
#get_acl ⇒ Object
154 155 156 |
# File 'lib/aliyunoss/bucket.rb', line 154 def get_acl Aliyun::Oss::API.get_bucket_acl(self).raise_unless(Net::HTTPOK).to_acl_status end |
#list_files(options = {}) ⇒ Object
List all files in an bucket
33 34 35 |
# File 'lib/aliyunoss/bucket.rb', line 33 def list_files( = {}) Aliyun::Oss::API.list_object(self, ).raise_unless(Net::HTTPOK).to_objects end |
#logging_status ⇒ Object
134 135 136 |
# File 'lib/aliyunoss/bucket.rb', line 134 def logging_status Aliyun::Oss::API.get_bucket_logging(self).raise_unless(Net::HTTPOK).to_logging_status end |
#multipart_abort(path, upload_id) ⇒ Object
76 77 78 79 |
# File 'lib/aliyunoss/bucket.rb', line 76 def multipart_abort(path, upload_id) Aliyun::Oss::API.multipart_upload_abort(self, path, upload_id) .raise_unless(Net::HTTPNoContent) end |
#multipart_copy_from(source_bucket, source_path, size, range = nil) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/aliyunoss/bucket.rb', line 91 def multipart_copy_from(source_bucket, source_path, size, range = nil) response = Aliyun::Oss::API.multipart_upload_from_copy(@multipart_id, source_bucket, source_path, self, @multipart_path, @multipart_sequence, size, range) response.raise_unless(Net::HTTPOK) @multipart_list[@multipart_sequence] = response['ETag'] @multipart_sequence = @multipart_sequence + 1 end |
#multipart_pending ⇒ Object
Multipart upload and copy
70 71 72 73 74 |
# File 'lib/aliyunoss/bucket.rb', line 70 def multipart_pending Aliyun::Oss::API.multipart_upload_unfinished_task(self) .raise_unless(Net::HTTPOK) .to_mutlipart_task end |
#multipart_upload(data) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/aliyunoss/bucket.rb', line 81 def multipart_upload(data) raise 'You must call multipart_upload_initiate before upload data.' unless @multipart_path response = Aliyun::Oss::API.multipart_upload_part(self, @multipart_path, @multipart_id, data, @multipart_sequence) response.raise_unless(Net::HTTPOK) @multipart_list[@multipart_sequence] = response['ETag'] @multipart_sequence = @multipart_sequence + 1 end |
#multipart_upload_complete ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/aliyunoss/bucket.rb', line 111 def multipart_upload_complete Aliyun::Oss::API.multipart_upload_complete(self, @multipart_path, @multipart_id, @multipart_list) .raise_unless(Net::HTTPOK) @multipart_path = nil end |
#multipart_upload_initiate(path) ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/aliyunoss/bucket.rb', line 102 def multipart_upload_initiate(path) @multipart_path = path @multipart_id = Aliyun::Oss::API.multipart_upload_initiate(self, path) .raise_unless(Net::HTTPOK) .to_multipart_id @multipart_list = {} @multipart_sequence = 1 end |
#set_acl(permission) ⇒ Object
150 151 152 |
# File 'lib/aliyunoss/bucket.rb', line 150 def set_acl() Aliyun::Oss::API.put_bucket_acl(self, ).raise_unless(Net::HTTPOK) end |
#share(path, expires_in = 3600) ⇒ Object
Generate a url that can be shared to others
56 57 58 |
# File 'lib/aliyunoss/bucket.rb', line 56 def share(path, expires_in = 3600) Aliyun::Oss::API.generate_share_url(self, path, expires_in) end |
#upload(data, path, options = {}) ⇒ Object
Upload data to bucket
40 41 42 |
# File 'lib/aliyunoss/bucket.rb', line 40 def upload(data, path, = {}) Aliyun::Oss::API.put_object(self, path, data, ).raise_unless(Net::HTTPOK) end |
#website_access_status ⇒ Object
146 147 148 |
# File 'lib/aliyunoss/bucket.rb', line 146 def website_access_status Aliyun::Oss::API.get_bucket_website(self).raise_unless(Net::HTTPOK).to_website_status end |