Browse files

Merge remote-tracking branch 'static/master'

Conflicts:
	lib/aws/s3/version.rb
  • Loading branch information...
2 parents 0572f4b + 0699179 commit 037e0ef48fac72736246140dd7b21fb221556d45 @winton committed Jun 10, 2012
View
6 INSTALL
@@ -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
View
25 README
@@ -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.
@@ -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.
@@ -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
View
6 README.erb
@@ -1,4 +1,5 @@
= AWS::S3
+Forked from https://github.com/marcel/aws-s3
<%= docs_for['AWS::S3'] %>
@@ -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
View
BIN aws-s3-1.0.0.gem
Binary file not shown.
View
12 aws-s3.gemspec
@@ -0,0 +1,12 @@
+Gem::Specification.new do |s|
+ s.platform = Gem::Platform::RUBY
+ s.author = "SuratPyari"
+ s.email = "suratpyari.db21@gmail.com"
+ 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
View
2 lib/aws/s3.rb
@@ -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
View
2 lib/aws/s3/authentication.rb
@@ -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
View
28 lib/aws/s3/bucket.rb
@@ -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.
@@ -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>.
#
@@ -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>.
@@ -316,4 +338,4 @@ def reload!(options = {})
end
end
end
-end
+end
View
5 lib/aws/s3/connection.rb
@@ -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)
@@ -275,4 +274,4 @@ def validate(options)
end
end
end
-end
+end
View
23 lib/aws/s3/content.rb
@@ -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
View
2 lib/aws/s3/error.rb
@@ -66,4 +66,4 @@ def method_missing(method, *args, &block)
end
end
end
-#:startdoc:
+#:startdoc:
View
2 lib/aws/s3/object.rb
@@ -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
View
8 lib/aws/s3/response.rb
@@ -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
View
102 lib/aws/s3/website.rb
@@ -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

0 comments on commit 037e0ef

Please sign in to comment.