Completed
Push — master ( 3d7154...87dec9 )
by Hector
05:10 queued 02:26
created

setTailoredAudienceId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Hborras\TwitterAdsSDK\TwitterAds\TailoredAudience;
4
5
use Hborras\TwitterAdsSDK\TONUpload;
6
use Hborras\TwitterAdsSDK\TwitterAds;
7
use Hborras\TwitterAdsSDK\TwitterAds\Account;
8
use Hborras\TwitterAdsSDK\TwitterAds\Cursor;
9
use Hborras\TwitterAdsSDK\TwitterAds\Resource;
10
use Hborras\TwitterAdsSDK\TwitterAds\TailoredAudience\Exception\InvalidType;
11
12
final class TailoredAudiencePermission extends Resource
13
{
14
    const RESOURCE_COLLECTION = 'accounts/{account_id}/tailored_audiences/{tailored_audience_id/permissions}';
15
    const RESOURCE = 'accounts/{account_id}/tailored_audiences/{tailored_audience_id/permissions}/{id}';
16
    const RESOURCE_TAILORED_AUDIENCE_ID_REPLACE = '{tailored_audience_id}';
17
18
19
    /** Writable */
20
    protected $tailored_audience_id;
21
    protected $granted_account_id;
22
    protected $permission_level;
23
24
    protected $properties = [
25
        'tailored_audience_id',
26
        'granted_account_id',
27
        'permission_level'
28
    ];
29
30
    /** Read Only */
31
    protected $deleted;
32
    protected $id;
33
    protected $updated_at;
34
    protected $created_at;
35
36
    /**
37
     * Returns a Cursor instance for the given tailored audience permission resource.
38
     *
39
     * @param array $tailoredAudienceId
40
     * @param array $params
41
     * @return Cursor
42
     */
43 View Code Duplication
    public function all($tailoredAudienceId, $params = [])
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...
44
    {
45
        $resource = str_replace(static::RESOURCE_REPLACE, $this->getAccount()->getId(), static::RESOURCE);
46
        $resource = str_replace(self::RESOURCE_TAILORED_AUDIENCE_ID_REPLACE, $tailoredAudienceId, $resource);
47
48
        $response = $this->getAccount()->getTwitterAds()->get($resource, $params);
49
50
        return new Cursor($this, $this->getAccount(), $response->getBody(), $params);
51
    }
52
53
    /**
54
     * Saves or updates the current tailored audience permission.
55
     *
56
     * @return $this
57
     */
58
    public function save()
59
    {
60
        if(!$this->getId()){
61
            $resource = str_replace(static::RESOURCE_REPLACE, $this->getAccount()->getId(), static::RESOURCE);
62
            $resource = str_replace(self::RESOURCE_TAILORED_AUDIENCE_ID_REPLACE, $this->getTailoredAudienceId(), $resource);
63
            $response = $this->getAccount()->getTwitterAds()->post($resource, []);
64
        } else {
65
            $resource = str_replace(static::RESOURCE_REPLACE, $this->getAccount()->getId(), static::RESOURCE);
66
            $resource = str_replace(self::RESOURCE_TAILORED_AUDIENCE_ID_REPLACE, $this->getTailoredAudienceId(), $resource);
67
            $resource = str_replace(static::RESOURCE_ID_REPLACE, $this->getId(), $resource);
68
            $response = $this->getAccount()->getTwitterAds()->put($resource, []);
69
        }
70
71
        return $this->fromResponse($response->getBody()->data);
72
    }
73
74
    /**
75
     * Saves or updates the current tailored audience permission.
76
     *
77
     * @return $this
78
     */
79
    public function delete()
80
    {
81
        $resource = str_replace(static::RESOURCE_REPLACE, $this->getAccount()->getId(), static::RESOURCE);
82
        $resource = str_replace(self::RESOURCE_TAILORED_AUDIENCE_ID_REPLACE, $this->getTailoredAudienceId(), $resource);
83
        $resource = str_replace(static::RESOURCE_ID_REPLACE, $this->getId(), $resource);
84
        $response = $this->getAccount()->getTwitterAds()->delete($resource, []);
85
86
        return $this->fromResponse($response->getBody()->data);
87
    }
88
89
    /**
90
     * @return mixed
91
     */
92
    public function getTailoredAudienceId()
93
    {
94
        return $this->tailored_audience_id;
95
    }
96
97
    /**
98
     * @param mixed $tailored_audience_id
99
     */
100
    public function setTailoredAudienceId($tailored_audience_id)
101
    {
102
        $this->tailored_audience_id = $tailored_audience_id;
103
    }
104
105
    /**
106
     * @return mixed
107
     */
108
    public function getGrantedAccountId()
109
    {
110
        return $this->granted_account_id;
111
    }
112
113
    /**
114
     * @param mixed $granted_account_id
115
     */
116
    public function setGrantedAccountId($granted_account_id)
117
    {
118
        $this->granted_account_id = $granted_account_id;
119
    }
120
121
    /**
122
     * @return mixed
123
     */
124
    public function getPermissionLevel()
125
    {
126
        return $this->permission_level;
127
    }
128
129
    /**
130
     * @param mixed $permission_level
131
     */
132
    public function setPermissionLevel($permission_level)
133
    {
134
        $this->permission_level = $permission_level;
135
    }
136
137
    /**
138
     * @return mixed
139
     */
140
    public function getDeleted()
141
    {
142
        return $this->deleted;
143
    }
144
145
    /**
146
     * @return mixed
147
     */
148
    public function getId()
149
    {
150
        return $this->id;
151
    }
152
153
    /**
154
     * @return mixed
155
     */
156
    public function getUpdatedAt()
157
    {
158
        return $this->updated_at;
159
    }
160
161
    /**
162
     * @return mixed
163
     */
164
    public function getCreatedAt()
165
    {
166
        return $this->created_at;
167
    }
168
}
169