Completed
Pull Request — master (#68)
by
unknown
08:11
created

Label::getBoardField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Trello\Api;
4
5
use Trello\Exception\InvalidArgumentException;
6
7
class Label extends AbstractApi
8
{
9
    /**
10
     * Base path of labels api
11
     * @var string
12
     */
13
    protected $path = 'labels';
14
15
16
    public static $fields = array(
17
        'idBoard',
18
        'name',
19
        'color',
20
    );
21
22
    /**
23
     * Find a label by id
24
     * @link https://developers.trello.com/reference/#id
25
     *
26
     * @param string $id     the label's id
27
     * @param array  $params optional attributes
28
     *
29
     * @return array label info
30
     */
31
    public function show($id, array $params = array())
32
    {
33
        return $this->get($this->getPath().'/'.rawurlencode($id), $params);
34
    }
35
36
    /**
37
     * Create a label
38
     * @link https://developers.trello.com/reference/#id-1
39
     *
40
     * @param array  $params optional attributes
41
     *
42
     * @return array label info
43
     */
44
    public function create(array $params = array())
45
    {
46
        $this->validateRequiredParameters(array('name', 'idBoard', 'color'), $params);
47
48
        return $this->post('boards/'.rawurlencode($params['idBoard']).'/labels/', $params);
49
    }
50
51
    /**
52
     * Update a label
53
     * @link https://developers.trello.com/reference/#id-1
54
     *
55
     * @param string $id     the label's id
56
     * @param array  $params label attributes to update
57
     *
58
     * @return array label info
59
     */
60
    public function update($id, array $params = array())
61
    {
62
        return $this->put($this->getPath().'/'.rawurlencode($id).'/labels/', $params);
63
    }
64
65
    /**
66
     * Set a given label's board
67
     * @link https://developers.trello.com/reference/#id-1
68
     *
69
     * @param string $id      the label's id
70
     * @param string $boardId the board's id
71
     *
72
     * @return array board info
73
     */
74
    public function setBoard($id, $boardId)
75
    {
76
        return $this->put($this->getPath().'/'.rawurlencode($id).'/idBoard', array('value' => $boardId));
77
    }
78
79
    /**
80
     * Get a given label's board
81
     * @link https://developers.trello.com/reference/#id
82
     *
83
     * @param string $id     the label's id
84
     * @param array  $params optional parameters
85
     *
86
     * @return array board info
87
     */
88
    public function getBoard($id, array $params = array())
89
    {
90
        return $this->get($this->getPath().'/'.rawurlencode($id).'/board', $params);
91
    }
92
93
    /**
94
     * Get the field of a board of a given label
95
     * @link https://developers.trello.com/reference/#id
96
     *
97
     * @param string $id    the label's id
98
     * @param array  $field the name of the field
99
     *
100
     * @return array
101
     *
102
     * @throws InvalidArgumentException if the field does not exist
103
     */
104
    public function getBoardField($id, $field)
105
    {
106
        $this->validateAllowedParameters(Board::$fields, $field, 'field');
107
108
        return $this->get($this->getPath().'/'.rawurlencode($id).'/board/'.rawurlencode($field));
109
    }
110
}
111