1
|
|
|
<?php |
2
|
|
|
namespace Datatrics\API\Modules; |
3
|
|
|
|
4
|
|
|
class Profile extends Base |
5
|
|
|
{ |
6
|
|
|
/** |
7
|
|
|
* Private constructor so only the client can create this |
8
|
|
|
* @param string $apikey |
9
|
|
|
* @param string $projectid |
10
|
|
|
*/ |
11
|
|
|
public function __construct($apikey, $projectid) |
12
|
|
|
{ |
13
|
|
|
parent::__construct($apikey, "/project/" . $projectid . "/profile"); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Get one or multiple profiles |
18
|
|
|
* @param string profile id, leave null for list of profiles |
19
|
|
|
* @param object Containing query arguments |
20
|
|
|
* @return object Result of the request |
21
|
|
|
*/ |
22
|
|
|
public function Get($profileId = null, $args = array("limit" => 50)) |
23
|
|
|
{ |
24
|
|
|
return $profileId == null ? $this->request(self::HTTP_GET, "?".http_build_query($args)) : $this->request(self::HTTP_GET, "/".$profileId."?".http_build_query($args)); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Create new profile |
29
|
|
|
* @param object Containing all the information of a profile |
30
|
|
|
* @return object Result of the request |
31
|
|
|
*/ |
32
|
|
|
public function Create($profile) |
33
|
|
|
{ |
34
|
|
|
return $this->request(self::HTTP_POST, "", $profile); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Delete a profile by profileid |
39
|
|
|
* @param string Id of the profile to be deleted |
40
|
|
|
* @return object Result of the request |
41
|
|
|
*/ |
42
|
|
|
public function Delete($profileid) |
43
|
|
|
{ |
44
|
|
|
return $this->request(self::HTTP_DELETE, "/".$profileid); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Update a profile |
49
|
|
|
* @param object Profile containing the profileid and fields that need to be updated |
50
|
|
|
* @throws \Exception When profileid is not present |
51
|
|
|
* @return object Result of the request |
52
|
|
|
*/ |
53
|
|
|
public function Update($profile) |
54
|
|
|
{ |
55
|
|
|
if (!isset($profile['profileid'])) { |
56
|
|
|
throw new \Exception("profile must contain a profileid"); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $this->request(self::HTTP_PUT, "/".$profile['profileid'], $profile); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Updates a maximum of 50 profiles at a time. |
64
|
|
|
* @param array Containing profiles with a maximum of 50 |
65
|
|
|
* @throws \Exception When more that 50 profiles are provided |
66
|
|
|
* @return object Result of the request |
67
|
|
|
*/ |
68
|
|
|
public function UpdateBulk($profiles) |
69
|
|
|
{ |
70
|
|
|
if (count($profiles) > 50) { |
71
|
|
|
throw new \Exception("Maximum of 50 profiles allowed at a time"); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $this->request(self::HTTP_POST, "/bulk", ['items' => $profiles]); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|