Sha256: c3a803de8af00b016864bc3dc8ce977176116f1e342ce18d660cacbeb2365acf

Contents?: true

Size: 1.55 KB

Versions: 14

Compression:

Stored size: 1.55 KB

Contents

module Rudy::AWS
  class S3
    
    def initialize(access_key=nil, secret_key=nil, region=nil, debug=nil)
      require 'aws/s3'    
      
      url ||= 'http://sdb.amazonaws.com'
      # There is a bug with passing :server to EC2::Base.new so 
      # we'll use the environment variable for now. 
      #if region && Rudy::AWS.valid_region?(region)
      #  "#{region}.sdb.amazonaws.com"
      #end
      
      @access_key_id = access_key || ENV['AWS_ACCESS_KEY'] || ENV['AMAZON_ACCESS_KEY_ID']
      @secret_access_key = secret_key || ENV['AWS_SECRET_KEY'] || ENV['AMAZON_SECRET_ACCESS_KEY']
      @base_url = url
      @debug = debug || StringIO.new
      
      
      AWS::S3::Base.establish_connection!(
        :access_key_id     => @access_key_id,
        :secret_access_key => @secret_access_key
      )
      
    end
    
    def list_buckets
      ::AWS::S3::Service.buckets
    end
    
    def create_bucket(name, location=nil)
      opts = {}
      opts[:location] = location.to_s.upcase if location
      ::AWS::S3::Bucket.create(name, opts)
    end
    
    def destroy_bucket(name)
      ::AWS::S3::Bucket.delete(name)
    end
    
    def find_bucket(name)
      blist = ::AWS::S3::Service.buckets
      blist.select { |bobj| bobj.name == name }.first
    end
    
    def list_bucket_objects(name)
      ::AWS::S3::Bucket.objects(name)
    end
    
    #def store(path, bucket)
    #  fname = File.basename(path)
    #  S3Object.store(fname, open(path), bucket)
    #end
    
    def bucket_exists?(name)
      b = find_bucket(name)
      !b.nil?
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
solutious-rudy-0.9.0 lib/rudy/aws/s3.rb
solutious-rudy-0.9.1 lib/rudy/aws/s3.rb
solutious-rudy-0.9.2 lib/rudy/aws/s3.rb
solutious-rudy-0.9.3 lib/rudy/aws/s3.rb
solutious-rudy-0.9.4 lib/rudy/aws/s3.rb
rudy-0.9.5.004 lib/rudy/aws/s3.rb
rudy-0.9.5.003 lib/rudy/aws/s3.rb
rudy-0.9.5.002 lib/rudy/aws/s3.rb
rudy-0.9.5 lib/rudy/aws/s3.rb
rudy-0.9.4 lib/rudy/aws/s3.rb
rudy-0.9.3 lib/rudy/aws/s3.rb
rudy-0.9.2 lib/rudy/aws/s3.rb
rudy-0.9.0 lib/rudy/aws/s3.rb
rudy-0.9.1 lib/rudy/aws/s3.rb