1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/storage.rb

46 lines
1.4 KiB
Ruby
Raw Normal View History

2010-10-29 19:24:34 -04:00
module Fog
class Storage
def self.new(attributes)
attributes = attributes.dup # prevent delete from having side effects
2011-01-07 21:14:39 -05:00
case provider = attributes[:provider] # attributes.delete(:provider)
when 'AWS'
2011-01-07 21:12:05 -05:00
require 'fog/storage/aws'
2010-10-29 19:24:34 -04:00
Fog::AWS::Storage.new(attributes)
when 'Google'
2011-01-07 21:12:05 -05:00
require 'fog/storage/google'
2010-10-29 19:24:34 -04:00
Fog::Google::Storage.new(attributes)
when 'Local'
2011-01-07 21:12:05 -05:00
require 'fog/storage/local'
2010-10-29 19:24:34 -04:00
Fog::Local::Storage.new(attributes)
when 'Rackspace'
2011-01-07 21:12:05 -05:00
require 'fog/storage/rackspace'
2010-10-29 19:24:34 -04:00
Fog::Rackspace::Storage.new(attributes)
else
raise ArgumentError.new("#{provider} is not a recognized storage provider")
end
end
2011-03-10 16:04:42 -05:00
def self.parse_data(data)
metadata = {
:body => nil,
:headers => {}
}
if data.is_a?(String)
metadata[:body] = data
metadata[:headers]['Content-Length'] = metadata[:body].size
else
filename = ::File.basename(data.path)
unless (mime_types = MIME::Types.of(filename)).empty?
metadata[:headers]['Content-Type'] = mime_types.first.content_type
end
metadata[:body] = data
metadata[:headers]['Content-Length'] = ::File.size(data.path)
end
# metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
metadata
end
2010-10-29 19:24:34 -04:00
end
2011-01-07 18:34:20 -05:00
end