Class: BosClient::Bucket
- Inherits:
-
Object
- Object
- BosClient::Bucket
- Defined in:
- lib/bos_client/bucket.rb
Instance Attribute Summary collapse
-
#bucket_host ⇒ Object
Returns the value of attribute bucket_host.
-
#creation_date ⇒ Object
Returns the value of attribute creation_date.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #accessable? ⇒ Boolean
-
#destory ⇒ Object
def save request = BosClient::Request.new @bucket_host, method: :put, params:params request.run end.
- #dir_objects(prefix, options = {}) ⇒ Object
- #dirs(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Bucket
constructor
A new instance of Bucket.
-
#objects(options = {}) ⇒ Object
objects.
Constructor Details
#initialize(options = {}) ⇒ Bucket
Returns a new instance of Bucket.
6 7 8 9 10 11 |
# File 'lib/bos_client/bucket.rb', line 6 def initialize( = {}) @name = [:name] @location = [:location] || BosClient.location @creation_date = [:creation_date] @bucket_host = "#{BosClient.scheme}://#{@name}.#{@location}.#{BosClient.url}" end |
Instance Attribute Details
#bucket_host ⇒ Object
Returns the value of attribute bucket_host.
4 5 6 |
# File 'lib/bos_client/bucket.rb', line 4 def bucket_host @bucket_host end |
#creation_date ⇒ Object
Returns the value of attribute creation_date.
4 5 6 |
# File 'lib/bos_client/bucket.rb', line 4 def creation_date @creation_date end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/bos_client/bucket.rb', line 4 def name @name end |
Instance Method Details
#accessable? ⇒ Boolean
13 14 15 16 17 |
# File 'lib/bos_client/bucket.rb', line 13 def accessable? request = BosClient::Request.new @bucket_host, method: :head response = request.run response[:result] end |
#destory ⇒ Object
def save
request = BosClient::Request.new @bucket_host, method: :put, params:params
request.run
end
27 28 29 30 31 |
# File 'lib/bos_client/bucket.rb', line 27 def destory request = BosClient::Request.new @bucket_host, method: :delete response = request.run response[:result] end |
#dir_objects(prefix, options = {}) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/bos_client/bucket.rb', line 47 def dir_objects prefix, = {} response = list_objects .merge({delimiter: '/',prefix:prefix}) data = response[:data][:contents] objs = data.find_all{|e| !is_dir?(e[:key]) } objs.map { |obj| BosClient::Object.new ({bucket:self}.merge(obj)) } end |
#dirs(options = {}) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/bos_client/bucket.rb', line 40 def dirs = {} response = list_objects data = response[:data][:contents] data = data.find_all{|e| is_dir?(e[:key]) } data.map { |e| e[:key] } end |
#objects(options = {}) ⇒ Object
objects
34 35 36 37 38 |
# File 'lib/bos_client/bucket.rb', line 34 def objects = {} response = list_objects .merge({delimiter: '/'}) objs = response[:data][:contents] objs.map { |obj| BosClient::Object.new ({bucket:self}.merge(obj)) } end |