Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

The easiest way to install aws/s3 is with Rubygems:

% sudo gem i aws-s3 -ry

== Directly from svn

% svn co svn://rubyforge.org/var/svn/amazon/s3/trunk aws
% sudo gem i surat-aws-s3 -ry

== As a Rails plugin

Expand Down
25 changes: 25 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
= AWS::S3
Forked from https://github.com/marcel/aws-s3

AWS::S3 is a Ruby library for Amazon's Simple Storage Service's REST API (http://aws.amazon.com/s3).
Full documentation of the currently supported API can be found at http://docs.amazonwebservices.com/AmazonS3/2006-03-01.
Expand Down Expand Up @@ -63,6 +64,9 @@ Buckets are containers for objects (the files you store on S3). To create a new
# Pick a unique name, or else you'll get an error
# if the name is already taken.
Bucket.create('jukebox')

To add location
Bucket.create('jukebox', {}, "EU")

Bucket names must be unique across the entire S3 system, sort of like domain names across the internet. If you try
to create a bucket with a name that is already taken, you will get an error.
Expand Down Expand Up @@ -498,6 +502,27 @@ Disabling logging is just as simple as enabling it:

Bucket.disable_logging_for('jukebox')

== Website
==== Enable bucket as website
To enable a bucket as a website you just specify its name.

Pick a existing bucket name, or else you'll get an error
Website.create('jukebox')
By default index document is "index.html" and error document is "error.html"

If Its different you can do
Website.create('jukebox', "about.html", "404.html")


Once you have succesfully enabled as website you can you can fetch it by name using Website.find.

music_website = Website.find('jukebox')

The bucket that is not website enabled will will throw an error.

You can remove website from bucket using Website.delete.

Website.delete('jukebox')

== Errors
==== When things go wrong
Expand Down
6 changes: 6 additions & 0 deletions README.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
= AWS::S3
Forked from https://github.com/marcel/aws-s3

<%= docs_for['AWS::S3'] %>

Expand Down Expand Up @@ -47,6 +48,11 @@ The three main concepts of S3 are the service, buckets and objects.

<%= docs_for['AWS::S3::Logging'] %>

== Website
==== Enable a bucket as website

<%= docs_for['AWS::S3::Website'] %>

== Errors
==== When things go wrong

Expand Down
Binary file added aws-s3-1.0.0.gem
Binary file not shown.
12 changes: 12 additions & 0 deletions aws-s3.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.author = "SuratPyari"
s.email = "[email protected]"
s.name = 'aws-s3'
s.version = '1.0.0'
s.description = 'Forked from https://github.com/marcel/aws-s3. Added New features.'
s.date = '2012-03-14'
s.summary = 'Forked from https://github.com/marcel/aws-s3. Added New features.'
s.require_paths = %w(lib)
s.files = Dir["bin/**/*", "lib/**/*", "site/**/*", "support/**/*", "test/**/*", "COPYING", "INSTALL", "Rakefile", "README", "README.erb"]
end
2 changes: 2 additions & 0 deletions lib/aws/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
require 's3/service'
require 's3/owner'
require 's3/bucket'
require 's3/website'
require 's3/object'
require 's3/error'
require 's3/exceptions'
require 's3/connection'
require 's3/authentication'
require 's3/response'
require 's3/content'

AWS::S3::Base.class_eval do
include AWS::S3::Connection::Management
Expand Down
2 changes: 1 addition & 1 deletion lib/aws/s3/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def path
end

def extract_significant_parameter
request.path[/[&?](acl|torrent|logging)(?:&|=|$)/, 1]
request.path[/[&?](acl|torrent|logging|website|)(?:&|=|$)/, 1]
end

def only_path
Expand Down
28 changes: 25 additions & 3 deletions lib/aws/s3/bucket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module S3
# # Pick a unique name, or else you'll get an error
# # if the name is already taken.
# Bucket.create('jukebox')
# To add location
# Bucket.create('jukebox', {}, "EU")
#
# Bucket names must be unique across the entire S3 system, sort of like domain names across the internet. If you try
# to create a bucket with a name that is already taken, you will get an error.
Expand Down Expand Up @@ -59,6 +61,23 @@ module S3
# Bucket.delete('photos', :force => true)
# # => true
class Bucket < Base

class Builder < XmlGenerator #:nodoc:
attr_reader :location
def initialize(location)
@location = location
super()
end

def build
return nil unless @location
xml.tag!('CreateBucketConfiguration', 'xmlns' => 'http://s3.amazonaws.com/doc/2006-03-01/') do
xml.LocationConstraint @location
end
end
end


class << self
# Creates a bucket named <tt>name</tt>.
#
Expand All @@ -71,12 +90,15 @@ class << self
# By default new buckets have their access level set to private. You can override this using the <tt>:access</tt> option.
#
# Bucket.create('internet_drop_box', :access => :public_read_write)

# If you want to change default location
# Bucket.create('internet_drop_box', {}, "EU")
#
# The full list of access levels that you can set on Bucket and S3Object creation are listed in the README[link:files/README.html]
# in the section called 'Setting access levels'.
def create(name, options = {})
def create(name, options = {}, location=nil)
validate_name!(name)
put("/#{name}", options).success?
put("/#{name}", options, Builder.new(location).to_s).success?
end

# Fetches the bucket named <tt>name</tt>.
Expand Down Expand Up @@ -316,4 +338,4 @@ def reload!(options = {})
end
end
end
end
end
5 changes: 2 additions & 3 deletions lib/aws/s3/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ def initialize(options = {})
end

def request(verb, path, headers = {}, body = nil, attempts = 0, &block)
body.rewind if body.respond_to?(:rewind) unless attempts.zero?

body.rewind if body.respond_to?(:rewind) unless attempts.zero?
requester = Proc.new do
path = self.class.prepare_path(path) if attempts.zero? # Only escape the path once
request = request_method(verb).new(path, headers)
Expand Down Expand Up @@ -275,4 +274,4 @@ def validate(options)
end
end
end
end
end
23 changes: 23 additions & 0 deletions lib/aws/s3/content.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Content
attr_reader :object_cache #:nodoc:

include Enumerable

def initialize(attributes = {}) #:nodoc:
super
@object_cache = []
build_contents!
end

private
def build_contents!
return unless has_contents?
attributes.delete('contents').each do |content|
add new_object(content)
end
end

def has_contents?
attributes.has_key?('contents')
end
end
2 changes: 1 addition & 1 deletion lib/aws/s3/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ def method_missing(method, *args, &block)
end
end
end
#:startdoc:
#:startdoc:
2 changes: 1 addition & 1 deletion lib/aws/s3/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def copy(key, copy_key, bucket = nil, options = {})
source_key = path!(bucket, key)
default_options = {'x-amz-copy-source' => source_key}
target_key = path!(bucket, copy_key)
returning put(target_key, default_options.merge(options)) do
returning put(target_key, default_options) do
acl(copy_key, bucket, acl(key, bucket)) if options[:copy_acl]
end
end
Expand Down
8 changes: 8 additions & 0 deletions lib/aws/s3/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ def bucket
end
end
end

class Website
class Response < Base::Response
def website
parsed
end
end
end

class S3Object
class Response < Base::Response
Expand Down
2 changes: 1 addition & 1 deletion lib/aws/s3/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module VERSION #:nodoc:
MAJOR = '0'
MINOR = '6'
TINY = '2'
BETA = Time.now.to_i.to_s
BETA = nil #Time.now.to_i.to_s
end

Version = [VERSION::MAJOR, VERSION::MINOR, VERSION::TINY, VERSION::BETA].compact * '.'
Expand Down
102 changes: 102 additions & 0 deletions lib/aws/s3/website.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
require File.dirname(__FILE__) + "/content"
module AWS
module S3
# To enable a bucket as a website you just specify its name.
#
# # Pick a existing bucket name, or else you'll get an error
# Website.create('jukebox')
# By default index document is "index.html" and error document is "error.html"
#
# If Its different you can do
# Website.create('jukebox', "about.html", "404.html")
#
#
# Once you have succesfully enabled as website you can you can fetch it by name using Website.find.
#
# music_website = Website.find('jukebox')
#
# The bucket that is not website enabled will will throw an error.
#
# You can remove website from bucket using Website.delete.
#
# Website.delete('jukebox')

class Website < Base

class Builder < XmlGenerator #:nodoc:
attr_reader :index_page, :error_page
def initialize(index_page, error_page)
@index_page = index_page
@error_page = error_page
super()
end

def build
xml.tag!('WebsiteConfiguration', 'xmlns' => 'http://s3.amazonaws.com/doc/2006-03-01/') do
xml.IndexDocument do
xml.Suffix index_page
end
xml.ErrorDocument do
xml.Key error_page
end
end
end
end

class << self
# To enable a bucket as a website you just specify its name.
#
# # Pick a existing bucket name, or else you'll get an error
# Website.create('jukebox')
# By default index document is "index.html" and error document is "error.html"
#
# If Its different you can do
# Website.create('jukebox', "about.html", "404.html")

def create(name=nil, index_page="index.html", error_page="error.html")
put(path(name), {}, Builder.new(index_page, error_page).to_s).success?
end

# Fetches if a bucket is website enabled.
#
# website=Website.find('jukebox')
#
# website.index_doc
# => 'index.html'
# website.error_doc
# => 'error.html'
def find(name = nil)
new(get(path(name)).website)
end

# disables a bucket aswebsite.
# Website.delete('photos')
def delete(name = nil, options = {})
Base.delete(path(name)).success?
end

private

def path(name, options = {})
if name.is_a?(Hash)
options = name
name = nil
end
# "/#{website_name(name)}#{RequestOptions.process(options).to_query_string}"
"/#{name}/?website"
end

include Content
end

def index_doc
self.index_document["suffix"]
end

def error_doc
self.error_document["key"]
end

end
end
end