1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hborras\TwitterAdsSDK\TwitterAds; |
4
|
|
|
|
5
|
|
|
use DateTimeImmutable; |
6
|
|
|
use Hborras\TwitterAdsSDK\TwitterAdsException; |
7
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Analytics\Job; |
8
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Creative\Video; |
9
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\AppList; |
10
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\Campaign; |
11
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\LineItem; |
12
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Fields\AccountFields; |
13
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Fields\AnalyticsFields; |
14
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\PromotableUser; |
15
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\FundingInstrument; |
16
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\TailoredAudience\TailoredAudience; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class Account |
20
|
|
|
* @package Hborras\TwitterAdsSDK\TwitterAds |
21
|
|
|
*/ |
22
|
|
|
class Account extends Analytics |
23
|
|
|
{ |
24
|
|
|
const RESOURCE_REPLACE = '{account_id}'; |
25
|
|
|
const RESOURCE_COLLECTION = 'accounts'; |
26
|
|
|
const RESOURCE = 'accounts/{account_id}'; |
27
|
|
|
const FEATURES = 'accounts/{account_id}/features'; |
28
|
|
|
const APP_LISTS = 'accounts/{account_id}/app_lists'; |
29
|
|
|
const SCOPED_TIMELINE = 'accounts/{account_id}/scoped_timeline'; |
30
|
|
|
const AUTHENTICATED_USER_ACCESS = 'accounts/{account_id}/authenticated_user_access'; |
31
|
|
|
|
32
|
|
|
const ENTITY = 'ACCOUNT'; |
33
|
|
|
|
34
|
|
|
protected $id; |
35
|
|
|
protected $salt; |
36
|
|
|
protected $name; |
37
|
|
|
protected $timezone; |
38
|
|
|
protected $timezone_switch_at; |
39
|
|
|
protected $created_at; |
40
|
|
|
protected $updated_at; |
41
|
|
|
protected $deleted; |
42
|
|
|
protected $approval_status; |
43
|
|
|
protected $business_id; |
44
|
|
|
protected $business_name; |
45
|
|
|
protected $industry_type; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param $metricGroups |
49
|
|
|
* @param array $params |
50
|
|
|
* @param bool $async |
51
|
|
|
* @return mixed |
52
|
|
|
* @throws Errors\BadRequest |
53
|
|
|
* @throws Errors\Forbidden |
54
|
|
|
* @throws Errors\NotAuthorized |
55
|
|
|
* @throws Errors\NotFound |
56
|
|
|
* @throws Errors\RateLimit |
57
|
|
|
* @throws Errors\ServerError |
58
|
|
|
* @throws Errors\ServiceUnavailable |
59
|
|
|
* @throws TwitterAdsException |
60
|
|
|
*/ |
61
|
|
|
public function stats($metricGroups, $params = [], $async = false) |
62
|
|
|
{ |
63
|
|
|
$params[AnalyticsFields::ENTITY] = AnalyticsFields::ACCOUNT; |
64
|
|
|
return parent::stats($metricGroups, $params, $async); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param array $params |
69
|
|
|
* @return Account |
70
|
|
|
* @throws Errors\BadRequest |
71
|
|
|
* @throws Errors\Forbidden |
72
|
|
|
* @throws Errors\NotAuthorized |
73
|
|
|
* @throws Errors\NotFound |
74
|
|
|
* @throws Errors\RateLimit |
75
|
|
|
* @throws Errors\ServerError |
76
|
|
|
* @throws Errors\ServiceUnavailable |
77
|
|
|
* @throws TwitterAdsException |
78
|
|
|
*/ |
79
|
|
|
public function read($params = []) |
80
|
|
|
{ |
81
|
|
|
$this->getTwitterAds()->setAccount($this); |
82
|
|
|
return parent::read($params); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Returns a collection of features available to the current account. |
87
|
|
|
* |
88
|
|
|
* @return mixed |
89
|
|
|
* |
90
|
|
|
* @throws TwitterAdsException |
91
|
|
|
*/ |
92
|
|
|
public function getFeatures() |
93
|
|
|
{ |
94
|
|
|
$this->validateLoaded(); |
95
|
|
|
|
96
|
|
|
$resource = str_replace(self::RESOURCE_REPLACE, $this->getId(), self::FEATURES); |
97
|
|
|
$response = $this->getTwitterAds()->get($resource); |
98
|
|
|
|
99
|
|
|
return $response->getBody()->data; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Returns a collection of promotable users available to the current account. |
104
|
|
|
* |
105
|
|
|
* @param string $id |
106
|
|
|
* |
107
|
|
|
* @param array $params |
108
|
|
|
* @return PromotableUser|Cursor |
109
|
|
|
* @throws Errors\BadRequest |
110
|
|
|
* @throws Errors\Forbidden |
111
|
|
|
* @throws Errors\NotAuthorized |
112
|
|
|
* @throws Errors\NotFound |
113
|
|
|
* @throws Errors\RateLimit |
114
|
|
|
* @throws Errors\ServerError |
115
|
|
|
* @throws Errors\ServiceUnavailable |
116
|
|
|
* @throws TwitterAdsException |
117
|
|
|
*/ |
118
|
|
|
public function getPromotableUsers($id = '', $params = []) |
119
|
|
|
{ |
120
|
|
|
$promotableUserClass = new PromotableUser(); |
121
|
|
|
|
122
|
|
|
return $promotableUserClass->loadResource($id, $params); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Returns a collection of funding instruments available to the current account. |
127
|
|
|
* |
128
|
|
|
* @param string $id |
129
|
|
|
* |
130
|
|
|
* @param array $params |
131
|
|
|
* @return FundingInstrument|Cursor |
132
|
|
|
* @throws Errors\BadRequest |
133
|
|
|
* @throws Errors\Forbidden |
134
|
|
|
* @throws Errors\NotAuthorized |
135
|
|
|
* @throws Errors\NotFound |
136
|
|
|
* @throws Errors\RateLimit |
137
|
|
|
* @throws Errors\ServerError |
138
|
|
|
* @throws Errors\ServiceUnavailable |
139
|
|
|
* @throws TwitterAdsException |
140
|
|
|
*/ |
141
|
|
|
public function getFundingInstruments($id = '', $params = []) |
142
|
|
|
{ |
143
|
|
|
$fundingInstrumentClass = new FundingInstrument(); |
144
|
|
|
|
145
|
|
|
return $fundingInstrumentClass->loadResource($id, $params); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Returns a collection of campaigns available to the current account. |
150
|
|
|
* |
151
|
|
|
* @param string $id |
152
|
|
|
* |
153
|
|
|
* @param array $params |
154
|
|
|
* @return Campaign|Cursor |
155
|
|
|
* @throws Errors\BadRequest |
156
|
|
|
* @throws Errors\Forbidden |
157
|
|
|
* @throws Errors\NotAuthorized |
158
|
|
|
* @throws Errors\NotFound |
159
|
|
|
* @throws Errors\RateLimit |
160
|
|
|
* @throws Errors\ServerError |
161
|
|
|
* @throws Errors\ServiceUnavailable |
162
|
|
|
* @throws TwitterAdsException |
163
|
|
|
*/ |
164
|
|
|
public function getCampaigns($id = '', $params = []) |
165
|
|
|
{ |
166
|
|
|
$campaignClass = new Campaign(); |
167
|
|
|
|
168
|
|
|
return $campaignClass->loadResource($id, $params); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Returns a collection of line items available to the current account. |
173
|
|
|
* |
174
|
|
|
* @param string $id |
175
|
|
|
* |
176
|
|
|
* @param array $params |
177
|
|
|
* @return LineItem|Cursor |
178
|
|
|
* @throws Errors\BadRequest |
179
|
|
|
* @throws Errors\Forbidden |
180
|
|
|
* @throws Errors\NotAuthorized |
181
|
|
|
* @throws Errors\NotFound |
182
|
|
|
* @throws Errors\RateLimit |
183
|
|
|
* @throws Errors\ServerError |
184
|
|
|
* @throws Errors\ServiceUnavailable |
185
|
|
|
* @throws TwitterAdsException |
186
|
|
|
*/ |
187
|
|
|
public function getLineItems($id = '', $params = []) |
188
|
|
|
{ |
189
|
|
|
$lineItemsClass = new LineItem(); |
190
|
|
|
|
191
|
|
|
return $lineItemsClass->loadResource($id, $params); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Returns a collection of app lists available to the current account. |
196
|
|
|
* |
197
|
|
|
* @param string $id |
198
|
|
|
* |
199
|
|
|
* @param array $params |
200
|
|
|
* @return AppList|Cursor |
201
|
|
|
* @throws Errors\BadRequest |
202
|
|
|
* @throws Errors\Forbidden |
203
|
|
|
* @throws Errors\NotAuthorized |
204
|
|
|
* @throws Errors\NotFound |
205
|
|
|
* @throws Errors\RateLimit |
206
|
|
|
* @throws Errors\ServerError |
207
|
|
|
* @throws Errors\ServiceUnavailable |
208
|
|
|
* @throws TwitterAdsException |
209
|
|
|
*/ |
210
|
|
|
public function getAppLists($id = '', $params = []) |
211
|
|
|
{ |
212
|
|
|
$appListsClass = new AppList(); |
213
|
|
|
|
214
|
|
|
return $appListsClass->loadResource($id, $params); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Returns a collection of jobs. Can specify job_ids parameter to filter |
219
|
|
|
* |
220
|
|
|
* @param array $params |
221
|
|
|
* @return Cursor|Resource |
222
|
|
|
* @throws Errors\BadRequest |
223
|
|
|
* @throws Errors\Forbidden |
224
|
|
|
* @throws Errors\NotAuthorized |
225
|
|
|
* @throws Errors\NotFound |
226
|
|
|
* @throws Errors\RateLimit |
227
|
|
|
* @throws Errors\ServerError |
228
|
|
|
* @throws Errors\ServiceUnavailable |
229
|
|
|
* @throws TwitterAdsException |
230
|
|
|
*/ |
231
|
|
|
public function getJobs($params = []) |
232
|
|
|
{ |
233
|
|
|
$jobsClass = new Job(); |
234
|
|
|
|
235
|
|
|
return $jobsClass->loadResource('', $params); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @param array $params |
241
|
|
|
* @return Cursor|Resource |
242
|
|
|
* @throws Errors\BadRequest |
243
|
|
|
* @throws Errors\Forbidden |
244
|
|
|
* @throws Errors\NotAuthorized |
245
|
|
|
* @throws Errors\NotFound |
246
|
|
|
* @throws Errors\RateLimit |
247
|
|
|
* @throws Errors\ServerError |
248
|
|
|
* @throws Errors\ServiceUnavailable |
249
|
|
|
* @throws TwitterAdsException |
250
|
|
|
*/ |
251
|
|
|
public function getTailoredAudiences($params = []) |
252
|
|
|
{ |
253
|
|
|
$tailoredAudienceClass = new TailoredAudience(); |
254
|
|
|
|
255
|
|
|
return $tailoredAudienceClass->loadResource('', $params); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Returns a collection of videos available to the current account. |
260
|
|
|
* |
261
|
|
|
* @param string $id |
262
|
|
|
* @param array $params |
263
|
|
|
* @return Cursor|Video |
264
|
|
|
*/ |
265
|
|
|
public function getVideos($id = '', $params = []) |
266
|
|
|
{ |
267
|
|
|
$videoClass = new Video(); |
268
|
|
|
|
269
|
|
|
return $videoClass->loadResource($id, $params); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* @return string |
274
|
|
|
*/ |
275
|
|
|
public function getId() |
276
|
|
|
{ |
277
|
|
|
return $this->id; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* @return string |
282
|
|
|
*/ |
283
|
|
|
public function getSalt() |
284
|
|
|
{ |
285
|
|
|
return $this->salt; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @return mixed |
290
|
|
|
*/ |
291
|
|
|
public function getTimezone() |
292
|
|
|
{ |
293
|
|
|
return $this->timezone; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* @return DateTimeImmutable |
298
|
|
|
*/ |
299
|
|
|
public function getTimezoneSwitchAt() |
300
|
|
|
{ |
301
|
|
|
return $this->timezone_switch_at; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* @return DateTimeImmutable |
306
|
|
|
*/ |
307
|
|
|
public function getCreatedAt() |
308
|
|
|
{ |
309
|
|
|
return $this->created_at; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* @return DateTimeImmutable |
314
|
|
|
*/ |
315
|
|
|
public function getUpdatedAt() |
316
|
|
|
{ |
317
|
|
|
return $this->updated_at; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* @return mixed |
322
|
|
|
*/ |
323
|
|
|
public function getDeleted() |
324
|
|
|
{ |
325
|
|
|
return filter_var($this->deleted, FILTER_VALIDATE_BOOLEAN); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* @return mixed |
330
|
|
|
*/ |
331
|
|
|
public function getApprovalStatus() |
332
|
|
|
{ |
333
|
|
|
return $this->approval_status; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* @return string |
338
|
|
|
*/ |
339
|
|
|
public function getName() |
340
|
|
|
{ |
341
|
|
|
return $this->name; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* @return mixed |
346
|
|
|
*/ |
347
|
|
|
public function getBusinessId() |
348
|
|
|
{ |
349
|
|
|
return $this->business_id; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* @return mixed |
354
|
|
|
*/ |
355
|
|
|
public function getBusinessName() |
356
|
|
|
{ |
357
|
|
|
return $this->business_name; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* @return mixed |
362
|
|
|
*/ |
363
|
|
|
public function getIndustryType() |
364
|
|
|
{ |
365
|
|
|
return $this->industry_type; |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* @param mixed $industry_type |
370
|
|
|
*/ |
371
|
|
|
public function setIndustryType($industry_type) |
372
|
|
|
{ |
373
|
|
|
$this->industry_type = $industry_type; |
374
|
|
|
} |
375
|
|
|
} |
376
|
|
|
|