Skip to content

Commit 44b1667

Browse files
Merge pull request #68 from ohdearapp/reseller-api-updates
Add reseller endpoints to the SDK
2 parents 833f817 + 2503e0e commit 44b1667

24 files changed

+456
-7
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,42 @@ $destination = $ohDear->updateTagGroupNotificationDestination($tagGroupId, $dest
10611061
$ohDear->deleteTagGroupNotificationDestination($tagGroupId, $destinationId);
10621062
```
10631063

1064+
### [Reseller / Managed Teams](https://ohdear.app/docs/api/reseller)
1065+
1066+
If you're an Oh Dear reseller, you can manage teams through the reseller API. All methods require your reseller team ID.
1067+
1068+
```php
1069+
// List all managed teams
1070+
$teams = $ohDear->managedTeams($resellerTeamId);
1071+
1072+
// Get a single managed team
1073+
$team = $ohDear->managedTeam($resellerTeamId, $managedTeamId);
1074+
1075+
// Create a managed team
1076+
$team = $ohDear->createManagedTeam($resellerTeamId, [
1077+
'name' => 'Client Company',
1078+
'timezone' => 'Europe/Brussels',
1079+
'default_uptime_check_location' => 'eu-west',
1080+
]);
1081+
1082+
// Update a managed team
1083+
$team = $ohDear->updateManagedTeam($resellerTeamId, $managedTeamId, [
1084+
'name' => 'Updated Company Name',
1085+
'timezone' => 'Europe/London',
1086+
'default_uptime_check_location' => 'us-east',
1087+
]);
1088+
1089+
// Get a login link for a managed team
1090+
$loginLink = $ohDear->managedTeamLoginLink($resellerTeamId, $managedTeamId);
1091+
echo $loginLink['login_url'];
1092+
1093+
// Decouple a team (team becomes independent)
1094+
$ohDear->decoupleManagedTeam($resellerTeamId, $managedTeamId);
1095+
1096+
// Delete a managed team and all its data
1097+
$ohDear->deleteManagedTeam($resellerTeamId, $managedTeamId);
1098+
```
1099+
10641100
### Using Saloon requests directly
10651101

10661102
This SDK uses [Saloon](https://docs.saloon.dev) to make the HTTP requests. Instead of using the `OhDear` class, you can the underlying request classes directly. This way, you have full power to customize the requests.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace OhDear\PhpSdk\Concerns;
4+
5+
use OhDear\PhpSdk\Dto\ManagedTeam;
6+
use OhDear\PhpSdk\Requests\ManagedTeams\CreateManagedTeamRequest;
7+
use OhDear\PhpSdk\Requests\ManagedTeams\DecoupleManagedTeamRequest;
8+
use OhDear\PhpSdk\Requests\ManagedTeams\DeleteManagedTeamRequest;
9+
use OhDear\PhpSdk\Requests\ManagedTeams\GetManagedTeamLoginLinkRequest;
10+
use OhDear\PhpSdk\Requests\ManagedTeams\GetManagedTeamRequest;
11+
use OhDear\PhpSdk\Requests\ManagedTeams\GetManagedTeamsRequest;
12+
use OhDear\PhpSdk\Requests\ManagedTeams\UpdateManagedTeamRequest;
13+
14+
/** @mixin \OhDear\PhpSdk\OhDear */
15+
trait SupportsManagedTeamEndpoints
16+
{
17+
public function managedTeams(int $resellerTeamId): array
18+
{
19+
$request = new GetManagedTeamsRequest($resellerTeamId);
20+
21+
return $this->send($request)->dtoOrFail();
22+
}
23+
24+
public function managedTeam(int $resellerTeamId, int $managedTeamId): ManagedTeam
25+
{
26+
$request = new GetManagedTeamRequest($resellerTeamId, $managedTeamId);
27+
28+
return $this->send($request)->dto();
29+
}
30+
31+
public function createManagedTeam(int $resellerTeamId, array $data): ManagedTeam
32+
{
33+
$request = new CreateManagedTeamRequest($resellerTeamId, $data);
34+
35+
return $this->send($request)->dto();
36+
}
37+
38+
public function updateManagedTeam(int $resellerTeamId, int $managedTeamId, array $data): ManagedTeam
39+
{
40+
$request = new UpdateManagedTeamRequest($resellerTeamId, $managedTeamId, $data);
41+
42+
return $this->send($request)->dto();
43+
}
44+
45+
public function decoupleManagedTeam(int $resellerTeamId, int $managedTeamId): self
46+
{
47+
$request = new DecoupleManagedTeamRequest($resellerTeamId, $managedTeamId);
48+
49+
$this->send($request);
50+
51+
return $this;
52+
}
53+
54+
public function deleteManagedTeam(int $resellerTeamId, int $managedTeamId): self
55+
{
56+
$request = new DeleteManagedTeamRequest($resellerTeamId, $managedTeamId);
57+
58+
$this->send($request);
59+
60+
return $this;
61+
}
62+
63+
public function managedTeamLoginLink(int $resellerTeamId, int $managedTeamId): array
64+
{
65+
$request = new GetManagedTeamLoginLinkRequest($resellerTeamId, $managedTeamId);
66+
67+
return $this->send($request)->dto();
68+
}
69+
}

src/Concerns/SupportsPortsHistoryItemsEndpoints.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public function portsHistoryItem(int $monitorId, int $portsHistoryItemId): Ports
2020
{
2121
$request = new GetPortsHistoryItemRequest($monitorId, $portsHistoryItemId);
2222

23-
return $this->send($request)->dto();
23+
return $this->send($request)->dtoOrFail();
2424
}
2525
}

src/Dto/ManagedTeam.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace OhDear\PhpSdk\Dto;
4+
5+
class ManagedTeam
6+
{
7+
public function __construct(
8+
public int $id,
9+
public string $name,
10+
public ?string $timezone,
11+
public ?string $createdAt,
12+
public ?int $monitorsCount,
13+
) {}
14+
15+
public static function fromResponse(array $data): self
16+
{
17+
return new self(
18+
id: $data['id'],
19+
name: $data['name'],
20+
timezone: $data['timezone'] ?? null,
21+
createdAt: $data['created_at'] ?? null,
22+
monitorsCount: $data['monitors_count'] ?? null,
23+
);
24+
}
25+
26+
public static function collect(array $items): array
27+
{
28+
return array_map(fn (array $item) => self::fromResponse($item), $items);
29+
}
30+
}

src/Dto/PortsHistoryItem.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class PortsHistoryItem
77
public function __construct(
88
public int $id,
99
public ?string $scannedHost,
10-
public array $expectedOpenResults,
11-
public array $expectedClosedResults,
10+
public ?string $resolvedIp,
11+
public array $openPorts,
1212
public array $issues,
1313
public ?int $scanTimeMs,
1414
public ?string $createdAt,
@@ -19,8 +19,8 @@ public static function fromResponse(array $data): self
1919
return new self(
2020
id: $data['id'],
2121
scannedHost: $data['scanned_host'] ?? null,
22-
expectedOpenResults: $data['expected_open_results'] ?? [],
23-
expectedClosedResults: $data['expected_closed_results'] ?? [],
22+
resolvedIp: $data['resolved_ip'] ?? null,
23+
openPorts: $data['open_ports'] ?? [],
2424
issues: $data['issues'] ?? [],
2525
scanTimeMs: $data['scan_time_ms'] ?? null,
2626
createdAt: $data['created_at'] ?? null,

src/OhDear.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OhDear\PhpSdk\Concerns\SupportsDowntimeEndpoints;
1616
use OhDear\PhpSdk\Concerns\SupportsLighthouseReportsEndpoints;
1717
use OhDear\PhpSdk\Concerns\SupportsMaintenancePeriodEndpoints;
18+
use OhDear\PhpSdk\Concerns\SupportsManagedTeamEndpoints;
1819
use OhDear\PhpSdk\Concerns\SupportsMeEndpoint;
1920
use OhDear\PhpSdk\Concerns\SupportsMixedContentEndpoints;
2021
use OhDear\PhpSdk\Concerns\SupportsMonitorEndpoints;
@@ -58,6 +59,7 @@ class OhDear extends Connector implements HasPagination
5859
use SupportsDowntimeEndpoints;
5960
use SupportsLighthouseReportsEndpoints;
6061
use SupportsMaintenancePeriodEndpoints;
62+
use SupportsManagedTeamEndpoints;
6163
use SupportsMeEndpoint;
6264
use SupportsMixedContentEndpoints;
6365
use SupportsMonitorEndpoints;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace OhDear\PhpSdk\Requests\ManagedTeams;
4+
5+
use OhDear\PhpSdk\Dto\ManagedTeam;
6+
use Saloon\Contracts\Body\HasBody;
7+
use Saloon\Enums\Method;
8+
use Saloon\Http\Request;
9+
use Saloon\Http\Response;
10+
use Saloon\Traits\Body\HasJsonBody;
11+
12+
class CreateManagedTeamRequest extends Request implements HasBody
13+
{
14+
use HasJsonBody;
15+
16+
protected Method $method = Method::POST;
17+
18+
public function __construct(
19+
protected int $resellerTeamId,
20+
protected array $data,
21+
) {}
22+
23+
public function resolveEndpoint(): string
24+
{
25+
return "/reseller/{$this->resellerTeamId}/managed-teams";
26+
}
27+
28+
protected function defaultBody(): array
29+
{
30+
return $this->data;
31+
}
32+
33+
public function createDtoFromResponse(Response $response): ManagedTeam
34+
{
35+
return ManagedTeam::fromResponse($response->json());
36+
}
37+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace OhDear\PhpSdk\Requests\ManagedTeams;
4+
5+
use Saloon\Enums\Method;
6+
use Saloon\Http\Request;
7+
8+
class DecoupleManagedTeamRequest extends Request
9+
{
10+
protected Method $method = Method::POST;
11+
12+
public function __construct(
13+
protected int $resellerTeamId,
14+
protected int $managedTeamId,
15+
) {}
16+
17+
public function resolveEndpoint(): string
18+
{
19+
return "/reseller/{$this->resellerTeamId}/managed-teams/{$this->managedTeamId}/decouple";
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace OhDear\PhpSdk\Requests\ManagedTeams;
4+
5+
use Saloon\Enums\Method;
6+
use Saloon\Http\Request;
7+
8+
class DeleteManagedTeamRequest extends Request
9+
{
10+
protected Method $method = Method::DELETE;
11+
12+
public function __construct(
13+
protected int $resellerTeamId,
14+
protected int $managedTeamId,
15+
) {}
16+
17+
public function resolveEndpoint(): string
18+
{
19+
return "/reseller/{$this->resellerTeamId}/managed-teams/{$this->managedTeamId}";
20+
}
21+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace OhDear\PhpSdk\Requests\ManagedTeams;
4+
5+
use Saloon\Enums\Method;
6+
use Saloon\Http\Request;
7+
use Saloon\Http\Response;
8+
9+
class GetManagedTeamLoginLinkRequest extends Request
10+
{
11+
protected Method $method = Method::GET;
12+
13+
public function __construct(
14+
protected int $resellerTeamId,
15+
protected int $managedTeamId,
16+
) {}
17+
18+
public function resolveEndpoint(): string
19+
{
20+
return "/reseller/{$this->resellerTeamId}/managed-teams/{$this->managedTeamId}/login-link";
21+
}
22+
23+
public function createDtoFromResponse(Response $response): array
24+
{
25+
return $response->json();
26+
}
27+
}

0 commit comments

Comments
 (0)