1
|
|
|
<?php |
2
|
|
|
namespace Datatrics\API\Modules; |
3
|
|
|
|
4
|
|
|
use Datatrics\API\Client; |
5
|
|
|
|
6
|
|
|
class User extends Base |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Private constructor so only the client can create this |
10
|
|
|
* @param Client $client |
11
|
|
|
*/ |
12
|
20 |
|
public function __construct(Client $client) |
13
|
|
|
{ |
14
|
20 |
|
parent::__construct($client); |
15
|
20 |
|
$this->SetUrl("/project/" . $this->GetClient()->GetProjectId() . "/user"); |
16
|
20 |
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Get one or multiple users |
20
|
|
|
* @param string user id, leave null for list of boxes |
21
|
|
|
* @param object Containing query arguments |
22
|
|
|
* @return object Result of the request |
23
|
|
|
*/ |
24
|
|
|
public function Get($userId = null, $args = array("limit" => 50)) |
25
|
|
|
{ |
26
|
|
|
if (is_null($userId)) { |
27
|
|
|
return $this->GetClient()->Get($this->GetUrl(), $args); |
28
|
|
|
} |
29
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$userId, $args); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Create new user |
34
|
|
|
* @param object Containing all the information of a user |
35
|
|
|
* @return object Result of the request |
36
|
|
|
*/ |
37
|
|
|
public function Create($user) |
38
|
|
|
{ |
39
|
|
|
return $this->GetClient()->Post($this->GetUrl(), $user); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Update a user |
44
|
|
|
* @param id of the user |
45
|
|
|
* @param object Containing all the information of a user |
46
|
|
|
* @return object Result of the request |
47
|
|
|
*/ |
48
|
|
|
public function Update($user) |
49
|
|
|
{ |
50
|
|
|
if (!isset($user['userid'])) { |
51
|
|
|
throw new \Exception('user must contain userid'); |
52
|
|
|
} |
53
|
|
|
return $this->GetClient()->Put($this->GetUrl()."/".$user['userid'], $user); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Delete a user object by user id |
58
|
|
|
* @param string Id of the user |
59
|
|
|
* @return object Result of the request |
60
|
|
|
*/ |
61
|
|
|
public function Delete($userId) |
62
|
|
|
{ |
63
|
|
|
return $this->GetClient()->Delete($this->GetUrl()."/".$userId); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Delete a user object by user id |
68
|
|
|
* @param string Id of the user |
69
|
|
|
* @return object Result of the request |
70
|
|
|
*/ |
71
|
|
|
public function Token($username, $password) |
72
|
|
|
{ |
73
|
|
|
$args = [ |
74
|
|
|
'username' => $username, |
75
|
|
|
'password' => $password |
76
|
|
|
]; |
77
|
|
|
return $this->GetClient()->Post($this->GetUrl()."/getToken", $args); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Delete a user object by user id |
82
|
|
|
* @param string Id of the user |
83
|
|
|
* @return object Result of the request |
84
|
|
|
*/ |
85
|
|
|
public function ApiKey($username, $password) |
86
|
|
|
{ |
87
|
|
|
$args = [ |
88
|
|
|
'username' => $username, |
89
|
|
|
'password' => $password |
90
|
|
|
]; |
91
|
|
|
return $this->GetClient()->Post($this->GetUrl()."/getApiKey", $args); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|