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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6797e0c960a77817f75d9f5a6c5b48e7e4f3b363
4
- data.tar.gz: 430f42e462d044897740dad2fb9dd21db6b707d9
3
+ metadata.gz: 0ed6f4d41c3ec2500ea5d08db74368eb77847e74
4
+ data.tar.gz: fe6d09eac8253dbaffd1e2f528bd958ea6d81304
5
5
  SHA512:
6
- metadata.gz: 7e1560a7e9a3ff8e13e628f1e77c1d135e0828dd1eb451b8702092122bf90575c4f11d77dc6f526787a6d7eeeb6818ae602007a5276acfccc51dc7f88d3e770e
7
- data.tar.gz: d99149310b57a8a766f448361cb46bf9e7d5d4699ed624422985d418cd3bc8529a86c425e87b8b367f5f5371ce2398241d90cbdac9065d3e504e7a7258429549
6
+ metadata.gz: acb99bf3123f2e1863631d45ba072cdacb5c7b0041430199128a66c35d889f3e6a6820066d11189f7cd759254ab6b75920f8d7468d965862605ddf6161303c5c
7
+ data.tar.gz: 9d32e98f724a2f23760d2081c5628203516d5b5f3e20406244529d102699f2709328ff54a5931b17fd6b36de41d70cd97bd21beaa2c16bb9305b20ad034b828c
@@ -1,6 +1,7 @@
1
1
  require "uri"
2
2
  require "fileutils"
3
3
  require "tempfile"
4
+ require "rest_client"
4
5
  require "logger"
5
6
  require "mime/types"
6
7
 
@@ -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
- file = open(url)
98
+ response = RestClient::Request.new(method: :get, url: url, raw_response: true).execute
101
99
  @metadata = {
102
- size: file.meta["content-length"].to_i,
103
- filename: ::File.basename(file.base_uri.path),
104
- content_type: file.meta["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 OpenURI::HTTPError, RuntimeError => error
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
@@ -1,3 +1,3 @@
1
1
  module Refile
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
3
3
  end
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.required_ruby_version = ">= 2.1.0"
21
21
 
22
+ spec.add_dependency "rest-client", "~> 1.7.2"
22
23
  spec.add_dependency "sinatra", "~> 1.4.5"
23
24
  spec.add_dependency "mime-types"
24
25
 
@@ -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(RuntimeError, /redirection loop/)
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.3
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-01-18 00:00:00.000000000 Z
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