class Contraption::S3Uploader

Public Class Methods

new(connection_args={}) click to toggle source
# File lib/contraption/s3_uploader.rb, line 6
def initialize connection_args={}, target_bucket, path
  AWS::S3::Base.establish_connection! connection_args
  @target_bucket = target_bucket
  @path = path.cd "drafts"
end

Public Instance Methods

handle(request) click to toggle source
# File lib/contraption/s3_uploader.rb, line 16
def handle request
  local_path = Pathname.new(@path.path) + request.last
  if local_path.exist?
    remote_path = "#{Time.now.year}" + "/#{"%02d" % Time.now.mon}/" + request.last.split('/').last
    upload local_path, remote_path
    ["http:", "#{@target_bucket}/#{remote_path}"]
  else
    raise "#{local_path.expand_path} does not exist"
  end
end
protocol() click to toggle source
# File lib/contraption/s3_uploader.rb, line 12
def protocol
  :s3
end
upload(local_path, remote_path) click to toggle source
# File lib/contraption/s3_uploader.rb, line 27
def upload local_path, remote_path
  puts "Uploading #{local_path} to #{remote_path}"
  AWS::S3::S3Object.store(remote_path, open(local_path), @target_bucket, :access => :public_read, 'Cache-Control' => 'max-age=3136000')
end