Reporting currently stops at three generated methods:
create_async_report(configuration:, start_date:, end_date:, name: nil)
get_async_report(report_id)
delete_async_report(report_id)
Getting actual report data out of those is entirely on the caller: poll until the
status is terminal, pull the presigned S3 url out of the response, fetch it, and
gunzip it.
report = reporting.create_async_report(...).parse
until (status = reporting.get_async_report(report["reportId"]).parse)["status"] == "COMPLETED"
sleep(30)
end
Zlib::GzipReader.new(URI.open(status["url"])).read
Note that :auto_inflate on the API client does not help here. The report is a
gzipped body fetched from S3, not a gzip content encoding on an API response.
Proposal
Follow the pattern Peddler uses: a hand-written helper module per API, mixed into
the generated class, so regeneration never clobbers it.
module AmazonAds
module Helpers
module Reporting
def download_report(report_id_or_url)
url = if report_id_or_url.start_with?("http")
report_id_or_url
else
get_async_report(report_id_or_url).parse.fetch("url")
end
HTTP.use(:auto_inflate).get(url)
end
end
end
end
The generator would include AmazonAds::Helpers::<ClassName> when
lib/amazon_ads/helpers/<file_name>.rb exists, matching
Generator::API#has_helper? in Peddler.
Open questions
- Do we also ship a polling helper, or leave the wait loop to the caller? Peddler
deliberately does not ship one. A blocking sleep loop in a client library is
easy to get wrong (no jitter, no cap, unusable from a reactor), so leaving it out
is defensible.
- Confirm whether the S3 object carries
Content-Encoding: gzip, which decides
whether :auto_inflate suffices or we need an explicit Zlib::GzipReader.
Peddler has an inconsistency here worth not copying: its Data Kiosk helper uses
HTTP.use(:auto_inflate) while its Reports helper does not.
Reportingcurrently stops at three generated methods:Getting actual report data out of those is entirely on the caller: poll until the
status is terminal, pull the presigned S3
urlout of the response, fetch it, andgunzip it.
Note that
:auto_inflateon the API client does not help here. The report is agzipped body fetched from S3, not a gzip content encoding on an API response.
Proposal
Follow the pattern Peddler uses: a hand-written helper module per API, mixed into
the generated class, so regeneration never clobbers it.
The generator would include
AmazonAds::Helpers::<ClassName>whenlib/amazon_ads/helpers/<file_name>.rbexists, matchingGenerator::API#has_helper?in Peddler.Open questions
deliberately does not ship one. A blocking
sleeploop in a client library iseasy to get wrong (no jitter, no cap, unusable from a reactor), so leaving it out
is defensible.
Content-Encoding: gzip, which decideswhether
:auto_inflatesuffices or we need an explicitZlib::GzipReader.Peddler has an inconsistency here worth not copying: its Data Kiosk helper uses
HTTP.use(:auto_inflate)while its Reports helper does not.