require File.join(File.dirname(__FILE__), './scribd-carrierwave/version') require File.join(File.dirname(__FILE__), './scribd-carrierwave/config') require 'carrierwave' require 'rscribd' require 'configatron' module ScribdCarrierWave class << self def included(base) base.extend ClassMethods end def upload uploader args = { file: full_path(uploader), access: 'private' } scribd_user.upload(args) end def destroy uploader document = scribd_user.find_document(uploader.ipaper_id) rescue nil document.destroy if !document.nil? end def full_path uploader if uploader.url =~ /^http(s?):\/\// uploader.url else uploader.root + uploader.url end end module ClassMethods def has_ipaper include InstanceMethods after :store, :upload_to_scribd before :remove, :delete_from_scribd end end module InstanceMethods def self.included(base) base.extend ClassMethods end def upload_to_scribd files res = ScribdCarrierWave::upload(self) set_params res end def delete_from_scribd ScribdCarrierWave::destroy(self) end def display_ipaper(options = {}) id = options.delete(:id) <<-END