refile 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/refile.rb +1 -0
- data/lib/refile/attacher.rb +6 -9
- data/lib/refile/version.rb +1 -1
- data/refile.gemspec +1 -0
- data/spec/refile/attachment_spec.rb +1 -2
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ed6f4d41c3ec2500ea5d08db74368eb77847e74
|
4
|
+
data.tar.gz: fe6d09eac8253dbaffd1e2f528bd958ea6d81304
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acb99bf3123f2e1863631d45ba072cdacb5c7b0041430199128a66c35d889f3e6a6820066d11189f7cd759254ab6b75920f8d7468d965862605ddf6161303c5c
|
7
|
+
data.tar.gz: 9d32e98f724a2f23760d2081c5628203516d5b5f3e20406244529d102699f2709328ff54a5931b17fd6b36de41d70cd97bd21beaa2c16bb9305b20ad034b828c
|
data/lib/refile.rb
CHANGED
data/lib/refile/attacher.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require "open-uri"
|
2
|
-
|
3
1
|
module Refile
|
4
2
|
# @api private
|
5
3
|
class Attacher
|
@@ -97,21 +95,20 @@ module Refile
|
|
97
95
|
|
98
96
|
def download(url)
|
99
97
|
unless url.to_s.empty?
|
100
|
-
|
98
|
+
response = RestClient::Request.new(method: :get, url: url, raw_response: true).execute
|
101
99
|
@metadata = {
|
102
|
-
size: file.
|
103
|
-
filename: ::File.basename(
|
104
|
-
content_type:
|
100
|
+
size: response.file.size,
|
101
|
+
filename: ::File.basename(url),
|
102
|
+
content_type: response.headers[:content_type]
|
105
103
|
}
|
106
104
|
if valid?
|
107
|
-
@metadata[:id] = cache.upload(file).id
|
105
|
+
@metadata[:id] = cache.upload(response.file).id
|
108
106
|
write_metadata
|
109
107
|
elsif @raise_errors
|
110
108
|
raise Refile::Invalid, @errors.join(", ")
|
111
109
|
end
|
112
110
|
end
|
113
|
-
rescue
|
114
|
-
raise if error.is_a?(RuntimeError) and error.message !~ /redirection loop/
|
111
|
+
rescue RestClient::Exception
|
115
112
|
@errors = [:download_failed]
|
116
113
|
raise if @raise_errors
|
117
114
|
end
|
data/lib/refile/version.rb
CHANGED
data/refile.gemspec
CHANGED
@@ -111,7 +111,6 @@ describe Refile::Attachment do
|
|
111
111
|
|
112
112
|
it "follows redirects and fetches the file, caches it and sets the _id parameter" do
|
113
113
|
instance.remote_document_url = "http://www.example.com/1"
|
114
|
-
expect(instance.document_filename).to eq("2")
|
115
114
|
expect(instance.document.read).to eq("woop")
|
116
115
|
expect(Refile.cache.get(instance.document.id).read).to eq("woop")
|
117
116
|
end
|
@@ -121,7 +120,7 @@ describe Refile::Attachment do
|
|
121
120
|
it "handles redirect loops by trowing errors" do
|
122
121
|
expect do
|
123
122
|
instance.remote_document_url = "http://www.example.com/loop"
|
124
|
-
end.to raise_error(
|
123
|
+
end.to raise_error(RestClient::MaxRedirectsReached)
|
125
124
|
end
|
126
125
|
end
|
127
126
|
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: refile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Nicklas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.7.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.7.2
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: sinatra
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|