Passed
Push — master ( 7fc19c...13cdec )
by Toby
04:11 queued 10s
created

UserGroupMembershipRequest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
/**
3
 * UserGroup Membership Request class
4
 */
5
namespace Twigger\UnionCloud\API\Request;
6
7
8
use Carbon\Carbon;
9
use Twigger\UnionCloud\API\Auth\Authentication;
10
use Twigger\UnionCloud\API\Configuration;
11
use Twigger\UnionCloud\API\Response\UserGroupMembershipResponse;
12
13
/**
14
 * Class UserRequest
15
 *
16
 * @package Twigger\UnionCloud\API\UserGroups\UserGroupMemberships
17
 *
18
 * @license    https://opensource.org/licenses/GPL-3.0  GNU Public License v3
19
 *
20
 * @author     Toby Twigger <[email protected]>
21
 *
22
 */
23
class UserGroupMembershipRequest extends BaseRequest implements IRequest
24
{
25
    /**
26
     * UserGroup Membership Request constructor.
27
     *
28
     * @param Authentication $authentication
29
     * @param Configuration $configuration
30
     */
31
    public function __construct($authentication, $configuration)
32
    {
33
        parent::__construct($authentication, $configuration, UserGroupMembershipResponse::class);
34
    }
35
36
37
    /**
38
     * Gets the current instance
39
     *
40
     * @return UserRequest
41
     *
42
     */
43
    public function getInstance()
44
    {
45
        return $this;
46
    }
47
48
49
50
51
52
    /*
53
   |--------------------------------------------------------------------------
54
   | API Endpoint Definitions
55
   |--------------------------------------------------------------------------
56
   |
57
   | Define your API endpoints below here
58
   |
59
   */
60
61
    /**
62
     * Get all UserGroup Memberships for a specific UserGroup
63
     *
64
     * @param integer $ugID ID of the UserGroup to get UGMs from
65
     * @param Carbon $from Get all that exist beyond this time
66
     * @param Carbon $to Get all that exist before this time
67
     *
68
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
69
     *
70
     * @throws \GuzzleHttp\Exception\GuzzleException
71
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
72
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
73
     */
74
    public function getByUserGroup($ugID, $from, $to)
75
    {
76
        $this->setAPIParameters(
77
            'user_groups/'.$ugID.'/user_group_memberships',
78
            'GET'
79
        );
80
81
        $this->addQueryParameter('from', $from->format('d-m-Y'));
82
        $this->addQueryParameter('to', $to->format('d-m-Y'));
83
84
        $this->enableMode();
85
        $this->enablePagination();
86
87
        $this->call();
88
89
        return $this->getReturnDetails();
90
    }
91
92
    /**
93
     * Create a new UserGroup Membership
94
     *
95
     * @param int $uid UID of the User
96
     * @param int $ugID UserGroup ID
97
     * @param Carbon $expiry Expiry Date of the UGM
98
     *
99
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
100
     *
101
     * @throws \GuzzleHttp\Exception\GuzzleException
102
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
103
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
104
     */
105
    public function create($uid, $ugID, $expiry)
106
    {
107
        $this->setAPIParameters(
108
            'user_group_memberships',
109
            'POST',
110
            [
111
                'uid' => $uid,
112
                'ug_id' => $ugID,
113
                'expire_date' => $expiry->format('d-m-Y')
114
            ]
115
        );
116
117
        $this->call();
118
119
        return $this->getReturnDetails();
120
    }
121
122
    /**
123
     * Create multiple new UserGroup Memberships
124
     *
125
     * @param mixed[] $ugms array of arrays, containing the keys uid, ug_id and expire_date
126
     *
127
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
128
     *
129
     * @throws \GuzzleHttp\Exception\GuzzleException
130
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
131
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
132
     */
133
    public function createMultiple($ugms)
134
    {
135
        $this->setAPIParameters(
136
            'user_group_memberships/upload',
137
            'POST',
138
            $ugms
139
        );
140
141
        $this->call();
142
143
        return $this->getReturnDetails();
144
    }
145
146
    /**
147
     * Update a UserGroup Membership
148
     *
149
     * @param int $ugmID UserGroup Membership ID
150
     * @param Carbon $expiry Expiry Date of the UGM
151
     *
152
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
153
     *
154
     * @throws \GuzzleHttp\Exception\GuzzleException
155
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
156
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
157
     */
158
    public function update($ugmID, $expiry)
159
    {
160
        $this->setAPIParameters(
161
            'user_group_memberships/'.$ugmID,
162
            'PUT',
163
            [
164
                'expire_date' => $expiry->format('d-m-Y')
165
            ]
166
        );
167
168
        $this->call();
169
170
        return $this->getReturnDetails();
171
    }
172
173
174
    /**
175
     * Delete a UserGroup Membership
176
     *
177
     * @param int $ugmID UserGroup Membership ID
178
     *
179
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
180
     *
181
     * @throws \GuzzleHttp\Exception\GuzzleException
182
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
183
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
184
     */
185
    public function delete($ugmID)
186
    {
187
        $this->setAPIParameters(
188
            'user_group_memberships/'.$ugmID,
189
            'DELETE'
190
        );
191
192
        $this->call();
193
194
        return $this->getReturnDetails();
195
    }
196
197
    /**
198
     * Delete multiple UserGroup Memberships
199
     *
200
     * @param mixed[] $ugms Array of UserGroup Membership IDs
201
     *
202
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
203
     *
204
     * @throws \GuzzleHttp\Exception\GuzzleException
205
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
206
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
207
     */
208
    public function deleteMultiple($ugms)
209
    {
210
        $userGroupMemberships = [];
211
        foreach($ugms as $ugm)
212
        {
213
            $userGroupMemberships[] = ['ugm_id' => $ugm];
214
        }
215
216
        $this->setAPIParameters(
217
            'user_group_memberships/upload',
218
            'POST',
219
            $userGroupMemberships
220
        );
221
222
        $this->call();
223
224
        return $this->getReturnDetails();
225
    }
226
227
    /**
228
     * Get all UserGroup Memberships belonging to a User
229
     *
230
     * @param int $uid User ID
231
     *
232
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
233
     *
234
     * @throws \GuzzleHttp\Exception\GuzzleException
235
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
236
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
237
     */
238
    public function getByUser($uid)
239
    {
240
        $this->setAPIParameters(
241
            'users/'.$uid.'/user_group_memberships',
242
            'GET'
243
        );
244
245
        $this->enableMode();
246
        $this->enablePagination();
247
        $this->enableTimes();
248
249
        $this->call();
250
251
        return $this->getReturnDetails();
252
    }
253
254
}