public function testRunAndDownloadReport()
 {
     $from = date('Y-m-d 00:00:00', time() - 24 * 60 * 60);
     $to = date('Y-m-d 00:00:00', time());
     $report = new Report(new AtomxAccountStore());
     $options = array('scope' => 'advertiser', 'groups' => ['campaign_id', 'domain_id', 'day_timestamp'], 'sums' => ['impressions', 'clicks', 'conversions', 'campaign_cost'], 'where' => [['advertiser_network_id', '==', '1']], 'from' => $from, 'to' => $to, 'timezone' => 'UTC');
     $streamer = $report->runAndDownload($options);
     $this->assertNotEquals(false, $streamer);
     var_dump($streamer->readLine());
 }
 public function runAndDownload($json, $timeout = 120, $returnReportId = false)
 {
     $reportData = $this->run($json);
     $secondsWaiting = 0;
     while (!Report::isReady($this->status(Report::getReportId($reportData)))) {
         sleep(1);
         if (++$secondsWaiting >= $timeout) {
             return false;
         }
     }
     if ($returnReportId) {
         return [$this->download($reportData), Report::getReportId($reportData)];
     } else {
         return $this->download($reportData);
     }
 }