Commit ccaaaad6 by David Chen Committed by Jon Yurek

First pass at making specs run with Aws-v2

parent 9ef9b512
...@@ -116,7 +116,11 @@ module Paperclip ...@@ -116,7 +116,11 @@ module Paperclip
begin begin
require 'aws-sdk' require 'aws-sdk'
const_set('AWS_CLASS', defined?(::Aws) ? ::Aws : ::AWS) const_set('AWS_CLASS', defined?(::Aws) ? ::Aws : ::AWS)
const_set('DEFAULT_PERMISSION', defined?(::AWS) ? :public_read : :'public-read') const_set('AWS_BASE_ERROR',
defined?(::Aws) ? Aws::Errors::ServiceError : AWS::Errors::Base)
const_set('DEFAULT_PERMISSION',
defined?(::AWS) ? :public_read : :'public-read')
rescue LoadError => e rescue LoadError => e
e.message << " (You may need to install the aws-sdk gem)" e.message << " (You may need to install the aws-sdk gem)"
raise e raise e
...@@ -253,7 +257,7 @@ module Paperclip ...@@ -253,7 +257,7 @@ module Paperclip
config[:proxy_uri] = URI::HTTP.build(proxy_opts) config[:proxy_uri] = URI::HTTP.build(proxy_opts)
end end
[:access_key_id, :secret_access_key, :credential_provider].each do |opt| [:access_key_id, :secret_access_key, :credential_provider, :credentials].each do |opt|
config[opt] = s3_credentials[opt] if s3_credentials[opt] config[opt] = s3_credentials[opt] if s3_credentials[opt]
end end
...@@ -332,7 +336,7 @@ module Paperclip ...@@ -332,7 +336,7 @@ module Paperclip
else else
false false
end end
rescue AWS_CLASS::Errors::Base => e rescue AWS_BASE_ERROR => e
false false
end end
...@@ -358,7 +362,11 @@ module Paperclip ...@@ -358,7 +362,11 @@ module Paperclip
end end
def create_bucket def create_bucket
if aws_v1?
s3_interface.buckets.create(bucket_name) s3_interface.buckets.create(bucket_name)
else
s3_interface.bucket(bucket_name).create
end
end end
def flush_writes #:nodoc: def flush_writes #:nodoc:
...@@ -426,7 +434,7 @@ module Paperclip ...@@ -426,7 +434,7 @@ module Paperclip
else else
s3_bucket.object(path.sub(%r{\A/},'')) s3_bucket.object(path.sub(%r{\A/},''))
end.delete end.delete
rescue AWS_CLASS::Errors::Base => e rescue AWS_BASE_ERROR => e
# Ignore this. # Ignore this.
end end
end end
...@@ -440,7 +448,7 @@ module Paperclip ...@@ -440,7 +448,7 @@ module Paperclip
local_file.write(chunk) local_file.write(chunk)
end end
end end
rescue AWS_CLASS::Errors::Base => e rescue AWS_BASE_ERROR => e
warn("#{e} - cannot copy #{path(style)} to local file #{local_dest_path}") warn("#{e} - cannot copy #{path(style)} to local file #{local_dest_path}")
false false
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment