Class: BosClient::Bucket

Inherits:
Object
  • Object
show all
Defined in:
lib/bos_client/bucket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  @name = options[:name]
  @location = options[:location] || BosClient.location
  @creation_date = options[:creation_date]
  @bucket_host = "#{BosClient.scheme}://#{@name}.#{@location}.#{BosClient.url}"
end

Instance Attribute Details

#bucket_hostObject

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_dateObject

Returns the value of attribute creation_date.



4
5
6
# File 'lib/bos_client/bucket.rb', line 4

def creation_date
  @creation_date
end

#nameObject

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

Returns:

  • (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

#destoryObject

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, options = {}
  response = list_objects options.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 options = {}
  response = list_objects options
  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 options = {}
  response = list_objects options.merge({delimiter: '/'})
  objs = response[:data][:contents]
  objs.map { |obj| BosClient::Object.new ({bucket:self}.merge(obj)) }
end