Class: Sndacs::Object
- Inherits:
-
Object
- Object
- Sndacs::Object
- Extended by:
- Forwardable
- Includes:
- Parser
- Defined in:
- lib/sndacs/object.rb
Overview
Class responsible for handling objects stored in CS buckets
Instance Attribute Summary collapse
-
#acl ⇒ Object
Returns the value of attribute acl.
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#cache_control ⇒ Object
Returns the value of attribute cache_control.
-
#content(reload = false) ⇒ Object
Downloads the content of the object, and caches it.
-
#content_disposition ⇒ Object
Returns the value of attribute content_disposition.
-
#content_encoding ⇒ Object
Returns the value of attribute content_encoding.
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#etag ⇒ Object
readonly
Returns the value of attribute etag.
-
#key ⇒ Object
Returns the value of attribute key.
-
#last_modified ⇒ Object
readonly
Returns the value of attribute last_modified.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#storage_class ⇒ Object
Returns the value of attribute storage_class.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Compares the object with other object.
-
#cname_url ⇒ Object
Returns Object’s CNAME URL (without
storage.grandcloud.cn
suffix) using protocol specified in Service, e.g. -
#copy(options = {}) ⇒ Object
copies the file from another key and/or bucket.
-
#destroy ⇒ Object
Destroys the file on the server.
-
#exists? ⇒ Boolean
Retrieves the object from the server, returns true if the object exists or false otherwise.
-
#full_key ⇒ Object
Returns full key of the object: e.g.
-
#inspect ⇒ Object
:nodoc:.
-
#retrieve ⇒ Object
Retrieves the object from the server.
-
#save(options = {}) ⇒ Object
Saves the object, returns true if successfull.
-
#temporary_url(expires_at = Time.now + 3600) ⇒ Object
Returns a temporary url to the object that expires on the timestamp given.
-
#url(public_accessible = false) ⇒ Object
Returns Object’s URL using protocol specified in service, Return url public reachable when the object is public accessible and public_accessible is true public_accessible given.Default to false e.g.
Methods included from Parser
#parse_all_buckets_result, #parse_all_objects_result, #parse_copy_object_result, #parse_error, #parse_is_truncated, #parse_location_constraint, #rexml_document
Instance Attribute Details
#acl ⇒ Object
Returns the value of attribute acl.
9 10 11 |
# File 'lib/sndacs/object.rb', line 9 def acl @acl end |
#bucket ⇒ Object
Returns the value of attribute bucket.
9 10 11 |
# File 'lib/sndacs/object.rb', line 9 def bucket @bucket end |
#cache_control ⇒ Object
Returns the value of attribute cache_control.
8 9 10 |
# File 'lib/sndacs/object.rb', line 8 def cache_control @cache_control end |
#content(reload = false) ⇒ Object
Downloads the content of the object, and caches it. Pass true to clear the cache and download the object again.
66 67 68 69 70 71 72 |
# File 'lib/sndacs/object.rb', line 66 def content(reload = false) return @content if defined?(@content) and not reload get_object @content end |
#content_disposition ⇒ Object
Returns the value of attribute content_disposition.
8 9 10 |
# File 'lib/sndacs/object.rb', line 8 def content_disposition @content_disposition end |
#content_encoding ⇒ Object
Returns the value of attribute content_encoding.
8 9 10 |
# File 'lib/sndacs/object.rb', line 8 def content_encoding @content_encoding end |
#content_type ⇒ Object
Returns the value of attribute content_type.
8 9 10 |
# File 'lib/sndacs/object.rb', line 8 def content_type @content_type end |
#etag ⇒ Object
Returns the value of attribute etag.
9 10 11 |
# File 'lib/sndacs/object.rb', line 9 def etag @etag end |
#key ⇒ Object
Returns the value of attribute key.
9 10 11 |
# File 'lib/sndacs/object.rb', line 9 def key @key end |
#last_modified ⇒ Object
Returns the value of attribute last_modified.
9 10 11 |
# File 'lib/sndacs/object.rb', line 9 def last_modified @last_modified end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
9 10 11 |
# File 'lib/sndacs/object.rb', line 9 def @metadata end |
#size ⇒ Object
Returns the value of attribute size.
9 10 11 |
# File 'lib/sndacs/object.rb', line 9 def size @size end |
#storage_class ⇒ Object
Returns the value of attribute storage_class.
9 10 11 |
# File 'lib/sndacs/object.rb', line 9 def storage_class @storage_class end |
Instance Method Details
#==(other) ⇒ Object
Compares the object with other object. Returns true if the key of the objects are the same, and both have the same buckets (see Bucket equality)
19 20 21 |
# File 'lib/sndacs/object.rb', line 19 def ==(other) other.equal?(self) || (other.instance_of?(self.class) && self.key == other.key && self.bucket == other.bucket) end |
#cname_url ⇒ Object
Returns Object’s CNAME URL (without storage.grandcloud.cn
suffix) using protocol specified in Service, e.g. http://domain.com/key/with/path.extension
. (you have to set the CNAME in your DNS before using the CNAME URL schema).
116 117 118 |
# File 'lib/sndacs/object.rb', line 116 def cname_url URI.escape("#{protocol}#{name}/#{key}") if bucket.vhost? end |
#copy(options = {}) ⇒ Object
copies the file from another key and/or bucket.
Options
-
:key
- key for copy -
:bucket
- bucket’s name which the source file stored -
:x_snda_metadata..
- params for copy which is not nessary
90 91 92 93 94 |
# File 'lib/sndacs/object.rb', line 90 def copy( = {}) copy_object() retrieve true end |
#destroy ⇒ Object
Destroys the file on the server
97 98 99 100 101 |
# File 'lib/sndacs/object.rb', line 97 def destroy delete_object true end |
#exists? ⇒ Boolean
Retrieves the object from the server, returns true if the object exists or false otherwise. Uses #retrieve method, but catches Sndacs::Error::NoSuchKey exception and returns false when it happens
135 136 137 138 139 140 141 |
# File 'lib/sndacs/object.rb', line 135 def exists? retrieve true rescue Error::NoSuchKey false end |
#full_key ⇒ Object
Returns full key of the object: e.g. bucket-name/object/key.ext
24 25 26 |
# File 'lib/sndacs/object.rb', line 24 def full_key [name, key].join("/") end |
#inspect ⇒ Object
:nodoc:
143 144 145 |
# File 'lib/sndacs/object.rb', line 143 def inspect #:nodoc: "#<#{self.class}:/#{name}/#{key}>" end |
#retrieve ⇒ Object
Retrieves the object from the server. Method is used to download object information only (content type, size and so on). It does NOT download the content of the object (use the #content method to do it).
58 59 60 61 62 |
# File 'lib/sndacs/object.rb', line 58 def retrieve object_headers self end |
#save(options = {}) ⇒ Object
Saves the object, returns true if successfull.
Options
request headers
78 79 80 81 |
# File 'lib/sndacs/object.rb', line 78 def save( = {}) put_object() true end |
#temporary_url(expires_at = Time.now + 3600) ⇒ Object
Returns a temporary url to the object that expires on the timestamp given. Defaults to 5min expire time.
122 123 124 125 126 127 128 129 130 |
# File 'lib/sndacs/object.rb', line 122 def temporary_url(expires_at = Time.now + 3600) url = URI.escape("#{protocol}#{host(true)}/#{path_prefix}#{key}") signature = Signature.generate_temporary_url_signature(:bucket => name, :resource => key, :expires_at => expires_at, :secret_access_key => secret_access_key) "#{url}?SNDAAccessKeyId=#{access_key_id}&Expires=#{expires_at.to_i.to_s}&Signature=#{signature}" end |
#url(public_accessible = false) ⇒ Object
Returns Object’s URL using protocol specified in service, Return url public reachable when the object is public accessible and public_accessible is true public_accessible given.Default to false e.g. http://storage.grandcloud.cn/bucket/key/file.extension
107 108 109 |
# File 'lib/sndacs/object.rb', line 107 def url(public_accessible = false) URI.escape("#{protocol}#{host(public_accessible)}/#{path_prefix}#{key}") end |