UserRequest::delete()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * UserRequest 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\UserResponse;
11
12
/**
13
 * Class UserRequest
14
 *
15
 * @package Twigger\UnionCloud\API\Users\Users
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 UserRequest extends BaseRequest implements IRequest
23
{
24
    /**
25
     * UserRequest constructor.
26
     *
27
     * @param Authentication $authentication
28
     * @param Configuration $configuration
29
     */
30
    public function __construct($authentication, $configuration)
31
    {
32
        parent::__construct($authentication, $configuration, UserResponse::class);
33
    }
34
35
36
    /**
37
     * Gets the current instance
38
     *
39
     * @return UserRequest
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
     * Search for a user by a variety of parameters
59
     *
60
     * Pass the parameters as [
61
     *      'parameter-name'=>'parameter-value'
62
     * ]
63
     *
64
     * @param array $parameters Parameter to search for a user with
65
     * @param boolean $searchAcrossEmail Should the API search across all email fields?
66
     *
67
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
68
     *
69
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
70
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
71
     * @throws \GuzzleHttp\Exception\GuzzleException
72
     */
73
    public function search($parameters, $searchAcrossEmail = true)
74
    {
75
        // Set the parameters to make the call
76
        $this->setAPIParameters(
77
            'users/search',
78
            'POST',
79
            $parameters
80
        );
81
82
        $this->addQueryParameter('search_across_email', $searchAcrossEmail);
83
84
        $this->enablePagination();
85
        $this->enableMode();
86
87
        $this->call();
88
89
90
        return $this->getReturnDetails();
91
    }
92
93
    /**
94
     * Get a User by their UID
95
     *
96
     * @param $uid
97
     *
98
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
99
     *
100
     * @throws \GuzzleHttp\Exception\GuzzleException
101
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
102
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
103
     */
104
    public function getByUID($uid)
105
    {
106
        $this->setAPIParameters(
107
            'users/'.$uid,
108
            'GET'
109
        );
110
111
        $this->enableMode();
112
113
        $this->call();
114
115
        return $this->getReturnDetails();
116
    }
117
    
118
119
    /**
120
     * Update a user
121
     *
122
     * @param string $uid
123
     * @param array $parameters Associative array of parameters to update
124
     *
125
     * // TODO Calls like this should be made from the response. (i.e. edit the resource and call update() on it)
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 update($uid, $parameters)
134
    {
135
        $this->setAPIParameters(
136
            'users/'.$uid,
137
            'PUT',
138
            $parameters
139
        );
140
141
        $this->call();
142
143
        return $this->getReturnDetails();
144
    }
145
146
    /**
147
     * Delete a user
148
     *
149
     * @param string $uid
150
     *
151
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
152
     *
153
     * @throws \GuzzleHttp\Exception\GuzzleException
154
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
155
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
156
     */
157
    public function delete($uid)
158
    {
159
        $this->setAPIParameters(
160
            'users/'.$uid,
161
            'DELETE'
162
        );
163
164
        $this->call();
165
166
        return $this->getReturnDetails();
167
    }
168
169
    /**
170
     * Upload a Student
171
     * 
172
     * @param array $details Parameters of the new student
173
     * 
174
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
175
     * 
176
     * @throws \GuzzleHttp\Exception\GuzzleException
177
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
178
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
179
     */
180
    public function uploadStudent($details)
181
    {
182
        $this->setAPIParameters(
183
            'json/upload/students',
184
            'POST',
185
            $details
186
        );
187
        
188
        $this->call();
189
        
190
        return $this->getReturnDetails();
191
    }
192
193
    /**
194
     * Upload a Guest
195
     *
196
     * @param array $details Parameters of the new guest
197
     *
198
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
199
     *
200
     * @throws \GuzzleHttp\Exception\GuzzleException
201
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
202
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
203
     */
204
    public function uploadGuest($details)
205
    {
206
        $this->setAPIParameters(
207
            'json/upload/guests',
208
            'POST',
209
            $details
210
        );
211
212
        $this->call();
213
214
        return $this->getReturnDetails();
215
    }
216
217
}