|
1
|
|
|
<?php |
|
2
|
|
|
namespace Datatrics\API\Modules; |
|
3
|
|
|
|
|
4
|
|
|
class Box 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 . "/box"); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Get one or multiple boxes |
|
18
|
|
|
* @param string box id, leave null for list of boxes |
|
19
|
|
|
* @param object Containing query arguments |
|
20
|
|
|
* @return object Result of the request |
|
21
|
|
|
*/ |
|
22
|
|
|
public function Get($boxId = null, $args = array("limit" => 50)) |
|
23
|
|
|
{ |
|
24
|
|
|
return $boxId == null ? $this->request(self::HTTP_GET, "?".http_build_query($args)) : $this->request(self::HTTP_GET, "/".$boxId."?".http_build_query($args)); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Get all box codes |
|
29
|
|
|
* @param string box id |
|
30
|
|
|
* @param object Containing query arguments |
|
31
|
|
|
* @return object Result of the request |
|
32
|
|
|
*/ |
|
33
|
|
|
public function GetCode($boxId, $args = array("limit" => 50)) |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->request(self::HTTP_GET, "/".$boxId."/code?".http_build_query($args)); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Get one or multiple versions of a box |
|
40
|
|
|
* @param string box id |
|
41
|
|
|
* @param string version id, leave null for list of versions |
|
42
|
|
|
* @param object Containing query arguments |
|
43
|
|
|
* @return object Result of the request |
|
44
|
|
|
*/ |
|
45
|
|
|
public function GetVersion($boxId, $versionId = null, $args = array("limit" => 50)) |
|
46
|
|
|
{ |
|
47
|
|
|
return $versionId == null ? $this->request(self::HTTP_GET, "/".$boxId."/version?".http_build_query($args)) : $this->request(self::HTTP_GET, "/".$boxId."/version/".$versionId."?".http_build_query($args)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Create new box |
|
52
|
|
|
* @param object Containing all the information of a box |
|
53
|
|
|
* @return object Result of the request |
|
54
|
|
|
*/ |
|
55
|
|
|
public function Create($box) |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->request(self::HTTP_POST, "", $box); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Create new box |
|
62
|
|
|
* @param object Containing all the information of a box |
|
63
|
|
|
* @return object Result of the request |
|
64
|
|
|
*/ |
|
65
|
|
|
public function CreateVersion($boxId, $version) |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->request(self::HTTP_POST, "/".$boxId."/version", $version); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Delete a box version by version id |
|
72
|
|
|
* @param string Id of the box |
|
73
|
|
|
* @param string Id of the version to be deleted |
|
74
|
|
|
* @return object Result of the request |
|
75
|
|
|
*/ |
|
76
|
|
|
public function Delete($boxId, $versionId) |
|
|
|
|
|
|
77
|
|
|
{ |
|
78
|
|
|
return $this->request(self::HTTP_DELETE, "/".$boxId); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Delete a box version by version id |
|
83
|
|
|
* @param string Id of the box |
|
84
|
|
|
* @param string Id of the version to be deleted |
|
85
|
|
|
* @return object Result of the request |
|
86
|
|
|
*/ |
|
87
|
|
|
public function DeleteVersion($boxId, $versionId) |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->request(self::HTTP_DELETE, "/".$boxId."/version/".$versionId); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Update a box |
|
94
|
|
|
* @param object Box containing the boxid and fields that need to be updated |
|
95
|
|
|
* @throws \Exception When boxid is not present |
|
96
|
|
|
* @return object Result of the request |
|
97
|
|
|
*/ |
|
98
|
|
|
public function Update($box) |
|
99
|
|
|
{ |
|
100
|
|
|
if (!isset($box['boxid'])) { |
|
101
|
|
|
throw new \Exception("box must contain a boxid"); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
return $this->request(self::HTTP_PUT, "/".$box['boxid'], $box); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Update a box |
|
109
|
|
|
* @param string Id of the box |
|
110
|
|
|
* @param object Version containing the version and fields that need to be updated |
|
111
|
|
|
* @throws \Exception When versionid is not present |
|
112
|
|
|
* @return object Result of the request |
|
113
|
|
|
*/ |
|
114
|
|
|
public function UpdateVersion($boxid, $version) |
|
115
|
|
|
{ |
|
116
|
|
|
if (!isset($version['versionid'])) { |
|
117
|
|
|
throw new \Exception("version must contain a versionid"); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return $this->request(self::HTTP_PUT, "/".$boxid."/version/".$version['versionid'], $version); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.