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 <http://opensource.org/licenses/MIT>. |
9
|
|
|
// |
10
|
|
|
// --------------------------------------------------------------------- |
11
|
|
|
|
12
|
|
|
namespace Linode\Entity; |
13
|
|
|
|
14
|
|
|
use Linode\Entity\Account\AccountInformation; |
15
|
|
|
use Linode\Entity\Account\AccountSettings; |
16
|
|
|
use Linode\Entity\Account\NetworkUtilization; |
17
|
|
|
use Linode\Exception\LinodeException; |
18
|
|
|
use Linode\Internal\Account\EventRepository; |
19
|
|
|
use Linode\Internal\Account\InvoiceRepository; |
20
|
|
|
use Linode\Internal\Account\NotificationRepository; |
21
|
|
|
use Linode\Internal\Account\OAuthClientRepository; |
22
|
|
|
use Linode\Internal\Account\PaymentRepository; |
23
|
|
|
use Linode\Internal\Account\UserRepository; |
24
|
|
|
use Linode\Internal\Longview\LongviewClientRepository; |
25
|
|
|
use Linode\Internal\Managed\ManagedContactRepository; |
26
|
|
|
use Linode\Internal\Managed\ManagedCredentialRepository; |
27
|
|
|
use Linode\Internal\Managed\ManagedIssueRepository; |
28
|
|
|
use Linode\Internal\Managed\ManagedLinodeSettingsRepository; |
29
|
|
|
use Linode\Internal\Managed\ManagedServiceRepository; |
30
|
|
|
use Linode\LinodeClient; |
31
|
|
|
use Linode\Repository\Account as AccountRepository; |
32
|
|
|
use Linode\Repository\Longview as LongviewRepository; |
33
|
|
|
use Linode\Repository\Managed as ManagedRepository; |
34
|
|
|
use Linode\Repository\RepositoryInterface; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Current user account. |
38
|
|
|
* |
39
|
|
|
* @property AccountRepository\EventRepositoryInterface $events |
40
|
|
|
* @property AccountRepository\InvoiceRepositoryInterface $invoices |
41
|
|
|
* @property LongviewRepository\LongviewClientRepositoryInterface $longviews_clients |
42
|
|
|
* @property ManagedRepository\ManagedContactRepositoryInterface $managed_contacts |
43
|
|
|
* @property ManagedRepository\ManagedCredentialRepositoryInterface $managed_credentials |
44
|
|
|
* @property ManagedRepository\ManagedIssueRepositoryInterface $managed_issues |
45
|
|
|
* @property ManagedRepository\ManagedLinodeSettingsRepositoryInterface $managed_linode_settings |
46
|
|
|
* @property ManagedRepository\ManagedServiceRepositoryInterface $managed_services |
47
|
|
|
* @property AccountRepository\NotificationRepositoryInterface $notifications |
48
|
|
|
* @property AccountRepository\OAuthClientRepositoryInterface $oauth_clients |
49
|
|
|
* @property AccountRepository\PaymentRepositoryInterface $payments |
50
|
|
|
* @property AccountRepository\UserRepositoryInterface $users |
51
|
|
|
*/ |
52
|
|
|
class Account |
53
|
|
|
{ |
54
|
|
|
/** |
55
|
|
|
* Account constructor. |
56
|
|
|
* |
57
|
|
|
* @param LinodeClient $client linode API client |
58
|
|
|
*/ |
59
|
|
|
public function __construct(protected LinodeClient $client) {} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Returns requested repository. |
63
|
|
|
* |
64
|
|
|
* @param string $name repository name |
65
|
|
|
*/ |
66
|
1 |
|
public function __get(string $name): ?RepositoryInterface |
67
|
|
|
{ |
68
|
1 |
|
return match ($name) { |
69
|
1 |
|
'events' => new EventRepository($this->client), |
70
|
1 |
|
'invoices' => new InvoiceRepository($this->client), |
71
|
1 |
|
'longviews_clients' => new LongviewClientRepository($this->client), |
72
|
1 |
|
'managed_contacts' => new ManagedContactRepository($this->client), |
73
|
1 |
|
'managed_credentials' => new ManagedCredentialRepository($this->client), |
74
|
1 |
|
'managed_issues' => new ManagedIssueRepository($this->client), |
75
|
1 |
|
'managed_linode_settings' => new ManagedLinodeSettingsRepository($this->client), |
76
|
1 |
|
'managed_services' => new ManagedServiceRepository($this->client), |
77
|
1 |
|
'notifications' => new NotificationRepository($this->client), |
78
|
1 |
|
'oauth_clients' => new OAuthClientRepository($this->client), |
79
|
1 |
|
'payments' => new PaymentRepository($this->client), |
80
|
1 |
|
'users' => new UserRepository($this->client), |
81
|
1 |
|
default => null, |
82
|
1 |
|
}; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Returns the contact and billing information related to your Account. |
87
|
|
|
* |
88
|
|
|
* @throws LinodeException |
89
|
|
|
*/ |
90
|
1 |
|
public function getAccountInformation(): AccountInformation |
91
|
|
|
{ |
92
|
1 |
|
$response = $this->client->api($this->client::REQUEST_GET, '/account'); |
93
|
1 |
|
$contents = $response->getBody()->getContents(); |
94
|
1 |
|
$json = json_decode($contents, true); |
95
|
|
|
|
96
|
1 |
|
return new AccountInformation($this->client, $json); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Updates contact and billing information related to your Account. |
101
|
|
|
* |
102
|
|
|
* @throws LinodeException |
103
|
|
|
*/ |
104
|
1 |
|
public function setAccountInformation(array $parameters): AccountInformation |
105
|
|
|
{ |
106
|
1 |
|
$response = $this->client->api($this->client::REQUEST_PUT, '/account', $parameters); |
107
|
1 |
|
$contents = $response->getBody()->getContents(); |
108
|
1 |
|
$json = json_decode($contents, true); |
109
|
|
|
|
110
|
1 |
|
return new AccountInformation($this->client, $json); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Adds/edit credit card information to your Account. |
115
|
|
|
* |
116
|
|
|
* Only one credit card can be associated with your Account, so using this |
117
|
|
|
* endpoint will overwrite your currently active card information with the |
118
|
|
|
* new credit card. |
119
|
|
|
* |
120
|
|
|
* @param string $card_number Your credit card number. No spaces or dashes allowed. |
121
|
|
|
* @param string $expiry_month a value from 1-12 representing the expiration month of your credit card |
122
|
|
|
* @param string $expiry_year a four-digit integer representing the expiration year of your credit card |
123
|
|
|
* |
124
|
|
|
* @throws LinodeException |
125
|
|
|
*/ |
126
|
1 |
|
public function updateCreditCard(string $card_number, string $expiry_month, string $expiry_year): void |
127
|
|
|
{ |
128
|
1 |
|
$parameters = [ |
129
|
1 |
|
'card_number' => $card_number, |
130
|
1 |
|
'expiry_month' => $expiry_month, |
131
|
1 |
|
'expiry_year' => $expiry_year, |
132
|
1 |
|
]; |
133
|
|
|
|
134
|
1 |
|
$this->client->api($this->client::REQUEST_POST, '/account/credit-card', $parameters); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Returns information related to your Account settings: Managed service |
139
|
|
|
* subscription, Longview subscription, and network helper. |
140
|
|
|
* |
141
|
|
|
* @throws LinodeException |
142
|
|
|
*/ |
143
|
1 |
|
public function getAccountSettings(): AccountSettings |
144
|
|
|
{ |
145
|
1 |
|
$response = $this->client->api($this->client::REQUEST_GET, '/account/settings'); |
146
|
1 |
|
$contents = $response->getBody()->getContents(); |
147
|
1 |
|
$json = json_decode($contents, true); |
148
|
|
|
|
149
|
1 |
|
return new AccountSettings($this->client, $json); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Updates your Account settings. |
154
|
|
|
* |
155
|
|
|
* @throws LinodeException |
156
|
|
|
*/ |
157
|
1 |
|
public function setAccountSettings(array $parameters): AccountSettings |
158
|
|
|
{ |
159
|
1 |
|
$response = $this->client->api($this->client::REQUEST_PUT, '/account/settings', $parameters); |
160
|
1 |
|
$contents = $response->getBody()->getContents(); |
161
|
1 |
|
$json = json_decode($contents, true); |
162
|
|
|
|
163
|
1 |
|
return new AccountSettings($this->client, $json); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Returns a Transfer object showing your network utilization, in GB, for the current month. |
168
|
|
|
* |
169
|
|
|
* @throws LinodeException |
170
|
|
|
*/ |
171
|
1 |
|
public function getNetworkUtilization(): NetworkUtilization |
172
|
|
|
{ |
173
|
1 |
|
$response = $this->client->api($this->client::REQUEST_GET, '/account/transfer'); |
174
|
1 |
|
$contents = $response->getBody()->getContents(); |
175
|
1 |
|
$json = json_decode($contents, true); |
176
|
|
|
|
177
|
1 |
|
return new NetworkUtilization($this->client, $json); |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|