Module: ExportHelper

Instance Method Summary collapse

Instance Method Details

#csv_response(request_uri, params = {}, filename_prefix = '') ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'frontend/app/helpers/export_helper.rb', line 3

def csv_response(request_uri, params = {}, filename_prefix = '')
  self.response.headers["Content-Type"] = "text/csv"
  self.response.headers["Content-Disposition"] = "attachment; filename=#{filename_prefix}#{Time.now.to_i}.csv"
  self.response.headers['Last-Modified'] = Time.now.ctime.to_s
  params["dt"] = "csv"
  self.response_body = Enumerator.new do |y|
    xml_response(request_uri, params) do |chunk, percent|
      y << chunk if !chunk.blank?
    end
  end
end

#xml_response(request_uri, params = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'frontend/app/helpers/export_helper.rb', line 15

def xml_response(request_uri, params = {})
  JSONModel::HTTP::stream(request_uri, params) do |res|
    size, total = 0, res.header['Content-Length'].to_i
    res.read_body do |chunk|
      size += chunk.size
      percent = total > 0 ? ((size * 100) / total) : 0
      yield chunk, percent
    end
  end
end