Class WAZ::Blobs::Service
In: lib/waz/blobs/service.rb
Parent: Object

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.

Methods

Included Modules

WAZ::Storage::SharedKeyCoreService

Public Instance methods

Copies a blob within the same account (not necessarily to the same container)

[Source]

     # File lib/waz/blobs/service.rb, line 125
125:       def copy_blob(source_path, dest_path)
126:         execute :put, dest_path, nil, { :x_ms_version => "2009-09-19", :x_ms_copy_source => canonicalize_message(source_path) }
127:       end

Creates a container on the current Windows Azure Storage account.

[Source]

    # File lib/waz/blobs/service.rb, line 9
 9:       def create_container(container_name)
10:         execute :put, container_name, {:restype => 'container'}, {:x_ms_version => '2009-09-19'}
11:       end

Deletes the blob existing on the current path.

[Source]

     # File lib/waz/blobs/service.rb, line 105
105:       def delete_blob(path)
106:         execute :delete, path, nil, {:x_ms_version => "2009-09-19"}
107:       end

Deletes the given container from the Windows Azure Storage account.

[Source]

    # File lib/waz/blobs/service.rb, line 57
57:       def delete_container(container_name)
58:         execute :delete, container_name, {:restype => 'container'}, {:x_ms_version => '2009-09-19'}
59:       end

Retrieves a blob (content + headers) from the current path.

[Source]

     # File lib/waz/blobs/service.rb, line 100
100:       def get_blob(path, options = {})
101:         execute :get, path, options, {:x_ms_version => "2009-09-19"}
102:       end

Retrieves the properties associated with the blob at the given path.

[Source]

     # File lib/waz/blobs/service.rb, line 110
110:       def get_blob_properties(path, options = {})
111:         execute(:head, path, options, {:x_ms_version => "2009-09-19"}).headers
112:       end

Retrieves the value of the :x_ms_prop_publicaccess header from the container properties indicating whether the container is publicly accessible or not.

[Source]

    # File lib/waz/blobs/service.rb, line 29
29:       def get_container_acl(container_name)
30:         headers = execute(:get, container_name, { :restype => 'container', :comp => 'acl' }, {:x_ms_version => '2009-09-19'}).headers
31:         headers[:x_ms_prop_publicaccess].downcase == true.to_s
32:       end

Retrieves all the properties existing on the container.

[Source]

    # File lib/waz/blobs/service.rb, line 14
14:       def get_container_properties(container_name)
15:         execute(:get, container_name, {:restype => 'container'}, {:x_ms_version => '2009-09-19'}).headers
16:       end

Lists all the blobs inside the given container.

[Source]

    # File lib/waz/blobs/service.rb, line 62
62:       def list_blobs(container_name)
63:         content = execute(:get, container_name, { :restype => 'container', :comp => 'list'}, {:x_ms_version => '2009-09-19'})
64:         doc = REXML::Document.new(content)
65:         containers = []
66:         REXML::XPath.each(doc, '//Blob/') do |item|
67:           containers << { :name => REXML::XPath.first(item, "Name").text,
68:                           :url => REXML::XPath.first(item, "Url").text,
69:                           :content_type =>  REXML::XPath.first(item.elements["Properties"], "Content-Type").text }
70: 
71:         end
72:         return containers
73:       end

Retrieves the list of blocks associated with a single blob. The list is filtered (or not) by type of blob

[Source]

     # File lib/waz/blobs/service.rb, line 135
135:       def list_blocks(path, block_list_type = 'all')
136:         raise WAZ::Storage::InvalidParameterValue , {:name => :blocklisttype, :values => ['all', 'uncommitted', 'committed']} unless (block_list_type or "") =~ /all|committed|uncommitted/i
137:         content = execute(:get, path, {:comp => 'blocklist'}.merge(:blocklisttype => block_list_type.downcase), { :x_ms_version => "2009-04-14" })
138:         doc = REXML::Document.new(content)
139:         blocks = []
140:         REXML::XPath.each(doc, '//Block/') do |item|
141:           blocks << { :name => REXML::XPath.first(item, "Name").text,
142:                       :size => REXML::XPath.first(item, "Size").text,
143:                       :committed => item.parent.name == "CommittedBlocks" }
144:         end
145:         return blocks
146:       end

Lists all the containers existing on the current storage account.

[Source]

    # File lib/waz/blobs/service.rb, line 44
44:       def list_containers(options = {})
45:         content = execute(:get, nil, options.merge(:comp => 'list'))
46:         doc = REXML::Document.new(content)
47:         containers = []
48:         REXML::XPath.each(doc, '//Container/') do |item|
49:           containers << { :name => REXML::XPath.first(item, "Name").text,
50:                           :url => REXML::XPath.first(item, "Url").text,
51:                           :last_modified => REXML::XPath.first(item, "LastModified").text}
52:         end
53:         return containers
54:       end

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.

[Source]

    # File lib/waz/blobs/service.rb, line 82
82:       def put_blob(path, payload, content_type = "application/octet-stream", metadata = {})
83:         default_headers = {"Content-Type" => content_type, :x_ms_version => "2009-09-19", :x_ms_blob_type => "BlockBlob"}
84:         execute :put, path, nil, metadata.merge(default_headers), payload
85:       end

Adds a block to the block list of the given blob

[Source]

     # File lib/waz/blobs/service.rb, line 130
130:       def put_block(path, identifier, payload)
131:         execute :put, path, { :comp => 'block', :blockid => identifier }, {'Content-Type' => "application/octet-stream"}, payload
132:       end

Commits a list of blocks to the given blob.

blockids is a list of valid, already-uploaded block IDs (base64-encoded)

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.

[Source]

    # File lib/waz/blobs/service.rb, line 94
94:       def put_block_list(path, blockids, content_type = "application/octet-stream", metadata = {})
95:         default_headers = {"Content-Type" => content_type, :x_ms_version => "2009-09-19"}
96:         execute :put, path, { :comp => 'blocklist' }, metadata.merge(default_headers), '<?xml version="1.0" encoding="utf-8"?><BlockList>' + blockids.map {|id| "<Latest>#{id.rstrip}</Latest>"}.join + '</BlockList>'
97:       end

Set user defined metadata - overwrites any previous metadata key:value pairs

[Source]

     # File lib/waz/blobs/service.rb, line 120
120:       def set_blob_metadata(path, metadata = {}) 
121:         execute :put, path, { :comp => 'metadata' }, metadata.merge({:x_ms_version => "2009-09-19"})
122:       end

Sets the properties (metadata) associated to the blob at given path.

[Source]

     # File lib/waz/blobs/service.rb, line 115
115:       def set_blob_properties(path, properties ={})
116:         execute :put, path, { :comp => 'properties' }, properties.merge({:x_ms_version => "2009-09-19"})
117:       end

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

[Source]

    # File lib/waz/blobs/service.rb, line 39
39:       def set_container_acl(container_name, public_available = false)
40:         execute :put, container_name, { :restype => 'container', :comp => 'acl' }, { :x_ms_prop_publicaccess => public_available.to_s, :x_ms_version => '2009-09-19' }
41:       end

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.

[Source]

    # File lib/waz/blobs/service.rb, line 22
22:       def set_container_properties(container_name, properties = {})
23:         execute :put, container_name, { :restype => 'container', :comp => 'metadata' }, properties.merge!({:x_ms_version => '2009-09-19'})
24:       end

Creates a read-only snapshot of a blob as it looked like in time.

[Source]

     # File lib/waz/blobs/service.rb, line 149
149:       def snapshot_blob(path)
150:         execute(:put, path, { :comp => 'snapshot' }, {:x_ms_version => "2009-09-19"}).headers[:x_ms_snapshot]
151:       end

[Validate]