-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathServiceClientFactoryTrait.php
More file actions
228 lines (197 loc) · 7.63 KB
/
ServiceClientFactoryTrait.php
File metadata and controls
228 lines (197 loc) · 7.63 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
declare( strict_types=1 );
/**
* Overrides vendor/googleads/google-ads-php/src/Google/Ads/GoogleAds/Lib/V20/ServiceClientFactoryTrait.php
*
* phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
* phpcs:disable WordPress.NamingConventions.ValidVariableName
* phpcs:disable Squiz.Commenting.VariableComment
*/
namespace Automattic\WooCommerce\GoogleListingsAndAds\Google\Ads;
use Google\Ads\GoogleAds\Constants;
use Google\Ads\GoogleAds\Lib\ConfigurationTrait;
use Google\Ads\GoogleAds\V23\Services\Client\AccountLinkServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\AdGroupAdLabelServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\AdGroupAdServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\AdGroupCriterionServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\AdGroupServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\AdServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\AssetGenerationServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\AssetGroupListingGroupFilterServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\AssetGroupServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\BillingSetupServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\IncentiveServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\CampaignBudgetServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\CampaignCriterionServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\CampaignServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\ConversionActionServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\CustomerServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\CustomerUserAccessServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\GeoTargetConstantServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\GoogleAdsServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\ProductLinkInvitationServiceClient;
use Google\Ads\GoogleAds\V23\Services\Client\RecommendationServiceClient;
/**
* Contains service client factory methods.
*/
trait ServiceClientFactoryTrait {
use ConfigurationTrait;
private static $CREDENTIALS_LOADER_KEY = 'credentials';
private static $DEVELOPER_TOKEN_KEY = 'developer-token';
private static $LOGIN_CUSTOMER_ID_KEY = 'login-customer-id';
private static $LINKED_CUSTOMER_ID_KEY = 'linked-customer-id';
private static $SERVICE_ADDRESS_KEY = 'serviceAddress';
private static $DEFAULT_SERVICE_ADDRESS = 'googleads.googleapis.com';
private static $TRANSPORT_KEY = 'transport';
/**
* Gets the Google Ads client options for making API calls.
*
* @return array the client options
*/
public function getGoogleAdsClientOptions(): array {
$clientOptions = [
self::$CREDENTIALS_LOADER_KEY => $this->getOAuth2Credential(),
self::$DEVELOPER_TOKEN_KEY => '',
self::$TRANSPORT_KEY => 'rest',
'libName' => Constants::LIBRARY_NAME,
'libVersion' => Constants::LIBRARY_VERSION,
];
if ( ! empty( $this->getEndpoint() ) ) {
$clientOptions += [ self::$SERVICE_ADDRESS_KEY => $this->getEndpoint() ];
}
if ( isset( $this->httpClient ) ) {
$clientOptions['transportConfig'] = [
'rest' => [
'httpHandler' => $this->buildHttpHandler(),
],
];
}
return $clientOptions;
}
/**
* @return AccountLinkServiceClient
*/
public function getAccountLinkServiceClient(): AccountLinkServiceClient {
return new AccountLinkServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return AdGroupAdLabelServiceClient
*/
public function getAdGroupAdLabelServiceClient(): AdGroupAdLabelServiceClient {
return new AdGroupAdLabelServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return AdGroupAdServiceClient
*/
public function getAdGroupAdServiceClient(): AdGroupAdServiceClient {
return new AdGroupAdServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return AdGroupCriterionServiceClient
*/
public function getAdGroupCriterionServiceClient(): AdGroupCriterionServiceClient {
return new AdGroupCriterionServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return AdGroupServiceClient
*/
public function getAdGroupServiceClient(): AdGroupServiceClient {
return new AdGroupServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return AdServiceClient
*/
public function getAdServiceClient(): AdServiceClient {
return new AdServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return AssetGroupListingGroupFilterServiceClient
*/
public function getAssetGroupListingGroupFilterServiceClient(): AssetGroupListingGroupFilterServiceClient {
return new AssetGroupListingGroupFilterServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return AssetGroupServiceClient
*/
public function getAssetGroupServiceClient(): AssetGroupServiceClient {
return new AssetGroupServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return BillingSetupServiceClient
*/
public function getBillingSetupServiceClient(): BillingSetupServiceClient {
return new BillingSetupServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return CampaignBudgetServiceClient
*/
public function getCampaignBudgetServiceClient(): CampaignBudgetServiceClient {
return new CampaignBudgetServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return CampaignCriterionServiceClient
*/
public function getCampaignCriterionServiceClient(): CampaignCriterionServiceClient {
return new CampaignCriterionServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return CampaignServiceClient
*/
public function getCampaignServiceClient(): CampaignServiceClient {
return new CampaignServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return ConversionActionServiceClient
*/
public function getConversionActionServiceClient(): ConversionActionServiceClient {
return new ConversionActionServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return CustomerServiceClient
*/
public function getCustomerServiceClient(): CustomerServiceClient {
return new CustomerServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return CustomerUserAccessServiceClient
*/
public function getCustomerUserAccessServiceClient(): CustomerUserAccessServiceClient {
return new CustomerUserAccessServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return GeoTargetConstantServiceClient
*/
public function getGeoTargetConstantServiceClient(): GeoTargetConstantServiceClient {
return new GeoTargetConstantServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return GoogleAdsServiceClient
*/
public function getGoogleAdsServiceClient(): GoogleAdsServiceClient {
return new GoogleAdsServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return IncentiveServiceClient
*/
public function getIncentiveServiceClient(): IncentiveServiceClient {
return new IncentiveServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return ProductLinkInvitationServiceClient
*/
public function getProductLinkInvitationServiceClient(): ProductLinkInvitationServiceClient {
return new ProductLinkInvitationServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return RecommendationServiceClient
*/
public function getRecommendationServiceClient(): RecommendationServiceClient {
return new RecommendationServiceClient( $this->getGoogleAdsClientOptions() );
}
/**
* @return AssetGenerationServiceClient
*/
public function getAssetGenerationServiceClient(): AssetGenerationServiceClient {
return new AssetGenerationServiceClient( $this->getGoogleAdsClientOptions() );
}
}