Passed
Branch api-functionality (902732)
by Toby
04:47
created

UserGroupRequest::getByID()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * User Groups Request class
4
 */
5
namespace Twigger\UnionCloud\API\Request;
6
7
8
use Twigger\UnionCloud\API\Auth\Authentication;
9
use Twigger\UnionCloud\API\Configuration;
10
use Twigger\UnionCloud\API\Response\UserGroupResponse;
11
12
/**
13
 * Class User Groups Request
14
 *
15
 * @package Twigger\UnionCloud\API\UserGroups\UserGroups
16
 *
17
 * @license    https://opensource.org/licenses/GPL-3.0  GNU Public License v3
18
 *
19
 * @author     Toby Twigger <[email protected]>
20
 *
21
 */
22
class UserGroupRequest extends BaseRequest implements IRequest
23
{
24
    /**
25
     * User Groups Request constructor.
26
     *
27
     * @param Authentication $authentication
28
     * @param Configuration $configuration
29
     */
30
    public function __construct($authentication, $configuration)
31
    {
32
        parent::__construct($authentication, $configuration, UserGroupResponse::class);
33
    }
34
35
36
    /**
37
     * Gets the current instance
38
     *
39
     * @return $this
40
     *
41
     */
42
    public function getInstance()
43
    {
44
        return $this;
45
    }
46
47
48
49
    /*
50
    |--------------------------------------------------------------------------
51
    | API Endpoint Definitions
52
    |--------------------------------------------------------------------------
53
    |
54
    | Define your API endpoints below here
55
    |
56
    */
57
58
    /**
59
     * Create a new UserGroup
60
     * 
61
     * @param string $ugName UserGroup Name
62
     * @param string $ugDescription UserGroup Description
63
     * @param integer $folderID ID of the folder to contain the UserGroup
64
     * 
65
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
66
     * 
67
     * @throws \GuzzleHttp\Exception\GuzzleException
68
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
69
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
70
     */
71
    public function create($ugName, $ugDescription, $folderID)
72
    {
73
        $this->setAPIParameters(
74
            'user_groups',
75
            'POST',
76
            [
77
                'ug_name' => $ugName,
78
                'ug_description' => $ugDescription,
79
                'folder_id' => $folderID
80
            ]
81
        );
82
        
83
        $this->call();
84
        
85
        return $this->getReturnDetails();
86
    }
87
88
    /**
89
     * Update a new UserGroup
90
     *
91
     * @param integer $ugID ID of the UserGroup
92
     * @param string $ugName UserGroup Name
93
     * @param string $ugDescription UserGroup Description
94
     * @param integer $folderID ID of the folder to contain the UserGroup
95
     *
96
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
97
     *
98
     * @throws \GuzzleHttp\Exception\GuzzleException
99
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
100
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
101
     */
102
    public function update($ugID, $ugName, $ugDescription, $folderID)
103
    {
104
        $this->setAPIParameters(
105
            'user_groups/'.$ugID,
106
            'PUT',
107
            [
108
                'ug_name' => $ugName,
109
                'ug_description' => $ugDescription,
110
                'folder_id' => $folderID
111
            ]
112
        );
113
114
        $this->call();
115
116
        return $this->getReturnDetails();
117
    }
118
119
    /**
120
     * Delete a UserGroup
121
     *
122
     * @param integer $ugID ID of the UserGroup to delete
123
     *
124
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
125
     *
126
     * @throws \GuzzleHttp\Exception\GuzzleException
127
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
128
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
129
     */
130
    public function delete($ugID)
131
    {
132
        $this->setAPIParameters(
133
            'user_groups/'.$ugID,
134
            'DELETE',
135
        );
136
137
        $this->call();
138
139
        return $this->getReturnDetails();
140
    }
141
142
    /**
143
     * Search for a UserGroup
144
     *
145
     * @param mixed[] $searchParameters Associative array of search parameters
146
     *
147
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
148
     *
149
     * @throws \GuzzleHttp\Exception\GuzzleException
150
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
151
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
152
     */
153
    public function search($searchParameters)
154
    {
155
        $this->setAPIParameters(
156
            'user_groups/search',
157
            'POST',
158
            $searchParameters
159
        );
160
161
        $this->enableMode();
162
        $this->enablePagination();
163
164
        $this->call();
165
166
        return $this->getReturnDetails();
167
    }
168
169
    /**
170
     * Get all UserGroups in the Union
171
     *
172
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
173
     *
174
     * @throws \GuzzleHttp\Exception\GuzzleException
175
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
176
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
177
     */
178
    public function getAll()
179
    {
180
        $this->setAPIParameters(
181
            'user_groups',
182
            'GET'
183
        );
184
185
        $this->enableMode();
186
        $this->enablePagination();
187
        $this->enableTimes();
188
189
        $this->call();
190
191
        return $this->getReturnDetails();
192
    }
193
194
    /**
195
     * Get a specific UserGroup
196
     *
197
     * @param integer $ugID ID of the UserGroup
198
     *
199
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
200
     *
201
     * @throws \GuzzleHttp\Exception\GuzzleException
202
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
203
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
204
     */
205
    public function getByID($ugID)
206
    {
207
        $this->setAPIParameters(
208
            'user_groups/'.$ugID,
209
            'GET'
210
        );
211
212
        $this->enableMode();
213
214
        $this->call();
215
216
        return $this->getReturnDetails();
217
    }
218
219
}