sunnyphp / ttlock
TTLock SDK
0.3.0
2023-11-28 14:22 UTC
Requires
- php: ^7.4 || ^8
- ext-json: *
- php-http/discovery: ^1.19
- symfony/polyfill-php80: ^1.28
- webmozart/assert: ^1.11
Requires (Dev)
- nyholm/psr7: ^1.8
- php-http/guzzle7-adapter: ^1.0
- php-http/mock-client: ^1.6
- phpunit/phpunit: ^9.6
- rector/rector: ^0.18.10
- roave/security-advisories: dev-latest
Suggests
- php-http/client-implementation: Any compatible HTTP client (see https://docs.php-http.org/en/latest/clients.html)
This package is auto-updated.
Last update: 2025-02-28 16:57:09 UTC
README
PHP SDK for TTLock Cloud API v3
Installation
See clients & adapters list in HTTPlug documentation if you're using another HTTP client (not Guzzle 7).
HTTP client should be compatible with PSR-18 (implementing psr/http-client-implementation
).
composer require sunnyphp/ttlock php-http/guzzle7-adapter
<?php declare(strict_types=1); require_once __DIR__ . '/vendor/autoload.php'; use SunnyPHP\TTLock\Configuration; use SunnyPHP\TTLock\Entrypoint; use SunnyPHP\TTLock\Request\Lock\GetList; use SunnyPHP\TTLock\Request\Lock\Initialize; use SunnyPHP\TTLock\Request\OAuth2\AccessToken; use SunnyPHP\TTLock\Request\User\Register; use SunnyPHP\TTLock\Transport; // initial configuration $entrypoint = new Entrypoint( new Configuration('client_id', 'client_secret', /* access token if needed */), new Transport(\Http\Adapter\Guzzle7\Client::createWithConfig([ 'verify' => false, // disable certificates check ])), ); // register user; retrieve TTLock Cloud API username $register = $entrypoint->getUserRegister(new Register('username', 'password')); var_dump($register->getResponseArray()); // get access token; retrieve access token, refresh token, expiration, etc $tokenResponse = $entrypoint->getOAuth2AccessToken(new AccessToken($register->getUsername(), 'password')); var_dump($tokenResponse->getResponseArray()); // save token response to future requests or refreshing token // ... // inject access token to entrypoint configuration (most of the requests required access token) $entrypoint = $entrypoint->withConfigurationAccessToken($tokenResponse->getAccessToken()); // initialize new lock; access token used under hood; retrieve lockId, keyId $lockData = 'TTLock SDK should return lockData here'; $newLockIds = $entrypoint->getLockInitialize(new Initialize($lockData)); var_dump($newLockIds->getResponseArray()); // get all initialized locks $locks = $entrypoint->getLockList(new GetList()); var_dump($locks->getResponseArray()); // other requests
Exception structure
\SunnyPHP\TTLock\Exception\ApiException
- communication or system errors\SunnyPHP\TTLock\Exception\CommonException
- if response has errors\SunnyPHP\TTLock\Exception\KeyException
- if response hasEkey
-associated errors\SunnyPHP\TTLock\Exception\GatewayException
- if response hasGateway
-associated errors\SunnyPHP\TTLock\Exception\LockException
- if response hasLock
-associated errors\SunnyPHP\TTLock\Exception\PasscodeException
- if response hasPasscode
orIC
-associated errors
\Webmozart\Assert\InvalidArgumentException
- if passed data is invalid