|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hborras\TwitterAdsSDK\TwitterAds\Analytics; |
|
4
|
|
|
|
|
5
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Resource; |
|
6
|
|
|
use Hborras\TwitterAdsSDK\TwitterAdsException; |
|
7
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Analytics; |
|
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\Fields\JobFields; |
|
12
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Errors\BadRequest; |
|
13
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Errors\ServerError; |
|
14
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Errors\NotAuthorized; |
|
15
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Errors\ServiceUnavailable; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class Job |
|
19
|
|
|
* @package Hborras\TwitterAdsSDK\TwitterAds\Analytics |
|
20
|
|
|
*/ |
|
21
|
|
|
class Job extends Analytics |
|
22
|
|
|
{ |
|
23
|
|
|
const RESOURCE_COLLECTION = 'stats/jobs/accounts/{account_id}'; |
|
24
|
|
|
const RESOURCE = 'stats/jobs/accounts/{account_id}'; |
|
25
|
|
|
const ENTITY = 'JOBS'; |
|
26
|
|
|
|
|
27
|
|
|
/** Read Only */ |
|
28
|
|
|
protected $id; |
|
29
|
|
|
protected $start_time; |
|
30
|
|
|
protected $segmentation_type; |
|
31
|
|
|
protected $url; |
|
32
|
|
|
protected $id_str; |
|
33
|
|
|
protected $entity_ids; |
|
34
|
|
|
protected $end_time; |
|
35
|
|
|
protected $placement; |
|
36
|
|
|
protected $expires_at; |
|
37
|
|
|
protected $account_id; |
|
38
|
|
|
protected $status; |
|
39
|
|
|
protected $granularity; |
|
40
|
|
|
protected $entity; |
|
41
|
|
|
protected $created_at; |
|
42
|
|
|
protected $updated_at; |
|
43
|
|
|
protected $metric_groups; |
|
44
|
|
|
|
|
45
|
|
|
protected $properties = []; |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param array $params |
|
50
|
|
|
* @return $this|Job|Resource |
|
51
|
|
|
* @throws TwitterAdsException |
|
52
|
|
|
* @throws BadRequest |
|
53
|
|
|
* @throws Forbidden |
|
54
|
|
|
* @throws NotAuthorized |
|
55
|
|
|
* @throws NotFound |
|
56
|
|
|
* @throws RateLimit |
|
57
|
|
|
* @throws ServerError |
|
58
|
|
|
* @throws ServiceUnavailable |
|
59
|
|
|
*/ |
|
60
|
|
|
public function read($params = []) |
|
61
|
|
|
{ |
|
62
|
|
|
if (isset($params[JobFields::ACCOUNT_ID])) { |
|
63
|
|
|
$account_id = $params[JobFields::ACCOUNT_ID]; |
|
64
|
|
|
} else { |
|
65
|
|
|
$account_id = $this->getTwitterAds()->getAccountId(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$resource = str_replace(static::RESOURCE_REPLACE, $account_id, static::RESOURCE); |
|
69
|
|
|
$params[JobFields::JOB_IDS] = $this->id; |
|
70
|
|
|
$response = $this->getTwitterAds()->get($resource, $params); |
|
71
|
|
|
if (isset($response->getBody()->data[0])) { |
|
72
|
|
|
return $this->fromResponse($response->getBody()->data[0]); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $this; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return mixed |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getId() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->id; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @return mixed |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getStartTime() |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->start_time; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return mixed |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getSegmentationType() |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->segmentation_type; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return mixed |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getUrl() |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->url; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return mixed |
|
112
|
|
|
*/ |
|
113
|
|
|
public function getIdStr() |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->id_str; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @return mixed |
|
120
|
|
|
*/ |
|
121
|
|
|
public function getEntityIds() |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->entity_ids; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @return mixed |
|
128
|
|
|
*/ |
|
129
|
|
|
public function getEndTime() |
|
130
|
|
|
{ |
|
131
|
|
|
return $this->end_time; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @return mixed |
|
136
|
|
|
*/ |
|
137
|
|
|
public function getPlacement() |
|
138
|
|
|
{ |
|
139
|
|
|
return $this->placement; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @return mixed |
|
144
|
|
|
*/ |
|
145
|
|
|
public function getExpiresAt() |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->expires_at; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @return mixed |
|
152
|
|
|
*/ |
|
153
|
|
|
public function getAccountId() |
|
154
|
|
|
{ |
|
155
|
|
|
return $this->account_id; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @return mixed |
|
160
|
|
|
*/ |
|
161
|
|
|
public function getStatus() |
|
162
|
|
|
{ |
|
163
|
|
|
return $this->status; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @return mixed |
|
168
|
|
|
*/ |
|
169
|
|
|
public function getGranularity() |
|
170
|
|
|
{ |
|
171
|
|
|
return $this->granularity; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @return mixed |
|
176
|
|
|
*/ |
|
177
|
|
|
public function getEntity() |
|
178
|
|
|
{ |
|
179
|
|
|
return $this->entity; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @return mixed |
|
184
|
|
|
*/ |
|
185
|
|
|
public function getCreatedAt() |
|
186
|
|
|
{ |
|
187
|
|
|
return $this->created_at; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @return mixed |
|
192
|
|
|
*/ |
|
193
|
|
|
public function getUpdatedAt() |
|
194
|
|
|
{ |
|
195
|
|
|
return $this->updated_at; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* @return mixed |
|
200
|
|
|
*/ |
|
201
|
|
|
public function getMetricGroups() |
|
202
|
|
|
{ |
|
203
|
|
|
return $this->metric_groups; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
} |
|
207
|
|
|
|