1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hborras\TwitterAdsSDK\TwitterAds\Campaign; |
4
|
|
|
|
5
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Cursor; |
6
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Resource; |
7
|
|
|
use Hborras\TwitterAdsSDK\TwitterAdsException; |
8
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Errors\NotFound; |
9
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Errors\Forbidden; |
10
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Errors\RateLimit; |
11
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Errors\BadRequest; |
12
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Errors\ServerError; |
13
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Errors\NotAuthorized; |
14
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Errors\ServiceUnavailable; |
15
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Fields\TargetingCriteriaFields; |
16
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Errors\MethodNotAllowedException; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class TargetingCriteria |
20
|
|
|
* @package Hborras\TwitterAdsSDK\TwitterAds\Campaign |
21
|
|
|
*/ |
22
|
|
|
class TargetingCriteria extends Resource |
23
|
|
|
{ |
24
|
|
|
const RESOURCE_COLLECTION = 'accounts/{account_id}/targeting_criteria'; |
25
|
|
|
const RESOURCE = 'accounts/{account_id}/targeting_criteria/{id}'; |
26
|
|
|
|
27
|
|
|
/** Read Only */ |
28
|
|
|
protected $id; |
29
|
|
|
protected $localized_name; |
30
|
|
|
protected $name; |
31
|
|
|
protected $created_at; |
32
|
|
|
protected $updated_at; |
33
|
|
|
protected $deleted; |
34
|
|
|
|
35
|
|
|
protected $properties = [ |
36
|
|
|
TargetingCriteriaFields::LINE_ITEM_ID, |
37
|
|
|
TargetingCriteriaFields::TARGETING_TYPE, |
38
|
|
|
TargetingCriteriaFields::TARGETING_VALUE, |
39
|
|
|
TargetingCriteriaFields::TAILORED_AUDIENCE_EXPANSION, |
40
|
|
|
TargetingCriteriaFields::TAILORED_AUDIENCE_TYPE, |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
protected $line_item_id; |
44
|
|
|
protected $targeting_type; |
45
|
|
|
protected $targeting_value; |
46
|
|
|
protected $tailored_audience_expansion; |
47
|
|
|
protected $tailored_audience_type; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param $line_item_id |
51
|
|
|
* @param array $params |
52
|
|
|
* |
53
|
|
|
* @return Cursor |
54
|
|
|
* @throws TwitterAdsException |
55
|
|
|
* @throws BadRequest |
56
|
|
|
* @throws Forbidden |
57
|
|
|
* @throws NotAuthorized |
58
|
|
|
* @throws NotFound |
59
|
|
|
* @throws RateLimit |
60
|
|
|
* @throws ServerError |
61
|
|
|
* @throws ServiceUnavailable |
62
|
|
|
*/ |
63
|
|
|
public function line_item_all($line_item_id, $params = []) |
64
|
|
|
{ |
65
|
|
|
$params[TargetingCriteriaFields::LINE_ITEM_IDS] = [$line_item_id]; |
66
|
|
|
|
67
|
|
|
$resource = str_replace(static::RESOURCE_REPLACE, $this->getTwitterAds()->getAccountId(), static::RESOURCE_COLLECTION); |
68
|
|
|
$request = $this->getTwitterAds()->get($resource, $params); |
69
|
|
|
|
70
|
|
|
return new Cursor($this, $this->getTwitterAds(), $request->getBody(), $params); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return Resource |
76
|
|
|
* @throws MethodNotAllowedException |
77
|
|
|
*/ |
78
|
|
|
public function save() |
79
|
|
|
{ |
80
|
|
|
if ($this->getId()) { |
81
|
|
|
throw new MethodNotAllowedException(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return parent::save(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return mixed |
89
|
|
|
*/ |
90
|
|
|
public function getName() |
91
|
|
|
{ |
92
|
|
|
return $this->name; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return mixed |
97
|
|
|
*/ |
98
|
|
|
public function getId() |
99
|
|
|
{ |
100
|
|
|
return $this->id; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return mixed |
105
|
|
|
*/ |
106
|
|
|
public function getLocalizedName() |
107
|
|
|
{ |
108
|
|
|
return $this->localized_name; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return mixed |
113
|
|
|
*/ |
114
|
|
|
public function getCreatedAt() |
115
|
|
|
{ |
116
|
|
|
return $this->created_at; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return mixed |
121
|
|
|
*/ |
122
|
|
|
public function getUpdatedAt() |
123
|
|
|
{ |
124
|
|
|
return $this->updated_at; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return mixed |
129
|
|
|
*/ |
130
|
|
|
public function getDeleted() |
131
|
|
|
{ |
132
|
|
|
return $this->deleted; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return mixed |
137
|
|
|
*/ |
138
|
|
|
public function getLineItemId() |
139
|
|
|
{ |
140
|
|
|
return $this->line_item_id; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return mixed |
145
|
|
|
*/ |
146
|
|
|
public function getTargetingType() |
147
|
|
|
{ |
148
|
|
|
return $this->targeting_type; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @return mixed |
153
|
|
|
*/ |
154
|
|
|
public function getTargetingValue() |
155
|
|
|
{ |
156
|
|
|
return $this->targeting_value; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @return mixed |
161
|
|
|
*/ |
162
|
|
|
public function getTailoredAudienceExpansion() |
163
|
|
|
{ |
164
|
|
|
return $this->tailored_audience_expansion; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @return mixed |
169
|
|
|
*/ |
170
|
|
|
public function getTailoredAudienceType() |
171
|
|
|
{ |
172
|
|
|
return $this->tailored_audience_type; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @param array $properties |
177
|
|
|
*/ |
178
|
|
|
public function setProperties($properties) |
179
|
|
|
{ |
180
|
|
|
$this->properties = $properties; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @param mixed $line_item_id |
185
|
|
|
*/ |
186
|
|
|
public function setLineItemId($line_item_id) |
187
|
|
|
{ |
188
|
|
|
$this->line_item_id = $line_item_id; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @param mixed $targeting_type |
193
|
|
|
*/ |
194
|
|
|
public function setTargetingType($targeting_type) |
195
|
|
|
{ |
196
|
|
|
$this->targeting_type = $targeting_type; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @param mixed $targeting_value |
201
|
|
|
*/ |
202
|
|
|
public function setTargetingValue($targeting_value) |
203
|
|
|
{ |
204
|
|
|
$this->targeting_value = $targeting_value; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param mixed $tailored_audience_expansion |
209
|
|
|
*/ |
210
|
|
|
public function setTailoredAudienceExpansion($tailored_audience_expansion) |
211
|
|
|
{ |
212
|
|
|
$this->tailored_audience_expansion = $tailored_audience_expansion; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @param mixed $tailored_audience_type |
217
|
|
|
*/ |
218
|
|
|
public function setTailoredAudienceType($tailored_audience_type) |
219
|
|
|
{ |
220
|
|
|
$this->tailored_audience_type = $tailored_audience_type; |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|