require 'image_fu/version' require 'image_fu/client' require 'base64' require 'openssl' require 'uuidtools' require 'rack/utils' require 'aws-sdk' module ImageFu CONFIG = { :access_key_id => ENV['IMAGE_FU_AWS_ACCESS_KEY'] || ENV['AWS_ACCESS_KEY'], :secret_access_key => ENV['IMAGE_FU_AWS_SECRET'] || ENV['AWS_SECRET'], :upload_bucket => ENV['IMAGE_FU_UPLOAD_BUCKET'] || ENV['UPLOAD_BUCKET'], :server => 'http://image-fu.heroku-apps.com' } def self.config(options) CONFIG.merge!(options) end def self.s3 AWS::S3.new(:access_key_id => CONFIG[:access_key_id], :secret_access_key => CONFIG[:secret_access_key]) end def self.signed_upload_params(options = {}) options.reverse_merge!( :acl => 'private', :max_size => 10.megabytes, :expiry => 1.hour, :bucket => CONFIG[:upload_bucket] ) key = UUIDTools::UUID.random_create.to_s bucket = s3.buckets[options[:bucket]] form = bucket.presigned_post( :key => key, :expires => options[:expiry].to_i, :acl => options[:acl], :success_action_status => 201, :content_length => 0..(options[:max_size]), :ignore => ['Filename'] ) { :server => CONFIG[:server], :bucket => options[:bucket], :parameters => form.fields } end def self.get_image(id) client.get_image(id) end def self.client ImageFu::Client.new end end require 'image_fu/engine' if defined?(::Rails::Engine)