require 'builder' require 'fileutils' require 'time' module Shuck class Store def initialize(root) @root = root @buckets = [] Dir[File.join(root,"*")].each do |bucket| @buckets << File.basename(bucket) end end def buckets 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("Curtis Spencer") } lam.Buckets { |buckets| @buckets.each do |bucket| buckets.Bucket do |b| b.Name(bucket) b.CreationDate(Time.now.xmlschema) end end } } output end def get_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) lbr.Prefix lbr.Marker lbr.MaxKeys("1000") lbr.IsTruncated("false") } output end def create_bucket(bucket) FileUtils.mkdir_p(File.join(@root,bucket)) end def get_object(bucket,object) begin io = File.open(File.join(@root,bucket,object),'rb') return io rescue puts $! return nil end end def store_object(bucket,object,request) begin File.open(File.join(@root,bucket,object),'w') do |f| request.body do |chunk| f << chunk end end rescue puts $! end end end end