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