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::PAUSED, |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
/** Writable */ |
35
|
|
|
protected $tweet_id; |
36
|
|
|
protected $paused; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param $metricGroups |
40
|
|
|
* @param array $params |
41
|
|
|
* @param bool $async |
42
|
|
|
* @return mixed |
43
|
|
|
*/ |
44
|
|
|
public function stats($metricGroups, $params = [], $async = false) |
45
|
|
|
{ |
46
|
|
|
$params[AnalyticsFields::ENTITY] = AnalyticsFields::PROMOTED_TWEET; |
47
|
|
|
return parent::stats($metricGroups, $params, $async); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Saves or updates the current object instance depending on the |
52
|
|
|
* presence of `object->getId()`. |
53
|
|
|
*/ |
54
|
|
|
public function save() |
55
|
|
|
{ |
56
|
|
|
$params = $this->toParams(); |
57
|
|
|
if (isset($params[PromotedTweetFields::TWEET_ID])) { |
58
|
|
|
$params[PromotedTweetFields::TWEET_IDS] = $params[PromotedTweetFields::TWEET_ID]; |
59
|
|
|
unset($params[PromotedTweetFields::TWEET_ID]); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if ($this->getId()) { |
63
|
|
|
$resource = str_replace(static::RESOURCE_REPLACE, $this->getTwitterAds()->getAccountId(), static::RESOURCE); |
64
|
|
|
$resource = str_replace(static::RESOURCE_ID_REPLACE, $this->getId(), $resource); |
65
|
|
|
$response = $this->getTwitterAds()->put($resource, $params); |
66
|
|
|
|
67
|
|
|
return $this->fromResponse($response->getBody()->data); |
68
|
|
|
} else { |
69
|
|
|
$resource = str_replace(static::RESOURCE_REPLACE, $this->getTwitterAds()->getAccountId(), static::RESOURCE_COLLECTION); |
70
|
|
|
$response = $this->getTwitterAds()->post($resource, $params); |
71
|
|
|
|
72
|
|
|
return $this->fromResponse($response->getBody()->data[0]); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return mixed |
78
|
|
|
*/ |
79
|
|
|
public function getId() |
80
|
|
|
{ |
81
|
|
|
return $this->id; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return mixed |
86
|
|
|
*/ |
87
|
|
|
public function getApprovalStatus() |
88
|
|
|
{ |
89
|
|
|
return $this->approval_status; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return mixed |
94
|
|
|
*/ |
95
|
|
|
public function getCreatedAt() |
96
|
|
|
{ |
97
|
|
|
return $this->created_at; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return mixed |
102
|
|
|
*/ |
103
|
|
|
public function getUpdatedAt() |
104
|
|
|
{ |
105
|
|
|
return $this->updated_at; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return mixed |
110
|
|
|
*/ |
111
|
|
|
public function getDeleted() |
112
|
|
|
{ |
113
|
|
|
return $this->deleted; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return array |
118
|
|
|
*/ |
119
|
|
|
public function getProperties() |
120
|
|
|
{ |
121
|
|
|
return $this->properties; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return mixed |
126
|
|
|
*/ |
127
|
|
|
public function getTweetId() |
128
|
|
|
{ |
129
|
|
|
return $this->tweet_id; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return mixed |
134
|
|
|
*/ |
135
|
|
|
public function getPaused() |
136
|
|
|
{ |
137
|
|
|
return $this->paused; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param array $properties |
142
|
|
|
*/ |
143
|
|
|
public function setProperties($properties) |
144
|
|
|
{ |
145
|
|
|
$this->properties = $properties; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param mixed $tweet_id |
150
|
|
|
*/ |
151
|
|
|
public function setTweetId($tweet_id) |
152
|
|
|
{ |
153
|
|
|
$this->tweet_id = $tweet_id; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @param mixed $paused |
158
|
|
|
*/ |
159
|
|
|
public function setPaused($paused) |
160
|
|
|
{ |
161
|
|
|
$this->paused = $paused; |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|