Search in sources :

Example 21 with ReportDownloadOptions

use of com.google.api.ads.admanager.axis.v202111.ReportDownloadOptions in project googleads-java-lib by googleads.

the class ReportDownloaderTest method testGetReportAsCharSource.

@Test
public void testGetReportAsCharSource() throws IOException {
    ReportDownloader downloader = new ReportDownloader(reportService, 1);
    URL resourceUrl = ReportProvider.TEST_REPORT_RESOURCE;
    String report = Resources.toString(resourceUrl, Charset.forName("UTF-8"));
    when(reportService.getReportJobStatus(ArgumentMatchers.anyLong())).thenReturn(ReportJobStatus.COMPLETED);
    when(reportService.getReportDownloadUrlWithOptions(ArgumentMatchers.anyLong(), ArgumentMatchers.any(ReportDownloadOptions.class))).thenReturn(resourceUrl.toString());
    ReportDownloadOptions options = new ReportDownloadOptions();
    options.setExportFormat(ExportFormat.CSV_DUMP);
    options.setUseGzipCompression(false);
    CharSource reportCharSource = downloader.getReportAsCharSource(options);
    assertEquals(report, reportCharSource.read());
}
Also used : CharSource(com.google.common.io.CharSource) ReportDownloadOptions(com.google.api.ads.admanager.axis.v202105.ReportDownloadOptions) URL(java.net.URL) Test(org.junit.Test)

Example 22 with ReportDownloadOptions

use of com.google.api.ads.admanager.axis.v202111.ReportDownloadOptions in project googleads-java-lib by googleads.

the class ReportDownloaderTest method testGetReportDownloadUrlWithOptions.

@Test
public void testGetReportDownloadUrlWithOptions() throws ApiException, RemoteException, MalformedURLException {
    ReportDownloader downloader = new ReportDownloader(reportService, 1);
    when(reportService.getReportJobStatus(ArgumentMatchers.anyLong())).thenReturn(ReportJobStatus.COMPLETED);
    when(reportService.getReportDownloadUrlWithOptions(ArgumentMatchers.anyLong(), ArgumentMatchers.any(ReportDownloadOptions.class))).thenReturn("https://www.google.com/");
    URL downloadUrl = downloader.getDownloadUrl(new ReportDownloadOptions());
    assertEquals("https://www.google.com/", downloadUrl.toString());
}
Also used : ReportDownloadOptions(com.google.api.ads.admanager.axis.v202105.ReportDownloadOptions) URL(java.net.URL) Test(org.junit.Test)

Example 23 with ReportDownloadOptions

use of com.google.api.ads.admanager.axis.v202111.ReportDownloadOptions in project googleads-java-lib by googleads.

the class ReportDownloaderTest method testGetReportAsCharSource.

@Test
public void testGetReportAsCharSource() throws IOException {
    ReportDownloader downloader = new ReportDownloader(reportService, 1);
    URL resourceUrl = ReportProvider.TEST_REPORT_RESOURCE;
    String report = Resources.toString(resourceUrl, Charset.forName("UTF-8"));
    when(reportService.getReportJobStatus(ArgumentMatchers.anyLong())).thenReturn(ReportJobStatus.COMPLETED);
    when(reportService.getReportDownloadUrlWithOptions(ArgumentMatchers.anyLong(), ArgumentMatchers.any(ReportDownloadOptions.class))).thenReturn(resourceUrl.toString());
    ReportDownloadOptions options = new ReportDownloadOptions();
    options.setExportFormat(ExportFormat.CSV_DUMP);
    options.setUseGzipCompression(false);
    CharSource reportCharSource = downloader.getReportAsCharSource(options);
    assertEquals(report, reportCharSource.read());
}
Also used : CharSource(com.google.common.io.CharSource) ReportDownloadOptions(com.google.api.ads.admanager.axis.v202108.ReportDownloadOptions) URL(java.net.URL) Test(org.junit.Test)

Example 24 with ReportDownloadOptions

use of com.google.api.ads.admanager.axis.v202111.ReportDownloadOptions in project googleads-java-lib by googleads.

the class ReportDownloaderTest method testGetReportDownloadUrlWithOptions.

@Test
public void testGetReportDownloadUrlWithOptions() throws ApiException, RemoteException, MalformedURLException {
    ReportDownloader downloader = new ReportDownloader(reportService, 1);
    when(reportService.getReportJobStatus(ArgumentMatchers.anyLong())).thenReturn(ReportJobStatus.COMPLETED);
    when(reportService.getReportDownloadUrlWithOptions(ArgumentMatchers.anyLong(), ArgumentMatchers.any(ReportDownloadOptions.class))).thenReturn("https://www.google.com/");
    URL downloadUrl = downloader.getDownloadUrl(new ReportDownloadOptions());
    assertEquals("https://www.google.com/", downloadUrl.toString());
}
Also used : ReportDownloadOptions(com.google.api.ads.admanager.axis.v202108.ReportDownloadOptions) URL(java.net.URL) Test(org.junit.Test)

Example 25 with ReportDownloadOptions

use of com.google.api.ads.admanager.axis.v202111.ReportDownloadOptions in project googleads-java-lib by googleads.

the class ReportDownloader method getDownloadUrl.

/**
 * Gets the download URL for a GZip or plain-text format report. If you requested a compressed
 * report, you may want to save your file with a gz or zip extension.
 *
 * <pre><code>
 *  URL url = reportDownloader.getDownloadUrl(options);
 *  Resources.asByteSource(url).copyTo(Files.asByteSink(file));
 * </code></pre>
 *
 * @param options the options to download the report with
 * @return the URL for the report download
 * @throws RemoteException if there was an error performing any Axis call
 * @throws MalformedURLException if there is an error forming the download URL
 * @throws IllegalStateException if the report is not ready to be downloaded
 */
public URL getDownloadUrl(ReportDownloadOptions options) throws RemoteException, MalformedURLException {
    ReportJobStatus status = reportService.getReportJobStatus(reportJobId);
    Preconditions.checkState(status == ReportJobStatus.COMPLETED, "Report " + reportJobId + " must be completed before downloading. It is currently: " + status);
    return new URL(reportService.getReportDownloadUrlWithOptions(reportJobId, options));
}
Also used : ReportJobStatus(com.google.api.ads.admanager.axis.v202111.ReportJobStatus) URL(java.net.URL)

Aggregations

URL (java.net.URL)33 File (java.io.File)24 ReportDownloadOptions (com.google.api.ads.admanager.axis.v202108.ReportDownloadOptions)10 ReportDownloadOptions (com.google.api.ads.admanager.axis.v202111.ReportDownloadOptions)10 ReportDownloadOptions (com.google.api.ads.admanager.axis.v202202.ReportDownloadOptions)10 ReportDownloader (com.google.api.ads.admanager.axis.utils.v202108.ReportDownloader)8 ReportDownloader (com.google.api.ads.admanager.axis.utils.v202111.ReportDownloader)8 ReportDownloader (com.google.api.ads.admanager.axis.utils.v202202.ReportDownloader)8 ReportJob (com.google.api.ads.admanager.axis.v202108.ReportJob)8 ReportQuery (com.google.api.ads.admanager.axis.v202108.ReportQuery)8 ReportServiceInterface (com.google.api.ads.admanager.axis.v202108.ReportServiceInterface)8 ReportJob (com.google.api.ads.admanager.axis.v202111.ReportJob)8 ReportQuery (com.google.api.ads.admanager.axis.v202111.ReportQuery)8 ReportServiceInterface (com.google.api.ads.admanager.axis.v202111.ReportServiceInterface)8 ReportJob (com.google.api.ads.admanager.axis.v202202.ReportJob)8 ReportQuery (com.google.api.ads.admanager.axis.v202202.ReportQuery)8 ReportServiceInterface (com.google.api.ads.admanager.axis.v202202.ReportServiceInterface)8 Test (org.junit.Test)8 CharSource (com.google.common.io.CharSource)4 ReportCallback (com.google.api.ads.admanager.lib.utils.ReportCallback)3