Skip to content

Commit ef483fb

Browse files
authored
Unifi API connector (alexjustesen#2450)
Co-authored-by: Alex Justesen <[email protected]>
1 parent 4ced281 commit ef483fb

File tree

7 files changed

+265
-1
lines changed

7 files changed

+265
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Http\Integrations\Unifi\Requests;
4+
5+
use Saloon\Enums\Method;
6+
use Saloon\Http\Request;
7+
8+
class GetApplicationInformationRequest extends Request
9+
{
10+
/**
11+
* The HTTP method of the request
12+
*/
13+
protected Method $method = Method::GET;
14+
15+
/**
16+
* The endpoint for the request
17+
*/
18+
public function resolveEndpoint(): string
19+
{
20+
return '/info';
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Http\Integrations\Unifi\Requests;
4+
5+
use Saloon\Enums\Method;
6+
use Saloon\Http\Request;
7+
8+
class ListSitesRequest extends Request
9+
{
10+
/**
11+
* The HTTP method of the request
12+
*/
13+
protected Method $method = Method::GET;
14+
15+
/**
16+
* The endpoint for the request
17+
*/
18+
public function resolveEndpoint(): string
19+
{
20+
return '/sites';
21+
}
22+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Http\Integrations\Unifi\Requests;
4+
5+
use Saloon\Enums\Method;
6+
use Saloon\Http\Request;
7+
8+
class ListWanInterfacesRequest extends Request
9+
{
10+
/**
11+
* The HTTP method of the request
12+
*/
13+
protected Method $method = Method::GET;
14+
15+
public function __construct(
16+
protected readonly string $siteId,
17+
) {}
18+
19+
/**
20+
* The endpoint for the request
21+
*/
22+
public function resolveEndpoint(): string
23+
{
24+
return '/sites/'.$this->siteId.'/wans';
25+
}
26+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace App\Http\Integrations\Unifi;
4+
5+
use Saloon\Http\Connector;
6+
use Saloon\Traits\Plugins\AcceptsJson;
7+
8+
class UnifiConnector extends Connector
9+
{
10+
use AcceptsJson;
11+
12+
/**
13+
* The Base URL of the API
14+
*/
15+
public function resolveBaseUrl(): string
16+
{
17+
return config('services.unifi-api.base_url').'/proxy/network/integration/v1';
18+
}
19+
20+
/**
21+
* Default config for the connector
22+
*/
23+
protected function defaultConfig(): array
24+
{
25+
return [
26+
'verify' => false,
27+
];
28+
}
29+
30+
/**
31+
* Default headers for the connector
32+
*/
33+
protected function defaultHeaders(): array
34+
{
35+
return [
36+
'X-API-KEY' => config('services.unifi-api.token'),
37+
];
38+
}
39+
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"livewire/livewire": "^3.6.4",
3030
"lorisleiva/laravel-actions": "^2.9.1",
3131
"maennchen/zipstream-php": "^2.4",
32+
"saloonphp/laravel-plugin": "^3.0",
3233
"secondnetwork/blade-tabler-icons": "^3.35.0",
3334
"spatie/laravel-json-api-paginate": "^1.16.3",
3435
"spatie/laravel-query-builder": "^6.3.6",

composer.lock

Lines changed: 150 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/services.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@
1010
'token' => env('TELEGRAM_BOT_TOKEN'),
1111
],
1212

13+
'unifi-api' => [
14+
'base_url' => env('UNIFI_API_BASE_URL', 'https://192.168.1.1'),
15+
'token' => env('UNIFI_API_TOKEN'),
16+
],
17+
1318
];

0 commit comments

Comments
 (0)