lib/refile/attacher.rb in leifcr-refile-0.6.3 vs lib/refile/attacher.rb in leifcr-refile-0.7.0

- old
+ new

@@ -71,10 +71,11 @@ store.get(id) end end def set(value) + self.remove = false case value when nil then self.remove = true when String, Hash then retrieve!(value) else cache!(value) end @@ -103,24 +104,23 @@ end end def download(url) unless url.to_s.empty? - response = RestClient::Request.new(method: :get, url: url, raw_response: true).execute + download = Refile::Download.new(url) @metadata = { - size: response.file.size, - filename: URI.parse(url).path.split("/").last, - content_type: response.headers[:content_type] + size: download.size, + filename: download.original_filename, + content_type: download.content_type } if valid? - response.file.open if response.file.closed? # https://github.com/refile/refile/pull/210 - @metadata[:id] = cache.upload(response.file).id + @metadata[:id] = cache.upload(download.io).id write_metadata elsif @definition.raise_errors? raise Refile::Invalid, @errors.join(", ") end end - rescue RestClient::Exception + rescue Refile::Error @errors = [:download_failed] raise if @definition.raise_errors? end def store!