Class: S33r::BucketListing
- Inherits:
-
Hash
- Object
- Hash
- S33r::BucketListing
- Defined in:
- lib/s33r/bucket_listing.rb
Overview
Represents a ListBucketResult (see docs.amazonwebservices.com/AmazonS3/2006-03-01/)
Instance Attribute Summary collapse
-
#common_prefixes ⇒ Object
readonly
Returns the value of attribute common_prefixes.
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#delimiter ⇒ Object
readonly
Returns the value of attribute delimiter.
-
#is_truncated ⇒ Object
readonly
Returns the value of attribute is_truncated.
-
#marker ⇒ Object
readonly
Returns the value of attribute marker.
-
#max_keys ⇒ Object
readonly
Returns the value of attribute max_keys.
-
#name ⇒ Object
readonly
Name of the bucket this listing is for.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
-
#initialize(bucket_listing_xml) ⇒ BucketListing
constructor
bucket_listing_xml
is a ListBucketResult document, as returned from a GET on a bucket. -
#parse_listing(bucket_listing_xml) ⇒ Object
Parse raw XML ListBucketResponse from S3 into object instances.
-
#set_listing_xml(bucket_listing_xml) ⇒ Object
Convert a ListBucketResult XML document into an object representation.
Constructor Details
#initialize(bucket_listing_xml) ⇒ BucketListing
bucket_listing_xml
is a ListBucketResult document, as returned from a GET on a bucket. bucket
is a Bucket instance; any objects in the listing are assigned to this bucket.
12 13 14 15 |
# File 'lib/s33r/bucket_listing.rb', line 12 def initialize(bucket_listing_xml) @common_prefixes = [] set_listing_xml(bucket_listing_xml) end |
Instance Attribute Details
#common_prefixes ⇒ Object (readonly)
Returns the value of attribute common_prefixes.
8 9 10 |
# File 'lib/s33r/bucket_listing.rb', line 8 def common_prefixes @common_prefixes end |
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
8 9 10 |
# File 'lib/s33r/bucket_listing.rb', line 8 def contents @contents end |
#delimiter ⇒ Object
Returns the value of attribute delimiter.
8 9 10 |
# File 'lib/s33r/bucket_listing.rb', line 8 def delimiter @delimiter end |
#is_truncated ⇒ Object
Returns the value of attribute is_truncated.
8 9 10 |
# File 'lib/s33r/bucket_listing.rb', line 8 def is_truncated @is_truncated end |
#marker ⇒ Object
Returns the value of attribute marker.
8 9 10 |
# File 'lib/s33r/bucket_listing.rb', line 8 def marker @marker end |
#max_keys ⇒ Object
Returns the value of attribute max_keys.
8 9 10 |
# File 'lib/s33r/bucket_listing.rb', line 8 def max_keys @max_keys end |
#name ⇒ Object
Name of the bucket this listing is for.
6 7 8 |
# File 'lib/s33r/bucket_listing.rb', line 6 def name @name end |
#prefix ⇒ Object
Returns the value of attribute prefix.
8 9 10 |
# File 'lib/s33r/bucket_listing.rb', line 8 def prefix @prefix end |
Instance Method Details
#parse_listing(bucket_listing_xml) ⇒ Object
Parse raw XML ListBucketResponse from S3 into object instances. The S3Objects are skeletons, and are not automatically populated from S3 (their @value attributes are nil). To load the data into an object, grab it from the listing and call the fetch method to pull the data down from S3.
– TODO: common_prefixes
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/s33r/bucket_listing.rb', line 35 def parse_listing(bucket_listing_xml) bucket_listing_xml = S33r.remove_namespace(bucket_listing_xml) doc = XML.get_xml_doc(bucket_listing_xml) prop_setter = lambda do |prop, path| node = doc.find("//ListBucketResult/#{path}").to_a.first self.send("#{prop}=", node.content) if node end # metadata on the bucket prop_setter.call(:name, 'Name') prop_setter.call(:delimiter, 'Delimiter') prop_setter.call(:prefix, 'Prefix') prop_setter.call(:marker, 'Marker') prop_setter.call(:max_keys, 'MaxKeys') prop_setter.call(:is_truncated, 'IsTruncated') # contents doc.find('//Contents').to_a.each do |node| obj = S3Object.from_xml_node(node) # Add to the contents for the bucket self[obj.key] = obj end end |
#set_listing_xml(bucket_listing_xml) ⇒ Object
Convert a ListBucketResult XML document into an object representation.
18 19 20 21 22 23 24 25 26 |
# File 'lib/s33r/bucket_listing.rb', line 18 def set_listing_xml(bucket_listing_xml) begin parse_listing(bucket_listing_xml) rescue = "Cannot create bucket listing from supplied XML" += " (was nil)" if bucket_listing_xml.nil? raise InvalidBucketListing, end end |