1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NStack\Clients; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class CollectionsClient |
7
|
|
|
* |
8
|
|
|
* @package NStack\Clients |
9
|
|
|
* @author Tiago Araujo <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
class CollectionsClient extends NStackClient |
12
|
|
|
{ |
13
|
|
|
/** @var string */ |
14
|
|
|
protected $path = 'content/collections'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* view |
18
|
|
|
* |
19
|
|
|
* @param int $collectionId |
20
|
|
|
* @return array |
21
|
|
|
*/ |
22
|
1 |
|
public function view(int $collectionId): array |
23
|
|
|
{ |
24
|
1 |
|
$response = $this->client->get($this->buildPath($this->path . '/' . $collectionId)); |
25
|
1 |
|
$contents = $response->getBody()->getContents(); |
26
|
|
|
|
27
|
1 |
|
return json_decode($contents, true)['data']; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* createItem |
32
|
|
|
* |
33
|
|
|
* @param int $collectionId |
34
|
|
|
* @param array $params |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
1 |
|
public function createItem(int $collectionId, array $params): array |
38
|
|
|
{ |
39
|
1 |
|
$response = $this->client->post($this->buildPath($this->path . '/' . $collectionId . '/items'), [ |
40
|
1 |
|
'form_params' => $params, |
41
|
|
|
]); |
42
|
1 |
|
$contents = $response->getBody()->getContents(); |
43
|
|
|
|
44
|
1 |
|
return json_decode($contents, true)['data']; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* deleteItem |
49
|
|
|
* |
50
|
|
|
* @param int $collectionId |
51
|
|
|
* @param int $itemId |
52
|
|
|
*/ |
53
|
|
|
public function deleteItem(int $collectionId, int $itemId) |
54
|
|
|
{ |
55
|
|
|
$this->client->delete($this->buildPath($this->path . '/' . $collectionId . '/items/' . $itemId)); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* updateItem |
60
|
|
|
* |
61
|
|
|
* @param int $collectionId |
62
|
|
|
* @param int $itemId |
63
|
|
|
* @param array $params |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
1 |
|
public function updateItem(int $collectionId, int $itemId, array $params): array |
67
|
|
|
{ |
68
|
1 |
|
$response = $this->client->post($this->buildPath($this->path . '/' . $collectionId . '/items/' . $itemId . |
69
|
1 |
|
'/update'), [ |
70
|
1 |
|
'form_params' => $params, |
71
|
|
|
]); |
72
|
1 |
|
$contents = $response->getBody()->getContents(); |
73
|
|
|
|
74
|
1 |
|
return json_decode($contents, true)['data']; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* viewItem |
79
|
|
|
* |
80
|
|
|
* @param int $collectionId |
81
|
|
|
* @param int $itemId |
82
|
|
|
* @return array |
83
|
|
|
*/ |
84
|
1 |
|
public function viewItem(int $collectionId, int $itemId): array |
85
|
|
|
{ |
86
|
1 |
|
$response = $this->client->get($this->buildPath($this->path . '/' . $collectionId . '/items/' . $itemId)); |
87
|
1 |
|
$contents = $response->getBody()->getContents(); |
88
|
|
|
|
89
|
1 |
|
return json_decode($contents, true)['data']; |
90
|
|
|
} |
91
|
|
|
} |