revolution / laravel-switchbot
SwitchBot API for Laravel
Installs: 5 383
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.5
- illuminate/support: ^10.0||^11.0
Requires (Dev)
- orchestra/testbench: ^8.0
- phpunit/phpunit: ^9.5
README
https://github.com/OpenWonderLabs/SwitchBotAPI
Requirements
- PHP >= 8.1
- Laravel >= 10.0
Versioning
- Basic : semver
- Drop old PHP or Laravel version :
+0.1
- Support only latest major version (
main
branch)
Installation
composer require revolution/laravel-switchbot
Configuration
Get tokens from the SwitchBot app.
.env
SWITCHBOT_TOKEN=
SWITCHBOT_SECRET=
Usage
Built as a Laravel HTTP client macro.
use Illuminate\Support\Facades\Http; $response = Http::switchbot()->get('devices'); dump($response->json()); $deviceId = $response->json('body.deviceList.0.deviceId'); if (filled($deviceId)) { $response = Http::switchbot()->get("devices/$deviceId/status"); dump($response->json()); }
use Illuminate\Support\Facades\Http; $response = Http::switchbot()->get('scenes'); dump($response->json());
Testing
use Illuminate\Support\Facades\Http; Http::fake([ '*' => Http::response([ "statusCode" => 100, "body" => [ "deviceList" => [], "infraredRemoteList" => [], ], "message" => "success", ]), ]); $response = Http::switchbot()->get('devices'); $this->assertSame(100, $response->json('statusCode'));
LICENSE
MIT