Completed
Push — master ( 7f6918...fb7822 )
by Matthew
02:21
created

Group::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Matt
5
 * Date: 20/04/2016
6
 * Time: 2:32 PM
7
 */
8
9
namespace Freshdesk\Resources;
10
11
use Freshdesk\Api;
12
use Freshdesk\Exceptions\AccessDeniedException;
13
use Freshdesk\Exceptions\ApiException;
14
use Freshdesk\Exceptions\ConflictingStateException;
15
use Freshdesk\Exceptions\MethodNotAllowedException;
16
use Freshdesk\Exceptions\NotFoundException;
17
use Freshdesk\Exceptions\RateLimitExceededException;
18
use Freshdesk\Exceptions\UnsupportedAcceptHeaderException;
19
use Freshdesk\Exceptions\UnsupportedContentTypeException;
20
use Freshdesk\Exceptions\ValidationException;
21
22
/**
23
 * Class GroupApi
24
 * @internal
25
 * @package Freshdesk
26
 */
27
class Group extends AbstractResource
28
{
29
30
    /**
31
     * The api endpoint
32
     *
33
     * @var string
34
     */
35
    protected $endpoint = '/groups';
36
37
    /**
38
     *
39
     * Create a group
40
     *
41
     * @param array|null $data
42
     * @return mixed|null
43
     * @throws ApiException
44
     * @throws ConflictingStateException
45
     * @throws RateLimitExceededException
46
     * @throws UnsupportedContentTypeException
47
     */
48
    public function create(array $data)
49
    {
50
        $this->api->request('POST', $this->endpoint(), $data);
51
    }
52
53
    /**
54
     *
55
     * Get a list of all groups
56
     *
57
     * @param array|null $query
58
     * @return mixed|null
59
     * @throws ApiException
60
     * @throws ConflictingStateException
61
     * @throws RateLimitExceededException
62
     * @throws UnsupportedContentTypeException
63
     */
64
    public function all(array $query = null)
65
    {
66
        $this->api->request('GET', $this->endpoint(), null, $query);
67
    }
68
69
    /**
70
     *
71
     * Get a group by id
72
     *
73
     * @param int $id
74
     * @param array|null $query
75
     * @return array|null
76
     * @throws AccessDeniedException
77
     * @throws ApiException
78
     * @throws ConflictingStateException
79
     * @throws MethodNotAllowedException
80
     * @throws NotFoundException
81
     * @throws RateLimitExceededException
82
     * @throws UnsupportedAcceptHeaderException
83
     * @throws UnsupportedContentTypeException
84
     * @throws ValidationException
85
     */
86
    public function view($id, array $query = null)
87
    {
88
        $this->api->request('GET', $this->endpoint($id), null, $query);
89
    }
90
91
    /**
92
     * Update a group
93
     *
94
     * @param $id
95
     * @param array|null $data
96
     * @return mixed|null
97
     * @throws ApiException
98
     * @throws ConflictingStateException
99
     * @throws RateLimitExceededException
100
     * @throws UnsupportedContentTypeException
101
     */
102
    public function update($id, array $data = null)
103
    {
104
        $this->api->request('PUT', $this->endpoint($id), $data);
105
    }
106
107
    /**
108
     * Delete a group
109
     *
110
     * @param $id
111
     * @return mixed|null
112
     * @throws ApiException
113
     * @throws ConflictingStateException
114
     * @throws RateLimitExceededException
115
     * @throws UnsupportedContentTypeException
116
     */
117
    public function delete($id)
118
    {
119
        $this->api->request('DELETE', $this->endpoint($id));
120
    }
121
}