diff --git a/INSTALL b/INSTALL index d36a8a0..8b7e284 100644 --- a/INSTALL +++ b/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 diff --git a/README b/README index 06c4da5..b292da9 100644 --- a/README +++ b/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 diff --git a/README.erb b/README.erb index e92efaf..168fb7b 100644 --- a/README.erb +++ b/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 diff --git a/aws-s3-1.0.0.gem b/aws-s3-1.0.0.gem new file mode 100644 index 0000000..41516dc Binary files /dev/null and b/aws-s3-1.0.0.gem differ diff --git a/aws-s3.gemspec b/aws-s3.gemspec new file mode 100644 index 0000000..0735477 --- /dev/null +++ b/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 diff --git a/lib/aws/s3.rb b/lib/aws/s3.rb index af115fb..88b17dc 100644 --- a/lib/aws/s3.rb +++ b/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 diff --git a/lib/aws/s3/authentication.rb b/lib/aws/s3/authentication.rb index 0efbc7a..264c824 100644 --- a/lib/aws/s3/authentication.rb +++ b/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 diff --git a/lib/aws/s3/bucket.rb b/lib/aws/s3/bucket.rb index 84d89d3..52d7ed5 100644 --- a/lib/aws/s3/bucket.rb +++ b/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 name. # @@ -71,12 +90,15 @@ class << self # By default new buckets have their access level set to private. You can override this using the :access 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 name. @@ -316,4 +338,4 @@ def reload!(options = {}) end end end -end \ No newline at end of file +end diff --git a/lib/aws/s3/connection.rb b/lib/aws/s3/connection.rb index 1b91127..3e1c989 100644 --- a/lib/aws/s3/connection.rb +++ b/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 \ No newline at end of file +end diff --git a/lib/aws/s3/content.rb b/lib/aws/s3/content.rb new file mode 100644 index 0000000..b2f4e01 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/lib/aws/s3/error.rb b/lib/aws/s3/error.rb index f4c4011..8fdd5e0 100644 --- a/lib/aws/s3/error.rb +++ b/lib/aws/s3/error.rb @@ -66,4 +66,4 @@ def method_missing(method, *args, &block) end end end -#:startdoc: \ No newline at end of file +#:startdoc: diff --git a/lib/aws/s3/object.rb b/lib/aws/s3/object.rb index 0fa03f5..bcdf9e1 100644 --- a/lib/aws/s3/object.rb +++ b/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 diff --git a/lib/aws/s3/response.rb b/lib/aws/s3/response.rb index fa3b8a1..1a4c237 100644 --- a/lib/aws/s3/response.rb +++ b/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 diff --git a/lib/aws/s3/version.rb b/lib/aws/s3/version.rb index b60aa3c..877874b 100644 --- a/lib/aws/s3/version.rb +++ b/lib/aws/s3/version.rb @@ -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 * '.' diff --git a/lib/aws/s3/website.rb b/lib/aws/s3/website.rb new file mode 100644 index 0000000..5051939 --- /dev/null +++ b/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