Skip to content

Commit

Permalink
[aws&google|storage] parse/return CommonPrefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed Nov 19, 2010
1 parent 5854e24 commit 3973d5f
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/fog/aws/models/storage/directories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get(key, options = {})
directory = new(:key => data['Name'])
options = {}
for k, v in data
if ['Delimiter', 'IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(k)
if ['CommonPrefixes', 'Delimiter', 'IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(k)
options[k] = v
end
end
Expand Down
11 changes: 6 additions & 5 deletions lib/fog/aws/models/storage/files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ class Storage

class Files < Fog::Collection

attribute :delimiter, :aliases => 'Delimiter'
attribute :common_prefixes, :aliases => 'CommonPrefixes'
attribute :delimiter, :aliases => 'Delimiter'
attribute :directory
attribute :is_truncated, :aliases => 'IsTruncated'
attribute :marker, :aliases => 'Marker'
attribute :max_keys, :aliases => ['MaxKeys', 'max-keys']
attribute :prefix, :aliases => 'Prefix'
attribute :is_truncated, :aliases => 'IsTruncated'
attribute :marker, :aliases => 'Marker'
attribute :max_keys, :aliases => ['MaxKeys', 'max-keys']
attribute :prefix, :aliases => 'Prefix'

model Fog::AWS::Storage::File

Expand Down
20 changes: 18 additions & 2 deletions lib/fog/aws/parsers/storage/get_bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@ class GetBucket < Fog::Parsers::Base

def reset
@object = { 'Owner' => {} }
@response = { 'Contents' => [] }
@response = { 'Contents' => [], 'CommonPrefixes' => [] }
end

def start_element(name, attrs = [])
super
case name
when 'CommonPrefixes'
@in_common_prefixes = true
end
end

def end_element(name)
case name
when 'CommonPrefixes'
@in_common_prefixes = false
when 'Contents'
@response['Contents'] << @object
@object = { 'Owner' => {} }
Expand All @@ -27,10 +37,16 @@ def end_element(name)
end
when 'LastModified'
@object['LastModified'] = Time.parse(@value)
when 'Marker', 'Name', 'Prefix'
when 'Marker', 'Name'
@response[name] = @value
when 'MaxKeys'
@response['MaxKeys'] = @value.to_i
when 'Prefix'
if @in_common_prefixes
@response['CommonPrefixes'] << @value
else
@response[name] = @value
end
when 'Size'
@object['Size'] = @value.to_i
when 'Delimeter', 'Key', 'StorageClass'
Expand Down
1 change: 1 addition & 0 deletions lib/fog/aws/requests/storage/get_bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Real
# * 'MaxKeys'<~Integer> - Maximum number of keys specified for query
# * 'Name'<~String> - Name of the bucket
# * 'Prefix'<~String> - Prefix specified for query
# * 'CommonPrefixes'<~Array> - Array of strings for common prefixes
# * 'Contents'<~Array>:
# * 'ETag'<~String>: Etag of object
# * 'Key'<~String>: Name of object
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/google/models/storage/directories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get(key, options = {})
directory = new(:key => data['Name'])
options = {}
for k, v in data
if ['Delimiter', 'IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(k)
if ['CommonPrefixes', 'Delimiter', 'IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(k)
options[k] = v
end
end
Expand Down
11 changes: 6 additions & 5 deletions lib/fog/google/models/storage/files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ class Storage

class Files < Fog::Collection

attribute :delimiter, :aliases => 'Delimiter'
attribute :common_prefixes, :aliases => 'CommonPrefixes'
attribute :delimiter, :aliases => 'Delimiter'
attribute :directory
attribute :is_truncated, :aliases => 'IsTruncated'
attribute :marker, :aliases => 'Marker'
attribute :max_keys, :aliases => ['MaxKeys', 'max-keys']
attribute :prefix, :aliases => 'Prefix'
attribute :is_truncated, :aliases => 'IsTruncated'
attribute :marker, :aliases => 'Marker'
attribute :max_keys, :aliases => ['MaxKeys', 'max-keys']
attribute :prefix, :aliases => 'Prefix'

model Fog::Google::Storage::File

Expand Down
20 changes: 18 additions & 2 deletions lib/fog/google/parsers/storage/get_bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@ class GetBucket < Fog::Parsers::Base

def reset
@object = { 'Owner' => {} }
@response = { 'Contents' => [] }
@response = { 'Contents' => [], 'CommonPrefixes' => [] }
end

def start_element(name, attrs = [])
super
case name
when 'CommonPrefixes'
@in_common_prefixes = true
end
end

def end_element(name)
case name
when 'CommonPrefixes'
@in_common_prefixes = false
when 'Contents'
@response['Contents'] << @object
@object = { 'Owner' => {} }
Expand All @@ -27,10 +37,16 @@ def end_element(name)
end
when 'LastModified'
@object['LastModified'] = Time.parse(@value)
when 'Marker', 'Name', 'Prefix'
when 'Marker', 'Name'
@response[name] = @value
when 'MaxKeys'
@response['MaxKeys'] = @value.to_i
when 'Prefix'
if @in_common_prefixes
@response['CommonPrefixes'] << @value
else
@response[name] = @value
end
when 'Size'
@object['Size'] = @value.to_i
when 'Delimeter', 'Key', 'StorageClass'
Expand Down
1 change: 1 addition & 0 deletions lib/fog/google/requests/storage/get_bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Real
# * 'MaxKeys'<~Integer> - Maximum number of keys specified for query
# * 'Name'<~String> - Name of the bucket
# * 'Prefix'<~String> - Prefix specified for query
# * 'CommonPrefixes'<~Array> - Array of strings for common prefixes
# * 'Contents'<~Array>:
# * 'ETag'<~String>: Etag of object
# * 'Key'<~String>: Name of object
Expand Down

0 comments on commit 3973d5f

Please sign in to comment.