Passed
Pull Request — master (#507)
by
unknown
02:18
created

Sites::getEnvironments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace AcquiaCloudApi\Endpoints;
4
5
use AcquiaCloudApi\Response\OperationResponse;
6
use AcquiaCloudApi\Response\SiteResponse;
7
use AcquiaCloudApi\Response\SitesResponse;
8
use AcquiaCloudApi\Response\CodebaseEnvironmentsResponse;
9
10
/**
11
 * Class Sites
12
 *
13
 * @package AcquiaCloudApi\CloudApi
14
 */
15
class Sites extends CloudApiBase
16
{
17
    /**
18
     * Retrieves a list of sites accessible by the user.
19
     *
20
     * @return SitesResponse<SiteResponse>
21
     */
22
    public function getAll(): SitesResponse
23
    {
24
        return new SitesResponse($this->client->request('get', '/sites'));
25
    }
26
27
    /**
28
     * Retrieves a site details by its ID.
29
     */
30
    public function get(string $siteId): SiteResponse
31
    {
32
        return new SiteResponse(
33
            $this->client->request(
34
                'get',
35
                "/sites/$siteId"
36
            )
37
        );
38
    }
39
40
    /**
41
     * Creates a site for a codebase.
42
     */
43
    public function create(string $name, string $label, string $codebaseId, ?string $description = null): OperationResponse
44
    {
45
        $options = [
46
            'json' => [
47
                'name' => $name,
48
                'label' => $label,
49
                'codebase_id' => $codebaseId,
50
            ],
51
        ];
52
53
        if ($description !== null) {
54
            $options['json']['description'] = $description;
55
        }
56
57
        return new OperationResponse(
58
            $this->client->request('post', '/sites', $options)
59
        );
60
    }
61
62
    /**
63
     * Update a site details by its id.
64
     */
65
    public function update(string $siteId, ?string $name = null, ?string $label = null, ?string $description = null): OperationResponse
66
    {
67
        $options = ['json' => []];
68
69
        if ($name !== null) {
70
            $options['json']['name'] = $name;
71
        }
72
73
        if ($label !== null) {
74
            $options['json']['label'] = $label;
75
        }
76
77
        if ($description !== null) {
78
            $options['json']['description'] = $description;
79
        }
80
81
        return new OperationResponse(
82
            $this->client->request('put', "/sites/$siteId", $options)
83
        );
84
    }
85
86
    /**
87
     * Deletes a site by its ID.
88
     */
89
    public function delete(string $siteId): OperationResponse
90
    {
91
        return new OperationResponse(
92
            $this->client->request('delete', "/sites/$siteId")
93
        );
94
    }
95
96
    /**
97
     * Retrieves a list of sites associated with an environment.
98
     *
99
     * @return SitesResponse<SiteResponse>
100
     */
101
    public function getByEnvironment(string $environmentId): SitesResponse
102
    {
103
        return new SitesResponse(
104
            $this->client->request('get', "/environments/$environmentId/sites")
105
        );
106
    }
107
108
    /**
109
     * Retrieves a list of sites associated with an organization.
110
     *
111
     * @return SitesResponse<SiteResponse>
112
     */
113
    public function getByOrganization(string $organizationUuid): SitesResponse
114
    {
115
        return new SitesResponse(
116
            $this->client->request('get', "/organizations/$organizationUuid/sites")
117
        );
118
    }
119
120
    /**
121
     * Retrieves a list of sites associated with a team.
122
     *
123
     * @return SitesResponse<SiteResponse>
124
     */
125
    public function getByTeam(string $teamId): SitesResponse
126
    {
127
        return new SitesResponse(
128
            $this->client->request('get', "/teams/$teamId/sites")
129
        );
130
    }
131
132
    /**
133
     * Retrieves all environments by site.
134
     *
135
     * @return CodebaseEnvironmentsResponse
136
     */
137
    public function getEnvironments(string $siteId): CodebaseEnvironmentsResponse
138
    {
139
        return new CodebaseEnvironmentsResponse(
140
            $this->client->request('get', "/sites/$siteId/environments")
141
        );
142
    }
143
}
144