Completed
Pull Request — master (#64)
by
unknown
01:31
created

PromotedTweet::getLineItemId()   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\PromotedTweetFields;
9
10
/**
11
 * Class PromotedTweet
12
 * @package Hborras\TwitterAdsSDK\TwitterAds\Creative
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::LINE_ITEM_ID,
32
        PromotedTweetFields::ENTITY_STATUS,
33
    ];
34
35
    /** Writable */
36
    protected $tweet_id;
37
    protected $line_item_id;
38
    protected $entity_status;
39
40
    /**
41
     * @param $metricGroups
42
     * @param array $params
43
     * @param bool $async
44
     * @return mixed
45
     * @throws BadRequest
46
     * @throws \Hborras\TwitterAdsSDK\TwitterAdsException
47
     * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\Forbidden
48
     * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\NotAuthorized
49
     * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\NotFound
50
     * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\RateLimit
51
     * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\ServerError
52
     * @throws \Hborras\TwitterAdsSDK\TwitterAds\Errors\ServiceUnavailable
53
     */
54
    public function stats($metricGroups, $params = [], $async = false)
55
    {
56
        $params[AnalyticsFields::ENTITY] = AnalyticsFields::PROMOTED_TWEET;
57
        return parent::stats($metricGroups, $params, $async);
58
    }
59
60
    /**
61
     * Saves or updates the current object instance depending on the
62
     * presence of `object->getId()`.
63
     */
64 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...
65
    {
66
        $params = $this->toParams();
67
        if (isset($params[PromotedTweetFields::TWEET_ID])) {
68
            $params[PromotedTweetFields::TWEET_IDS] = $params[PromotedTweetFields::TWEET_ID];
69
            unset($params[PromotedTweetFields::TWEET_ID]);
70
        }
71
72
        if ($this->getId()) {
73
            $resource = str_replace(static::RESOURCE_REPLACE, $this->getTwitterAds()->getAccountId(), static::RESOURCE);
74
            $resource = str_replace(static::RESOURCE_ID_REPLACE, $this->getId(), $resource);
75
            $response = $this->getTwitterAds()->put($resource, $params);
76
77
            return $this->fromResponse($response->getBody()->data);
78
        }
79
80
        $resource = str_replace(static::RESOURCE_REPLACE, $this->getTwitterAds()->getAccountId(), static::RESOURCE_COLLECTION);
81
        $response = $this->getTwitterAds()->post($resource, $params);
82
83
        return $this->fromResponse($response->getBody()->data[0]);
84
    }
85
86
    /**
87
     * @return mixed
88
     */
89
    public function getId()
90
    {
91
        return $this->id;
92
    }
93
94
    /**
95
     * @return mixed
96
     */
97
    public function getApprovalStatus()
98
    {
99
        return $this->approval_status;
100
    }
101
102
    /**
103
     * @return mixed
104
     */
105
    public function getCreatedAt()
106
    {
107
        return $this->created_at;
108
    }
109
110
    /**
111
     * @return mixed
112
     */
113
    public function getUpdatedAt()
114
    {
115
        return $this->updated_at;
116
    }
117
118
    /**
119
     * @return mixed
120
     */
121
    public function getDeleted()
122
    {
123
        return $this->deleted;
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)
178
    {
179
        $this->line_item_id = $line_item_id;
180
    }
181
}
182