Passed
Push — master ( 0676a7...01ab94 )
by Artem
11:54
created

OAuthClientRepository   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 29
dl 0
loc 71
c 0
b 0
f 0
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseUri() 0 3 1
A setClientThumbnail() 0 7 1
A createClient() 0 7 1
A getClientThumbnail() 0 5 1
A resetClientSecret() 0 7 1
A jsonToEntity() 0 3 1
A deleteClient() 0 3 1
A updateClient() 0 7 1
A getSupportedFields() 0 10 1
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\Account\Repository;
13
14
use Linode\Account\OAuthClient;
15
use Linode\Account\OAuthClientRepositoryInterface;
16
use Linode\Entity;
17
use Linode\Internal\AbstractRepository;
18
19
/**
20
 * @codeCoverageIgnore This class was autogenerated.
21
 */
22
class OAuthClientRepository extends AbstractRepository implements OAuthClientRepositoryInterface
23
{
24
    public function createClient(array $parameters = []): OAuthClient
25
    {
26
        $response = $this->client->post($this->getBaseUri(), $parameters);
27
        $contents = $response->getBody()->getContents();
28
        $json     = json_decode($contents, true);
29
30
        return new OAuthClient($this->client, $json);
31
    }
32
33
    public function updateClient(string $clientId, array $parameters = []): OAuthClient
34
    {
35
        $response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $clientId), $parameters);
36
        $contents = $response->getBody()->getContents();
37
        $json     = json_decode($contents, true);
38
39
        return new OAuthClient($this->client, $json);
40
    }
41
42
    public function deleteClient(string $clientId): void
43
    {
44
        $this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $clientId));
45
    }
46
47
    public function resetClientSecret(string $clientId): OAuthClient
48
    {
49
        $response = $this->client->post(sprintf('%s/%s/reset-secret', $this->getBaseUri(), $clientId));
50
        $contents = $response->getBody()->getContents();
51
        $json     = json_decode($contents, true);
52
53
        return new OAuthClient($this->client, $json);
54
    }
55
56
    public function getClientThumbnail(string $clientId): string
57
    {
58
        $response = $this->client->get(sprintf('%s/%s/thumbnail', $this->getBaseUri(), $clientId));
59
60
        return $response->getBody()->getContents();
61
    }
62
63
    public function setClientThumbnail(string $clientId, string $file): void
64
    {
65
        $options = [
66
            'body' => fopen($file, 'r'),
67
        ];
68
69
        $this->client->put(sprintf('%s/%s/thumbnail', $this->getBaseUri(), $clientId), [], $options);
70
    }
71
72
    protected function getBaseUri(): string
73
    {
74
        return '/account/oauth-clients';
75
    }
76
77
    protected function getSupportedFields(): array
78
    {
79
        return [
80
            OAuthClient::FIELD_ID,
81
            OAuthClient::FIELD_LABEL,
82
            OAuthClient::FIELD_STATUS,
83
            OAuthClient::FIELD_PUBLIC,
84
            OAuthClient::FIELD_REDIRECT_URI,
85
            OAuthClient::FIELD_SECRET,
86
            OAuthClient::FIELD_THUMBNAIL_URL,
87
        ];
88
    }
89
90
    protected function jsonToEntity(array $json): Entity
91
    {
92
        return new OAuthClient($this->client, $json);
93
    }
94
}
95