public class ReportDownloader extends Object
ReportServiceInterface
.
There are two main functions of this class:
OutputStream
ReportUtils
also provides the method whenReportReady(ReportCallback)
to wait
for a scheduled report to finish processing before taking an action on the report through the
supplied ReportCallback
.
Modifier and Type | Field and Description |
---|---|
static Charset |
REPORT_CHARSET |
static int |
SLEEP_TIMER
The time to sleep before each request to the service.
|
Constructor and Description |
---|
ReportDownloader(com.google.api.ads.admanager.axis.v202002.ReportServiceInterface reportService,
long reportJobId)
Constructs a
ReportDownloader object for a ReportServiceInterface and a report
job id that the class works on. |
Modifier and Type | Method and Description |
---|---|
URL |
getDownloadUrl(com.google.api.ads.admanager.axis.v202002.ReportDownloadOptions options)
Gets the download URL for a GZip or plain-text format report.
|
com.google.common.io.CharSource |
getReportAsCharSource(com.google.api.ads.admanager.axis.v202002.ReportDownloadOptions options)
Returns a CharSource of report contents with
ReportDownloadOptions . |
boolean |
waitForReportReady()
Blocks and waits for a report to be ready.
|
Thread |
whenReportReady(ReportCallback callback)
Waits for the report to be ready and then calls:
ReportCallback.onSuccess() for a successful scheduling
ReportCallback.onFailure() for a failed scheduling due to a ReportJobStatus.FAILED
ReportCallback.onInterruption() if the wait thread is interrupted
ReportCallback.onException(Exception) if there was an exception while waiting for
the report to finish
|
public static final Charset REPORT_CHARSET
public static final int SLEEP_TIMER
public ReportDownloader(com.google.api.ads.admanager.axis.v202002.ReportServiceInterface reportService, long reportJobId)
ReportDownloader
object for a ReportServiceInterface
and a report
job id that the class works on.reportService
- the ReportService stub to make calls toreportJobId
- the report job IDpublic Thread whenReportReady(ReportCallback callback)
ReportCallback.onSuccess()
for a successful scheduling
ReportCallback.onFailure()
for a failed scheduling due to a ReportJobStatus.FAILED
ReportCallback.onInterruption()
if the wait thread is interrupted
ReportCallback.onException(Exception)
if there was an exception while waiting for
the report to finish
callback
- the ReportCallback
to call when the job has finished, successfully or
otherwiseThread.interrupt()
can
be called on the returned thread to interrupt it.IllegalArgumentException
- if callback == null
public boolean waitForReportReady() throws RemoteException, InterruptedException
ReportJobStatus
is received that is
not ReportJobStatus#Pending
or ReportJobStatus#InProgress
, the report is
considered finished, and the method is returned with a true
if the report was
successful, or an false
if not.true
if the report was successful, false
otherwiseRemoteException
- if there was an error performing one of the SOAP callsInterruptedException
- if the thread was interruptedpublic URL getDownloadUrl(com.google.api.ads.admanager.axis.v202002.ReportDownloadOptions options) throws RemoteException, MalformedURLException
URL url = reportDownloader.getDownloadUrl(options);
Resources.asByteSource(url).copyTo(Files.asByteSink(file));
options
- the options to download the report withRemoteException
- if there was an error performing any Axis callMalformedURLException
- if there is an error forming the download URLIllegalStateException
- if the report is not ready to be downloadedpublic com.google.common.io.CharSource getReportAsCharSource(com.google.api.ads.admanager.axis.v202002.ReportDownloadOptions options) throws IOException
ReportDownloadOptions
. The ExportFormat
must be string-based, such as ExportFormat.CSV_DUMP
.options
- the options to download the report withIOException
- if there was an error performing any I/O action, including any SOAP callsIllegalStateException
- if the report is not ready to be downloadedIllegalArgumentException
- if the ExportFormat
is not a string-based formatCopyright © 2020. All Rights Reserved.