0
- @@content_types = ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg']
0
- mattr_reader :content_types
0
- # doc, ppt, pps, xls, pdf, ps, odt, odp, sxw, sxi, jpg, jpeg, png, gif, txt, rtf
0
- class ConfigFileNotFoundError < StandardError; end
0
def self.included(base)
0
- base.extend ActsAsScribd
Document
0
+ base.extend ActsAsScribd
Object
0
- module ActsAsScribd
Document
0
+ module ActsAsScribd
Object
0
def acts_as_scribd_document(options = {})
0
- include MDarby::Acts::Scribd
fu::InstanceMethods
0
+ include MDarby::Acts::Scribd
_fu::InstanceMethods
0
def self.included(base)
0
base.extend ClassMethods
0
mattr_reader :scribd_config
0
@@ -37,89 +27,117 @@ module MDarby
0
- @@scribd_config_path =
RAILS_ROOT + '/config/scribd.yml'0
+ @@scribd_config_path =
"#{RAILS_ROOT}/config/scribd.yml"0
@@scribd_config = YAML.load_file(@@scribd_config_path).symbolize_keys
0
+ # Ensure we can connect to the Service
0
+ Scribd::API.instance.key = @@scribd_config[:key]
0
+ Scribd::API.instance.secret = @@scribd_config[:secret]
0
+ @@user = Scribd::User.login(@@scribd_config[:user], @@scribd_config[:password])
0
- raise ConfigFileNotFoundError.new('File %s not found' % @@scribd_config_path)
0
+ puts "Config file not found, or your credentials are b0rked!"
0
- delegate :content_types, :to => MDarby::Acts
0
- def validates_as_scribd_document
0
- validates_presence_of :scribd_id, :scribd_access_id
0
- validate :scribd_attributes_valid?
0
- # validates the size and content_type attributes according to the current model's options
0
- def scribd_attributes_valid?
0
- [:size, :content_type].each do |attr_name|
0
- enum = scribd_options[attr_name]
0
- errors.add attr_name, ActiveRecord::Errors.default_error_messages[:inclusion] unless enum.nil? || enum.include?(send(attr_name))
0
+ @@user.find_document(id)
0
+ # doc, ppt, pps, xls, pdf, ps, odt, odp, sxw, sxi, jpg, jpeg, png, gif, txt, rtf
0
- # Returns true or false if the given content type is recognized as an Scribdable Document.
0
- def scribdable?(content_type)
0
- content_types.include?(content_type)
0
+ @@content_types = ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg']
0
+ mattr_reader :content_types
0
- def self.extended(base)
0
- base.class_inheritable_accessor :scribd_options
0
- base.before_destroy :destroy_scribd_document
0
- base.after_save :upload_to_scribd
0
- write_attribute :scribd_id, id.to_s.strip
0
+ def self.extended(base)
0
+ base.class_inheritable_accessor :scribd_options
0
+ base.before_destroy :destroy_scribd_document
0
+ base.after_save :upload_to_scribd
0
- def scribd_access_key=(key)
0
- write_attribute :scribd_access_key, key.to_s.strip
0
- def destroy_scribd_document
0
- user = Scribd::User.login 'XXX', 'XXXXX'
0
- document = user.find_document(self.scribd_id)
0
- unless document.destroy
0
- logger.info "#{Time.now.rfc2822}: Removing Scribd Document #{self.id} failed!"
0
+ MDarby::Acts::Scribd_fu::InstanceMethods.scribd_user
0
+ def validates_as_scribd_document
0
+ validates_presence_of :scribd_id, :scribd_access_id
0
+ validate :scribd_attributes_valid?
0
+ def scribd_attributes_valid?
0
+ [:scribd_id, :scribd_access_id].each do |attr_name|
0
+ enum = scribd_options[attr_name]
0
+ errors.add attr_name, ActiveRecord::Errors.default_error_messages[:inclusion] unless enum.nil? || enum.include?(send(attr_name))
0
- if doc = Scribd::Document.create(:file => "#{document.public_filename}", :access => "private")
0
- logger.info "#{Time.now.rfc2822}: Document #{document.id} successfully converted to iPaper."
0
+ def scribdable?(content_type)
0
+ content_types.include?(content_type)
0
+ write_attribute :scribd_id, id.to_s.strip
0
- document.scribd_id = doc.doc_id
0
- document.scribd_access_key = doc.access_key
0
+ def scribd_access_key=(key)
0
+ write_attribute :scribd_access_key, key.to_s.strip
0
- logger.info "#{Time.now.rfc2822}: Document #{document.id} saved after being converted to iPaper."
0
- # Upload to S3 via the S3_worker
0
- logger.info "#{Time.now.rfc2822}: Scheduling Document #{document.id} for S3 upload"
0
- logger.info "#{Time.now.rfc2822}: Document #{document.id} failed to save after being converted to iPaper!"
0
+ def edit(options = {})
0
+ def destroy_scribd_document
0
+ unless self.scribd_id.blank?
0
+ document = scribd_user.find_document(self.scribd_id)
0
+ logger.info "#{Time.now.rfc2822}: Removing Scribd Object #{self.id} successful"
0
- logger.info "#{Time.now.rfc2822}:
Document #{document.id} iPaper conversion failed..."
0
+ logger.info "#{Time.now.rfc2822}:
Removing Scribd Object #{self.id} failed!"
0
+ # if document = Scribd::Object.create(:file => "#{self.public_filename}", :access => scribd_config[:access])
0
+ # logger.info "#{Time.now.rfc2822}: Object #{self.id} successfully converted to iPaper."
0
+ # self.scribd_id = document.doc_id
0
+ # self.scribd_access_key = document.access_key
0
+ # logger.info "#{Time.now.rfc2822}: Object #{self.id} saved after being converted to iPaper."
0
+ # logger.info "#{Time.now.rfc2822}: Object #{self.id} failed to save after being converted to iPaper!"
0
+ # logger.info "#{Time.now.rfc2822}: Object #{self.id} iPaper conversion failed..."
0
+ # logger.info "#{Time.now.rfc2822}: Object #{self.id} is not Scribdable!"
0
\ No newline at end of file
Comments
No one has commented yet.