Skip to content

Commit 0bb9f05

Browse files
committed
Add responses
1 parent b6d6a0d commit 0bb9f05

33 files changed

Lines changed: 1002 additions & 212 deletions

README.md

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,62 @@ $client = new VectorProClient(
3939
$factory,
4040
);
4141

42-
// List all sites
43-
$sites = $client->sites->list();
42+
// List all sites (returns PaginatedResponse<Site>)
43+
$response = $client->sites->list();
44+
foreach ($response->data as $site) {
45+
echo $site->id . ': ' . $site->partner_customer_id . "\n";
46+
}
4447

45-
// Get a specific site
48+
// Get a specific site (returns Site)
4649
$site = $client->sites->get('site-id');
50+
echo $site->dev_php_version; // '8.3'
51+
```
52+
53+
## Response Objects
54+
55+
All API methods return typed response objects for IDE autocomplete and type safety:
56+
57+
```php
58+
use VectorPro\Response\Site;
59+
use VectorPro\Response\Environment;
60+
use VectorPro\Response\Deployment;
61+
use VectorPro\Response\PaginatedResponse;
62+
63+
// Site properties
64+
$site = $client->sites->get('site-id');
65+
$site->id; // string
66+
$site->partner_customer_id; // string
67+
$site->dev_php_version; // string
68+
$site->tags; // string[]
69+
$site->status; // ?string
70+
$site->created_at; // ?string
71+
$site->updated_at; // ?string
72+
73+
// Paginated responses
74+
$response = $client->sites->list(['per_page' => 10, 'page' => 2]);
75+
$response->data; // Site[]
76+
$response->current_page; // int
77+
$response->per_page; // int
78+
$response->total; // int
79+
$response->last_page; // int
4780
```
4881

4982
## API Reference
5083

5184
### Sites
5285

5386
```php
87+
// Returns PaginatedResponse<Site>
5488
$client->sites->list(['per_page' => 10, 'page' => 1]);
89+
90+
// Returns Site
5591
$client->sites->get('site-id');
5692
$client->sites->create(['partner_customer_id' => 'cust-123', 'dev_php_version' => '8.3']);
5793
$client->sites->update('site-id', ['tags' => ['production']]);
58-
$client->sites->delete('site-id');
5994
$client->sites->clone('site-id');
95+
96+
// Returns array
97+
$client->sites->delete('site-id');
6098
$client->sites->suspend('site-id');
6199
$client->sites->unsuspend('site-id');
62100
$client->sites->resetSftpPassword('site-id');
@@ -67,22 +105,30 @@ $client->sites->purgeCache('site-id', ['paths' => ['/wp-content/*']]);
67105
### Environments
68106

69107
```php
108+
// Returns Environment[]
70109
$client->environments->list('site-id');
110+
111+
// Returns Environment
71112
$client->environments->get('site-id', 'env-id');
72113
$client->environments->create('site-id', [
73114
'name' => 'staging',
74115
'php_version' => '8.3',
75116
'is_production' => false,
76117
]);
77118
$client->environments->update('site-id', 'env-id', ['php_version' => '8.2']);
119+
120+
// Returns array
78121
$client->environments->delete('site-id', 'env-id');
79122
$client->environments->resetDatabasePassword('site-id', 'env-id');
80123
```
81124

82125
### Deployments
83126

84127
```php
128+
// Returns PaginatedResponse<Deployment>
85129
$client->environments->deployments->list('site-id', 'env-id');
130+
131+
// Returns Deployment
86132
$client->environments->deployments->create('site-id', 'env-id', ['description' => 'Release v1.0']);
87133
$client->environments->deployments->get('site-id', 'env-id', 'deployment-id');
88134
$client->environments->deployments->rollback('site-id', 'env-id', ['deployment_id' => 'prev-id']);
@@ -91,6 +137,7 @@ $client->environments->deployments->rollback('site-id', 'env-id', ['deployment_i
91137
### Database
92138

93139
```php
140+
// Returns ImportStatus
94141
$client->sites->db->import('site-id', [
95142
'url' => 'https://example.com/backup.sql.gz',
96143
'search_replace' => [
@@ -100,8 +147,12 @@ $client->sites->db->import('site-id', [
100147
$client->sites->db->createImportSession('site-id', ['filename' => 'backup.sql']);
101148
$client->sites->db->runImport('site-id', 'import-id');
102149
$client->sites->db->getImportStatus('site-id', 'import-id');
150+
151+
// Returns ExportStatus
103152
$client->sites->db->createExport('site-id', ['format' => 'sql']);
104153
$client->sites->db->getExportStatus('site-id', 'export-id');
154+
155+
// Returns array
105156
$client->sites->db->resetPassword('site-id');
106157
```
107158

@@ -138,19 +189,23 @@ $client->sites->waf->deleteRateLimit('site-id', 'rule-id');
138189
### SSL
139190

140191
```php
141-
$client->sites->ssl->getStatus('site-id');
142-
$client->sites->ssl->nudge('site-id');
192+
// Returns SslStatus
193+
$client->sites->ssl->getStatus('site-id', 'env-id');
194+
195+
// Returns array
196+
$client->sites->ssl->nudge('site-id', 'env-id');
143197
```
144198

145199
### SSH Keys
146200

147201
```php
148-
// Account-level
202+
// Account-level - Returns SshKey[] or SshKey
149203
$client->account->sshKeys->list();
150204
$client->account->sshKeys->create(['name' => 'My Key', 'public_key' => 'ssh-ed25519 ...']);
205+
$client->account->sshKeys->get('key-id');
151206
$client->account->sshKeys->delete('key-id');
152207

153-
// Site-level
208+
// Site-level - Returns array
154209
$client->sites->sshKeys->list('site-id');
155210
$client->sites->sshKeys->attach('site-id', ['ssh_key_id' => 'key-id']);
156211
$client->sites->sshKeys->detach('site-id', 'key-id');
@@ -159,39 +214,47 @@ $client->sites->sshKeys->detach('site-id', 'key-id');
159214
### Secrets
160215

161216
```php
162-
// Global secrets
217+
// Global secrets - Returns Secret[] or Secret
163218
$client->account->secrets->list();
164219
$client->account->secrets->create(['name' => 'API_KEY', 'value' => 'secret']);
220+
$client->account->secrets->get('secret-id');
165221
$client->account->secrets->update('secret-id', ['value' => 'new-secret']);
166222
$client->account->secrets->delete('secret-id');
167223

168-
// Environment secrets
224+
// Environment secrets - Returns Secret[] or Secret
169225
$client->environments->secrets->list('site-id', 'env-id');
170226
$client->environments->secrets->create('site-id', 'env-id', ['name' => 'DB_HOST', 'value' => 'localhost']);
227+
$client->environments->secrets->get('site-id', 'env-id', 'secret-id');
171228
$client->environments->secrets->update('site-id', 'env-id', 'secret-id', ['value' => 'newhost']);
172229
$client->environments->secrets->delete('site-id', 'env-id', 'secret-id');
173230
```
174231

175232
### Webhooks
176233

177234
```php
235+
// Returns Webhook[] or Webhook
178236
$client->webhooks->list();
179237
$client->webhooks->get('webhook-id');
180238
$client->webhooks->create([
181239
'url' => 'https://example.com/webhook',
182240
'events' => ['site.created', 'deployment.completed'],
183241
]);
184242
$client->webhooks->update('webhook-id', ['enabled' => false]);
243+
$client->webhooks->rotateSecret('webhook-id');
244+
245+
// Returns array
185246
$client->webhooks->delete('webhook-id');
186247
$client->webhooks->listLogs('webhook-id');
187-
$client->webhooks->rotateSecret('webhook-id');
188248
```
189249

190250
### API Keys
191251

192252
```php
253+
// Returns ApiKey[] or ApiKey
193254
$client->account->apiKeys->list();
194255
$client->account->apiKeys->create(['name' => 'CI/CD Key']);
256+
257+
// Returns array
195258
$client->account->apiKeys->delete('key-id');
196259
```
197260

src/Api/Account/ApiKeysApi.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace VectorPro\Api\Account;
66

77
use VectorPro\HttpClient;
8+
use VectorPro\Response\ApiKey;
89

910
final class ApiKeysApi
1011
{
@@ -17,22 +18,25 @@ public function __construct(
1718
/**
1819
* List API keys.
1920
*
20-
* @return array<string, mixed>
21+
* @return ApiKey[]
2122
*/
2223
public function list(): array
2324
{
24-
return $this->http->get(self::BASE_PATH);
25+
$response = $this->http->get(self::BASE_PATH);
26+
27+
return array_map(ApiKey::fromArray(...), $response['data'] ?? $response);
2528
}
2629

2730
/**
2831
* Create an API key.
2932
*
3033
* @param array{name: string, scopes?: string[]} $data
31-
* @return array<string, mixed>
3234
*/
33-
public function create(array $data): array
35+
public function create(array $data): ApiKey
3436
{
35-
return $this->http->post(self::BASE_PATH, $data);
37+
$response = $this->http->post(self::BASE_PATH, $data);
38+
39+
return ApiKey::fromArray($response);
3640
}
3741

3842
/**

src/Api/Account/SecretsApi.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace VectorPro\Api\Account;
66

77
use VectorPro\HttpClient;
8+
use VectorPro\Response\Secret;
89

910
final class SecretsApi
1011
{
@@ -17,43 +18,47 @@ public function __construct(
1718
/**
1819
* List global secrets.
1920
*
20-
* @return array<string, mixed>
21+
* @return Secret[]
2122
*/
2223
public function list(): array
2324
{
24-
return $this->http->get(self::BASE_PATH);
25+
$response = $this->http->get(self::BASE_PATH);
26+
27+
return array_map(Secret::fromArray(...), $response['data'] ?? $response);
2528
}
2629

2730
/**
2831
* Create a global secret.
2932
*
3033
* @param array{name: string, value: string} $data
31-
* @return array<string, mixed>
3234
*/
33-
public function create(array $data): array
35+
public function create(array $data): Secret
3436
{
35-
return $this->http->post(self::BASE_PATH, $data);
37+
$response = $this->http->post(self::BASE_PATH, $data);
38+
39+
return Secret::fromArray($response);
3640
}
3741

3842
/**
3943
* Get a global secret.
40-
*
41-
* @return array<string, mixed>
4244
*/
43-
public function get(string $secretId): array
45+
public function get(string $secretId): Secret
4446
{
45-
return $this->http->get(self::BASE_PATH."/{$secretId}");
47+
$response = $this->http->get(self::BASE_PATH."/{$secretId}");
48+
49+
return Secret::fromArray($response);
4650
}
4751

4852
/**
4953
* Update a global secret.
5054
*
5155
* @param array{value: string} $data
52-
* @return array<string, mixed>
5356
*/
54-
public function update(string $secretId, array $data): array
57+
public function update(string $secretId, array $data): Secret
5558
{
56-
return $this->http->put(self::BASE_PATH."/{$secretId}", $data);
59+
$response = $this->http->put(self::BASE_PATH."/{$secretId}", $data);
60+
61+
return Secret::fromArray($response);
5762
}
5863

5964
/**

src/Api/Account/SshKeysApi.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace VectorPro\Api\Account;
66

77
use VectorPro\HttpClient;
8+
use VectorPro\Response\SshKey;
89

910
final class SshKeysApi
1011
{
@@ -17,32 +18,35 @@ public function __construct(
1718
/**
1819
* List account SSH keys.
1920
*
20-
* @return array<string, mixed>
21+
* @return SshKey[]
2122
*/
2223
public function list(): array
2324
{
24-
return $this->http->get(self::BASE_PATH);
25+
$response = $this->http->get(self::BASE_PATH);
26+
27+
return array_map(SshKey::fromArray(...), $response['data'] ?? $response);
2528
}
2629

2730
/**
2831
* Create an SSH key.
2932
*
3033
* @param array{name: string, public_key: string} $data
31-
* @return array<string, mixed>
3234
*/
33-
public function create(array $data): array
35+
public function create(array $data): SshKey
3436
{
35-
return $this->http->post(self::BASE_PATH, $data);
37+
$response = $this->http->post(self::BASE_PATH, $data);
38+
39+
return SshKey::fromArray($response);
3640
}
3741

3842
/**
3943
* Get an SSH key.
40-
*
41-
* @return array<string, mixed>
4244
*/
43-
public function get(string $keyId): array
45+
public function get(string $keyId): SshKey
4446
{
45-
return $this->http->get(self::BASE_PATH."/{$keyId}");
47+
$response = $this->http->get(self::BASE_PATH."/{$keyId}");
48+
49+
return SshKey::fromArray($response);
4650
}
4751

4852
/**

0 commit comments

Comments
 (0)