1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: hborras |
5
|
|
|
* Date: 17/04/16 |
6
|
|
|
* Time: 22:41. |
7
|
|
|
*/ |
8
|
|
|
namespace Hborras\TwitterAdsSDK\TwitterAds\Creative; |
9
|
|
|
|
10
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Analytics; |
11
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Fields\AnalyticsFields; |
12
|
|
|
use Hborras\TwitterAdsSDK\TwitterAds\Fields\PromotedTweetFields; |
13
|
|
|
|
14
|
|
|
class PromotedTweet extends Analytics |
15
|
|
|
{ |
16
|
|
|
const RESOURCE_COLLECTION = 'accounts/{account_id}/promoted_tweets'; |
17
|
|
|
const RESOURCE = 'accounts/{account_id}/promoted_tweets/{id}'; |
18
|
|
|
const RESOURCE_STATS = 'stats/accounts/{account_id}/promoted_tweets/{id}'; |
19
|
|
|
|
20
|
|
|
const ENTITY = 'PROMOTED_TWEET'; |
21
|
|
|
|
22
|
|
|
/** Read Only */ |
23
|
|
|
protected $id; |
24
|
|
|
protected $approval_status; |
25
|
|
|
protected $created_at; |
26
|
|
|
protected $updated_at; |
27
|
|
|
protected $deleted; |
28
|
|
|
|
29
|
|
|
protected $properties = [ |
30
|
|
|
PromotedTweetFields::TWEET_ID, |
31
|
|
|
PromotedTweetFields::ENTITY_STATUS, |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
/** Writable */ |
35
|
|
|
protected $tweet_id; |
36
|
|
|
protected $line_item_id; |
37
|
|
|
protected $entity_status; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param $metricGroups |
41
|
|
|
* @param array $params |
42
|
|
|
* @param bool $async |
43
|
|
|
* @return mixed |
44
|
|
|
* @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\BadRequest |
45
|
|
|
*/ |
46
|
|
|
public function stats($metricGroups, $params = [], $async = false) |
47
|
|
|
{ |
48
|
|
|
$params[AnalyticsFields::ENTITY] = AnalyticsFields::PROMOTED_TWEET; |
49
|
|
|
return parent::stats($metricGroups, $params, $async); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Saves or updates the current object instance depending on the |
54
|
|
|
* presence of `object->getId()`. |
55
|
|
|
*/ |
56
|
|
|
public function save() |
57
|
|
|
{ |
58
|
|
|
$params = $this->toParams(); |
59
|
|
|
if (isset($params[PromotedTweetFields::TWEET_ID])) { |
60
|
|
|
$params[PromotedTweetFields::TWEET_IDS] = $params[PromotedTweetFields::TWEET_ID]; |
61
|
|
|
unset($params[PromotedTweetFields::TWEET_ID]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if ($this->getId()) { |
65
|
|
|
$resource = str_replace(static::RESOURCE_REPLACE, $this->getTwitterAds()->getAccountId(), static::RESOURCE); |
66
|
|
|
$resource = str_replace(static::RESOURCE_ID_REPLACE, $this->getId(), $resource); |
67
|
|
|
$response = $this->getTwitterAds()->put($resource, $params); |
68
|
|
|
|
69
|
|
|
return $this->fromResponse($response->getBody()->data); |
70
|
|
|
} else { |
71
|
|
|
$resource = str_replace(static::RESOURCE_REPLACE, $this->getTwitterAds()->getAccountId(), static::RESOURCE_COLLECTION); |
72
|
|
|
$response = $this->getTwitterAds()->post($resource, $params); |
73
|
|
|
|
74
|
|
|
return $this->fromResponse($response->getBody()->data[0]); |
75
|
|
|
} |
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 getApprovalStatus() |
90
|
|
|
{ |
91
|
|
|
return $this->approval_status; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return mixed |
96
|
|
|
*/ |
97
|
|
|
public function getCreatedAt() |
98
|
|
|
{ |
99
|
|
|
return $this->created_at; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return mixed |
104
|
|
|
*/ |
105
|
|
|
public function getUpdatedAt() |
106
|
|
|
{ |
107
|
|
|
return $this->updated_at; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return mixed |
112
|
|
|
*/ |
113
|
|
|
public function getDeleted() |
114
|
|
|
{ |
115
|
|
|
return $this->deleted; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return array |
120
|
|
|
*/ |
121
|
|
|
public function getProperties() |
122
|
|
|
{ |
123
|
|
|
return $this->properties; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return mixed |
128
|
|
|
*/ |
129
|
|
|
public function getTweetId() |
130
|
|
|
{ |
131
|
|
|
return $this->tweet_id; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param array $properties |
136
|
|
|
*/ |
137
|
|
|
public function setProperties($properties) |
138
|
|
|
{ |
139
|
|
|
$this->properties = $properties; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param mixed $tweet_id |
144
|
|
|
*/ |
145
|
|
|
public function setTweetId($tweet_id) |
146
|
|
|
{ |
147
|
|
|
$this->tweet_id = $tweet_id; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return mixed |
152
|
|
|
*/ |
153
|
|
|
public function getEntityStatus() |
154
|
|
|
{ |
155
|
|
|
return $this->entity_status; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param mixed $entity_status |
160
|
|
|
*/ |
161
|
|
|
public function setEntityStatus($entity_status) |
162
|
|
|
{ |
163
|
|
|
$this->entity_status = $entity_status; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return mixed |
168
|
|
|
*/ |
169
|
|
|
public function getLineItemId() |
170
|
|
|
{ |
171
|
|
|
return $this->line_item_id; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @param mixed $line_item_id |
176
|
|
|
*/ |
177
|
|
|
public function setLineItemId($line_item_id): void |
178
|
|
|
{ |
179
|
|
|
$this->line_item_id = $line_item_id; |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|