Completed
Push — master ( 7abbf4...2d1d94 )
by Hector
02:51 queued 01:26
created

ScheduledPromotedTweet::getUpdatedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Hborras\TwitterAdsSDK\TwitterAds\Creative;
4
5
use Hborras\TwitterAdsSDK\TwitterAds\Analytics;
6
use Hborras\TwitterAdsSDK\TwitterAds\Errors\BadRequest;
7
use Hborras\TwitterAdsSDK\TwitterAds\Fields\AnalyticsFields;
8
use Hborras\TwitterAdsSDK\TwitterAds\Fields\ScheduledPromotedTweetFields;
9
10
/**
11
 * Class ScheduledTweet
12
 * @package Hborras\TwitterAdsSDK\TwitterAds\Creative
13
 */
14
class ScheduledPromotedTweet extends Analytics
15
{
16
    const RESOURCE_COLLECTION = 'accounts/{account_id}/scheduled_promoted_tweets';
17
    const RESOURCE            = 'accounts/{account_id}/scheduled_promoted_tweets/{id}';
18
    const RESOURCE_STATS      = 'stats/accounts/{account_id}/scheduled_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
        ScheduledPromotedTweetFields::TWEET_ID,
31
        ScheduledPromotedTweetFields::ENTITY_STATUS,
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
     * @throws BadRequest
44
     * @throws \Hborras\TwitterAdsSDK\TwitterAdsException
45
     * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\Forbidden
46
     * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\NotAuthorized
47
     * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\NotFound
48
     * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\RateLimit
49
     * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\ServerError
50
     * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\ServiceUnavailable
51
     */
52
    public function stats($metricGroups, $params = [], $async = false)
53
    {
54
        $params[AnalyticsFields::ENTITY] = AnalyticsFields::PROMOTED_TWEET;
55
        return parent::stats($metricGroups, $params, $async);
56
    }
57
58
    /**
59
     * Saves or updates the current object instance depending on the
60
     * presence of `object->getId()`.
61
     */
62 View Code Duplication
    public function save()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64
        $params = $this->toParams();
65
        if (isset($params[ScheduledPromotedTweetFields::TWEET_ID])) {
66
            $params[ScheduledPromotedTweetFields::TWEET_IDS] = $params[ScheduledPromotedTweetFields::TWEET_ID];
67
            unset($params[ScheduledPromotedTweetFields::TWEET_ID]);
68
        }
69
70
        if ($this->getId()) {
71
            $resource = str_replace(static::RESOURCE_REPLACE, $this->getTwitterAds()->getAccountId(), static::RESOURCE);
72
            $resource = str_replace(static::RESOURCE_ID_REPLACE, $this->getId(), $resource);
73
            $response = $this->getTwitterAds()->put($resource, $params);
74
75
            return $this->fromResponse($response->getBody()->data);
76
        }
77
78
        $resource = str_replace(static::RESOURCE_REPLACE, $this->getTwitterAds()->getAccountId(), static::RESOURCE_COLLECTION);
79
        $response = $this->getTwitterAds()->post($resource, $params);
80
81
        return $this->fromResponse($response->getBody()->data[0]);
82
    }
83
84
    /**
85
     * @return mixed
86
     */
87
    public function getId()
88
    {
89
        return $this->id;
90
    }
91
92
    /**
93
     * @return mixed
94
     */
95
    public function getApprovalStatus()
96
    {
97
        return $this->approval_status;
98
    }
99
100
    /**
101
     * @return mixed
102
     */
103
    public function getCreatedAt()
104
    {
105
        return $this->created_at;
106
    }
107
108
    /**
109
     * @return mixed
110
     */
111
    public function getUpdatedAt()
112
    {
113
        return $this->updated_at;
114
    }
115
116
    /**
117
     * @return mixed
118
     */
119
    public function getDeleted()
120
    {
121
        return $this->deleted;
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