1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: hborras |
5
|
|
|
* Date: 27/03/16 |
6
|
|
|
* Time: 13:16. |
7
|
|
|
*/ |
8
|
|
|
namespace Hborras\TwitterAdsSDK\TwitterAds; |
9
|
|
|
|
10
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds; |
11
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Analytics\Job; |
12
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\AppList; |
13
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\Campaign; |
14
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\FundingInstrument; |
15
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\LineItem; |
16
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Campaign\PromotableUser; |
17
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Creative\Video; |
18
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Fields\AnalyticsFields; |
19
|
|
|
use Hborras\TwitterAdsSDK\TwitterAdsException; |
20
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Fields\AccountFields; |
21
|
|
|
|
22
|
|
|
class Account extends Analytics |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
const RESOURCE_REPLACE = '{account_id}'; |
26
|
|
|
const RESOURCE_COLLECTION = 'accounts'; |
27
|
|
|
const RESOURCE = 'accounts/{account_id}'; |
28
|
|
|
const FEATURES = 'accounts/{account_id}/features'; |
29
|
|
|
const APP_LISTS = 'accounts/{account_id}/app_lists'; |
30
|
|
|
const SCOPED_TIMELINE = 'accounts/{account_id}/scoped_timeline'; |
31
|
|
|
const AUTHENTICATED_USER_ACCESS = 'accounts/{account_id}/authenticated_user_access'; |
32
|
|
|
|
33
|
|
|
const ENTITY = 'ACCOUNT'; |
34
|
|
|
|
35
|
|
|
protected $id; |
36
|
|
|
protected $salt; |
37
|
|
|
protected $name; |
38
|
|
|
protected $timezone; |
39
|
|
|
protected $timezone_switch_at; |
40
|
|
|
protected $created_at; |
41
|
|
|
protected $updated_at; |
42
|
|
|
protected $deleted; |
43
|
|
|
protected $approval_status; |
44
|
|
|
protected $business_id; |
45
|
|
|
protected $business_name; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param $metricGroups |
49
|
|
|
* @param array $params |
50
|
|
|
* @param bool $async |
51
|
|
|
* @return mixed |
52
|
|
|
*/ |
53
|
|
|
public function stats($metricGroups, $params = [], $async = false) |
54
|
|
|
{ |
55
|
|
|
$params[AnalyticsFields::ENTITY] = AnalyticsFields::ACCOUNT; |
56
|
|
|
return parent::stats($metricGroups, $params, $async); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param array $params |
61
|
|
|
* @return Account |
62
|
|
|
*/ |
63
|
|
|
public function read($params = []) |
64
|
|
|
{ |
65
|
|
|
$this->getTwitterAds()->setAccountId($this->getId()); |
66
|
|
|
return parent::read($params); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Returns a collection of features available to the current account. |
71
|
|
|
* |
72
|
|
|
* @return mixed |
73
|
|
|
* |
74
|
|
|
* @throws TwitterAdsException |
75
|
|
|
*/ |
76
|
|
|
public function getFeatures() |
77
|
|
|
{ |
78
|
|
|
$this->validateLoaded(); |
79
|
|
|
|
80
|
|
|
$resource = str_replace(self::RESOURCE_REPLACE, $this->getId(), self::FEATURES); |
81
|
|
|
$response = $this->getTwitterAds()->get($resource); |
82
|
|
|
|
83
|
|
|
return $response->getBody()->data; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Returns a collection of promotable users available to the current account. |
88
|
|
|
* |
89
|
|
|
* @param string $id |
90
|
|
|
* |
91
|
|
|
* @param array $params |
92
|
|
|
* @return PromotableUser|Cursor |
93
|
|
|
*/ |
94
|
|
|
public function getPromotableUsers($id = '', $params = []) |
95
|
|
|
{ |
96
|
|
|
$promotableUserClass = new PromotableUser(); |
97
|
|
|
|
98
|
|
|
return $promotableUserClass->loadResource($id, $params); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Returns a collection of funding instruments available to the current account. |
103
|
|
|
* |
104
|
|
|
* @param string $id |
105
|
|
|
* |
106
|
|
|
* @param array $params |
107
|
|
|
* @return FundingInstrument|Cursor |
108
|
|
|
*/ |
109
|
|
|
public function getFundingInstruments($id = '', $params = []) |
110
|
|
|
{ |
111
|
|
|
$fundingInstrumentClass = new FundingInstrument(); |
112
|
|
|
|
113
|
|
|
return $fundingInstrumentClass->loadResource($id, $params); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Returns a collection of campaigns available to the current account. |
118
|
|
|
* |
119
|
|
|
* @param string $id |
120
|
|
|
* |
121
|
|
|
* @param array $params |
122
|
|
|
* @return Campaign|Cursor |
123
|
|
|
*/ |
124
|
|
|
public function getCampaigns($id = '', $params = []) |
125
|
|
|
{ |
126
|
|
|
$campaignClass = new Campaign(); |
127
|
|
|
|
128
|
|
|
return $campaignClass->loadResource($id, $params); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Returns a collection of line items available to the current account. |
133
|
|
|
* |
134
|
|
|
* @param string $id |
135
|
|
|
* |
136
|
|
|
* @param array $params |
137
|
|
|
* @return LineItem|Cursor |
138
|
|
|
*/ |
139
|
|
|
public function getLineItems($id = '', $params = []) |
140
|
|
|
{ |
141
|
|
|
$lineItemsClass = new LineItem(); |
142
|
|
|
|
143
|
|
|
return $lineItemsClass->loadResource($id, $params); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Returns a collection of app lists available to the current account. |
148
|
|
|
* |
149
|
|
|
* @param string $id |
150
|
|
|
* |
151
|
|
|
* @param array $params |
152
|
|
|
* @return AppList|Cursor |
153
|
|
|
*/ |
154
|
|
|
public function getAppLists($id = '', $params = []) |
155
|
|
|
{ |
156
|
|
|
$appListsClass = new AppList(); |
157
|
|
|
|
158
|
|
|
return $appListsClass->loadResource($id, $params); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Returns a collection of jobs. Can specify job_ids parameter to filter |
163
|
|
|
* |
164
|
|
|
* @param array $params |
165
|
|
|
* @return Cursor|Resource |
166
|
|
|
*/ |
167
|
|
|
public function getJobs($params = []) |
168
|
|
|
{ |
169
|
|
|
$jobsClass = new Job(); |
170
|
|
|
|
171
|
|
|
return $jobsClass->loadResource('', $params); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
|
175
|
|
|
public function getTailoredAudiences($id = '', $params = []) |
|
|
|
|
176
|
|
|
{ |
177
|
|
|
// TODO: Next Release |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Returns a collection of videos available to the current account. |
182
|
|
|
* |
183
|
|
|
* @param string $id |
184
|
|
|
* @param array $params |
185
|
|
|
* @return Cursor|Video |
186
|
|
|
*/ |
187
|
|
|
public function getVideos($id = '', $params = []) |
188
|
|
|
{ |
189
|
|
|
$videoClass = new Video(); |
190
|
|
|
|
191
|
|
|
return $videoClass->loadResource($id, $params); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Returns the most recent promotable Tweets created by one or more specified Twitter users. |
196
|
|
|
* |
197
|
|
|
* @param $ids |
198
|
|
|
* @param $params |
199
|
|
|
*/ |
200
|
|
|
public function getScopedTimeline($ids, $params) |
201
|
|
|
{ |
202
|
|
|
$this->validateLoaded(); |
203
|
|
|
|
204
|
|
|
if (is_array($ids)) { |
205
|
|
|
$ids = implode(',', $ids); |
206
|
|
|
} |
207
|
|
|
$params[] = [AccountFields::USER_IDS => $ids]; |
208
|
|
|
|
209
|
|
|
$resource = str_replace(self::RESOURCE_REPLACE, $this->getId(), self::SCOPED_TIMELINE); |
210
|
|
|
$response = $this->getTwitterAds()->get($resource, $params); |
211
|
|
|
|
212
|
|
|
return $response->getBody()->data; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @return string |
217
|
|
|
*/ |
218
|
|
|
public function getId() |
219
|
|
|
{ |
220
|
|
|
return $this->id; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @return string |
225
|
|
|
*/ |
226
|
|
|
public function getSalt() |
227
|
|
|
{ |
228
|
|
|
return $this->salt; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @return mixed |
233
|
|
|
*/ |
234
|
|
|
public function getTimezone() |
235
|
|
|
{ |
236
|
|
|
return $this->timezone; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @return \DateTimeImmutable |
241
|
|
|
*/ |
242
|
|
|
public function getTimezoneSwitchAt() |
243
|
|
|
{ |
244
|
|
|
return $this->timezone_switch_at; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @return \DateTimeImmutable |
249
|
|
|
*/ |
250
|
|
|
public function getCreatedAt() |
251
|
|
|
{ |
252
|
|
|
return $this->created_at; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* @return \DateTimeImmutable |
257
|
|
|
*/ |
258
|
|
|
public function getUpdatedAt() |
259
|
|
|
{ |
260
|
|
|
return $this->updated_at; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @return mixed |
265
|
|
|
*/ |
266
|
|
|
public function getDeleted() |
267
|
|
|
{ |
268
|
|
|
return filter_var($this->deleted, FILTER_VALIDATE_BOOLEAN); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* @return mixed |
273
|
|
|
*/ |
274
|
|
|
public function getApprovalStatus() |
275
|
|
|
{ |
276
|
|
|
return $this->approval_status; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* @return string |
281
|
|
|
*/ |
282
|
|
|
public function getName() |
283
|
|
|
{ |
284
|
|
|
return $this->name; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @return mixed |
289
|
|
|
*/ |
290
|
|
|
public function getBusinessId() |
291
|
|
|
{ |
292
|
|
|
return $this->business_id; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* @return mixed |
297
|
|
|
*/ |
298
|
|
|
public function getBusinessName() |
299
|
|
|
{ |
300
|
|
|
return $this->business_name; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
} |
304
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.