Passed
Push — master ( 01ab94...851c5d )
by Artem
01:46
created

cancelObjectStorage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
// ---------------------------------------------------------------------
4
//
5
//  Copyright (C) 2018-2024 Artem Rodygin
6
//
7
//  You should have received a copy of the MIT License along with
8
//  this file. If not, see <https://opensource.org/licenses/MIT>.
9
//
10
// ---------------------------------------------------------------------
11
12
namespace Linode\ObjectStorage\Repository;
13
14
use Linode\Entity;
15
use Linode\Internal\AbstractRepository;
16
use Linode\ObjectStorage\ObjectStorageBucket;
17
use Linode\ObjectStorage\ObjectStorageBucketRepositoryInterface;
18
use Linode\ObjectStorage\ObjectStorageObject;
19
20
/**
21
 * @codeCoverageIgnore This class was autogenerated.
22
 */
23
class ObjectStorageBucketRepository extends AbstractRepository implements ObjectStorageBucketRepositoryInterface
24
{
25
    public function createObjectStorageBucket(array $parameters = []): ObjectStorageBucket
26
    {
27
        $response = $this->client->post($this->getBaseUri(), $parameters);
28
        $contents = $response->getBody()->getContents();
29
        $json     = json_decode($contents, true);
30
31
        return new ObjectStorageBucket($this->client, $json);
32
    }
33
34
    public function getObjectStorageBucket(string $clusterId, string $bucket): ObjectStorageBucket
35
    {
36
        $response = $this->client->get(sprintf('%s/%s/%s', $this->getBaseUri(), $clusterId, $bucket));
37
        $contents = $response->getBody()->getContents();
38
        $json     = json_decode($contents, true);
39
40
        return new ObjectStorageBucket($this->client, $json);
41
    }
42
43
    public function deleteObjectStorageBucket(string $clusterId, string $bucket): void
44
    {
45
        $this->client->delete(sprintf('%s/%s/%s', $this->getBaseUri(), $clusterId, $bucket));
46
    }
47
48
    public function modifyObjectStorageBucketAccess(string $clusterId, string $bucket, array $parameters = []): void
49
    {
50
        $this->client->post(sprintf('%s/%s/%s/access', $this->getBaseUri(), $clusterId, $bucket), $parameters);
51
    }
52
53
    public function getObjectStorageBucketContent(string $clusterId, string $bucket): array
54
    {
55
        $response = $this->client->get(sprintf('%s/%s/%s/object-list', $this->getBaseUri(), $clusterId, $bucket));
56
        $contents = $response->getBody()->getContents();
57
        $json     = json_decode($contents, true);
58
59
        return array_map(fn ($data) => new ObjectStorageObject($this->client, $data), $json['data']);
60
    }
61
62
    public function createObjectStorageObjectURL(string $clusterId, string $bucket, array $parameters = []): string
63
    {
64
        $response = $this->client->post(sprintf('%s/%s/%s/object-url', $this->getBaseUri(), $clusterId, $bucket), $parameters);
65
        $contents = $response->getBody()->getContents();
66
        $json     = json_decode($contents, true);
67
68
        return $json['url'];
69
    }
70
71
    public function cancelObjectStorage(): void
72
    {
73
        $this->client->post('beta/object-storage/cancel');
74
    }
75
76
    protected function getBaseUri(): string
77
    {
78
        return 'beta/object-storage/buckets';
79
    }
80
81
    protected function getSupportedFields(): array
82
    {
83
        return [
84
            ObjectStorageBucket::FIELD_CREATED,
85
            ObjectStorageBucket::FIELD_CLUSTER,
86
            ObjectStorageBucket::FIELD_LABEL,
87
            ObjectStorageBucket::FIELD_HOSTNAME,
88
        ];
89
    }
90
91
    protected function jsonToEntity(array $json): Entity
92
    {
93
        return new ObjectStorageBucket($this->client, $json);
94
    }
95
}
96