1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hborras\TwitterAdsSDK\TwitterAds\Campaign; |
4
|
|
|
|
5
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Cursor; |
6
|
|
|
use Hborras\TwitterAdsSDK\TwitterAdsException; |
7
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Analytics; |
8
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Analytics\Job; |
9
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Errors\BadRequest; |
10
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Fields\LineItemFields; |
11
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Creative\PromotedTweet; |
12
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Fields\AnalyticsFields; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class LineItem |
16
|
|
|
* @package Hborras\TwitterAdsSDK\TwitterAds\Campaign |
17
|
|
|
*/ |
18
|
|
|
class LineItem extends Analytics |
19
|
|
|
{ |
20
|
|
|
const RESOURCE_COLLECTION = 'accounts/{account_id}/line_items'; |
21
|
|
|
const RESOURCE = 'accounts/{account_id}/line_items/{id}'; |
22
|
|
|
|
23
|
|
|
const ENTITY = 'LINE_ITEM'; |
24
|
|
|
|
25
|
|
|
/** Read Only */ |
26
|
|
|
protected $id; |
27
|
|
|
protected $created_at; |
28
|
|
|
protected $updated_at; |
29
|
|
|
protected $deleted; |
30
|
|
|
protected $target_cpa_local_micro; |
31
|
|
|
protected $currency; |
32
|
|
|
|
33
|
|
|
protected $properties = [ |
34
|
|
|
LineItemFields::CAMPAIGN_ID, |
35
|
|
|
LineItemFields::BID_AMOUNT_LOCAL_MICRO, |
36
|
|
|
LineItemFields::NAME, |
37
|
|
|
LineItemFields::BID_TYPE, |
38
|
|
|
LineItemFields::AUTOMATICALLY_SELECT_BID, |
39
|
|
|
LineItemFields::PRODUCT_TYPE, |
40
|
|
|
LineItemFields::PLACEMENTS, |
41
|
|
|
LineItemFields::OBJECTIVE, |
42
|
|
|
LineItemFields::ENTITY_STATUS, |
43
|
|
|
LineItemFields::INCLUDE_SENTIMENT, |
44
|
|
|
LineItemFields::TOTAL_BUDGET_AMOUNT_LOCAL_MICRO, |
45
|
|
|
LineItemFields::START_TIME, |
46
|
|
|
LineItemFields::END_TIME, |
47
|
|
|
LineItemFields::PRIMARY_WEB_EVENT_TAG, |
48
|
|
|
LineItemFields::OPTIMIZATION, |
49
|
|
|
LineItemFields::BID_UNIT, |
50
|
|
|
LineItemFields::CHARGE_BY, |
51
|
|
|
LineItemFields::ADVERTISER_DOMAIN, |
52
|
|
|
LineItemFields::ADVERTISER_USER_ID, |
53
|
|
|
LineItemFields::CATEGORIES |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
/** Writable */ |
57
|
|
|
protected $campaign_id; |
58
|
|
|
protected $bid_amount_local_micro; |
59
|
|
|
protected $name; |
60
|
|
|
protected $bid_type; |
61
|
|
|
protected $automatically_select_bid; |
62
|
|
|
protected $product_type; |
63
|
|
|
protected $placements; |
64
|
|
|
protected $objective; |
65
|
|
|
protected $entity_status; |
66
|
|
|
protected $include_sentiment; |
67
|
|
|
protected $total_budget_amount_local_micro; |
68
|
|
|
protected $start_time; |
69
|
|
|
protected $end_time; |
70
|
|
|
protected $primary_web_event_tag; |
71
|
|
|
protected $optimization; |
72
|
|
|
protected $bid_unit; |
73
|
|
|
protected $charge_by; |
74
|
|
|
protected $advertiser_domain; |
75
|
|
|
protected $tracking_tags; |
76
|
|
|
protected $advertiser_user_id; |
77
|
|
|
protected $categories; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param array $params |
81
|
|
|
* @return Cursor|\Hborras\TwitterAdsSDK\TwitterAds\Resource |
82
|
|
|
* @throws BadRequest |
83
|
|
|
* @throws TwitterAdsException |
84
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\Forbidden |
85
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\NotAuthorized |
86
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\NotFound |
87
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\RateLimit |
88
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\ServerError |
89
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\ServiceUnavailable |
90
|
|
|
*/ |
91
|
|
|
public function getPromotedTweets($params = []) |
92
|
|
|
{ |
93
|
|
|
$params[LineItemFields::LINE_ITEM_IDS] = $this->getId(); |
94
|
|
|
$promotedTweetClass = new PromotedTweet(); |
95
|
|
|
return $promotedTweetClass->loadResource('', $params); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param $metricGroups |
100
|
|
|
* @param array $params |
101
|
|
|
* @param bool $async |
102
|
|
|
* @return Job| mixed |
103
|
|
|
* @throws BadRequest |
104
|
|
|
* @throws TwitterAdsException |
105
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\Forbidden |
106
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\NotAuthorized |
107
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\NotFound |
108
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\RateLimit |
109
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\ServerError |
110
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\ServiceUnavailable |
111
|
|
|
*/ |
112
|
|
|
public function stats($metricGroups, $params = [], $async = false) |
113
|
|
|
{ |
114
|
|
|
$params[AnalyticsFields::ENTITY] = AnalyticsFields::LINE_ITEM; |
115
|
|
|
return parent::stats($metricGroups, $params, $async); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Returns a collection of targeting criteria available to the |
120
|
|
|
* current line item. |
121
|
|
|
* |
122
|
|
|
* @param string $id |
123
|
|
|
* @param array $params |
124
|
|
|
* |
125
|
|
|
* @return Cursor | Resource |
126
|
|
|
* |
127
|
|
|
* @throws TwitterAdsException |
128
|
|
|
*/ |
129
|
|
|
public function getTargetingCriteria($id = '', $params = []) |
130
|
|
|
{ |
131
|
|
|
$targetingCriteria = new TargetingCriteria(); |
132
|
|
|
|
133
|
|
|
$this->validateLoaded(); |
134
|
|
|
if ($id == '') { |
135
|
|
|
$cursor = $targetingCriteria->line_item_all($this->getId(), $params); |
136
|
|
|
} else { |
137
|
|
|
$cursor = $targetingCriteria->load($id, $params); |
|
|
|
|
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
return $cursor; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return mixed |
145
|
|
|
*/ |
146
|
|
|
public function getId() |
147
|
|
|
{ |
148
|
|
|
return $this->id; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @return mixed |
153
|
|
|
*/ |
154
|
|
|
public function getCreatedAt() |
155
|
|
|
{ |
156
|
|
|
return $this->created_at; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @return mixed |
161
|
|
|
*/ |
162
|
|
|
public function getUpdatedAt() |
163
|
|
|
{ |
164
|
|
|
return $this->updated_at; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @return mixed |
169
|
|
|
*/ |
170
|
|
|
public function getDeleted() |
171
|
|
|
{ |
172
|
|
|
return $this->deleted; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @param array $properties |
177
|
|
|
*/ |
178
|
|
|
public function setProperties($properties) |
179
|
|
|
{ |
180
|
|
|
$this->properties = $properties; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @return mixed |
185
|
|
|
*/ |
186
|
|
|
public function getCampaignId() |
187
|
|
|
{ |
188
|
|
|
return $this->campaign_id; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @param mixed $campaign_id |
193
|
|
|
*/ |
194
|
|
|
public function setCampaignId($campaign_id) |
195
|
|
|
{ |
196
|
|
|
$this->campaign_id = $campaign_id; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @return mixed |
201
|
|
|
*/ |
202
|
|
|
public function getBidAmountLocalMicro() |
203
|
|
|
{ |
204
|
|
|
return $this->bid_amount_local_micro; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param mixed $bid_amount_local_micro |
209
|
|
|
*/ |
210
|
|
|
public function setBidAmountLocalMicro($bid_amount_local_micro) |
211
|
|
|
{ |
212
|
|
|
$this->bid_amount_local_micro = $bid_amount_local_micro; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @return mixed |
217
|
|
|
*/ |
218
|
|
|
public function getName() |
219
|
|
|
{ |
220
|
|
|
return $this->name; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @param mixed $name |
225
|
|
|
*/ |
226
|
|
|
public function setName($name) |
227
|
|
|
{ |
228
|
|
|
$this->name = $name; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @return mixed |
233
|
|
|
*/ |
234
|
|
|
public function getBidType() |
235
|
|
|
{ |
236
|
|
|
return $this->bid_type; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @param mixed $bid_type |
241
|
|
|
*/ |
242
|
|
|
public function setBidType($bid_type) |
243
|
|
|
{ |
244
|
|
|
$this->bid_type = $bid_type; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @return mixed |
249
|
|
|
*/ |
250
|
|
|
public function getAutomaticallySelectdBid() |
251
|
|
|
{ |
252
|
|
|
return $this->automatically_select_bid; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* @param mixed $automatically_select_bid |
257
|
|
|
*/ |
258
|
|
|
public function setAutomaticallySelectBid($automatically_select_bid) |
259
|
|
|
{ |
260
|
|
|
$this->automatically_select_bid = $automatically_select_bid; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @return mixed |
265
|
|
|
*/ |
266
|
|
|
public function getProductType() |
267
|
|
|
{ |
268
|
|
|
return $this->product_type; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* @param mixed $product_type |
273
|
|
|
*/ |
274
|
|
|
public function setProductType($product_type) |
275
|
|
|
{ |
276
|
|
|
$this->product_type = $product_type; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* @return mixed |
281
|
|
|
*/ |
282
|
|
|
public function getPlacements() |
283
|
|
|
{ |
284
|
|
|
return $this->placements; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @param mixed $placements |
289
|
|
|
*/ |
290
|
|
|
public function setPlacements($placements) |
291
|
|
|
{ |
292
|
|
|
$this->placements = $placements; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* @return mixed |
297
|
|
|
*/ |
298
|
|
|
public function getObjective() |
299
|
|
|
{ |
300
|
|
|
return $this->objective; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* @param mixed $objective |
305
|
|
|
*/ |
306
|
|
|
public function setObjective($objective) |
307
|
|
|
{ |
308
|
|
|
$this->objective = $objective; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @return mixed |
313
|
|
|
*/ |
314
|
|
|
public function getEntityStatus() |
315
|
|
|
{ |
316
|
|
|
return $this->entity_status; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* @param mixed $entity_status |
321
|
|
|
*/ |
322
|
|
|
public function setEntityStatus($entity_status) |
323
|
|
|
{ |
324
|
|
|
$this->entity_status = $entity_status; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* @return mixed |
329
|
|
|
*/ |
330
|
|
|
public function getIncludeSentiment() |
331
|
|
|
{ |
332
|
|
|
return $this->include_sentiment; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* @param mixed $include_sentiment |
337
|
|
|
*/ |
338
|
|
|
public function setIncludeSentiment($include_sentiment) |
339
|
|
|
{ |
340
|
|
|
$this->include_sentiment = $include_sentiment; |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* @return mixed |
345
|
|
|
*/ |
346
|
|
|
public function getTotalBudgetAmountLocalMicro() |
347
|
|
|
{ |
348
|
|
|
return $this->total_budget_amount_local_micro; |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
/** |
352
|
|
|
* @param mixed $total_budget_amount_local_micro |
353
|
|
|
*/ |
354
|
|
|
public function setTotalBudgetAmountLocalMicro($total_budget_amount_local_micro) |
355
|
|
|
{ |
356
|
|
|
$this->total_budget_amount_local_micro = $total_budget_amount_local_micro; |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
/** |
360
|
|
|
* @return mixed |
361
|
|
|
*/ |
362
|
|
|
public function getStartTime() |
363
|
|
|
{ |
364
|
|
|
return $this->start_time; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* @param mixed $start_time |
369
|
|
|
*/ |
370
|
|
|
public function setStartTime($start_time) |
371
|
|
|
{ |
372
|
|
|
$this->start_time = $start_time; |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
/** |
376
|
|
|
* @return mixed |
377
|
|
|
*/ |
378
|
|
|
public function getEndTime() |
379
|
|
|
{ |
380
|
|
|
return $this->end_time; |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* @param mixed $end_time |
385
|
|
|
*/ |
386
|
|
|
public function setEndTime($end_time) |
387
|
|
|
{ |
388
|
|
|
$this->end_time = $end_time; |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* @return mixed |
393
|
|
|
*/ |
394
|
|
|
public function getPrimaryWebEventTag() |
395
|
|
|
{ |
396
|
|
|
return $this->primary_web_event_tag; |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* @param mixed $primary_web_event_tag |
401
|
|
|
*/ |
402
|
|
|
public function setPrimaryWebEventTag($primary_web_event_tag) |
403
|
|
|
{ |
404
|
|
|
$this->primary_web_event_tag = $primary_web_event_tag; |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* @return mixed |
409
|
|
|
*/ |
410
|
|
|
public function getOptimization() |
411
|
|
|
{ |
412
|
|
|
return $this->optimization; |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
/** |
416
|
|
|
* @param mixed $optimization |
417
|
|
|
*/ |
418
|
|
|
public function setOptimization($optimization) |
419
|
|
|
{ |
420
|
|
|
$this->optimization = $optimization; |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
/** |
424
|
|
|
* @return mixed |
425
|
|
|
*/ |
426
|
|
|
public function getBidUnit() |
427
|
|
|
{ |
428
|
|
|
return $this->bid_unit; |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* @param mixed $bid_unit |
433
|
|
|
*/ |
434
|
|
|
public function setBidUnit($bid_unit) |
435
|
|
|
{ |
436
|
|
|
$this->bid_unit = $bid_unit; |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
/** |
440
|
|
|
* @return mixed |
441
|
|
|
*/ |
442
|
|
|
public function getChargeBy() |
443
|
|
|
{ |
444
|
|
|
return $this->charge_by; |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
/** |
448
|
|
|
* @param mixed $charge_by |
449
|
|
|
*/ |
450
|
|
|
public function setChargeBy($charge_by) |
451
|
|
|
{ |
452
|
|
|
$this->charge_by = $charge_by; |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
/** |
456
|
|
|
* @return mixed |
457
|
|
|
*/ |
458
|
|
|
public function getAdvertiserDomain() |
459
|
|
|
{ |
460
|
|
|
return $this->advertiser_domain; |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* @param mixed $advertiser_domain |
465
|
|
|
*/ |
466
|
|
|
public function setAdvertiserDomain($advertiser_domain) |
467
|
|
|
{ |
468
|
|
|
$this->advertiser_domain = $advertiser_domain; |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
/** |
472
|
|
|
* @return mixed |
473
|
|
|
*/ |
474
|
|
|
public function getTrackingTags() |
475
|
|
|
{ |
476
|
|
|
return $this->tracking_tags; |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
/** |
480
|
|
|
* @param mixed $tracking_tags |
481
|
|
|
*/ |
482
|
|
|
public function setTrackingTags($tracking_tags) |
483
|
|
|
{ |
484
|
|
|
$this->tracking_tags = $tracking_tags; |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
/** |
488
|
|
|
* @return mixed |
489
|
|
|
*/ |
490
|
|
|
public function getAdvertiserUserId() |
491
|
|
|
{ |
492
|
|
|
return $this->advertiser_user_id; |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
/** |
496
|
|
|
* @param mixed $advertiser_user_id |
497
|
|
|
*/ |
498
|
|
|
public function setAdvertiserUserId($advertiser_user_id) |
499
|
|
|
{ |
500
|
|
|
$this->advertiser_user_id = $advertiser_user_id; |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
/** |
504
|
|
|
* @return mixed |
505
|
|
|
*/ |
506
|
|
|
public function getTargetCpaLocalMicro() |
507
|
|
|
{ |
508
|
|
|
return $this->target_cpa_local_micro; |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
/** |
512
|
|
|
* @return mixed |
513
|
|
|
*/ |
514
|
|
|
public function getAutomaticallySelectBid() |
515
|
|
|
{ |
516
|
|
|
return $this->automatically_select_bid; |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
/** |
520
|
|
|
* @return mixed |
521
|
|
|
*/ |
522
|
|
|
public function getCategories() |
523
|
|
|
{ |
524
|
|
|
return $this->categories; |
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
/** |
528
|
|
|
* @param mixed $categories |
529
|
|
|
*/ |
530
|
|
|
public function setCategories($categories) |
531
|
|
|
{ |
532
|
|
|
$this->categories = $categories; |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
/** |
536
|
|
|
* @return mixed |
537
|
|
|
*/ |
538
|
|
|
public function getCurrency() |
539
|
|
|
{ |
540
|
|
|
return $this->currency; |
541
|
|
|
} |
542
|
|
|
} |
543
|
|
|
|