Class: Openstack::Swift::Client
- Inherits:
-
Object
- Object
- Openstack::Swift::Client
- Defined in:
- lib/openstack-swift/client.rb
Instance Method Summary collapse
-
#account_info ⇒ Object
Returns the following informations about the object: bytes_used: Number of bytes used by this account object_count: Number of objects that this account have allocated container_count: Number of container.
-
#authenticate! ⇒ Object
Authentication method It stores the authentication url and token for future commands avoiding to request a new token for each request It should be used to force a new token.
-
#delete(container, object) ⇒ Object
Delete a given object from a given container.
-
#download(container, object, options = {}) ⇒ Object
This method downloads a object from a given container.
-
#initialize(proxy, user, password) ⇒ Client
constructor
Initialize method It uses the authenticate method to store the tokens for future requests.
-
#object_info(container, object) ⇒ Object
Returns the following informations about the account: last_modified md5 content_type manifest content_length.
-
#upload(container, file_path, options = {}) ⇒ Object
This method uploads a file from a given to a given container.
Constructor Details
#initialize(proxy, user, password) ⇒ Client
Initialize method It uses the authenticate method to store the tokens for future requests
7 8 9 10 |
# File 'lib/openstack-swift/client.rb', line 7 def initialize(proxy, user, password) @proxy, @user, @password = proxy, user, password authenticate! end |
Instance Method Details
#account_info ⇒ Object
Returns the following informations about the object:
bytes_used: Number of bytes used by this account
object_count: Number of objects that this account have allocated
container_count: Number of container
30 31 32 33 34 35 36 37 |
# File 'lib/openstack-swift/client.rb', line 30 def account_info headers = Api.account(@url, @token) { "bytes_used" => headers["x-account-bytes-used"], "object_count" => headers["x-account-object-count"], "container_count" => headers["x-account-container-count"] } end |
#authenticate! ⇒ Object
Authentication method It stores the authentication url and token for future commands avoiding to request a new token for each request It should be used to force a new token
16 17 18 19 20 21 22 23 24 |
# File 'lib/openstack-swift/client.rb', line 16 def authenticate! @url, _, @token = Api.auth(@proxy, @user, @password) if @url.blank? or @token.blank? raise AuthenticationError else true end end |
#delete(container, object) ⇒ Object
Delete a given object from a given container
67 68 69 70 71 72 73 |
# File 'lib/openstack-swift/client.rb', line 67 def delete(container, object) if object_info(container, object)["manifest"] Api.delete_objects_from_manifest(@url, @token, container, object) else Api.delete_object(@url, @token, container, object) end end |
#download(container, object, options = {}) ⇒ Object
This method downloads a object from a given container
62 63 64 |
# File 'lib/openstack-swift/client.rb', line 62 def download(container, object, ={}) Api.download_object(@url, @token, container, object, [:file_path]) end |
#object_info(container, object) ⇒ Object
Returns the following informations about the account:
last_modified
md5
content_type
manifest
content_length
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/openstack-swift/client.rb', line 45 def object_info(container, object) headers = Api.object_stat(@url, @token, container, object) { "last_modified" => headers["last-modified"], "md5" => headers["etag"], "content_type" => headers["content-type"], "manifest" => headers["x-object-manifest"], "content_length" => headers["content-length"] } end |
#upload(container, file_path, options = {}) ⇒ Object
This method uploads a file from a given to a given container
57 58 59 |
# File 'lib/openstack-swift/client.rb', line 57 def upload(container, file_path, ={}) Api.upload_object(@url, @token, container, file_path, ) end |