Module: Bearcat::Client::Reports

Extended by:
ClientModule
Defined in:
lib/bearcat/client/reports.rb

Constant Summary

Constants included from ClientModule

ClientModule::ARG_REGEX

Instance Attribute Summary

Attributes included from ClientModule

#_registered_endpoints

Instance Method Summary collapse

Methods included from ClientModule

context_types, endpoint, prefix

Instance Method Details

#download_report(url, save_location = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bearcat/client/reports.rb', line 16

def download_report(url, save_location=nil)
  require 'open-uri'
  open_uri_stream = URI.open(url, {
    'User-Agent' => "Bearcat/#{Bearcat::VERSION} (#{RUBY_PLATFORM})",
    'Authorization' => "Bearer #{config[:token]}"
  })

  if save_location
    save_location = save_location.path if save_location.respond_to?(:path)
    IO.copy_stream(open_uri_stream, save_location)
    save_location
  else
    CSV.parse(open_uri_stream.read, headers: true)
  end
end