Search in sources :

Example 26 with ReportDownloadOptions

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

the class RunReachReport method runExample.

/**
 * Runs the example.
 *
 * @param adManagerServices the services factory.
 * @param session the session.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 * @throws IOException if unable to write the response to a file.
 * @throws InterruptedException if the thread is interrupted while waiting for the report to
 *     complete.
 */
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session) throws IOException, InterruptedException {
    // Get the ReportService.
    ReportServiceInterface reportService = adManagerServices.get(session, ReportServiceInterface.class);
    // Create report query.
    ReportQuery reportQuery = new ReportQuery();
    reportQuery.setDimensions(new Dimension[] { Dimension.COUNTRY_NAME, Dimension.LINE_ITEM_ID, Dimension.LINE_ITEM_NAME });
    reportQuery.setColumns(new Column[] { Column.UNIQUE_REACH_FREQUENCY, Column.UNIQUE_REACH_IMPRESSIONS, Column.UNIQUE_REACH });
    // Set the dynamic date range type or a custom start and end date that is
    // the beginning of the week (Sunday) to the end of the week (Saturday), or
    // the first of the month to the end of the month.
    reportQuery.setDateRangeType(DateRangeType.REACH_LIFETIME);
    // Create report job.
    ReportJob reportJob = new ReportJob();
    reportJob.setReportQuery(reportQuery);
    // Run report job.
    reportJob = reportService.runReportJob(reportJob);
    // Create report downloader.
    ReportDownloader reportDownloader = new ReportDownloader(reportService, reportJob.getId());
    // Wait for the report to be ready.
    reportDownloader.waitForReportReady();
    // Change to your file location.
    File file = File.createTempFile("reach-report-", ".csv.gz");
    System.out.printf("Downloading report to %s ...", file.toString());
    // Download the report.
    ReportDownloadOptions options = new ReportDownloadOptions();
    options.setExportFormat(ExportFormat.CSV_DUMP);
    options.setUseGzipCompression(true);
    URL url = reportDownloader.getDownloadUrl(options);
    Resources.asByteSource(url).copyTo(Files.asByteSink(file));
    System.out.println("done.");
}
Also used : ReportDownloader(com.google.api.ads.admanager.axis.utils.v202108.ReportDownloader) ReportDownloadOptions(com.google.api.ads.admanager.axis.v202108.ReportDownloadOptions) ReportQuery(com.google.api.ads.admanager.axis.v202108.ReportQuery) ReportServiceInterface(com.google.api.ads.admanager.axis.v202108.ReportServiceInterface) ReportJob(com.google.api.ads.admanager.axis.v202108.ReportJob) File(java.io.File) URL(java.net.URL)

Example 27 with ReportDownloadOptions

use of com.google.api.ads.admanager.axis.v202205.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 28 with ReportDownloadOptions

use of com.google.api.ads.admanager.axis.v202205.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 29 with ReportDownloadOptions

use of com.google.api.ads.admanager.axis.v202205.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.v202111.ReportDownloadOptions) URL(java.net.URL) Test(org.junit.Test)

Example 30 with ReportDownloadOptions

use of com.google.api.ads.admanager.axis.v202205.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.v202205.ReportDownloadOptions) URL(java.net.URL) Test(org.junit.Test)

Aggregations

URL (java.net.URL)42 File (java.io.File)31 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 Test (org.junit.Test)10 ReportDownloadOptions (com.google.api.ads.admanager.axis.v202205.ReportDownloadOptions)9 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 ReportDownloader (com.google.api.ads.admanager.axis.utils.v202205.ReportDownloader)7