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