Completed
Pull Request — master (#16)
by
unknown
07:40
created

Checklist::show()   A

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 2
crap 1
1
<?php
2
3
namespace Trello\Api;
4
5
use Trello\Exception\InvalidArgumentException;
6
7
/**
8
 * Trello Checkist API
9
 * @link https://trello.com/docs/api/checklist
10
 *
11
 * Fully implemented.
12
 */
13
class Checklist extends AbstractApi
14
{
15
    /**
16
     * Base path of checklists api
17
     * @var string
18
     */
19
    protected $path = 'checklists';
20
21
    /**
22
     * Card fields
23
     * @link https://trello.com/docs/api/list/#get-1-lists-list-id-or-shortlink-field
24
     * @var array
25
     */
26
    public static $fields = array(
27
        'name',
28
        'idBoard',
29
        'idCard',
30
        'pos',
31
    );
32
33
    /**
34
     * Find a list by id
35
     * @link https://trello.com/docs/api/checklist/#get-1-checklists-idchecklist
36
     *
37
     * @param string $id     the checklist's id
38
     * @param array  $params optional attributes
39
     *
40
     * @return array list info
41
     */
42 1
    public function show($id, array $params = array())
43
    {
44 1
        return $this->get($this->getPath().'/'.rawurlencode($id), $params);
45
    }
46
47
    /**
48
     * Create a checklist
49
     * @link https://trello.com/docs/api/checklist/#post-1-checklists
50
     *
51
     * @param array $params optional attributes: 'name', 'idBoard', 'idCard', 'pos', 'idChecklistSource'
52
     *
53
     * @return array
54
     */
55 3
    public function create(array $params = array())
56
    {
57 3
        $this->validateRequiredParameters(array('name', 'idCard'), $params);
58
59 1
        return $this->post($this->getPath(), $params);
60
    }
61
62
    /**
63
     * Update a checklist
64
     * @link https://trello.com/docs/api/checklist/#put-1-checklists-idchecklist
65
     *
66
     * @param string $id     the list's id
67
     * @param array  $params list attributes to update
68
     *
69
     * @return array list info
70
     */
71 1
    public function update($id, array $params = array())
72
    {
73 1
        return $this->put($this->getPath().'/'.rawurlencode($id), $params);
74
    }
75
76
    /**
77
     * Remove a checklist
78
     * @link https://trello.com/docs/api/checklist/#delete-1-checklists-idchecklist
79
     *
80
     * @param string $id the checklist's id
81
     *
82
     * @return array
83
     */
84 1
    public function remove($id)
85
    {
86 1
        return $this->delete($this->getPath().'/'.rawurlencode($id));
87
    }
88
89
    /**
90
     * Remove a listitem from a checklist
91
     * @link https://trello.com/docs/api/checklist/index.html#delete-1-checklists-idchecklist-checkitems-idcheckitem
92
     *
93
     * @param string $checkListId the checklist's id
94
     * @param string $listItemId the listItem id
95
     *
96
     * @return array
97
     */
98 1
    public function removeListItem($checkListId, $listItemId)
99
    {
100 1
        return $this->delete($this->getPath().'/'.rawurlencode($checkListId).'/checkItems/'.rawurlencode($listItemId));
101
    }
102
    
103
    /**
104
     * Get the board of a given checklist
105
     * @link https://trello.com/docs/api/checklist/#get-1-checklists-idchecklist-board
106
     *
107
     * @param string $id     the checklist's id
108
     * @param array  $params optional parameters
109
     *
110
     * @return array board info
111
     */
112
    public function getBoard($id, array $params = array())
113
    {
114 2
        return $this->get($this->getPath().'/'.rawurlencode($id).'/board', $params);
115
    }
116 2
117
    /**
118 1
     * Get the field of a board of a given checklist
119
     * @link https://trello.com/docs/api/checklist/#get-1-checklists-idchecklist-board-field
120
     *
121
     * @param string $id    the checklist's id
122
     * @param array  $field the name of the field
123
     *
124
     * @return array board info
125
     *
126
     * @throws InvalidArgumentException if the field does not exist
127
     */
128
    public function getBoardField($id, $field)
129
    {
130 1
        $this->validateAllowedParameters(Board::$fields, $field, 'field');
131
132 1
        return $this->get($this->getPath().'/'.rawurlencode($id).'/board/'.rawurlencode($field));
133
    }
134
135
    /**
136
     * Set a given checklist's card
137
     * @link https://trello.com/docs/api/checklist/#put-1-checklists-idchecklist-idcard
138
     *
139
     * @param string $id     the list's id
140
     * @param string $cardId the card's id
141
     *
142
     * @return array
143
     */
144 1
    public function setCard($id, $cardId)
145
    {
146 1
        return $this->put($this->getPath().'/'.rawurlencode($id).'/idCard', array('value' => $cardId));
147
    }
148
149
    /**
150
     * Set a given checklist's name
151
     * @link https://trello.com/docs/api/checklist/#put-1-checklists-idchecklist-name
152
     *
153
     * @param string $id   the checklist's id
154
     * @param string $name the name
155
     *
156
     * @return array
157
     */
158
    public function setName($id, $name)
159 1
    {
160
        return $this->put($this->getPath().'/'.rawurlencode($id).'/name', array('value' => $name));
161 1
    }
162
163
    /**
164
     * Set a given checklist's position
165
     * @link https://trello.com/docs/api/checklist/#put-1-checklists-idchecklist-pos
166
     *
167
     * @param string         $id       the list's id
168
     * @param string|integer $position the position, eg. 'top', 'bottom'
169 1
     *                                 or a positive number
170
     *
171 1
     * @return array list info
172
     */
173
    public function setPosition($id, $position)
174
    {
175
        return $this->put($this->getPath().'/'.rawurlencode($id).'/pos', array('value' => $position));
176
    }
177
178
    /**
179 1
     * Cards API
180
     *
181 1
     * @return Checklist\Cards
182
     */
183
    public function cards()
184
    {
185
        return new Checklist\Cards($this->client);
186
    }
187
188
    /**
189
     * Items API
190
     *
191
     * @return Checklist\Items
192
     */
193
    public function items()
194
    {
195
        return new Checklist\Items($this->client);
196
    }
197
}
198