Permalink
Browse files

Added support for continuation on list_containers

  • Loading branch information...
1 parent 23054cc commit 1127de4d20a2623857c7783bd6b796223a9b860c @shadysayed committed Sep 9, 2012
@@ -6,13 +6,33 @@ module Storage
class Azure
class Directories < Fog::Collection
model Fog::Storage::Azure::Directory
- def all
- data = connection.list_containers.body['Containers']
+ attribute :next_marker, :aliases => ['NextMarker']
+ attribute :marker, :aliases => ["Marker"]
+ attribute :prefix, :aliases => ['Prefix']
+ attribute :max_results, :aliases => ['MaxResuls']
+ def all(options = {})
+ response = connection.list_containers(options)
+ merge_attributes(response.body)
+ data = response.body['Containers']
load(data)
end
def get(key, options = {})
end
+
+ alias :each_dir_this_page :each
+ def each
+ if block_given?
+ subset = dup.all
+
+ subset.each_dir_this_page { |d| yield d }
+ while subset.next_marker != nil
+ subset = subset.all(:marker => subset.next_marker)
+ subset.each_dir_this_page { |d| yield d }
+ end
+ end
+ self
+ end
end
end
end
@@ -4,9 +4,11 @@ module Fog
module Storage
class Azure
class Directory < Fog::Model
- # identity :key, :aliases => ['name']
- identity :name, :aliases => ['Name']
- attribute :metadata
+ identity :key, :aliases => ['Name']
+ attribute :last_modified, :aliases => ['Last-Modified']
+ attribute :url, :aliases => ['Url']
+ attribute :etag, :aliases => ['Etag']
+ attribute :metadata, :aliases => ['Metadata']
end
end
end
@@ -8,18 +8,35 @@ def reset
@response = {'Containers' => []}
end
+ def start_element(name, attrs = [])
+ super
+ case name
+ when 'Metadata'
+ @in_metadata = true
+ @container['Metadata'] ||= {}
+ end
+ end
+
def end_element(name)
case name
when "Container"
- @response['Containers'] << @container
- @container = {}
+ unless @in_metadata
+ @response['Containers'] << @container
+ @container = {}
+ end
when "Name", "Url", "Etag"
- @container[name] = value
+ @container[name] = value unless @in_metadata
when "Last-Modified"
- @container[name] = Time.parse(value)
+ @container[name] = Time.parse(value) unless @in_metadata
#when "MaxResults"
- when "NextMarker"
- @response[name] = value
+ when "Prefix", "Marker", "NextMarker", "MaxResults"
+ @response[name] = value unless @in_metadata
+ when 'Metadata'
+ @in_metadata = false
+ end
+
+ if @in_metadata
+ @container['Metadata'][name] = value
end
end
end
@@ -5,15 +5,17 @@ class Real
require 'fog/azure/parsers/storage/list_containers'
def list_containers(options = {})
- # establish_connection do
- # WAZ::Blobs::Container.list.map{ |container| { name: container.name } }
- # end
+ # This operation will only nead to change the query string
+ # So the options hash is passed to the query and not headers
request(
expects: 200,
- headers: options,
+ headers: {},
method: :get,
parser: Fog::Parsers::Storage::Azure::ListContainers.new,
- query: {'comp' => 'list'}
+ query: {
+ 'comp' => 'list',
+ 'include' => 'metadata'
+ }.merge!(options || {})
)
end
end

0 comments on commit 1127de4

Please sign in to comment.