public
Description: A Ruby on Rails plugin that streamlines interactions with the Scribd service
Homepage: http://blog.matt-darby.com/category/code-stuff/scribd_fu/
Clone URL: git://github.com/mdarby/scribd_fu.git
Search Repo:
Sequence from config reading to login is working
get_all_documents returns good data
mdarby (author)
Tue Mar 25 16:30:37 -0700 2008
commit  fffb0695d05ea19ee57c239a25742fc69b5e8da7
tree    2a0a9236227d559d8565f9daeca3b2d6d487a15b
parent  4d825e3a238fbf31a0d56ff06e0636fe29c1522a
...
1
2
3
 
4
...
1
 
2
3
4
0
@@ -1,2 +1,2 @@
0
 require 'act_as_scribd_document'
0
-ActiveRecord::Base.send(:include, MDarby::Acts::Stuff)
0
\ No newline at end of file
0
+ActiveRecord::Base.send(:include, MDarby::Acts::Scribd_fu)
0
\ No newline at end of file
...
1
2
3
4
5
6
7
8
9
10
11
12
13
 
 
14
15
 
16
17
18
 
19
20
21
 
22
23
24
25
26
27
28
29
30
 
31
32
33
...
37
38
39
40
 
41
 
 
 
 
 
 
42
43
 
 
44
45
46
47
48
49
50
51
52
53
 
 
54
 
 
 
 
 
55
56
57
58
59
60
61
62
 
 
 
 
63
64
65
66
 
 
 
67
68
69
70
71
 
 
72
73
74
75
76
77
78
79
80
81
 
 
 
 
 
82
83
84
85
86
87
88
89
90
91
92
93
94
95
 
 
 
 
 
 
 
 
 
 
 
 
 
96
97
98
99
100
 
 
 
 
 
 
 
 
 
101
102
103
 
 
 
104
105
106
 
 
107
108
109
110
111
112
113
 
 
114
 
 
 
 
 
 
 
115
116
 
117
118
119
120
 
121
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
124
125
126
...
1
2
 
 
 
 
 
 
 
 
 
 
 
3
4
5
 
6
7
8
 
9
10
11
 
12
13
14
15
16
17
 
18
19
 
20
21
22
23
...
27
28
29
 
30
31
32
33
34
35
36
37
38
 
39
40
41
 
42
 
 
 
 
 
 
 
43
44
45
46
47
48
49
50
51
 
 
 
 
 
 
 
52
53
54
55
56
 
 
 
57
58
59
60
 
 
 
 
61
62
63
 
 
 
 
 
 
 
 
 
64
65
66
67
68
69
 
 
 
 
 
 
 
 
 
 
 
 
 
70
71
72
73
74
75
76
77
78
79
80
81
82
83
 
 
 
 
84
85
86
87
88
89
90
91
92
93
 
 
94
95
96
97
 
 
98
99
100
 
 
 
 
 
 
101
102
103
104
105
106
107
108
109
110
111
 
112
113
114
 
 
115
116
 
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
0
@@ -1,33 +1,23 @@
0
 module MDarby
0
   module Acts
0
-
0
- @@content_types = ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg']
0
- mattr_reader :content_types
0
-
0
- # Supported Filetypes
0
- # doc, ppt, pps, xls, pdf, ps, odt, odp, sxw, sxi, jpg, jpeg, png, gif, txt, rtf
0
-
0
- module Scribdfu
0
-
0
- class ConfigFileNotFoundError < StandardError; end
0
-
0
+ module Scribd_fu
0
+
0
       def self.included(base)
0
- base.extend ActsAsScribdDocument
0
+ base.extend ActsAsScribdObject
0
       end
0
 
0
- module ActsAsScribdDocument
0
+ module ActsAsScribdObject
0
         def acts_as_scribd_document(options = {})
0
           class_eval <<-END
0
- include MDarby::Acts::Scribdfu::InstanceMethods
0
+ include MDarby::Acts::Scribd_fu::InstanceMethods
0
           END
0
         end
0
       end
0
 
0
       module InstanceMethods
0
-
0
         def self.included(base)
0
           base.extend ClassMethods
0
-
0
+
0
           mattr_reader :scribd_config
0
 
0
           begin
0
@@ -37,89 +27,117 @@ module MDarby
0
           end
0
 
0
           begin
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
+
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
+
0
+ @@user = Scribd::User.login(@@scribd_config[:user], @@scribd_config[:password])
0
           rescue
0
- raise ConfigFileNotFoundError.new('File %s not found' % @@scribd_config_path)
0
+ puts "Config file not found, or your credentials are b0rked!"
0
+ exit
0
           end
0
- end
0
 
0
- module ClassMethods
0
-
0
- delegate :content_types, :to => MDarby::Acts
0
-
0
- def validates_as_scribd_document
0
- validates_presence_of :scribd_id, :scribd_access_id
0
- validate :scribd_attributes_valid?
0
+ def self.scribd_user
0
+ @scribd_user = @@user
0
           end
0
+ end
0
+
0
+ def get_all_documents
0
+ @@user.documents
0
+ end
0
 
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
- end
0
- end
0
+ def get_document(id)
0
+ @@user.find_document(id)
0
+ end
0
+ end
0
 
0
-
0
- # self.class?
0
-
0
+ module ClassMethods
0
+ # Supported Filetypes
0
+ # doc, ppt, pps, xls, pdf, ps, odt, odp, sxw, sxi, jpg, jpeg, png, gif, txt, rtf
0
 
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
- end
0
+ @@content_types = ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png', 'image/jpg']
0
+ mattr_reader :content_types
0
 
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
- end
0
-
0
- def scribd_id=(id)
0
- write_attribute :scribd_id, id.to_s.strip
0
- end
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
+ end
0
 
0
- def scribd_access_key=(key)
0
- write_attribute :scribd_access_key, key.to_s.strip
0
- end
0
-
0
- def destroy_scribd_document
0
- if self.scribd_id
0
- user = Scribd::User.login 'XXX', 'XXXXX'
0
- document = user.find_document(self.scribd_id)
0
-
0
- unless document.destroy
0
- logger.info "#{Time.now.rfc2822}: Removing Scribd Document #{self.id} failed!"
0
- end
0
- end
0
+ def scribd_user
0
+ MDarby::Acts::Scribd_fu::InstanceMethods.scribd_user
0
+ end
0
+
0
+ def validates_as_scribd_document
0
+ validates_presence_of :scribd_id, :scribd_access_id
0
+ validate :scribd_attributes_valid?
0
+ end
0
+
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
           end
0
-
0
- def upload_to_scribd
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
+ end
0
+
0
+ def scribdable?(content_type)
0
+ content_types.include?(content_type)
0
+ end
0
+
0
+ def scribd_id=(id)
0
+ write_attribute :scribd_id, id.to_s.strip
0
+ end
0
 
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
+ end
0
 
0
- if document.save!
0
- logger.info "#{Time.now.rfc2822}: Document #{document.id} saved after being converted to iPaper."
0
+ def show
0
+ end
0
 
0
- # Upload to S3 via the S3_worker
0
- logger.info "#{Time.now.rfc2822}: Scheduling Document #{document.id} for S3 upload"
0
- document.upload_to_s3
0
- else
0
- logger.info "#{Time.now.rfc2822}: Document #{document.id} failed to save after being converted to iPaper!"
0
- end
0
+ def edit(options = {})
0
+ end
0
 
0
+ def destroy_scribd_document
0
+ puts "HERE!"
0
+ unless self.scribd_id.blank?
0
+ document = scribd_user.find_document(self.scribd_id)
0
+
0
+ if document.destroy
0
+ logger.info "#{Time.now.rfc2822}: Removing Scribd Object #{self.id} successful"
0
             else
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
             end
0
           end
0
-
0
- end
0
+ end
0
 
0
- end
0
+ def upload_to_scribd
0
+ puts self.to_yaml
0
+ # if scribdable?
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
+ #
0
+ # self.scribd_id = document.doc_id
0
+ # self.scribd_access_key = document.access_key
0
+ #
0
+ # if save!
0
+ # logger.info "#{Time.now.rfc2822}: Object #{self.id} saved after being converted to iPaper."
0
+ # else
0
+ # logger.info "#{Time.now.rfc2822}: Object #{self.id} failed to save after being converted to iPaper!"
0
+ # end
0
+ # else
0
+ # logger.info "#{Time.now.rfc2822}: Object #{self.id} iPaper conversion failed..."
0
+ # end
0
+ # else
0
+ # logger.info "#{Time.now.rfc2822}: Object #{self.id} is not Scribdable!"
0
+ # end
0
+ end
0
+
0
+ end
0
+
0
     end
0
   end
0
 end
0
\ No newline at end of file
...
5
6
7
8
9
 
10
...
5
6
7
 
8
9
10
0
@@ -5,4 +5,4 @@ scribd:
0
   secret:
0
   user:
0
   password:
0
-
0
\ No newline at end of file
0
+ access:
0
\ No newline at end of file

Comments

    No one has commented yet.