-
Notifications
You must be signed in to change notification settings - Fork 767
/
BatchJobUtils.php
executable file
·117 lines (110 loc) · 4.55 KB
/
BatchJobUtils.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* Copyright 2015, Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package GoogleApiAdsAdWordsUtil
* @subpackage v201609
* @category WebServices
* @copyright 2015, Google Inc. All Rights Reserved.
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License,
* Version 2.0
*/
require_once 'Google/Api/Ads/AdWords/Util/BatchJobException.php';
require_once 'Google/Api/Ads/AdWords/Util/v201609/BatchJobUtilsDelegate.php';
require_once 'Google/Api/Ads/Common/Util/AdsUtility.php';
require_once 'Google/Api/Ads/Common/Util/AdsUtilityRegistry.php';
require_once 'Google/Api/Ads/Common/Util/CurlUtils.php';
/**
* A collection of utility methods for working with BatchJobService to upload
* batch operations and download the results of batch processing.
*/
class BatchJobUtils {
public static $CLASS_MAP = array(
"ErrorList" => "ErrorList",
"MutateResult" => "MutateResult",
"Operand" => "Operand",
"mutate" => "BatchJobOpsMutate",
"mutateResponse" => "BatchJobOpsMutateResponse",
);
private $batchJobUtilsDelegate;
private $adsUtilityRegistry;
/**
* Create an instance of BatchJobUtils with the specified upload URL, total
* uploaded content bytes, CurlUtils object, BatchJobUtilsDelegate object and
* ads utility registry.
*
* @param string $uploadUrl the upload URL to which the operations will be
* uploaded
* @param int|null $totalContentBytes the total content bytes uploaded so far,
* used in incremental batch job uploads
* @param CurlUtils|null $curlUtils the CurlUtils object for uploading batch
* job operations and downloading the results of batch job processing
* @param BatchJobUtilsDelegate|null $batchJobUtilsDelegate the batch job
* utils delegate that uploads batch job operations and downloads the
* results
* @param AdsUtilityRegistry|null $adsUtilityRegistry the ads utility registry
*/
public function __construct(
$uploadUrl,
$totalContentBytes = null,
CurlUtils $curlUtils = null,
BatchJobUtilsDelegate $batchJobUtilsDelegate = null,
AdsUtilityRegistry $adsUtilityRegistry = null
) {
$this->batchJobUtilsDelegate = ($batchJobUtilsDelegate === null)
? new BatchJobUtilsDelegate($uploadUrl, $totalContentBytes, $curlUtils)
: $batchJobUtilsDelegate;
$this->adsUtilityRegistry = ($adsUtilityRegistry === null)
? AdsUtilityRegistry::getInstance()
: $adsUtilityRegistry;
}
/**
* Uploads batch job operations to the specified upload URL.
*
* @param array $operations operations to be uploaded via the upload URL
* $uploadUrl
* @throws BatchJobException if the HTTP code is not equal to 200
*/
public function UploadBatchJobOperations(array $operations) {
// Starting with v201601, all uploads must go through the incremental
// upload workflow.
$this->UploadIncrementalBatchJobOperations($operations, true);
}
/**
* Uploads batch job operations incrementally to the specified upload URL.
*
* @param array $operations operations to be uploaded via the upload URL
* @param bool $isLastRequest if this is last upload request
* @throws BatchJobException if the HTTP code is not equal to 200 and 308
*/
public function UploadIncrementalBatchJobOperations(array $operations,
$isLastRequest = null) {
$this->adsUtilityRegistry->addUtility(AdsUtility::BATCHJOB_UTILS);
$this->batchJobUtilsDelegate
->UploadIncrementalBatchJobOperations($operations, $isLastRequest);
}
/**
* Downloads the results of batch processing from $downloadUrl.
*
* @param string $downloadUrl the download URL from which the results are
* downloaded
* @throws BatchJobException if the HTTP code is not equal to 200
* @return string the contents of returned HTTP response
*/
public function DownloadBatchJobResults($downloadUrl) {
$this->adsUtilityRegistry->addUtility(AdsUtility::BATCHJOB_UTILS);
return $this->batchJobUtilsDelegate->DownloadBatchJobResults($downloadUrl);
}
}