Sha256: cb478171557f771f2853a49fa5f54aa80a7913568fe795227b5ba0351bdb24e7

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

# TODO: provide access to metadata on the enclosed bucket_listing

module S3
  # a client for dealing with a single bucket
  class NamedBucket < Client
    attr_accessor :bucket_name
  
    # options available:
    # :public_contents => true: all items put into bucket are made public (can be overridden per request)
    # :strict => true: check whether the bucket exists before attempting to initialize
    def initialize(aws_access_key, aws_secret_access_key, bucket_name, options={}, &block)
      @bucket_name = bucket_name

      # holds a BucketListing instance
      @bucket_listing = nil

      # all content should be created as public-read
      @client_headers.merge!(canned_acl_header('public-read')) if options[:public_contents]
    
      super(aws_access_key, aws_secret_access_key, options)
      
      if true == options[:strict]
        raise S3Exception::MissingResource unless bucket_exists?(bucket_name)
      end
    end

    def metadata
      # TODO: get bucket metadata from the bucket_listing
    end

    def contents
      # TODO: S3Object instances inside the bucket_listing
    end

    def listing
      # TODO: build a bucket_listing whose objects are associated with the bucket
      # and set the @bucket_listing instance variable
      list_bucket(@bucket_name)
    end

    def put_text(string, resource_key, headers={})
      super(string, @bucket_name, resource_key, headers)
    end

    def put_file(filename, resource_key=nil, headers={}, options={})
      super(filename, @bucket_name, resource_key, headers, options)
    end
    
    # expires: time in secs since the epoch when 
    def s3_authenticated_url(resource_key, expires=(Time.now.to_i + DEFAULT_EXPIRY_SECS))
      super(@aws_access_key, @aws_secret_access_key, @bucket_name, resource_key, expires)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
s33r-0.2 lib/s33r/named_bucket.rb