Class: Fog::Aliyun::Storage::Directories

Inherits:
Collection
  • Object
show all
Defined in:
lib/fog/aliyun/models/storage/directories.rb

Instance Method Summary collapse

Instance Method Details

#allObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fog/aliyun/models/storage/directories.rb', line 12

def all
  buckets = service.get_service[0]
  return nil if buckets.size < 1
  data = []
  i = 0
  buckets.each do |b|
    data[i] = { key: b.name }
    i += 1
  end
  load(data)
end

#get(key, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fog/aliyun/models/storage/directories.rb', line 25

def get(key, options = {})
  data = service.get_bucket(key, options)

  directory = new(:key => key, :is_persisted => true)

  options = data[1]
  options[:max_keys] = options[:limit]
  directory.files.merge_attributes(options)

  objects = []
  i = 0
  data[0].each do |o|
    objects[i] = {
        'Key' => o.key,
        'Type' => o.type,
        'Size' => o.size,
        'ETag' => o.etag,
        'LastModified' => o.last_modified
    }
    i += 1
  end
  directory.files.load(objects)
  directory
rescue AliyunOssSdk::ServerError => error
  if error.error_code == "NoSuchBucket"
    nil
  else
    raise(error)
  end
end