Class: Economic::Pdf
Instance Method Summary collapse
Methods inherited from Base
add_attribute, add_relation, #dirty?, field, #initialize, low_camel_case, #model_class, relation, #repo, snake_case, #to_h, #values_based_on_hash
Constructor Details
This class inherits a constructor from Economic::Base
Instance Method Details
#download_pdf(path: nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/economic/pdf.rb', line 6 def download_pdf(path: nil) raise StandardError, "There is no download url set" if download.nil? response = Economic::BaseRepo.send_request(method: :get, url: download) return response.body if path.nil? dirname = File.dirname(path) unless File.directory?(dirname) FileUtils.mkdir_p(dirname) end File.open(path, "wb") { |f| f.puts response.body } end |