1
|
|
|
<?php |
2
|
|
|
namespace Datatrics\API\Modules; |
3
|
|
|
|
4
|
|
|
use Datatrics\API\Client; |
5
|
|
|
|
6
|
|
|
class Bucket extends Base |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Private constructor so only the client can create this |
10
|
|
|
* @param Client $client |
11
|
|
|
*/ |
12
|
11 |
|
public function __construct(Client $client) |
13
|
|
|
{ |
14
|
11 |
|
parent::__construct($client); |
15
|
11 |
|
$this->SetUrl("/project/" . $this->GetClient()->GetProjectId() . "/bucket"); |
16
|
11 |
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Get one or multiple buckets |
20
|
|
|
* @param string bucket id, leave null for list of buckets |
21
|
|
|
* @param object Containing query arguments |
22
|
|
|
* @return object Result of the request |
23
|
|
|
*/ |
24
|
|
|
public function Get($bucketId = null, $args = array("limit" => 50)) |
25
|
|
|
{ |
26
|
|
|
if (is_null($bucketId)) { |
27
|
|
|
return $this->GetClient()->Get($this->GetUrl(), $args); |
28
|
|
|
} |
29
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$bucketId, $args); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get one or multiple buckets |
34
|
|
|
* @param string bucket id |
35
|
|
|
* @param string object id, leave null for list of objects |
36
|
|
|
* @param object Containing query arguments |
37
|
|
|
* @return object Result of the request |
38
|
|
|
*/ |
39
|
|
|
public function GetObject($bucketId, $objectId, $args = array("limit" => 50)) |
40
|
|
|
{ |
41
|
|
|
if (is_null($objectId)) { |
42
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$bucketId."/object", $args); |
43
|
|
|
} |
44
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$bucketId."/object/".$objectId, $args); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Create new bucket |
49
|
|
|
* @param object Containing all the information of a bucket |
50
|
|
|
* @return object Result of the request |
51
|
|
|
*/ |
52
|
|
|
public function Create($bucket) |
53
|
|
|
{ |
54
|
|
|
return $this->request(self::HTTP_POST, "", $bucket); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Create new bucket |
59
|
|
|
* @param string bucket id |
60
|
|
|
* @param object Containing all the information of a bucket |
61
|
|
|
* @return object Result of the request |
62
|
|
|
*/ |
63
|
|
|
public function CreateObject($bucketId, $object) |
64
|
|
|
{ |
65
|
|
|
return $this->GetClient()->Post($this->GetUrl()."/".$bucketId."/object", $object); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Delete a bucket object by bucket id |
70
|
|
|
* @param string Id of the bucket |
71
|
|
|
* @return object Result of the request |
72
|
|
|
*/ |
73
|
|
|
public function Delete($bucketId) |
74
|
|
|
{ |
75
|
|
|
return $this->GetClient()->Delete($this->GetUrl()."/".$bucketId); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* List fields of a bucket |
80
|
|
|
* @param string Id of the bucket |
81
|
|
|
* @return object Result of the request |
82
|
|
|
*/ |
83
|
|
|
public function Fields($bucketId) |
84
|
|
|
{ |
85
|
|
|
return $this->GetClient()->Get($this->GetUrl()."/".$bucketId."/fields"); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Updates a maximum of 50 object at a time |
90
|
|
|
* @param array Containing objects with a maximum of 50 |
91
|
|
|
* @throws \Exception When more that 50 objects are provided |
92
|
|
|
* @return object Result of the request |
93
|
|
|
*/ |
94
|
|
|
public function Bulk($bucketId, $items) |
95
|
|
|
{ |
96
|
|
|
if (count($items) > 50) { |
97
|
|
|
throw new \Exception("Maximum of 50 content items allowed at a time"); |
98
|
|
|
} |
99
|
|
|
return $this->GetClient()->Post($this->GetUrl()."/".$bucketId."/object/bulk", ['items' => $items]); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|