Module: Peddler::Helpers::Reports20210630

Included in:
APIs::Reports20210630
Defined in:
lib/peddler/helpers/reports_2021_06_30.rb

Instance Method Summary collapse

Instance Method Details

#download_report_document(report_document_id_or_url) ⇒ HTTP::Response

Convenience method to download a report by its document ID or URL. This method can handle both document IDs and direct download URLs.

Parameters:

  • report_document_id_or_url (String)

    The report document identifier or download URL

Returns:

  • (HTTP::Response)

    The API response containing the report content



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/peddler/helpers/reports_2021_06_30.rb', line 15

def download_report_document(report_document_id_or_url)
  # If it looks like a URL, use direct download
  if report_document_id_or_url.start_with?("http")
    return download_report_document_from_url(report_document_id_or_url)
  end

  # Otherwise, treat it as a document ID and get the download URL first
  document_info = get_report_document(report_document_id_or_url)
  download_url = document_info.dig("url")

  download_report_document_from_url(download_url)
end