Passed
Push — master ( 62dee2...4b8e5c )
by Dane
02:13
created

Sites::getByOrganization()   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(
44
        string $name,
45
        string $label,
46
        string $codebaseId,
47
        ?string $description = null
48
    ): OperationResponse {
49
        $options = [
50
            'json' => [
51
                'name' => $name,
52
                'label' => $label,
53
                'codebase_id' => $codebaseId,
54
            ],
55
        ];
56
57
        if ($description !== null) {
58
            $options['json']['description'] = $description;
59
        }
60
61
        return new OperationResponse(
62
            $this->client->request('post', '/sites', $options)
63
        );
64
    }
65
66
    /**
67
     * Update a site details by its id.
68
     */
69
    public function update(
70
        string $siteId,
71
        ?string $name = null,
72
        ?string $label = null,
73
        ?string $description = null
74
    ): OperationResponse {
75
        $options = ['json' => []];
76
77
        if ($name !== null) {
78
            $options['json']['name'] = $name;
79
        }
80
81
        if ($label !== null) {
82
            $options['json']['label'] = $label;
83
        }
84
85
        if ($description !== null) {
86
            $options['json']['description'] = $description;
87
        }
88
89
        return new OperationResponse(
90
            $this->client->request('put', "/sites/$siteId", $options)
91
        );
92
    }
93
94
    /**
95
     * Deletes a site by its ID.
96
     */
97
    public function delete(string $siteId): OperationResponse
98
    {
99
        return new OperationResponse(
100
            $this->client->request('delete', "/sites/$siteId")
101
        );
102
    }
103
104
    /**
105
     * Retrieves a list of sites associated with an environment.
106
     *
107
     * @return SitesResponse<SiteResponse>
108
     */
109
    public function getByEnvironment(string $environmentId): SitesResponse
110
    {
111
        return new SitesResponse(
112
            $this->client->request('get', "/environments/$environmentId/sites")
113
        );
114
    }
115
116
    /**
117
     * Retrieves a list of sites associated with an organization.
118
     *
119
     * @return SitesResponse<SiteResponse>
120
     */
121
    public function getByOrganization(string $organizationUuid): SitesResponse
122
    {
123
        return new SitesResponse(
124
            $this->client->request('get', "/organizations/$organizationUuid/sites")
125
        );
126
    }
127
128
    /**
129
     * Retrieves a list of sites associated with a team.
130
     *
131
     * @return SitesResponse<SiteResponse>
132
     */
133
    public function getByTeam(string $teamId): SitesResponse
134
    {
135
        return new SitesResponse(
136
            $this->client->request('get', "/teams/$teamId/sites")
137
        );
138
    }
139
140
    /**
141
     * Retrieves all environments by site.
142
     */
143
    public function getEnvironments(string $siteId): CodebaseEnvironmentsResponse
144
    {
145
        return new CodebaseEnvironmentsResponse(
146
            $this->client->request('get', "/sites/$siteId/environments")
147
        );
148
    }
149
}
150