Skip to content

Commit 75078dd

Browse files
dpskpythonicrubyist
authored andcommitted
more robust way to fetch remote file, httparty dependency added. (#35)
1 parent b3bc431 commit 75078dd

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

creek.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
2727

2828
spec.add_dependency 'nokogiri', '~> 1.6.0'
2929
spec.add_dependency 'rubyzip', '>= 1.0.0'
30+
spec.add_dependency 'httparty', '~> 0.14.0'
3031
end

lib/creek/book.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'zip/filesystem'
22
require 'nokogiri'
33
require 'date'
4-
require 'open-uri'
4+
require 'httparty'
55

66
module Creek
77

@@ -20,8 +20,14 @@ def initialize path, options = {}
2020
extension = File.extname(options[:original_filename] || path).downcase
2121
raise 'Not a valid file format.' unless (['.xlsx', '.xlsm'].include? extension)
2222
end
23-
path = open(path) if options[:remote]
24-
@files = Zip::File.open path
23+
if options[:remote]
24+
zipfile = Tempfile.new("file")
25+
zipfile.binmode
26+
zipfile.write(HTTParty.get(path).body)
27+
zipfile.close
28+
path = zipfile.path
29+
end
30+
@files = Zip::File.open(path)
2531
@shared_strings = SharedStrings.new(self)
2632
end
2733

0 commit comments

Comments
 (0)