Class: S3Batch::WebsiteEnabler
- Inherits:
-
Happening::S3::Item
- Object
- Happening::S3::Item
- S3Batch::WebsiteEnabler
- Defined in:
- lib/s3batch/website_enabler.rb
Class Method Summary collapse
Instance Method Summary collapse
- #enable(index_doc, error_doc, request_options = {}, &blk) ⇒ Object
- #path(with_bucket = true) ⇒ Object
Class Method Details
.run(s3id, s3key, bucket, index_doc = "index.html", error_doc = "404.html") ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/s3batch/website_enabler.rb', line 26 def self.run s3id, s3key, bucket, index_doc = "index.html", error_doc = "404.html" EM.run { on_error = Proc.new {|response| puts "An error occured: #{response.response}"; EM.stop; } on_success = Proc.new {|response| puts "Enabled #{response.response}"; EM.stop; } item = S3Batch::WebsiteEnabler.new(bucket, "NO_USE", :aws_access_key_id => s3id, :aws_secret_access_key => s3key, :protocol => 'http') item.enable(index_doc, error_doc, :on_error => on_error, :on_success => on_success) } end |
Instance Method Details
#enable(index_doc, error_doc, request_options = {}, &blk) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/s3batch/website_enabler.rb', line 7 def enable index_doc, error_doc, = {}, &blk data =<<EOF <WebsiteConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <IndexDocument> <Suffix>#{index_doc}</Suffix> </IndexDocument> <ErrorDocument> <Key>#{error_doc}</Key> </ErrorDocument> </WebsiteConfiguration> EOF md5 = Base64.encode64(Digest::MD5.digest(data)).strip headers = aws.sign("PUT", path, {"Content-MD5" => md5}) [:on_success] = blk if blk .update(:headers => headers, :data => data) Happening::S3::Request.new(:put, url, {:ssl => [:ssl]}.update()).execute end |
#path(with_bucket = true) ⇒ Object
3 4 5 |
# File 'lib/s3batch/website_enabler.rb', line 3 def path(with_bucket=true) with_bucket ? "/#{bucket}/?website" : "/?website" end |