Class: WAZ::Blobs::Service
- Inherits:
-
Object
- Object
- WAZ::Blobs::Service
- Includes:
- Storage::SharedKeyCoreService
- Defined in:
- lib/waz/blobs/service.rb
Overview
This is internally used by the waz-blobs part of the gem and it exposes the Windows Azure Blob API REST methods implementation. You can use this class to perform an specific operation that isn’t provided by the current API.
Instance Attribute Summary
Attributes included from Storage::SharedKeyCoreService
#access_key, #account_name, #base_url, #type_of_service, #use_devenv, #use_ssl
Instance Method Summary collapse
-
#copy_blob(source_path, dest_path) ⇒ Object
Copies a blob within the same account (not necessarily to the same container).
-
#create_container(container_name) ⇒ Object
Creates a container on the current Windows Azure Storage account.
-
#delete_blob(path) ⇒ Object
Deletes the blob existing on the current path.
-
#delete_container(container_name) ⇒ Object
Deletes the given container from the Windows Azure Storage account.
-
#get_blob(path, options = {}) ⇒ Object
Retrieves a blob (content + headers) from the current path.
-
#get_blob_properties(path, options = {}) ⇒ Object
Retrieves the properties associated with the blob at the given path.
-
#get_container_acl(container_name) ⇒ Object
Retrieves the value of the :x_ms_prop_publicaccess header from the container properties indicating whether the container is publicly accessible or not.
-
#get_container_properties(container_name) ⇒ Object
Retrieves all the properties existing on the container.
-
#list_blobs(container_name) ⇒ Object
Lists all the blobs inside the given container.
-
#list_blocks(path, block_list_type = 'all') ⇒ Object
Retrieves the list of blocks associated with a single blob.
-
#list_containers(options = {}) ⇒ Object
Lists all the containers existing on the current storage account.
-
#put_blob(path, payload, content_type = "application/octet-stream", metadata = {}) ⇒ Object
Stores a blob on the given container.
-
#put_block(path, identifier, payload) ⇒ Object
Adds a block to the block list of the given blob.
-
#set_blob_properties(path, properties = {}) ⇒ Object
Sets the properties (metadata) associated to the blob at given path.
-
#set_container_acl(container_name, public_available = false) ⇒ Object
Sets the value of the :x_ms_prop_publicaccess header from the container properties indicating whether the container is publicly accessible or not.
-
#set_container_properties(container_name, properties = {}) ⇒ Object
Set the container properties (metadata).
-
#snapshot_blob(path) ⇒ Object
Creates a read-only snapshot of a blob as it looked like in time.
Methods included from Storage::SharedKeyCoreService
#canonicalize_headers, #canonicalize_message, #canonicalize_message20090919, #execute, #generate_request, #generate_request_uri, #generate_signature, #generate_signature20090919, #initialize
Instance Method Details
#copy_blob(source_path, dest_path) ⇒ Object
Copies a blob within the same account (not necessarily to the same container)
107 108 109 |
# File 'lib/waz/blobs/service.rb', line 107 def copy_blob(source_path, dest_path) execute :put, dest_path, nil, { :x_ms_version => "2009-09-19", :x_ms_copy_source => (source_path) } end |
#create_container(container_name) ⇒ Object
Creates a container on the current Windows Azure Storage account.
9 10 11 |
# File 'lib/waz/blobs/service.rb', line 9 def create_container(container_name) execute :put, container_name, {:restype => 'container'}, {:x_ms_version => '2009-09-19'} end |
#delete_blob(path) ⇒ Object
Deletes the blob existing on the current path.
92 93 94 |
# File 'lib/waz/blobs/service.rb', line 92 def delete_blob(path) execute :delete, path, nil, {:x_ms_version => "2009-09-19"} end |
#delete_container(container_name) ⇒ Object
Deletes the given container from the Windows Azure Storage account.
57 58 59 |
# File 'lib/waz/blobs/service.rb', line 57 def delete_container(container_name) execute :delete, container_name, {:restype => 'container'}, {:x_ms_version => '2009-09-19'} end |
#get_blob(path, options = {}) ⇒ Object
Retrieves a blob (content + headers) from the current path.
87 88 89 |
# File 'lib/waz/blobs/service.rb', line 87 def get_blob(path, = {}) execute :get, path, , {:x_ms_version => "2009-09-19"} end |
#get_blob_properties(path, options = {}) ⇒ Object
Retrieves the properties associated with the blob at the given path.
97 98 99 |
# File 'lib/waz/blobs/service.rb', line 97 def get_blob_properties(path, = {}) execute(:head, path, , {:x_ms_version => "2009-09-19"}).headers end |
#get_container_acl(container_name) ⇒ Object
Retrieves the value of the :x_ms_prop_publicaccess header from the container properties indicating whether the container is publicly accessible or not.
29 30 31 32 |
# File 'lib/waz/blobs/service.rb', line 29 def get_container_acl(container_name) headers = execute(:get, container_name, { :restype => 'container', :comp => 'acl' }, {:x_ms_version => '2009-09-19'}).headers headers[:x_ms_prop_publicaccess].downcase == true.to_s end |
#get_container_properties(container_name) ⇒ Object
Retrieves all the properties existing on the container.
14 15 16 |
# File 'lib/waz/blobs/service.rb', line 14 def get_container_properties(container_name) execute(:get, container_name, {:restype => 'container'}, {:x_ms_version => '2009-09-19'}).headers end |
#list_blobs(container_name) ⇒ Object
Lists all the blobs inside the given container.
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/waz/blobs/service.rb', line 62 def list_blobs(container_name) content = execute(:get, container_name, { :comp => 'list'}) doc = REXML::Document.new(content) containers = [] REXML::XPath.each(doc, '//Blob/') do |item| containers << { :name => REXML::XPath.first(item, "Name").text, :url => REXML::XPath.first(item, "Url").text, :content_type => REXML::XPath.first(item, "ContentType").text } end return containers end |
#list_blocks(path, block_list_type = 'all') ⇒ Object
Retrieves the list of blocks associated with a single blob. The list is filtered (or not) by type of blob
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/waz/blobs/service.rb', line 117 def list_blocks(path, block_list_type = 'all') raise WAZ::Storage::InvalidParameterValue , {:name => :blocklisttype, :values => ['all', 'uncommitted', 'committed']} unless (block_list_type or "") =~ /all|committed|uncommitted/i content = execute(:get, path, {:comp => 'blocklist'}.merge(:blocklisttype => block_list_type.downcase), { :x_ms_version => "2009-04-14" }) doc = REXML::Document.new(content) blocks = [] REXML::XPath.each(doc, '//Block/') do |item| blocks << { :name => REXML::XPath.first(item, "Name").text, :size => REXML::XPath.first(item, "Size").text, :committed => item.parent.name == "CommittedBlocks" } end return blocks end |
#list_containers(options = {}) ⇒ Object
Lists all the containers existing on the current storage account.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/waz/blobs/service.rb', line 44 def list_containers( = {}) content = execute(:get, nil, .merge(:comp => 'list')) doc = REXML::Document.new(content) containers = [] REXML::XPath.each(doc, '//Container/') do |item| containers << { :name => REXML::XPath.first(item, "Name").text, :url => REXML::XPath.first(item, "Url").text, :last_modified => REXML::XPath.first(item, "LastModified").text} end return containers end |
#put_blob(path, payload, content_type = "application/octet-stream", metadata = {}) ⇒ Object
Stores a blob on the given container.
Remarks path and payload are just text.
content_type is required by the blobs api, but on this method is defaulted to “application/octect-stream”
metadata is a hash that stores all the properties that you want to add to the blob when creating it.
81 82 83 84 |
# File 'lib/waz/blobs/service.rb', line 81 def put_blob(path, payload, content_type = "application/octet-stream", = {}) default_headers = {"Content-Type" => content_type, :x_ms_version => "2009-09-19", :x_ms_blob_type => "BlockBlob"} execute :put, path, nil, .merge(default_headers), payload end |
#put_block(path, identifier, payload) ⇒ Object
Adds a block to the block list of the given blob
112 113 114 |
# File 'lib/waz/blobs/service.rb', line 112 def put_block(path, identifier, payload) execute :put, path, { :comp => 'block', :blockid => identifier }, {'Content-Type' => "application/octet-stream"}, payload end |
#set_blob_properties(path, properties = {}) ⇒ Object
Sets the properties (metadata) associated to the blob at given path.
102 103 104 |
# File 'lib/waz/blobs/service.rb', line 102 def set_blob_properties(path, properties ={}) execute :put, path, { :comp => 'properties' }, properties.merge({:x_ms_version => "2009-09-19"}) end |
#set_container_acl(container_name, public_available = false) ⇒ Object
Sets the value of the :x_ms_prop_publicaccess header from the container properties indicating whether the container is publicly accessible or not.
Default is false
39 40 41 |
# File 'lib/waz/blobs/service.rb', line 39 def set_container_acl(container_name, public_available = false) execute :put, container_name, { :restype => 'container', :comp => 'acl' }, { :x_ms_prop_publicaccess => public_available.to_s, :x_ms_version => '2009-09-19' } end |
#set_container_properties(container_name, properties = {}) ⇒ Object
Set the container properties (metadata).
Remember that custom properties should be named as :x_ms_meta_propertyName in order to have Windows Azure to persist them.
22 23 24 |
# File 'lib/waz/blobs/service.rb', line 22 def set_container_properties(container_name, properties = {}) execute :put, container_name, { :restype => 'container', :comp => 'metadata' }, properties.merge!({:x_ms_version => '2009-09-19'}) end |
#snapshot_blob(path) ⇒ Object
Creates a read-only snapshot of a blob as it looked like in time.
131 132 133 |
# File 'lib/waz/blobs/service.rb', line 131 def snapshot_blob(path) execute(:put, path, { :comp => 'snapshot' }, {:x_ms_version => "2009-09-19"}).headers[:x_ms_snapshot] end |