Module: Bearcat::Client::Reports

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

Constant Summary collapse

PREFIX =
"/api/v1/accounts"

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bearcat/client/reports.rb', line 21

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

#start_report(canvas_account_id, report_name, payload = {}) ⇒ Object



15
16
17
18
19
# File 'lib/bearcat/client/reports.rb', line 15

def start_report(, report_name, payload = {})
  post("#{PREFIX}/#{}/reports/#{report_name}", payload)
rescue Bearcat::MiscExceptions::Conflict => e
  JSON.parse(e.response.response_body)
end