Card::stickers()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Trello\Api;
4
5
use Trello\Exception\InvalidArgumentException;
6
7
/**
8
 * Trello Card API
9
 * @link https://trello.com/docs/api/card
10
 *
11
 * Unimplemented:
12
 * - https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-name
13
 * - https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-pos
14
 * - https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-state
15
 * - https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklistcurrent-checkitem-idcheckitem
16
 * - https://trello.com/docs/api/card/#post-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem
17
 * - https://trello.com/docs/api/card/#post-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-converttocard
18
 * - https://trello.com/docs/api/card/#post-1-cards-card-id-or-shortlink-markassociatednotificationsread
19
 */
20
class Card extends AbstractApi
21
{
22
    /**
23
     * Base path of cards api
24
     * @var string
25
     */
26
    protected $path = 'cards';
27
28
    /**
29
     * Card fields
30
     * @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink-field
31
     * @var array
32
     */
33
    public static $fields = array(
34
        'badges',
35
        'checkItemStates',
36
        'closed',
37
        'dateLastActivity',
38
        'desc',
39
        'descData',
40
        'due',
41
        'email',
42
        'idBoard',
43
        'idChecklists',
44
        'idList',
45
        'idMembers',
46
        'idMembersVoted',
47
        'idShort',
48
        'idAttachmentCover',
49
        'manualCoverAttachment',
50
        'labels',
51
        'name',
52
        'pos',
53
        'shortLink',
54
        'shortUrl',
55
        'subscribed',
56
        'url',
57
    );
58
59
    /**
60
     * Find a card by id
61
     * @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink
62
     *
63
     * @param string $id     the card's id or short link
64
     * @param array  $params optional attributes
65
     *
66
     * @return array card info
67
     */
68 1
    public function show($id, array $params = array())
69
    {
70 1
        return $this->get($this->getPath().'/'.rawurlencode($id), $params);
71
    }
72
73
    /**
74
     * Create a card
75
     * @link https://trello.com/docs/api/card/#post-1-cards
76
     *
77
     * @param array  $params optional attributes
78
     *
79
     * @return array card info
80
     */
81 3
    public function create(array $params = array())
82
    {
83 3
        $this->validateRequiredParameters(array('idList', 'name'), $params);
84
85 1
        if (!array_key_exists('due', $params)) {
86 1
            $params['due'] = null;
87 1
        }
88 1
        if (!array_key_exists('urlSource', $params)) {
89 1
            $params['urlSource'] = null;
90 1
        }
91
92 1
        return $this->post($this->getPath(), $params);
93
    }
94
95
    /**
96
     * Update a card
97
     * @link https://trello.com/docs/api/card/#put-1-cards
98
     *
99
     * @param string $id     the card's id or short link
100
     * @param array  $params card attributes to update
101
     *
102
     * @return array card info
103
     */
104 1
    public function update($id, array $params = array())
105
    {
106 1
        return $this->put($this->getPath().'/'.rawurlencode($id), $params);
107
    }
108
109
    /**
110
     * Set a given card's board
111
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-idboard
112
     *
113
     * @param string $id      the card's id or short link
114
     * @param string $boardId the board's id
115
     *
116
     * @return array board info
117
     */
118 1
    public function setBoard($id, $boardId)
119
    {
120 1
        return $this->put($this->getPath().'/'.rawurlencode($id).'/idBoard', array('value' => $boardId));
121
    }
122
123
    /**
124
     * Get a given card's board
125
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-idboard
126
     *
127
     * @param string $id     the card's id or short link
128
     * @param array  $params optional parameters
129
     *
130
     * @return array board info
131
     */
132 1
    public function getBoard($id, array $params = array())
133
    {
134 1
        return $this->get($this->getPath().'/'.rawurlencode($id).'/board', $params);
135
    }
136
137
    /**
138
     * Get the field of a board of a given card
139
     * @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink-board-field
140
     *
141
     * @param string $id    the card's id
142
     * @param array  $field the name of the field
143
     *
144
     * @return array board info
145
     *
146
     * @throws InvalidArgumentException if the field does not exist
147
     */
148 2
    public function getBoardField($id, $field)
149
    {
150 2
        $this->validateAllowedParameters(Board::$fields, $field, 'field');
151
152 1
        return $this->get($this->getPath().'/'.rawurlencode($id).'/board/'.rawurlencode($field));
153
    }
154
155
    /**
156
     * Set a given card's list
157
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-idlist
158
     *
159
     * @param string $id     the card's id or short link
160
     * @param string $listId the list's id
161
     *
162
     * @return array list info
163
     */
164 1
    public function setList($id, $listId)
165
    {
166 1
        return $this->put($this->getPath().'/'.rawurlencode($id).'/idList', array('value' => $listId));
167
    }
168
169
    /**
170
     * Get a given card's list
171
     * @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink-list
172
     *
173
     * @param string $id     the card's id or short link
174
     * @param array  $params optional parameters
175
     *
176
     * @return array list info
177
     */
178 1
    public function getList($id, array $params = array())
179
    {
180 1
        return $this->get($this->getPath().'/'.rawurlencode($id).'/list', $params);
181
    }
182
183
    /**
184
     * Get the field of a list of a given card
185
     * @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink-list-field
186
     *
187
     * @param string $id    the card's id
188
     * @param array  $field the name of the field
189
     *
190
     * @return array board info
191
     *
192
     * @throws InvalidArgumentException if the field does not exist
193
     */
194 2
    public function getListField($id, $field)
195
    {
196 2
        $this->validateAllowedParameters(Cardlist::$fields, $field, 'field');
197
198 1
        return $this->get($this->getPath().'/'.rawurlencode($id).'/list/'.rawurlencode($field));
199
    }
200
201
    /**
202
     * Set a given card's name
203
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-name
204
     *
205
     * @param string $id   the card's id or short link
206
     * @param string $name the name
207
     *
208
     * @return array card info
209
     */
210 1
    public function setName($id, $name)
211
    {
212 1
        return $this->put($this->getPath().'/'.rawurlencode($id).'/name', array('value' => $name));
213
    }
214
215
    /**
216
     * Set a given card's description
217
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-desc
218
     *
219
     * @param string $id          the card's id or short link
220
     * @param string $description the description
221
     *
222
     * @return array card info
223
     */
224 1
    public function setDescription($id, $description)
225
    {
226 1
        return $this->put($this->getPath().'/'.rawurlencode($id).'/desc', array('value' => $description));
227
    }
228
229
    /**
230
     * Set a given card's state
231
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-closed
232
     *
233
     * @param string $id     the card's id or short link
234
     * @param bool   $closed whether the card should be closed or not
235
     *
236
     * @return array card info
237
     */
238 1
    public function setClosed($id, $closed = true)
239
    {
240 1
        return $this->put($this->getPath().'/'.rawurlencode($id).'/closed', array('value' => $closed));
241
    }
242
243
    /**
244
     * Set a given card's due date
245
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-due
246
     *
247
     * @param string    $id   the card's id or short link
248
     * @param \DateTime $date the due date
249
     *
250
     * @return array card info
251
     */
252 1
    public function setDueDate($id, \DateTime $date = null)
253
    {
254 1
        return $this->put($this->getPath().'/'.rawurlencode($id).'/due', array('value' => $date));
255
    }
256
257
    /**
258
     * Set a given card's position
259
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-pos
260
     *
261
     * @param string         $id       the card's id or short link
262
     * @param string|integer $position the position, eg. 'top', 'bottom'
263
     *                                 or a positive number
264
     *
265
     * @return array card info
266
     */
267 1
    public function setPosition($id, $position)
268
    {
269 1
        return $this->put($this->getPath().'/'.rawurlencode($id).'/pos', array('value' => $position));
270
    }
271
272
    /**
273
     * Set a given card's subscription state
274
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-subscribed
275
     *
276
     * @param string $id         the list's id
277
     * @param bool   $subscribed subscription state
278
     *
279
     * @return array list info
280
     */
281 1
    public function setSubscribed($id, $subscribed)
282
    {
283 1
        return $this->put($this->getPath().'/'.rawurlencode($id).'/subscribed', array('value' => $subscribed));
284
    }
285
286
    /**
287
     * Actions API
288
     *
289
     * @return Card\Actions
290
     */
291 1
    public function actions()
292
    {
293 1
        return new Card\Actions($this->client);
294
    }
295
296
    /**
297
     * Attachments API
298
     *
299
     * @return Card\Attachments
300
     */
301 1
    public function attachments()
302
    {
303 1
        return new Card\Attachments($this->client);
304
    }
305
306
    /**
307
     * Checklists API
308
     *
309
     * @return Card\Checklists
310
     */
311 1
    public function checklists()
312
    {
313 1
        return new Card\Checklists($this->client);
314
    }
315
316
    /**
317
     * Labels API
318
     *
319
     * @return Card\Labels
320
     */
321 1
    public function labels()
322
    {
323 1
        return new Card\Labels($this->client);
324
    }
325
326
    /**
327
     * Members API
328
     *
329
     * @return Card\Members
330
     */
331 1
    public function members()
332
    {
333 1
        return new Card\Members($this->client);
334
    }
335
336
    /**
337
     * Stickers API
338
     *
339
     * @return Card\Stickers
340
     */
341 1
    public function stickers()
342
    {
343 1
        return new Card\Stickers($this->client);
344
    }
345
}
346