|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hborras\TwitterAdsSDK\TwitterAds\Campaign; |
|
4
|
|
|
|
|
5
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Analytics; |
|
6
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Fields\AnalyticsFields; |
|
7
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Errors\BadRequest; |
|
8
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Fields\ScheduledTweetFields; |
|
9
|
|
|
|
|
10
|
|
|
class ScheduledTweet extends Analytics |
|
11
|
|
|
{ |
|
12
|
|
|
const RESOURCE_COLLECTION = 'accounts/{account_id}/scheduled_tweets'; |
|
13
|
|
|
const RESOURCE = 'accounts/{account_id}/scheduled_tweets/{id}'; |
|
14
|
|
|
const RESOURCE_STATS = 'stats/accounts/{account_id}/scheduled_tweets/{id}'; |
|
15
|
|
|
|
|
16
|
|
|
const ENTITY = 'SCHEDULED_TWEET'; |
|
17
|
|
|
|
|
18
|
|
|
/** Read Only */ |
|
19
|
|
|
protected $id; |
|
20
|
|
|
protected $completed_at; |
|
21
|
|
|
protected $user_id; |
|
22
|
|
|
protected $scheduled_status; |
|
23
|
|
|
|
|
24
|
|
|
protected $properties = [ |
|
25
|
|
|
ScheduledTweetFields::SCHEDULED_AT, |
|
26
|
|
|
ScheduledTweetFields::AS_USER_ID, |
|
27
|
|
|
ScheduledTweetFields::TEXT, |
|
28
|
|
|
ScheduledTweetFields::CARD_URI, |
|
29
|
|
|
ScheduledTweetFields::MEDIA_KEYS, |
|
30
|
|
|
ScheduledTweetFields::NULLCAST, |
|
31
|
|
|
]; |
|
32
|
|
|
|
|
33
|
|
|
/** Writable */ |
|
34
|
|
|
protected $scheduled_at; |
|
35
|
|
|
protected $as_user_id; |
|
36
|
|
|
protected $text; |
|
37
|
|
|
protected $card_uri; |
|
38
|
|
|
protected $media_keys; |
|
39
|
|
|
protected $nullcast; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param $metricGroups |
|
43
|
|
|
* @param array $params |
|
44
|
|
|
* @param bool $async |
|
45
|
|
|
* @return mixed |
|
46
|
|
|
* @throws BadRequest |
|
47
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAdsException |
|
48
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\Forbidden |
|
49
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\NotAuthorized |
|
50
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\NotFound |
|
51
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\RateLimit |
|
52
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\ServerError |
|
53
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\ServiceUnavailable |
|
54
|
|
|
*/ |
|
55
|
|
|
public function stats($metricGroups, $params = [], $async = false) |
|
56
|
|
|
{ |
|
57
|
|
|
$params[AnalyticsFields::ENTITY] = AnalyticsFields::PROMOTED_TWEET; |
|
58
|
|
|
return parent::stats($metricGroups, $params, $async); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Saves or updates the current object instance depending on the |
|
63
|
|
|
* presence of `object->getId()`. |
|
64
|
|
|
*/ |
|
65
|
|
|
public function save() |
|
66
|
|
|
{ |
|
67
|
|
|
$params = $this->toParams(); |
|
68
|
|
|
if ($this->getId()) { |
|
69
|
|
|
$resource = str_replace(static::RESOURCE_REPLACE, $this->getTwitterAds()->getAccountId(), static::RESOURCE); |
|
70
|
|
|
$resource = str_replace(static::RESOURCE_ID_REPLACE, $this->getId(), $resource); |
|
71
|
|
|
$response = $this->getTwitterAds()->put($resource, $params); |
|
72
|
|
|
|
|
73
|
|
|
return $this->fromResponse($response->getBody()->data); |
|
74
|
|
|
} |
|
75
|
|
|
$resource = str_replace(static::RESOURCE_REPLACE, $this->getTwitterAds()->getAccountId(), static::RESOURCE_COLLECTION); |
|
76
|
|
|
$response = $this->getTwitterAds()->post($resource, $params); |
|
77
|
|
|
|
|
78
|
|
|
return $this->fromResponse($response->getBody()->data[0]); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return mixed |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getId() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->id; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param array $properties |
|
91
|
|
|
*/ |
|
92
|
|
|
public function setProperties($properties) |
|
93
|
|
|
{ |
|
94
|
|
|
$this->properties = $properties; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return mixed |
|
99
|
|
|
*/ |
|
100
|
|
|
public function completed_at() |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->completed_at; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return mixed |
|
107
|
|
|
*/ |
|
108
|
|
|
public function user_id() |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->user_id; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return mixed |
|
115
|
|
|
*/ |
|
116
|
|
|
public function scheduled_status() |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->scheduled_status; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @return array |
|
123
|
|
|
*/ |
|
124
|
|
|
public function properties(): array |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->properties; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @return mixed |
|
131
|
|
|
*/ |
|
132
|
|
|
public function scheduled_at() |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->scheduled_at; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @return mixed |
|
139
|
|
|
*/ |
|
140
|
|
|
public function as_user_id() |
|
141
|
|
|
{ |
|
142
|
|
|
return $this->as_user_id; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @return mixed |
|
147
|
|
|
*/ |
|
148
|
|
|
public function text() |
|
149
|
|
|
{ |
|
150
|
|
|
return $this->text; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @return mixed |
|
155
|
|
|
*/ |
|
156
|
|
|
public function card_uri() |
|
157
|
|
|
{ |
|
158
|
|
|
return $this->card_uri; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* @return mixed |
|
163
|
|
|
*/ |
|
164
|
|
|
public function media_keys() |
|
165
|
|
|
{ |
|
166
|
|
|
return $this->media_keys; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @return mixed |
|
171
|
|
|
*/ |
|
172
|
|
|
public function nullcast() |
|
173
|
|
|
{ |
|
174
|
|
|
return $this->nullcast; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* @param mixed $scheduled_at |
|
179
|
|
|
*/ |
|
180
|
|
|
public function setScheduledAt($scheduled_at): void |
|
181
|
|
|
{ |
|
182
|
|
|
$this->scheduled_at = $scheduled_at; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* @param mixed $as_user_id |
|
187
|
|
|
*/ |
|
188
|
|
|
public function setAsUserId($as_user_id): void |
|
189
|
|
|
{ |
|
190
|
|
|
$this->as_user_id = $as_user_id; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* @param mixed $text |
|
195
|
|
|
*/ |
|
196
|
|
|
public function setText($text): void |
|
197
|
|
|
{ |
|
198
|
|
|
$this->text = $text; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* @param mixed $card_uri |
|
203
|
|
|
*/ |
|
204
|
|
|
public function setCardUri($card_uri): void |
|
205
|
|
|
{ |
|
206
|
|
|
$this->card_uri = $card_uri; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* @param mixed $media_keys |
|
211
|
|
|
*/ |
|
212
|
|
|
public function setMediaKeys($media_keys): void |
|
213
|
|
|
{ |
|
214
|
|
|
$this->media_keys = $media_keys; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* @param mixed $nullcast |
|
219
|
|
|
*/ |
|
220
|
|
|
public function setNullcast($nullcast): void |
|
221
|
|
|
{ |
|
222
|
|
|
$this->nullcast = $nullcast; |
|
223
|
|
|
} |
|
224
|
|
|
} |