stripe-ruby icon indicating copy to clipboard operation
stripe-ruby copied to clipboard

Add ReportRun#contents to get the actual report data

Open willbryant opened this issue 3 years ago • 5 comments

As far as I can see the Ruby client currently only has methods to create a report run and retrieve it (ie. its metadata), not the actual report content.

This PR adds an action to download the content, based on Quote#pdf.

I tried to add a test to cover it, but found that stripe-mock doesn't have mocked reponses for the binary contents endpoint on files (only the file metadata endpoint), so I can't add a working test at this time.

willbryant avatar Dec 19 '22 08:12 willbryant

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Dec 19 '22 08:12 CLAassistant

Hi @willbryant,

Thank you for the submission. I think this is valuable. Instead of this interface:

report_run = Stripe::Reporting::ReportRun.retrieve("...")
report_run.contents do |bytes|
  file.write(bytes)
end

What do you think of a method on the File class instead?

report_run = Stripe::Reporting::ReportRun.retrieve("...")
if report_run.result
  report_run.result.download do |bytes|
    file.write(bytes)
  end
end

I think it's less discoverable on the File class, but it also then generalizes and provides similar methods for all file types in the Stripe API, not just report runs. Also I think it's nicer with respect to the possibility of report_run.result being nil.

(Please just discuss for now, don't change your implementation)

cc @pakrym-stripe @anniel-stripe

richardm-stripe avatar Feb 25 '23 00:02 richardm-stripe

That would be fine too, but it's not the approach taken for the existing Quote API. It seems File is only used for file resources, not for all file-like downloadables? So at the moment there is no way to construct a File object for anything other than an actual file resource, which is not exposed for report runs by the API.

willbryant avatar Feb 25 '23 02:02 willbryant

Try with manually downloading the report content using the provided metadata. Check if the report run has a PDF file associated with it and try accessing the PDF file directly through its URL. If this approach doesn't work, consider contacting the Stripe support team for further assistance.

msf-caesar avatar Sep 01 '23 03:09 msf-caesar