mdarby-scribd_fu 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.textile +4 -0
- data/lib/scribd_fu/attachment_fu.rb +1 -1
- data/lib/scribd_fu/paperclip.rb +1 -1
- data/lib/scribd_fu.rb +6 -1
- data/scribd_fu.gemspec +2 -2
- data/spec/scribd_fu_spec.rb +31 -5
- metadata +2 -2
data/README.textile
CHANGED
@@ -57,6 +57,10 @@ h2. Access
|
|
57
57
|
|
58
58
|
You can set the access level on all documents by setting the @access@ key in the scribd_fu.yml file to either 'private' or 'public'. ScribdFu assumes that you'd like to keep your documents private.
|
59
59
|
|
60
|
+
h2. Help
|
61
|
+
|
62
|
+
Add a ticket to "ScribdFu's Lighthouse Account":http://mdarby.lighthouseapp.com/projects/28697-scribdfu/overview
|
63
|
+
|
60
64
|
h2. About the Author
|
61
65
|
|
62
66
|
My name is "Matt Darby.":http://blog.matt-darby.com I’m an IT Manager and pro-web-dev at for "Dynamix Engineering":http://dynamix-ltd.com and hold a Master’s Degree in Computer Science from "Franklin University":http://www.franklin.edu in sunny "Columbus, OH.":http://en.wikipedia.org/wiki/Columbus,_Ohio
|
@@ -28,7 +28,7 @@ module ScribdFu
|
|
28
28
|
|
29
29
|
# Yields the correct path to the file, either the local filename or the S3 URL.
|
30
30
|
def file_path
|
31
|
-
if public_filename
|
31
|
+
if public_filename =~ /^https{0,1}:\/\/s3.amazonaws.com/
|
32
32
|
public_filename
|
33
33
|
else
|
34
34
|
"#{RAILS_ROOT}/public#{public_filename}"
|
data/lib/scribd_fu/paperclip.rb
CHANGED
@@ -35,7 +35,7 @@ module ScribdFu
|
|
35
35
|
# stored on S3, this is a full S3 URI, while it is a full path to the
|
36
36
|
# local file if the file is stored locally.
|
37
37
|
def file_path
|
38
|
-
if attached_file.url =~ /^https{0,1}:\/\/s3.amazonaws.com
|
38
|
+
if attached_file.url =~ /^https{0,1}:\/\/s3.amazonaws.com/
|
39
39
|
attached_file.url
|
40
40
|
else
|
41
41
|
attached_file.path
|
data/lib/scribd_fu.rb
CHANGED
@@ -62,7 +62,7 @@ module ScribdFu
|
|
62
62
|
# Upload a file to Scribd
|
63
63
|
def upload(obj, file_path)
|
64
64
|
begin
|
65
|
-
res = scribd_user.upload(:file =>
|
65
|
+
res = scribd_user.upload(:file => escape(file_path), :access => access_level)
|
66
66
|
obj.update_attributes({:ipaper_id => res.doc_id, :ipaper_access_key => res.access_key})
|
67
67
|
rescue
|
68
68
|
raise ScribdFuUploadError, "Sorry, but #{obj.class} ##{obj.id} could not be uploaded to Scribd"
|
@@ -96,6 +96,11 @@ module ScribdFu
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
+
# Replace spaces with '%20' (needed by Paperclip models).
|
100
|
+
def escape(str)
|
101
|
+
str.gsub(' ', '%20')
|
102
|
+
end
|
103
|
+
|
99
104
|
end
|
100
105
|
|
101
106
|
module ClassMethods
|
data/scribd_fu.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "scribd_fu"
|
3
|
-
s.version = "2.0.
|
4
|
-
s.date = "2009-04-
|
3
|
+
s.version = "2.0.3"
|
4
|
+
s.date = "2009-04-06"
|
5
5
|
s.summary = "Quick and easy interactions with Scribd's iPaper service"
|
6
6
|
s.email = "matt@matt-darby.com"
|
7
7
|
s.homepage = "http://github.com/mdarby/scribd_fu/tree/master"
|
data/spec/scribd_fu_spec.rb
CHANGED
@@ -57,7 +57,16 @@ describe "An AttachmentFu model" do
|
|
57
57
|
|
58
58
|
describe "and is scribdable?" do
|
59
59
|
before do
|
60
|
-
@document.stub!(:
|
60
|
+
@document.stub!(:update_attributes)
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "and has spaces in the filename" do
|
64
|
+
it "should sanitize the file path" do
|
65
|
+
res = mock('response', :doc_id => 1, :access_key => "ASDF")
|
66
|
+
@scribd_user.should_receive(:upload).with(:file => "some%20filename%20with%20spaces", :access => 'access').and_return(res)
|
67
|
+
ScribdFu::upload(@document, "some filename with spaces")
|
68
|
+
end
|
69
|
+
|
61
70
|
end
|
62
71
|
|
63
72
|
describe "and uploading to Scribd succeeded" do
|
@@ -162,7 +171,6 @@ describe "A Paperclip model" do
|
|
162
171
|
describe "that was just created" do
|
163
172
|
before do
|
164
173
|
@attachment.attributes = {:ipaper_id => nil, :ipaper_access_key => nil, :attachment_content_type => "application/pdf"}
|
165
|
-
@attachment.stub!(:file_path => "/path/to/somewhere")
|
166
174
|
end
|
167
175
|
|
168
176
|
describe "and is scribdable?" do
|
@@ -170,6 +178,20 @@ describe "A Paperclip model" do
|
|
170
178
|
@attachment.stub!(:scribdable? => true)
|
171
179
|
end
|
172
180
|
|
181
|
+
describe "and has spaces in the filename" do
|
182
|
+
before do
|
183
|
+
@attached_file.stub!(:path => "/path/to/somewhere with spaces.pdf")
|
184
|
+
@attachment.stub!(:update_attributes)
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should sanitize the file path" do
|
188
|
+
res = mock('response', :doc_id => 1, :access_key => "ASDF")
|
189
|
+
@scribd_user.should_receive(:upload).with(:file => "/path/to/somewhere%20with%20spaces.pdf", :access => 'access').and_return(res)
|
190
|
+
ScribdFu::upload(@attachment, "/path/to/somewhere with spaces.pdf")
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
|
173
195
|
describe "and uploading to Scribd succeeded" do
|
174
196
|
before do
|
175
197
|
@scribd_response = mock('scribd_response', :doc_id => "doc_id", :access_key => "access_key")
|
@@ -258,17 +280,21 @@ describe "Viewing an iPaper document" do
|
|
258
280
|
end
|
259
281
|
|
260
282
|
it "should return this HTML by default" do
|
261
|
-
@document.display_ipaper.should == "
|
283
|
+
@document.display_ipaper.gsub(/\s{2,}/, "").should == "<script type=\"text/javascript\" src=\"http://www.scribd.com/javascripts/view.js\"></script><div id=\"embedded_flash\"></div><script type=\"text/javascript\">var scribd_doc = scribd.Document.getDoc(doc_id, 'access_key');scribd_doc.write(\"embedded_flash\");</script>\n"
|
262
284
|
end
|
263
285
|
|
264
286
|
it "should allow custom Javascript params" do
|
265
287
|
options = {:height => 100, :width => 100}
|
266
|
-
|
288
|
+
|
289
|
+
@document.display_ipaper(options).should =~ /.*scribd_doc\.addParam\('height', '100'\);.*/
|
290
|
+
@document.display_ipaper(options).should =~ /.*scribd_doc\.addParam\('width', '100'\);.*/
|
267
291
|
end
|
268
292
|
|
269
293
|
it "should allow not allow crazy custom Javascript params" do
|
270
294
|
options = {:some_dumb_setting => 100, :width => 100}
|
271
|
-
|
295
|
+
|
296
|
+
@document.display_ipaper(options).should =~ /.*scribd_doc\.addParam\('width', '100'\);.*/
|
297
|
+
@document.display_ipaper(options).should_not =~ /.*scribd_doc\.addParam\('some_dumb_setting', '100'\);.*/
|
272
298
|
end
|
273
299
|
|
274
300
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mdarby-scribd_fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Darby
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-06 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|