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



25
26
27
28
29
# File 'lib/bos_client/bucket.rb', line 25

def destory
  request = BosClient::Request.new @bucket_host, method: :delete
  response = request.run
  response[:result]
end

#dir_objects(prefix, options = {}) ⇒ Object



45
46
47
48
49
50
# File 'lib/bos_client/bucket.rb', line 45

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



38
39
40
41
42
43
# File 'lib/bos_client/bucket.rb', line 38

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



32
33
34
35
36
# File 'lib/bos_client/bucket.rb', line 32

def objects(options = {})
  response = list_objects options.merge(delimiter: '/')
  objs = response[:data][:contents]
  objs.map { |obj| BosClient::Object.new ({bucket: self}.merge(obj)) }
end

#saveObject



19
20
21
22
23
# File 'lib/bos_client/bucket.rb', line 19

def save
  request = BosClient::Request.new @bucket_host, method: :put
  response = request.run
  response[:result]
end