Class: Aliyun::Oss::Struct::Object

Inherits:
Base
  • Object
show all
Defined in:
lib/aliyun/oss/struct/object.rb

Direct Known Subclasses

Directory, File

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Aliyun::Oss::Struct::Base

Instance Attribute Details

#bucketObject

bucket of object placed



31
32
33
# File 'lib/aliyun/oss/struct/object.rb', line 31

def bucket
  @bucket
end

#clientObject

reference to client



34
35
36
# File 'lib/aliyun/oss/struct/object.rb', line 34

def client
  @client
end

#etagObject

etag of object



12
13
14
# File 'lib/aliyun/oss/struct/object.rb', line 12

def etag
  @etag
end

#keyObject

Key of object



6
7
8
# File 'lib/aliyun/oss/struct/object.rb', line 6

def key
  @key
end

#last_modifiedObject

last modified time of object



9
10
11
# File 'lib/aliyun/oss/struct/object.rb', line 9

def last_modified
  @last_modified
end

#locationObject

location of object



28
29
30
# File 'lib/aliyun/oss/struct/object.rb', line 28

def location
  @location
end

#ownerObject

owner of object



25
26
27
# File 'lib/aliyun/oss/struct/object.rb', line 25

def owner
  @owner
end

#sizeObject

size of object



19
20
21
# File 'lib/aliyun/oss/struct/object.rb', line 19

def size
  @size
end

#storage_classObject

storage class of object



22
23
24
# File 'lib/aliyun/oss/struct/object.rb', line 22

def storage_class
  @storage_class
end

#typeObject

type of object



16
17
18
# File 'lib/aliyun/oss/struct/object.rb', line 16

def type
  @type
end

Class Method Details

.init_from_object(object, client) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/aliyun/oss/struct/object.rb', line 77

def init_from_object(object, client)
  if object.key?('Key') && object['Key'].end_with?('/')
    Struct::Directory.new(object.merge(client: client))
  elsif object.key?('Prefix') && object['Prefix'].end_with?('/')
    Struct::Directory.new(object.merge(client: client))
  else
    Struct::File.new(object.merge(client: client))
  end
end

.init_from_response(result, keys, client) ⇒ Object



71
72
73
74
75
# File 'lib/aliyun/oss/struct/object.rb', line 71

def init_from_response(result, keys, client)
  Utils.wrap(Utils.dig_value(result, *keys)).map do |object|
    init_from_object(object, client)
  end
end

Instance Method Details

#acl!String

Get ACL for object

Returns:

  • (String)

Raises:



41
42
43
44
45
# File 'lib/aliyun/oss/struct/object.rb', line 41

def acl!
  result = client.bucket_get_object_acl(key).parsed_response
  acl_keys = %w(AccessControlPolicy AccessControlList Grant)
  Utils.dig_value(result, *acl_keys).strip
end

#meta!(*args) ⇒ HTTParty::Response::Headers

Get meta information of object

Parameters:

  • headers (Hash)

    headers

Returns:

  • (HTTParty::Response::Headers)

Raises:



66
67
68
# File 'lib/aliyun/oss/struct/object.rb', line 66

def meta!(*args)
  client.bucket_get_meta_object(*args.unshift(key)).headers
end

#set_acl(acl) ⇒ true

Set ACL for object

Parameters:

  • acl (String)

    access value, supported value: private, public-read, public-read-write

Returns:

  • (true)

Raises:



54
55
56
# File 'lib/aliyun/oss/struct/object.rb', line 54

def set_acl(acl)
  !!client.bucket_set_object_acl(key, acl)
end