Module: Bearcat::Client::Reports
- Defined in:
- lib/bearcat/client/reports.rb
Instance Method Summary collapse
- #delete_report(account, report_name, report_id) ⇒ Object
- #download_report(url, save_location = nil) ⇒ Object
- #report_history(account, report_name) ⇒ Object
- #report_list(account) ⇒ Object
- #report_status(account, report_name, report_id) ⇒ Object
- #start_report(account, report_name, params = {}) ⇒ Object
Instance Method Details
#delete_report(account, report_name, report_id) ⇒ Object
23 24 25 |
# File 'lib/bearcat/client/reports.rb', line 23 def delete_report(account, report_name, report_id) delete("/api/v1/accounts/#{account}/reports/#{report_name}/#{report_id}") end |
#download_report(url, save_location = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/bearcat/client/reports.rb', line 27 def download_report(url, save_location=nil) #This method takes the verified URL returned in a Canvas report (attachment['url']), and if #a save_location is included, it will download it in chunks to the disk to save memory. You #can also download the report to memory if you do not include a save location. attempts = 0 begin uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if url.start_with?('https') response = http.head(uri.to_s) url = response['Location'] attempts += 1 end while attempts <= 5 && (response.code == '301' || response.code == '302' || response.code == '307') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if uri.to_s.start_with?('https') if save_location File.open(save_location, 'wb') do |file| http.request_get(uri.to_s) do |resp| resp.read_body do |segment| file.write(segment) end end end else response = http.request_get(uri.to_s) CSV.parse(response.read_body, headers: true) end end |
#report_history(account, report_name) ⇒ Object
15 16 17 |
# File 'lib/bearcat/client/reports.rb', line 15 def report_history(account, report_name) get("/api/v1/accounts/#{account}/reports/#{report_name}") end |
#report_list(account) ⇒ Object
7 8 9 |
# File 'lib/bearcat/client/reports.rb', line 7 def report_list(account) get("/api/v1/accounts/#{account}/reports") end |
#report_status(account, report_name, report_id) ⇒ Object
19 20 21 |
# File 'lib/bearcat/client/reports.rb', line 19 def report_status(account, report_name, report_id) get("/api/v1/accounts/#{account}/reports/#{report_name}/#{report_id}") end |
#start_report(account, report_name, params = {}) ⇒ Object
11 12 13 |
# File 'lib/bearcat/client/reports.rb', line 11 def start_report(account, report_name, params = {}) post("/api/v1/accounts/#{account}/reports/#{report_name}", params) end |