Module: ScribdFu
- Defined in:
- lib/scribd_fu.rb,
lib/scribd_fu/paperclip.rb,
lib/scribd_fu/attachment_fu.rb
Defined Under Namespace
Modules: AttachmentFu, ClassMethods, InstanceMethods, Paperclip Classes: ScribdFuError, ScribdFuUploadError
Constant Summary collapse
- ConfigPath =
"#{RAILS_ROOT}/config/scribd_fu.yml".freeze
- ContentTypes =
A list of content types supported by iPaper.
[ 'application/pdf', 'application/msword', 'application/mspowerpoint', 'application/vnd.ms-powerpoint', 'application/excel', 'application/vnd.ms-excel', 'application/postscript', 'text/plain', 'text/rtf', 'application/rtf', 'application/vnd.oasis.opendocument.text', 'application/vnd.oasis.opendocument.presentation', 'application/vnd.oasis.opendocument.spreadsheet', 'application/vnd.sun.xml.writer', 'application/vnd.sun.xml.impress', 'application/vnd.sun.xml.calc', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', 'application/vnd.openxmlformats-officedocument.presentationml.template', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' ]
- Available_JS_Params =
Available parameters for the JS API www.scribd.com/publisher/api/api?method_name=Javascript+API
[ :height, :width, :page, :my_user_id, :search_query, :jsapi_version, :disable_related_docs, :mode, :auto_size ]
Class Method Summary collapse
-
.access_level ⇒ Object
Get the preferred access level for iPaper documents.
-
.config ⇒ Object
Read, store, and return the ScribdFu config file’s contents.
-
.destroy(document) ⇒ Object
Delete an iPaper document.
-
.included(base) ⇒ Object
:nodoc:.
-
.load_ipaper_document(id) ⇒ Object
Load, store, and return the associated iPaper document.
-
.scribd_user ⇒ Object
Login, store, and return a handle to the Scribd user account.
-
.upload(obj, file_path) ⇒ Object
Upload a file to Scribd.
Class Method Details
.access_level ⇒ Object
Get the preferred access level for iPaper documents
86 87 88 |
# File 'lib/scribd_fu.rb', line 86 def access_level config[:access] || 'private' end |
.config ⇒ Object
Read, store, and return the ScribdFu config file’s contents
78 79 80 81 82 83 |
# File 'lib/scribd_fu.rb', line 78 def config raise ScribdFuError, "#{ConfigPath} does not exist" unless File.file?(ConfigPath) # Load the config file and strip any whitespace from the values @config ||= YAML.load_file(ConfigPath).each_pair{|k,v| {k=>v.to_s.strip}}.symbolize_keys! end |
.destroy(document) ⇒ Object
Delete an iPaper document
73 74 75 |
# File 'lib/scribd_fu.rb', line 73 def destroy(document) document.destroy end |
.included(base) ⇒ Object
:nodoc:
46 47 48 |
# File 'lib/scribd_fu.rb', line 46 def included(base) #:nodoc: base.extend ClassMethods end |
.load_ipaper_document(id) ⇒ Object
Load, store, and return the associated iPaper document
91 92 93 94 95 96 97 |
# File 'lib/scribd_fu.rb', line 91 def load_ipaper_document(id) begin @document ||= scribd_user.find_document(id) rescue raise ScribdFuError, "Scribd Document ##{id} not found!" end end |
.scribd_user ⇒ Object
Login, store, and return a handle to the Scribd user account
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/scribd_fu.rb', line 51 def scribd_user begin # Ensure we can login to Scribd, and get a handle on the account Scribd::API.instance.key = config[:key] Scribd::API.instance.secret = config[:secret] @scribd_user = Scribd::User.login(config[:user], config[:password]) rescue raise ScribdFuError, "Your Scribd credentials are incorrect" end end |
.upload(obj, file_path) ⇒ Object
Upload a file to Scribd
63 64 65 66 67 68 69 70 |
# File 'lib/scribd_fu.rb', line 63 def upload(obj, file_path) begin res = scribd_user.upload(:file => "#{file_path}", :access => access_level) obj.update_attributes({:ipaper_id => res.doc_id, :ipaper_access_key => res.access_key}) rescue raise ScribdFuUploadError, "Sorry, but #{obj.class} ##{obj.id} could not be uploaded to Scribd" end end |