lib/roo/generic_spreadsheet.rb in roo-1.2.2 vs lib/roo/generic_spreadsheet.rb in roo-1.2.3
- old
+ new
@@ -432,24 +432,59 @@
col = GenericSpreadsheet.letter_to_number(col)
end
return row,col
end
+ # def open_from_uri(uri)
+ # require 'open-uri' ;
+ # tempfilename = File.join(@tmpdir, File.basename(uri))
+ # f = File.open(tempfilename,"wb")
+ # begin
+ # open(uri) do |net|
+ # f.write(net.read)
+ # end
+ # rescue
+ # raise "could not open #{uri}"
+ # end
+ # f.close
+ # File.join(@tmpdir, File.basename(uri))
+ # end
+
+ # OpenURI::HTTPError
+ # def open_from_uri(uri)
+ # require 'open-uri'
+ # #existiert URL?
+ # r = Net::HTTP.get_response(URI.parse(uri))
+ # raise "URL nicht verfuegbar" unless r.is_a? Net::HTTPOK
+ # tempfilename = File.join(@tmpdir, File.basename(uri))
+ # f = File.open(tempfilename,"wb")
+ # open(uri) do |net|
+ # f.write(net.read)
+ # end
+ # # rescue
+ # # raise "could not open #{uri}"
+ # # end
+ # f.close
+ # File.join(@tmpdir, File.basename(uri))
+ # end
+
def open_from_uri(uri)
- require 'open-uri' ;
- tempfilename = File.join(@tmpdir, File.basename(uri))
- f = File.open(tempfilename,"wb")
+ require 'open-uri'
+ response = ''
begin
- open(uri) do |net|
- f.write(net.read)
- end
- rescue
+ open(uri, "User-Agent" => "Ruby/#{RUBY_VERSION}") { |net|
+ response = net.read
+ tempfilename = File.join(@tmpdir, File.basename(uri))
+ f = File.open(tempfilename,"wb")
+ f.write(response)
+ f.close
+ }
+ rescue OpenURI::HTTPError
raise "could not open #{uri}"
end
- f.close
File.join(@tmpdir, File.basename(uri))
end
-
+
def open_from_stream(stream)
tempfilename = File.join(@tmpdir, "spreadsheet")
f = File.open(tempfilename,"wb")
f.write(stream[7..-1])
f.close