require 'builder' require 'time' module Shuck class XmlAdapter def self.buckets(bucket_objects) output = "" xml = Builder::XmlMarkup.new(:target => output) xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" xml.ListAllMyBucketsResult(:xmlns => "http://s3.amazonaws.com/doc/2006-03-01/") { |lam| lam.Owner { |owner| owner.ID("123") owner.DisplayName("Shuck") } lam.Buckets { |buckets| bucket_objects.each do |bucket| buckets.Bucket do |b| b.Name(bucket.name) b.CreationDate(bucket.creation_date.strftime("%Y-%m-%dT%H:%M:%S.000Z")) end end } } output end # # # NoSuchKey # The resource you requested does not exist # /mybucket/myfoto.jpg # 4442587FB7D0A2F9 # def self.error_no_such_bucket(name) output = "" xml = Builder::XmlMarkup.new(:target => output) xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" xml.Error { |err| err.Code("NoSuchBucket") err.Message("The resource you requested does not exist") err.Resource(name) err.RequestId(1) } output end def self.bucket(bucket) output = "" xml = Builder::XmlMarkup.new(:target => output) xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8" xml.ListBucketResult(:xmlns => "http://s3.amazonaws.com/doc/2006-03-01/") { |lbr| lbr.Name(bucket.name) lbr.Prefix lbr.Marker lbr.MaxKeys("1000") lbr.IsTruncated("false") } output end end end