Skip to content

Commit d953608

Browse files
authored
Merge pull request #164 from gitazem/master
Provide support for setting custom curl options in ReportUtils.
2 parents bfee7c0 + 3eb207b commit d953608

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/Google/Api/Ads/AdWords/Util/v201607/ReportUtils.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ public function __construct(AdsUtilityRegistry $adsUtilityRegistry = null) {
7070
* otherwise the size in bytes of the downloaded report
7171
*/
7272
public function DownloadReport($reportDefinition, $path = null,
73-
AdWordsUser $user, array $options = null) {
73+
AdWordsUser $user, array $options = null, $customCurlOptions = null) {
7474
if ($path === null || $path === '') {
7575
$this->adsUtilityRegistry->addUtility(AdsUtility::REPORT_UTILS_STRING);
7676
} else {
7777
$this->adsUtilityRegistry->addUtility(AdsUtility::REPORT_UTILS_FILE);
7878
}
7979
return ReportUtilsDelegate::DownloadReport($reportDefinition, $path, $user,
80-
$options);
80+
$options, $customCurlOptions);
8181
}
8282

8383
/**
@@ -97,13 +97,13 @@ public function DownloadReport($reportDefinition, $path = null,
9797
* otherwise the size in bytes of the downloaded report
9898
*/
9999
public function DownloadReportWithAwql($reportQuery, $path = null,
100-
AdWordsUser $user, $reportFormat, array $options = null) {
100+
AdWordsUser $user, $reportFormat, array $options = null, array $customCurlOptions = null) {
101101
if ($path === null || $path === '') {
102102
$this->adsUtilityRegistry->addUtility(AdsUtility::REPORT_UTILS_STRING);
103103
} else {
104104
$this->adsUtilityRegistry->addUtility(AdsUtility::REPORT_UTILS_FILE);
105105
}
106106
return ReportUtilsDelegate::DownloadReportWithAwql($reportQuery, $path,
107-
$user, $reportFormat, $options);
107+
$user, $reportFormat, $options, $customCurlOptions);
108108
}
109109
}

src/Google/Api/Ads/AdWords/Util/v201607/ReportUtilsDelegate.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,22 @@ private function __construct() {}
7070
* @see ReportUtils::DownloadReport
7171
*/
7272
public static function DownloadReport($reportDefinition, $path = null,
73-
AdWordsUser $user, array $options = null) {
73+
AdWordsUser $user, array $options = null, array $customCurlOptions = null) {
7474
$url = self::GetUrl($user, $options);
7575
$headers = self::GetHeaders($user, $url, $options);
7676
$params = self::GetParams($reportDefinition);
77-
return self::DownloadReportFromUrl($url, $headers, $params, $path);
77+
return self::DownloadReportFromUrl($url, $headers, $params, $path, $customCurlOptions);
7878
}
7979

8080
/**
8181
* @see ReportUtils::DownloadReportWithAwql
8282
*/
8383
public static function DownloadReportWithAwql($reportQuery, $path = null,
84-
AdWordsUser $user, $reportFormat, array $options = null) {
84+
AdWordsUser $user, $reportFormat, array $options = null, array $customCurlOptions = null) {
8585
$url = self::GetUrl($user, $options);
8686
$headers = self::GetHeaders($user, $url, $options);
8787
$params = self::GetQueryParams($reportQuery, $reportFormat);
88-
return self::DownloadReportFromUrl($url, $headers, $params, $path);
88+
return self::DownloadReportFromUrl($url, $headers, $params, $path, $customCurlOptions);
8989
}
9090

9191
/**
@@ -98,7 +98,7 @@ public static function DownloadReportWithAwql($reportQuery, $path = null,
9898
* otherwise the size in bytes of the downloaded report
9999
*/
100100
private static function DownloadReportFromUrl($url, $headers, $params,
101-
$path = null) {
101+
$path = null, $customCurlOptions = null) {
102102
/*
103103
* This method should not be static and instantiation of this class should
104104
* be allowed so we can "inject" CurlUtils, but would break too many things
@@ -126,6 +126,13 @@ private static function DownloadReportFromUrl($url, $headers, $params,
126126
$curlUtils->SetOpt($ch, CURLOPT_FILE, $file);
127127
}
128128

129+
## sometimes need to set some useful curl options. example: $customCurlOptions = ['CURLOPT_TIMEOUT' => 1];
130+
if(!empty($customCurlOptions)) {
131+
foreach ($customCurlOptions as $curlOption => $curlValue) {
132+
$curlUtils->SetOpt($ch, $curlOption, $curlValue);
133+
}
134+
}
135+
129136
$response = $curlUtils->Exec($ch);
130137
$error = $curlUtils->Error($ch);
131138
$code = $curlUtils->GetInfo($ch, CURLINFO_HTTP_CODE);

0 commit comments

Comments
 (0)