/** * Downloads a report from a URL. If the filePath parameter is specified it * will be downloaded to the file at that path, otherwise it will be * downloaded to memory and be returned as a string. * @param string $downloadUrl the URL of the report download * @param string $filePath an optional path of a file to download the report * to * @return mixed if $filePath isn't specified it will return the contents of * the report, otherwise the size in bytes of the downloaded report */ public static function DownloadReport($downloadUrl, $filePath = null) { DeprecationUtils::LogDeprecatedMethodUsage('ReportUtils::DownloadReport', 'Please use ReportDownloader.php instead.'); // TODO(vtsao): This method should not be static and instantiation of this // class should be allowed so we can "inject" CurlUtils, but would break too // many things that rely on this method being static. $curlUtils = new CurlUtils(); $ch = $curlUtils->CreateSession($downloadUrl); if (isset($filePath)) { $file = fopen($filePath, 'w'); $curlUtils->SetOpt($ch, CURLOPT_FILE, $file); } else { $curlUtils->SetOpt($ch, CURLOPT_RETURNTRANSFER, 1); } $result = $curlUtils->Exec($ch); $httpCode = $curlUtils->GetInfo($ch, CURLINFO_HTTP_CODE); $error = $curlUtils->Error($ch); $downloadSize = $curlUtils->GetInfo($ch, CURLINFO_SIZE_DOWNLOAD); $curlUtils->Close($ch); if (isset($file)) { fclose($file); } if ($httpCode != 200) { $message = sprintf('Invalid report download URL: %s', $downloadUrl); throw new InvalidArgumentException($message, $httpCode); } if (isset($filePath)) { return $downloadSize; } else { return $result; } }
/** * Returns some of the objects from an account, using the service and method * name provided. * @param DfpSoapClient $service the service to use * @param string $methodName the name of the method * @param string $filterText filter text * @return array the objects retrieved from the service using the method * @throws InvalidArgumentException if <var>$methodName</var> is not a * get*ByStatement method or the filterText contains the LIMIT or * OFFSET options */ public static function GetSomeObjects(DfpSoapClient $service, $methodName, $filterText) { DeprecationUtils::LogDeprecatedMethodUsage('GetSomeObjects', 'https://github.com/googleads/googleads-php-lib/wiki/Migrating-off-of-DFP-ServiceUtils-functions'); if (!preg_match(self::GET_BY_STATEMENT_METHOD_NAME_REGEX, $methodName)) { throw new InvalidArgumentException('The method name must be in the format a "get*ByStatement".'); } $filterStatement = new Statement(); $filterStatement->query = $filterText; $page = $service->{$methodName}($filterStatement); return $page->results; }