scribd_fu 2.0.7 → 2.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -10,6 +10,7 @@ begin
10
10
  gem.email = "matt@matt-darby.com"
11
11
  gem.homepage = "http://github.com/mdarby/scribd_fu"
12
12
  gem.authors = ["Matt Darby"]
13
+ gem.add_dependency('rscribd')
13
14
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
15
  end
15
16
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.7
1
+ 2.0.8
@@ -22,11 +22,13 @@ module ScribdFu
22
22
 
23
23
  # Yields the correct path to the file, either the local filename or the S3 URL.
24
24
  def file_path
25
- if public_filename =~ ScribdFu::S3 || public_filename =~ ScribdFu::CLOUD_FRONT
26
- public_filename
25
+ if ScribdFu::amazon_based?(public_filename)
26
+ path = public_filename
27
27
  else
28
- "#{RAILS_ROOT}/public#{public_filename}"
28
+ path = "#{RAILS_ROOT}/public#{public_filename}"
29
29
  end
30
+
31
+ ScribdFu::strip_cache_string(path)
30
32
  end
31
33
  end
32
34
 
@@ -28,9 +28,13 @@ module ScribdFu
28
28
  # stored on S3, this is a full S3 URI, while it is a full path to the
29
29
  # local file if the file is stored locally.
30
30
  def file_path
31
- path = (attached_file.url =~ ScribdFu::S3) ? attached_file.url : attached_file.path
32
- pos = path.rindex('?')
33
- (pos) ? path[0, pos] : path
31
+ if ScribdFu::amazon_based?(attached_file.url)
32
+ path = attached_file.url
33
+ else
34
+ path = attached_file.path
35
+ end
36
+
37
+ ScribdFu::strip_cache_string(path)
34
38
  end
35
39
 
36
40
 
data/lib/scribd_fu.rb CHANGED
@@ -103,6 +103,18 @@ module ScribdFu
103
103
  str.gsub(' ', '%20')
104
104
  end
105
105
 
106
+ # See if a URL is S3 or CloudFront based
107
+ def amazon_based?(url)
108
+ url =~ S3 || url =~ CLOUD_FRONT
109
+ end
110
+
111
+ # Strip off any trailing "?1234567890" cache strings
112
+ # They cause headaches on Scribd's end.
113
+ def strip_cache_string(url)
114
+ pos = url.rindex('?')
115
+ (pos) ? url[0, pos] : url
116
+ end
117
+
106
118
  end
107
119
 
108
120
  module ClassMethods
data/scribd_fu.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{scribd_fu}
8
- s.version = "2.0.7"
8
+ s.version = "2.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matt Darby"]
@@ -50,9 +50,12 @@ Gem::Specification.new do |s|
50
50
  s.specification_version = 3
51
51
 
52
52
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
+ s.add_runtime_dependency(%q<rscribd>, [">= 0"])
53
54
  else
55
+ s.add_dependency(%q<rscribd>, [">= 0"])
54
56
  end
55
57
  else
58
+ s.add_dependency(%q<rscribd>, [">= 0"])
56
59
  end
57
60
  end
58
61
 
@@ -69,6 +69,28 @@ describe "An AttachmentFu model" do
69
69
 
70
70
  end
71
71
 
72
+ context "and is destined for CloudFront" do
73
+ before do
74
+ @document.stub!(:public_filename => "http://a9.cloudfront.net/something.pdf?0000000000")
75
+ end
76
+
77
+ it "should return the CloudFront URL, not the local filesystem path" do
78
+ @document.file_path.should == "http://a9.cloudfront.net/something.pdf"
79
+ end
80
+
81
+ end
82
+
83
+ context "and is destined for S3" do
84
+ before do
85
+ @document.stub!(:public_filename => "http://s3.amazonaws.com/something.pdf")
86
+ end
87
+
88
+ it "should return the AWS URL, not the local filesystem path" do
89
+ @document.file_path.should == "http://s3.amazonaws.com/something.pdf"
90
+ end
91
+
92
+ end
93
+
72
94
  describe "and uploading to Scribd succeeded" do
73
95
  before do
74
96
  @scribd_response = mock('scribd_response', :doc_id => "doc_id", :access_key => "access_key")
@@ -206,6 +228,17 @@ describe "A Paperclip model" do
206
228
  end
207
229
  end
208
230
 
231
+ context "and is destined for CloudFront" do
232
+ before do
233
+ @attached_file.stub!(:url => "http://a9.cloudfront.net/something.pdf?0000000000")
234
+ end
235
+
236
+ it "should return the CloudFront URL, not the local filesystem path" do
237
+ @attachment.file_path.should == "http://a9.cloudfront.net/something.pdf"
238
+ end
239
+
240
+ end
241
+
209
242
  describe "and uploading to Scribd succeeded" do
210
243
  before do
211
244
  @scribd_response = mock('scribd_response', :doc_id => "doc_id", :access_key => "access_key")
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scribd_fu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 7
10
- version: 2.0.7
9
+ - 8
10
+ version: 2.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Darby
@@ -17,8 +17,21 @@ cert_chain: []
17
17
 
18
18
  date: 2010-06-30 00:00:00 -04:00
19
19
  default_executable:
20
- dependencies: []
21
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rscribd
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
22
35
  description: A Rails gem that streamlines interactions with the Scribd service
23
36
  email: matt@matt-darby.com
24
37
  executables: []