diff --git a/.gitattributes b/.gitattributes index a31dbc4d..1602424c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -src/Objects/**/*.php linguist-generated +src/Routes/**/*.php linguist-generated diff --git a/.github/workflows/generate.yml b/.github/workflows/generate.yml index 98269747..e8653dcd 100644 --- a/.github/workflows/generate.yml +++ b/.github/workflows/generate.yml @@ -3,8 +3,8 @@ name: Generate on: push: - branches-ignore: - - main + branches: + - 'no-branch-will-match-this-pattern' workflow_dispatch: {} jobs: diff --git a/README.md b/README.md index dd85a49f..a9e435f9 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,9 @@ Check out [the documentation](https://docs.seam.co) or the usage below. ## Usage ```php -$seam = new Seam\SeamClient("YOUR_API_KEY"); +use Seam\Seam; + +$seam = new Seam("YOUR_API_KEY"); # Create a Connect Webview to login to a provider $connect_webview = $seam->connect_webviews->create( diff --git a/src/Auth.php b/src/Auth.php new file mode 100644 index 00000000..e8a084df --- /dev/null +++ b/src/Auth.php @@ -0,0 +1,197 @@ + "Bearer {$api_key}"]; + } + + public static function getAuthHeadersForPersonalAccessToken( + string $personal_access_token, + string $workspace_id + ): array { + if (self::isJwt($personal_access_token)) { + throw new SeamInvalidTokenError( + "A JWT cannot be used as a personal_access_token" + ); + } + + if (self::isClientSessionToken($personal_access_token)) { + throw new SeamInvalidTokenError( + "A Client Session Token cannot be used as a personal_access_token" + ); + } + + if (self::isPublishableKey($personal_access_token)) { + throw new SeamInvalidTokenError( + "A Publishable Key cannot be used as a personal_access_token" + ); + } + + if (!self::isAccessToken($personal_access_token)) { + throw new SeamInvalidTokenError( + "Unknown or invalid personal_access_token format, expected token to start with " . + self::ACCESS_TOKEN_PREFIX + ); + } + + return [ + "Authorization" => "Bearer {$personal_access_token}", + "Seam-Workspace-Id" => $workspace_id, + ]; + } + + public static function getAuthHeadersForMultiWorkspacePersonalAccessToken( + string $personal_access_token + ): array { + if (self::isJwt($personal_access_token)) { + throw new SeamInvalidTokenError( + "A JWT cannot be used as a personal_access_token" + ); + } + + if (self::isClientSessionToken($personal_access_token)) { + throw new SeamInvalidTokenError( + "A Client Session Token cannot be used as a personal_access_token" + ); + } + + if (self::isPublishableKey($personal_access_token)) { + throw new SeamInvalidTokenError( + "A Publishable Key cannot be used as a personal_access_token" + ); + } + + if (!self::isAccessToken($personal_access_token)) { + throw new SeamInvalidTokenError( + "Unknown or invalid personal_access_token format, expected token to start with " . + self::ACCESS_TOKEN_PREFIX + ); + } + + return ["Authorization" => "Bearer {$personal_access_token}"]; + } + + public static function isAccessToken(string $token): bool + { + return str_starts_with($token, self::ACCESS_TOKEN_PREFIX); + } + + public static function isJwt(string $token): bool + { + return str_starts_with($token, self::JWT_PREFIX); + } + + public static function isSeamToken(string $token): bool + { + return str_starts_with($token, self::TOKEN_PREFIX); + } + + public static function isApiKey(string $token): bool + { + return !self::isClientSessionToken($token) && + !self::isJwt($token) && + !self::isAccessToken($token) && + !self::isPublishableKey($token) && + self::isSeamToken($token); + } + + public static function isClientSessionToken(string $token): bool + { + return str_starts_with($token, self::CLIENT_SESSION_TOKEN_PREFIX); + } + + public static function isPublishableKey(string $token): bool + { + return str_starts_with($token, self::PUBLISHABLE_KEY_TOKEN_PREFIX); + } + + public static function isConsoleSessionToken(string $token): bool + { + return self::isJwt($token); + } + + public static function isPersonalAccessToken(string $token): bool + { + return self::isAccessToken($token); + } +} diff --git a/src/Config.php b/src/Config.php new file mode 100644 index 00000000..03bff3aa --- /dev/null +++ b/src/Config.php @@ -0,0 +1,9 @@ +push(self::createErrorHandlingMiddleware()); + + $clientOptions = [ + "base_uri" => $baseUrl, + "timeout" => $timeout, + "headers" => $headers, + "handler" => $handlerStack, + "http_errors" => false, + ]; + + $guzzleOptions = $config["guzzle_options"] ?? []; + $clientOptions = array_merge($clientOptions, $guzzleOptions); + + return new GuzzleHttpClient($clientOptions); + } + + public static function createErrorHandlingMiddleware(): callable + { + return function (callable $nextHandler) { + return function ($request, array $options) use ($nextHandler) { + return $nextHandler($request, $options)->then(function ( + ResponseInterface $response + ) use ($request) { + $statusCode = $response->getStatusCode(); + $requestId = trim( + $response->getHeaderLine("seam-request-id") + ); + $body = (string) $response->getBody(); + $decodedBody = json_decode($body); + + if ($statusCode === 401) { + throw new HttpUnauthorizedError($requestId); + } + + if (!self::isApiErrorResponse($response, $decodedBody)) { + if ($statusCode >= 400) { + throw RequestException::create($request, $response); + } + + return $response; + } + + $errorData = $decodedBody->error; + if ( + isset($errorData->type) && + $errorData->type === "invalid_input" + ) { + throw new HttpInvalidInputError( + $errorData, + $statusCode, + $requestId + ); + } + + throw new HttpApiError($errorData, $statusCode, $requestId); + }); + }; + }; + } + + public static function isApiErrorResponse( + ResponseInterface $response, + $decodedBody + ): bool { + $contentType = $response->getHeaderLine("Content-Type"); + if (stripos($contentType, "application/json") !== 0) { + return false; + } + + if (!is_object($decodedBody) || !isset($decodedBody->error)) { + return false; + } + + $error = $decodedBody->error; + if (!is_object($error)) { + return false; + } + + if (!isset($error->type) || !is_string($error->type)) { + return false; + } + + if (!isset($error->message) || !is_string($error->message)) { + return false; + } + + return true; + } +} diff --git a/src/Options.php b/src/Options.php new file mode 100644 index 00000000..7d68d886 --- /dev/null +++ b/src/Options.php @@ -0,0 +1,117 @@ + "Seam PHP Client " . $sdk_version, + "seam-sdk-name" => "seamapi/php", + "seam-sdk-version" => $sdk_version, + ]); + + $endpoint = self::getEndpoint($endpoint); + + return [ + "headers" => $headers, + "endpoint" => $endpoint, + ]; + } + + public static function getEndpoint(?string $endpoint = null): string + { + return $endpoint ?? (self::getEndpointFromEnv() ?? DEFAULT_ENDPOINT); + } + + public static function getEndpointFromEnv(): ?string + { + $seam_api_url = getenv("SEAM_API_URL"); + $seam_endpoint = getenv("SEAM_ENDPOINT"); + + if ($seam_api_url) { + trigger_error( + "Using the SEAM_API_URL environment variable is deprecated. Support will be removed in a later major version. Use SEAM_ENDPOINT instead.", + E_USER_DEPRECATED + ); + } + + if ($seam_api_url && $seam_endpoint) { + trigger_error( + "Detected both the SEAM_API_URL and SEAM_ENDPOINT environment variables. Using SEAM_ENDPOINT.", + E_USER_NOTICE + ); + } + + return $seam_endpoint ?: $seam_api_url; + } + + public static function isSeamOptionsWithApiKey( + ?string $api_key, + ?string $personal_access_token + ): bool { + if ($api_key === null) { + return false; + } + + if ($personal_access_token !== null) { + throw new SeamInvalidOptionsError( + "The personal_access_token option cannot be used with the api_key option" + ); + } + + return true; + } + + public static function isSeamOptionsWithPersonalAccessToken( + ?string $personal_access_token, + ?string $api_key, + ?string $workspace_id + ): bool { + if ($personal_access_token === null) { + return false; + } + + if ($api_key !== null) { + throw new SeamInvalidOptionsError( + "The api_key option cannot be used with the personal_access_token option" + ); + } + + if ($workspace_id === null) { + throw new SeamInvalidOptionsError( + "Must pass a workspace_id when using a personal_access_token" + ); + } + + return true; + } +} diff --git a/src/Routes/Clients/AccessCodes.php b/src/Routes/Clients/AccessCodes.php new file mode 100644 index 00000000..685533b7 --- /dev/null +++ b/src/Routes/Clients/AccessCodes.php @@ -0,0 +1,444 @@ +seam = $seam; + $this->simulate = new AccessCodesSimulate($seam); + $this->unmanaged = new AccessCodesUnmanaged($seam); + } + + public function create( + string $device_id, + ?string $name = null, + ?string $starts_at = null, + ?string $ends_at = null, + ?string $code = null, + ?bool $sync = null, + ?bool $attempt_for_offline_device = null, + ?string $common_code_key = null, + ?bool $prefer_native_scheduling = null, + ?bool $use_backup_access_code_pool = null, + ?bool $allow_external_modification = null, + ?bool $is_external_modification_allowed = null, + ?float $preferred_code_length = null, + ?bool $use_offline_access_code = null, + ?bool $is_offline_access_code = null, + ?bool $is_one_time_use = null, + ?string $max_time_rounding = null + ): AccessCode { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($name !== null) { + $request_payload["name"] = $name; + } + if ($starts_at !== null) { + $request_payload["starts_at"] = $starts_at; + } + if ($ends_at !== null) { + $request_payload["ends_at"] = $ends_at; + } + if ($code !== null) { + $request_payload["code"] = $code; + } + if ($sync !== null) { + $request_payload["sync"] = $sync; + } + if ($attempt_for_offline_device !== null) { + $request_payload[ + "attempt_for_offline_device" + ] = $attempt_for_offline_device; + } + if ($common_code_key !== null) { + $request_payload["common_code_key"] = $common_code_key; + } + if ($prefer_native_scheduling !== null) { + $request_payload[ + "prefer_native_scheduling" + ] = $prefer_native_scheduling; + } + if ($use_backup_access_code_pool !== null) { + $request_payload[ + "use_backup_access_code_pool" + ] = $use_backup_access_code_pool; + } + if ($allow_external_modification !== null) { + $request_payload[ + "allow_external_modification" + ] = $allow_external_modification; + } + if ($is_external_modification_allowed !== null) { + $request_payload[ + "is_external_modification_allowed" + ] = $is_external_modification_allowed; + } + if ($preferred_code_length !== null) { + $request_payload["preferred_code_length"] = $preferred_code_length; + } + if ($use_offline_access_code !== null) { + $request_payload[ + "use_offline_access_code" + ] = $use_offline_access_code; + } + if ($is_offline_access_code !== null) { + $request_payload[ + "is_offline_access_code" + ] = $is_offline_access_code; + } + if ($is_one_time_use !== null) { + $request_payload["is_one_time_use"] = $is_one_time_use; + } + if ($max_time_rounding !== null) { + $request_payload["max_time_rounding"] = $max_time_rounding; + } + + $res = $this->seam->client->post("/access_codes/create", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return AccessCode::from_json($json->access_code); + } + + public function create_multiple( + array $device_ids, + ?string $behavior_when_code_cannot_be_shared = null, + ?float $preferred_code_length = null, + ?string $name = null, + ?string $starts_at = null, + ?string $ends_at = null, + ?string $code = null, + ?bool $attempt_for_offline_device = null, + ?bool $prefer_native_scheduling = null, + ?bool $use_backup_access_code_pool = null, + ?bool $allow_external_modification = null, + ?bool $is_external_modification_allowed = null, + ?bool $use_offline_access_code = null, + ?bool $is_offline_access_code = null, + ?bool $is_one_time_use = null, + ?string $max_time_rounding = null + ): array { + $request_payload = []; + + if ($device_ids !== null) { + $request_payload["device_ids"] = $device_ids; + } + if ($behavior_when_code_cannot_be_shared !== null) { + $request_payload[ + "behavior_when_code_cannot_be_shared" + ] = $behavior_when_code_cannot_be_shared; + } + if ($preferred_code_length !== null) { + $request_payload["preferred_code_length"] = $preferred_code_length; + } + if ($name !== null) { + $request_payload["name"] = $name; + } + if ($starts_at !== null) { + $request_payload["starts_at"] = $starts_at; + } + if ($ends_at !== null) { + $request_payload["ends_at"] = $ends_at; + } + if ($code !== null) { + $request_payload["code"] = $code; + } + if ($attempt_for_offline_device !== null) { + $request_payload[ + "attempt_for_offline_device" + ] = $attempt_for_offline_device; + } + if ($prefer_native_scheduling !== null) { + $request_payload[ + "prefer_native_scheduling" + ] = $prefer_native_scheduling; + } + if ($use_backup_access_code_pool !== null) { + $request_payload[ + "use_backup_access_code_pool" + ] = $use_backup_access_code_pool; + } + if ($allow_external_modification !== null) { + $request_payload[ + "allow_external_modification" + ] = $allow_external_modification; + } + if ($is_external_modification_allowed !== null) { + $request_payload[ + "is_external_modification_allowed" + ] = $is_external_modification_allowed; + } + if ($use_offline_access_code !== null) { + $request_payload[ + "use_offline_access_code" + ] = $use_offline_access_code; + } + if ($is_offline_access_code !== null) { + $request_payload[ + "is_offline_access_code" + ] = $is_offline_access_code; + } + if ($is_one_time_use !== null) { + $request_payload["is_one_time_use"] = $is_one_time_use; + } + if ($max_time_rounding !== null) { + $request_payload["max_time_rounding"] = $max_time_rounding; + } + + $res = $this->seam->client->post("/access_codes/create_multiple", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => AccessCode::from_json($r), + $json->access_codes + ); + } + + public function delete( + string $access_code_id, + ?string $device_id = null, + ?bool $sync = null + ): void { + $request_payload = []; + + if ($access_code_id !== null) { + $request_payload["access_code_id"] = $access_code_id; + } + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($sync !== null) { + $request_payload["sync"] = $sync; + } + + $this->seam->client->post("/access_codes/delete", [ + "json" => (object) $request_payload, + ]); + } + + public function generate_code(string $device_id): AccessCode + { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + + $res = $this->seam->client->post("/access_codes/generate_code", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return AccessCode::from_json($json->generated_code); + } + + public function get( + ?string $device_id = null, + ?string $access_code_id = null, + ?string $code = null + ): AccessCode { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($access_code_id !== null) { + $request_payload["access_code_id"] = $access_code_id; + } + if ($code !== null) { + $request_payload["code"] = $code; + } + + $res = $this->seam->client->post("/access_codes/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return AccessCode::from_json($json->access_code); + } + + public function list( + ?string $device_id = null, + ?array $access_code_ids = null, + ?string $user_identifier_key = null + ): array { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($access_code_ids !== null) { + $request_payload["access_code_ids"] = $access_code_ids; + } + if ($user_identifier_key !== null) { + $request_payload["user_identifier_key"] = $user_identifier_key; + } + + $res = $this->seam->client->post("/access_codes/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => AccessCode::from_json($r), + $json->access_codes + ); + } + + public function pull_backup_access_code(string $access_code_id): AccessCode + { + $request_payload = []; + + if ($access_code_id !== null) { + $request_payload["access_code_id"] = $access_code_id; + } + + $res = $this->seam->client->post( + "/access_codes/pull_backup_access_code", + ["json" => (object) $request_payload] + ); + $json = json_decode($res->getBody()); + + return AccessCode::from_json($json->access_code); + } + + public function update( + string $access_code_id, + ?string $name = null, + ?string $starts_at = null, + ?string $ends_at = null, + ?string $code = null, + ?bool $sync = null, + ?bool $attempt_for_offline_device = null, + ?bool $prefer_native_scheduling = null, + ?bool $use_backup_access_code_pool = null, + ?bool $allow_external_modification = null, + ?bool $is_external_modification_allowed = null, + ?float $preferred_code_length = null, + ?bool $use_offline_access_code = null, + ?bool $is_offline_access_code = null, + ?bool $is_one_time_use = null, + ?string $max_time_rounding = null, + ?string $device_id = null, + ?string $type = null, + ?bool $is_managed = null + ): void { + $request_payload = []; + + if ($access_code_id !== null) { + $request_payload["access_code_id"] = $access_code_id; + } + if ($name !== null) { + $request_payload["name"] = $name; + } + if ($starts_at !== null) { + $request_payload["starts_at"] = $starts_at; + } + if ($ends_at !== null) { + $request_payload["ends_at"] = $ends_at; + } + if ($code !== null) { + $request_payload["code"] = $code; + } + if ($sync !== null) { + $request_payload["sync"] = $sync; + } + if ($attempt_for_offline_device !== null) { + $request_payload[ + "attempt_for_offline_device" + ] = $attempt_for_offline_device; + } + if ($prefer_native_scheduling !== null) { + $request_payload[ + "prefer_native_scheduling" + ] = $prefer_native_scheduling; + } + if ($use_backup_access_code_pool !== null) { + $request_payload[ + "use_backup_access_code_pool" + ] = $use_backup_access_code_pool; + } + if ($allow_external_modification !== null) { + $request_payload[ + "allow_external_modification" + ] = $allow_external_modification; + } + if ($is_external_modification_allowed !== null) { + $request_payload[ + "is_external_modification_allowed" + ] = $is_external_modification_allowed; + } + if ($preferred_code_length !== null) { + $request_payload["preferred_code_length"] = $preferred_code_length; + } + if ($use_offline_access_code !== null) { + $request_payload[ + "use_offline_access_code" + ] = $use_offline_access_code; + } + if ($is_offline_access_code !== null) { + $request_payload[ + "is_offline_access_code" + ] = $is_offline_access_code; + } + if ($is_one_time_use !== null) { + $request_payload["is_one_time_use"] = $is_one_time_use; + } + if ($max_time_rounding !== null) { + $request_payload["max_time_rounding"] = $max_time_rounding; + } + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($type !== null) { + $request_payload["type"] = $type; + } + if ($is_managed !== null) { + $request_payload["is_managed"] = $is_managed; + } + + $this->seam->client->post("/access_codes/update", [ + "json" => (object) $request_payload, + ]); + } + + public function update_multiple( + string $common_code_key, + ?string $ends_at = null, + ?string $starts_at = null, + ?string $name = null + ): void { + $request_payload = []; + + if ($common_code_key !== null) { + $request_payload["common_code_key"] = $common_code_key; + } + if ($ends_at !== null) { + $request_payload["ends_at"] = $ends_at; + } + if ($starts_at !== null) { + $request_payload["starts_at"] = $starts_at; + } + if ($name !== null) { + $request_payload["name"] = $name; + } + + $this->seam->client->post("/access_codes/update_multiple", [ + "json" => (object) $request_payload, + ]); + } +} diff --git a/src/Routes/Clients/AccessCodesSimulate.php b/src/Routes/Clients/AccessCodesSimulate.php new file mode 100644 index 00000000..101e1c77 --- /dev/null +++ b/src/Routes/Clients/AccessCodesSimulate.php @@ -0,0 +1,42 @@ +seam = $seam; + } + + public function create_unmanaged_access_code( + string $device_id, + string $name, + string $code + ): UnmanagedAccessCode { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($name !== null) { + $request_payload["name"] = $name; + } + if ($code !== null) { + $request_payload["code"] = $code; + } + + $res = $this->seam->client->post( + "/access_codes/simulate/create_unmanaged_access_code", + ["json" => (object) $request_payload] + ); + $json = json_decode($res->getBody()); + + return UnmanagedAccessCode::from_json($json->access_code); + } +} diff --git a/src/Routes/Clients/AccessCodesUnmanaged.php b/src/Routes/Clients/AccessCodesUnmanaged.php new file mode 100644 index 00000000..dfeed702 --- /dev/null +++ b/src/Routes/Clients/AccessCodesUnmanaged.php @@ -0,0 +1,150 @@ +seam = $seam; + } + + public function convert_to_managed( + string $access_code_id, + ?bool $is_external_modification_allowed = null, + ?bool $allow_external_modification = null, + ?bool $force = null, + ?bool $sync = null + ): void { + $request_payload = []; + + if ($access_code_id !== null) { + $request_payload["access_code_id"] = $access_code_id; + } + if ($is_external_modification_allowed !== null) { + $request_payload[ + "is_external_modification_allowed" + ] = $is_external_modification_allowed; + } + if ($allow_external_modification !== null) { + $request_payload[ + "allow_external_modification" + ] = $allow_external_modification; + } + if ($force !== null) { + $request_payload["force"] = $force; + } + if ($sync !== null) { + $request_payload["sync"] = $sync; + } + + $this->seam->client->post( + "/access_codes/unmanaged/convert_to_managed", + ["json" => (object) $request_payload] + ); + } + + public function delete(string $access_code_id, ?bool $sync = null): void + { + $request_payload = []; + + if ($access_code_id !== null) { + $request_payload["access_code_id"] = $access_code_id; + } + if ($sync !== null) { + $request_payload["sync"] = $sync; + } + + $this->seam->client->post("/access_codes/unmanaged/delete", [ + "json" => (object) $request_payload, + ]); + } + + public function get( + ?string $device_id = null, + ?string $access_code_id = null, + ?string $code = null + ): UnmanagedAccessCode { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($access_code_id !== null) { + $request_payload["access_code_id"] = $access_code_id; + } + if ($code !== null) { + $request_payload["code"] = $code; + } + + $res = $this->seam->client->post("/access_codes/unmanaged/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return UnmanagedAccessCode::from_json($json->access_code); + } + + public function list( + string $device_id, + ?string $user_identifier_key = null + ): array { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($user_identifier_key !== null) { + $request_payload["user_identifier_key"] = $user_identifier_key; + } + + $res = $this->seam->client->post("/access_codes/unmanaged/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => UnmanagedAccessCode::from_json($r), + $json->access_codes + ); + } + + public function update( + string $access_code_id, + bool $is_managed, + ?bool $allow_external_modification = null, + ?bool $is_external_modification_allowed = null, + ?bool $force = null + ): void { + $request_payload = []; + + if ($access_code_id !== null) { + $request_payload["access_code_id"] = $access_code_id; + } + if ($is_managed !== null) { + $request_payload["is_managed"] = $is_managed; + } + if ($allow_external_modification !== null) { + $request_payload[ + "allow_external_modification" + ] = $allow_external_modification; + } + if ($is_external_modification_allowed !== null) { + $request_payload[ + "is_external_modification_allowed" + ] = $is_external_modification_allowed; + } + if ($force !== null) { + $request_payload["force"] = $force; + } + + $this->seam->client->post("/access_codes/unmanaged/update", [ + "json" => (object) $request_payload, + ]); + } +} diff --git a/src/Routes/Clients/Acs.php b/src/Routes/Clients/Acs.php new file mode 100644 index 00000000..f19b9c76 --- /dev/null +++ b/src/Routes/Clients/Acs.php @@ -0,0 +1,26 @@ +seam = $seam; + $this->access_groups = new AcsAccessGroups($seam); + $this->credentials = new AcsCredentials($seam); + $this->encoders = new AcsEncoders($seam); + $this->entrances = new AcsEntrances($seam); + $this->systems = new AcsSystems($seam); + $this->users = new AcsUsers($seam); + } +} diff --git a/src/Routes/Clients/AcsAccessGroups.php b/src/Routes/Clients/AcsAccessGroups.php new file mode 100644 index 00000000..e1865387 --- /dev/null +++ b/src/Routes/Clients/AcsAccessGroups.php @@ -0,0 +1,131 @@ +seam = $seam; + } + + public function add_user( + string $acs_access_group_id, + string $acs_user_id + ): void { + $request_payload = []; + + if ($acs_access_group_id !== null) { + $request_payload["acs_access_group_id"] = $acs_access_group_id; + } + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + + $this->seam->client->post("/acs/access_groups/add_user", [ + "json" => (object) $request_payload, + ]); + } + + public function get(string $acs_access_group_id): AcsAccessGroup + { + $request_payload = []; + + if ($acs_access_group_id !== null) { + $request_payload["acs_access_group_id"] = $acs_access_group_id; + } + + $res = $this->seam->client->post("/acs/access_groups/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return AcsAccessGroup::from_json($json->acs_access_group); + } + + public function list( + ?string $acs_system_id = null, + ?string $acs_user_id = null + ): array { + $request_payload = []; + + if ($acs_system_id !== null) { + $request_payload["acs_system_id"] = $acs_system_id; + } + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + + $res = $this->seam->client->post("/acs/access_groups/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => AcsAccessGroup::from_json($r), + $json->acs_access_groups + ); + } + + public function list_accessible_entrances( + string $acs_access_group_id + ): array { + $request_payload = []; + + if ($acs_access_group_id !== null) { + $request_payload["acs_access_group_id"] = $acs_access_group_id; + } + + $res = $this->seam->client->post( + "/acs/access_groups/list_accessible_entrances", + ["json" => (object) $request_payload] + ); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => AcsEntrance::from_json($r), + $json->acs_entrances + ); + } + + public function list_users(string $acs_access_group_id): array + { + $request_payload = []; + + if ($acs_access_group_id !== null) { + $request_payload["acs_access_group_id"] = $acs_access_group_id; + } + + $res = $this->seam->client->post("/acs/access_groups/list_users", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map(fn($r) => AcsUser::from_json($r), $json->acs_users); + } + + public function remove_user( + string $acs_access_group_id, + string $acs_user_id + ): void { + $request_payload = []; + + if ($acs_access_group_id !== null) { + $request_payload["acs_access_group_id"] = $acs_access_group_id; + } + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + + $this->seam->client->post("/acs/access_groups/remove_user", [ + "json" => (object) $request_payload, + ]); + } +} diff --git a/src/Routes/Clients/AcsCredentials.php b/src/Routes/Clients/AcsCredentials.php new file mode 100644 index 00000000..bd1f6613 --- /dev/null +++ b/src/Routes/Clients/AcsCredentials.php @@ -0,0 +1,229 @@ +seam = $seam; + } + + public function assign(string $acs_user_id, string $acs_credential_id): void + { + $request_payload = []; + + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + if ($acs_credential_id !== null) { + $request_payload["acs_credential_id"] = $acs_credential_id; + } + + $this->seam->client->post("/acs/credentials/assign", [ + "json" => (object) $request_payload, + ]); + } + + public function create( + string $acs_user_id, + string $access_method, + ?string $credential_manager_acs_system_id = null, + ?string $code = null, + ?bool $is_multi_phone_sync_credential = null, + ?array $allowed_acs_entrance_ids = null, + mixed $visionline_metadata = null, + mixed $assa_abloy_vostio_metadata = null, + mixed $salto_space_metadata = null, + ?string $starts_at = null, + ?string $ends_at = null + ): AcsCredential { + $request_payload = []; + + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + if ($access_method !== null) { + $request_payload["access_method"] = $access_method; + } + if ($credential_manager_acs_system_id !== null) { + $request_payload[ + "credential_manager_acs_system_id" + ] = $credential_manager_acs_system_id; + } + if ($code !== null) { + $request_payload["code"] = $code; + } + if ($is_multi_phone_sync_credential !== null) { + $request_payload[ + "is_multi_phone_sync_credential" + ] = $is_multi_phone_sync_credential; + } + if ($allowed_acs_entrance_ids !== null) { + $request_payload[ + "allowed_acs_entrance_ids" + ] = $allowed_acs_entrance_ids; + } + if ($visionline_metadata !== null) { + $request_payload["visionline_metadata"] = $visionline_metadata; + } + if ($assa_abloy_vostio_metadata !== null) { + $request_payload[ + "assa_abloy_vostio_metadata" + ] = $assa_abloy_vostio_metadata; + } + if ($salto_space_metadata !== null) { + $request_payload["salto_space_metadata"] = $salto_space_metadata; + } + if ($starts_at !== null) { + $request_payload["starts_at"] = $starts_at; + } + if ($ends_at !== null) { + $request_payload["ends_at"] = $ends_at; + } + + $res = $this->seam->client->post("/acs/credentials/create", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return AcsCredential::from_json($json->acs_credential); + } + + public function delete(string $acs_credential_id): void + { + $request_payload = []; + + if ($acs_credential_id !== null) { + $request_payload["acs_credential_id"] = $acs_credential_id; + } + + $this->seam->client->post("/acs/credentials/delete", [ + "json" => (object) $request_payload, + ]); + } + + public function get(string $acs_credential_id): AcsCredential + { + $request_payload = []; + + if ($acs_credential_id !== null) { + $request_payload["acs_credential_id"] = $acs_credential_id; + } + + $res = $this->seam->client->post("/acs/credentials/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return AcsCredential::from_json($json->acs_credential); + } + + public function list( + ?string $acs_user_id = null, + ?string $acs_system_id = null, + ?string $user_identity_id = null, + ?float $limit = null, + ?string $created_before = null, + ?bool $is_multi_phone_sync_credential = null + ): array { + $request_payload = []; + + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + if ($acs_system_id !== null) { + $request_payload["acs_system_id"] = $acs_system_id; + } + if ($user_identity_id !== null) { + $request_payload["user_identity_id"] = $user_identity_id; + } + if ($limit !== null) { + $request_payload["limit"] = $limit; + } + if ($created_before !== null) { + $request_payload["created_before"] = $created_before; + } + if ($is_multi_phone_sync_credential !== null) { + $request_payload[ + "is_multi_phone_sync_credential" + ] = $is_multi_phone_sync_credential; + } + + $res = $this->seam->client->post("/acs/credentials/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => AcsCredential::from_json($r), + $json->acs_credentials + ); + } + + public function list_accessible_entrances(string $acs_credential_id): array + { + $request_payload = []; + + if ($acs_credential_id !== null) { + $request_payload["acs_credential_id"] = $acs_credential_id; + } + + $res = $this->seam->client->post( + "/acs/credentials/list_accessible_entrances", + ["json" => (object) $request_payload] + ); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => AcsEntrance::from_json($r), + $json->acs_entrances + ); + } + + public function unassign( + string $acs_user_id, + string $acs_credential_id + ): void { + $request_payload = []; + + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + if ($acs_credential_id !== null) { + $request_payload["acs_credential_id"] = $acs_credential_id; + } + + $this->seam->client->post("/acs/credentials/unassign", [ + "json" => (object) $request_payload, + ]); + } + + public function update( + string $acs_credential_id, + ?string $code = null, + ?string $ends_at = null + ): void { + $request_payload = []; + + if ($acs_credential_id !== null) { + $request_payload["acs_credential_id"] = $acs_credential_id; + } + if ($code !== null) { + $request_payload["code"] = $code; + } + if ($ends_at !== null) { + $request_payload["ends_at"] = $ends_at; + } + + $this->seam->client->post("/acs/credentials/update", [ + "json" => (object) $request_payload, + ]); + } +} diff --git a/src/Routes/Clients/AcsEncoders.php b/src/Routes/Clients/AcsEncoders.php new file mode 100644 index 00000000..bf374542 --- /dev/null +++ b/src/Routes/Clients/AcsEncoders.php @@ -0,0 +1,105 @@ +seam = $seam; + } + + public function encode_credential( + string $acs_encoder_id, + string $acs_credential_id, + bool $wait_for_action_attempt = true + ): ActionAttempt { + $request_payload = []; + + if ($acs_encoder_id !== null) { + $request_payload["acs_encoder_id"] = $acs_encoder_id; + } + if ($acs_credential_id !== null) { + $request_payload["acs_credential_id"] = $acs_credential_id; + } + + $res = $this->seam->client->post("/acs/encoders/encode_credential", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + if (!$wait_for_action_attempt) { + return ActionAttempt::from_json($json->action_attempt); + } + + $action_attempt = $this->seam->action_attempts->poll_until_ready( + $json->action_attempt->action_attempt_id + ); + + return $action_attempt; + } + + public function list( + ?string $acs_system_id = null, + ?float $limit = null, + ?array $acs_system_ids = null, + ?array $acs_encoder_ids = null + ): array { + $request_payload = []; + + if ($acs_system_id !== null) { + $request_payload["acs_system_id"] = $acs_system_id; + } + if ($limit !== null) { + $request_payload["limit"] = $limit; + } + if ($acs_system_ids !== null) { + $request_payload["acs_system_ids"] = $acs_system_ids; + } + if ($acs_encoder_ids !== null) { + $request_payload["acs_encoder_ids"] = $acs_encoder_ids; + } + + $res = $this->seam->client->post("/acs/encoders/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => AcsEncoder::from_json($r), + $json->acs_encoders + ); + } + + public function scan_credential( + string $acs_encoder_id, + bool $wait_for_action_attempt = true + ): ActionAttempt { + $request_payload = []; + + if ($acs_encoder_id !== null) { + $request_payload["acs_encoder_id"] = $acs_encoder_id; + } + + $res = $this->seam->client->post("/acs/encoders/scan_credential", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + if (!$wait_for_action_attempt) { + return ActionAttempt::from_json($json->action_attempt); + } + + $action_attempt = $this->seam->action_attempts->poll_until_ready( + $json->action_attempt->action_attempt_id + ); + + return $action_attempt; + } +} diff --git a/src/Routes/Clients/AcsEncodersSimulate.php b/src/Routes/Clients/AcsEncodersSimulate.php new file mode 100644 index 00000000..1e22d7e4 --- /dev/null +++ b/src/Routes/Clients/AcsEncodersSimulate.php @@ -0,0 +1,107 @@ +seam = $seam; + } + + public function next_credential_encode_will_fail( + string $acs_encoder_id, + ?string $error_code = null, + ?string $acs_credential_id = null + ): void { + $request_payload = []; + + if ($acs_encoder_id !== null) { + $request_payload["acs_encoder_id"] = $acs_encoder_id; + } + if ($error_code !== null) { + $request_payload["error_code"] = $error_code; + } + if ($acs_credential_id !== null) { + $request_payload["acs_credential_id"] = $acs_credential_id; + } + + $this->seam->client->post( + "/acs/encoders/simulate/next_credential_encode_will_fail", + ["json" => (object) $request_payload] + ); + } + + public function next_credential_encode_will_succeed( + string $acs_encoder_id, + ?string $scenario = null + ): void { + $request_payload = []; + + if ($acs_encoder_id !== null) { + $request_payload["acs_encoder_id"] = $acs_encoder_id; + } + if ($scenario !== null) { + $request_payload["scenario"] = $scenario; + } + + $this->seam->client->post( + "/acs/encoders/simulate/next_credential_encode_will_succeed", + ["json" => (object) $request_payload] + ); + } + + public function next_credential_scan_will_fail( + string $acs_encoder_id, + ?string $error_code = null, + ?string $acs_credential_id_on_seam = null + ): void { + $request_payload = []; + + if ($acs_encoder_id !== null) { + $request_payload["acs_encoder_id"] = $acs_encoder_id; + } + if ($error_code !== null) { + $request_payload["error_code"] = $error_code; + } + if ($acs_credential_id_on_seam !== null) { + $request_payload[ + "acs_credential_id_on_seam" + ] = $acs_credential_id_on_seam; + } + + $this->seam->client->post( + "/acs/encoders/simulate/next_credential_scan_will_fail", + ["json" => (object) $request_payload] + ); + } + + public function next_credential_scan_will_succeed( + string $acs_encoder_id, + ?string $scenario = null, + ?string $acs_credential_id_on_seam = null + ): void { + $request_payload = []; + + if ($acs_encoder_id !== null) { + $request_payload["acs_encoder_id"] = $acs_encoder_id; + } + if ($scenario !== null) { + $request_payload["scenario"] = $scenario; + } + if ($acs_credential_id_on_seam !== null) { + $request_payload[ + "acs_credential_id_on_seam" + ] = $acs_credential_id_on_seam; + } + + $this->seam->client->post( + "/acs/encoders/simulate/next_credential_scan_will_succeed", + ["json" => (object) $request_payload] + ); + } +} diff --git a/src/Routes/Clients/AcsEntrances.php b/src/Routes/Clients/AcsEntrances.php new file mode 100644 index 00000000..75373d57 --- /dev/null +++ b/src/Routes/Clients/AcsEntrances.php @@ -0,0 +1,100 @@ +seam = $seam; + } + + public function get(string $acs_entrance_id): AcsEntrance + { + $request_payload = []; + + if ($acs_entrance_id !== null) { + $request_payload["acs_entrance_id"] = $acs_entrance_id; + } + + $res = $this->seam->client->post("/acs/entrances/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return AcsEntrance::from_json($json->acs_entrance); + } + + public function grant_access( + string $acs_entrance_id, + string $acs_user_id + ): void { + $request_payload = []; + + if ($acs_entrance_id !== null) { + $request_payload["acs_entrance_id"] = $acs_entrance_id; + } + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + + $this->seam->client->post("/acs/entrances/grant_access", [ + "json" => (object) $request_payload, + ]); + } + + public function list( + ?string $acs_system_id = null, + ?string $acs_credential_id = null + ): array { + $request_payload = []; + + if ($acs_system_id !== null) { + $request_payload["acs_system_id"] = $acs_system_id; + } + if ($acs_credential_id !== null) { + $request_payload["acs_credential_id"] = $acs_credential_id; + } + + $res = $this->seam->client->post("/acs/entrances/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => AcsEntrance::from_json($r), + $json->acs_entrances + ); + } + + public function list_credentials_with_access( + string $acs_entrance_id, + ?array $include_if = null + ): array { + $request_payload = []; + + if ($acs_entrance_id !== null) { + $request_payload["acs_entrance_id"] = $acs_entrance_id; + } + if ($include_if !== null) { + $request_payload["include_if"] = $include_if; + } + + $res = $this->seam->client->post( + "/acs/entrances/list_credentials_with_access", + ["json" => (object) $request_payload] + ); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => AcsCredential::from_json($r), + $json->acs_credentials + ); + } +} diff --git a/src/Routes/Clients/AcsSystems.php b/src/Routes/Clients/AcsSystems.php new file mode 100644 index 00000000..012120c2 --- /dev/null +++ b/src/Routes/Clients/AcsSystems.php @@ -0,0 +1,72 @@ +seam = $seam; + } + + public function get(string $acs_system_id): AcsSystem + { + $request_payload = []; + + if ($acs_system_id !== null) { + $request_payload["acs_system_id"] = $acs_system_id; + } + + $res = $this->seam->client->post("/acs/systems/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return AcsSystem::from_json($json->acs_system); + } + + public function list(?string $connected_account_id = null): array + { + $request_payload = []; + + if ($connected_account_id !== null) { + $request_payload["connected_account_id"] = $connected_account_id; + } + + $res = $this->seam->client->post("/acs/systems/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => AcsSystem::from_json($r), + $json->acs_systems + ); + } + + public function list_compatible_credential_manager_acs_systems( + string $acs_system_id + ): array { + $request_payload = []; + + if ($acs_system_id !== null) { + $request_payload["acs_system_id"] = $acs_system_id; + } + + $res = $this->seam->client->post( + "/acs/systems/list_compatible_credential_manager_acs_systems", + ["json" => (object) $request_payload] + ); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => AcsSystem::from_json($r), + $json->acs_systems + ); + } +} diff --git a/src/Routes/Clients/AcsUsers.php b/src/Routes/Clients/AcsUsers.php new file mode 100644 index 00000000..07a088e8 --- /dev/null +++ b/src/Routes/Clients/AcsUsers.php @@ -0,0 +1,273 @@ +seam = $seam; + } + + public function add_to_access_group( + string $acs_user_id, + string $acs_access_group_id + ): void { + $request_payload = []; + + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + if ($acs_access_group_id !== null) { + $request_payload["acs_access_group_id"] = $acs_access_group_id; + } + + $this->seam->client->post("/acs/users/add_to_access_group", [ + "json" => (object) $request_payload, + ]); + } + + public function create( + string $full_name, + string $acs_system_id, + ?array $acs_access_group_ids = null, + ?string $user_identity_id = null, + mixed $access_schedule = null, + ?string $email = null, + ?string $phone_number = null, + ?string $email_address = null + ): AcsUser { + $request_payload = []; + + if ($full_name !== null) { + $request_payload["full_name"] = $full_name; + } + if ($acs_system_id !== null) { + $request_payload["acs_system_id"] = $acs_system_id; + } + if ($acs_access_group_ids !== null) { + $request_payload["acs_access_group_ids"] = $acs_access_group_ids; + } + if ($user_identity_id !== null) { + $request_payload["user_identity_id"] = $user_identity_id; + } + if ($access_schedule !== null) { + $request_payload["access_schedule"] = $access_schedule; + } + if ($email !== null) { + $request_payload["email"] = $email; + } + if ($phone_number !== null) { + $request_payload["phone_number"] = $phone_number; + } + if ($email_address !== null) { + $request_payload["email_address"] = $email_address; + } + + $res = $this->seam->client->post("/acs/users/create", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return AcsUser::from_json($json->acs_user); + } + + public function delete(string $acs_user_id): void + { + $request_payload = []; + + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + + $this->seam->client->post("/acs/users/delete", [ + "json" => (object) $request_payload, + ]); + } + + public function get(string $acs_user_id): AcsUser + { + $request_payload = []; + + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + + $res = $this->seam->client->post("/acs/users/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return AcsUser::from_json($json->acs_user); + } + + public function list( + ?string $user_identity_id = null, + ?string $user_identity_phone_number = null, + ?string $user_identity_email_address = null, + ?string $acs_system_id = null, + ?string $search = null, + mixed $limit = null, + ?string $created_before = null, + ?string $page_cursor = null + ): array { + $request_payload = []; + + if ($user_identity_id !== null) { + $request_payload["user_identity_id"] = $user_identity_id; + } + if ($user_identity_phone_number !== null) { + $request_payload[ + "user_identity_phone_number" + ] = $user_identity_phone_number; + } + if ($user_identity_email_address !== null) { + $request_payload[ + "user_identity_email_address" + ] = $user_identity_email_address; + } + if ($acs_system_id !== null) { + $request_payload["acs_system_id"] = $acs_system_id; + } + if ($search !== null) { + $request_payload["search"] = $search; + } + if ($limit !== null) { + $request_payload["limit"] = $limit; + } + if ($created_before !== null) { + $request_payload["created_before"] = $created_before; + } + if ($page_cursor !== null) { + $request_payload["page_cursor"] = $page_cursor; + } + + $res = $this->seam->client->post("/acs/users/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map(fn($r) => AcsUser::from_json($r), $json->acs_users); + } + + public function list_accessible_entrances(string $acs_user_id): array + { + $request_payload = []; + + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + + $res = $this->seam->client->post( + "/acs/users/list_accessible_entrances", + ["json" => (object) $request_payload] + ); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => AcsEntrance::from_json($r), + $json->acs_entrances + ); + } + + public function remove_from_access_group( + string $acs_user_id, + string $acs_access_group_id + ): void { + $request_payload = []; + + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + if ($acs_access_group_id !== null) { + $request_payload["acs_access_group_id"] = $acs_access_group_id; + } + + $this->seam->client->post("/acs/users/remove_from_access_group", [ + "json" => (object) $request_payload, + ]); + } + + public function revoke_access_to_all_entrances(string $acs_user_id): void + { + $request_payload = []; + + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + + $this->seam->client->post("/acs/users/revoke_access_to_all_entrances", [ + "json" => (object) $request_payload, + ]); + } + + public function suspend(string $acs_user_id): void + { + $request_payload = []; + + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + + $this->seam->client->post("/acs/users/suspend", [ + "json" => (object) $request_payload, + ]); + } + + public function unsuspend(string $acs_user_id): void + { + $request_payload = []; + + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + + $this->seam->client->post("/acs/users/unsuspend", [ + "json" => (object) $request_payload, + ]); + } + + public function update( + string $acs_user_id, + mixed $access_schedule = null, + ?string $full_name = null, + ?string $email = null, + ?string $phone_number = null, + ?string $email_address = null, + ?string $hid_acs_system_id = null + ): void { + $request_payload = []; + + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + if ($access_schedule !== null) { + $request_payload["access_schedule"] = $access_schedule; + } + if ($full_name !== null) { + $request_payload["full_name"] = $full_name; + } + if ($email !== null) { + $request_payload["email"] = $email; + } + if ($phone_number !== null) { + $request_payload["phone_number"] = $phone_number; + } + if ($email_address !== null) { + $request_payload["email_address"] = $email_address; + } + if ($hid_acs_system_id !== null) { + $request_payload["hid_acs_system_id"] = $hid_acs_system_id; + } + + $this->seam->client->post("/acs/users/update", [ + "json" => (object) $request_payload, + ]); + } +} diff --git a/src/Routes/Clients/ActionAttempts.php b/src/Routes/Clients/ActionAttempts.php new file mode 100644 index 00000000..0fc0d0a3 --- /dev/null +++ b/src/Routes/Clients/ActionAttempts.php @@ -0,0 +1,79 @@ +seam = $seam; + } + + public function get(string $action_attempt_id): ActionAttempt + { + $request_payload = []; + + if ($action_attempt_id !== null) { + $request_payload["action_attempt_id"] = $action_attempt_id; + } + + $res = $this->seam->client->post("/action_attempts/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return ActionAttempt::from_json($json->action_attempt); + } + + public function list(array $action_attempt_ids): array + { + $request_payload = []; + + if ($action_attempt_ids !== null) { + $request_payload["action_attempt_ids"] = $action_attempt_ids; + } + + $res = $this->seam->client->post("/action_attempts/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => ActionAttempt::from_json($r), + $json->action_attempts + ); + } + public function poll_until_ready( + string $action_attempt_id, + float $timeout = 20.0 + ): ActionAttempt { + $seam = $this->seam; + $time_waiting = 0.0; + $polling_interval = 0.4; + $action_attempt = $seam->action_attempts->get($action_attempt_id); + + while ($action_attempt->status == "pending") { + $action_attempt = $seam->action_attempts->get( + $action_attempt->action_attempt_id + ); + if ($time_waiting > $timeout) { + throw new ActionAttemptTimeoutError($action_attempt, $timeout); + } + $time_waiting += $polling_interval; + usleep($polling_interval * 1000000); + } + + if ($action_attempt->status == "error") { + throw new ActionAttemptFailedError($action_attempt); + } + + return $action_attempt; + } +} diff --git a/src/Routes/Clients/Bridges.php b/src/Routes/Clients/Bridges.php new file mode 100644 index 00000000..9290f607 --- /dev/null +++ b/src/Routes/Clients/Bridges.php @@ -0,0 +1,37 @@ +seam = $seam; + } + + public function get(string $bridge_id): void + { + $request_payload = []; + + if ($bridge_id !== null) { + $request_payload["bridge_id"] = $bridge_id; + } + + $this->seam->client->post("/bridges/get", [ + "json" => (object) $request_payload, + ]); + } + + public function list(): void + { + $request_payload = []; + + $this->seam->client->post("/bridges/list", [ + "json" => (object) $request_payload, + ]); + } +} diff --git a/src/Routes/Clients/ClientSessions.php b/src/Routes/Clients/ClientSessions.php new file mode 100644 index 00000000..c95d895e --- /dev/null +++ b/src/Routes/Clients/ClientSessions.php @@ -0,0 +1,197 @@ +seam = $seam; + } + + public function create( + ?string $user_identifier_key = null, + ?array $connect_webview_ids = null, + ?array $connected_account_ids = null, + ?array $user_identity_ids = null, + ?string $expires_at = null + ): ClientSession { + $request_payload = []; + + if ($user_identifier_key !== null) { + $request_payload["user_identifier_key"] = $user_identifier_key; + } + if ($connect_webview_ids !== null) { + $request_payload["connect_webview_ids"] = $connect_webview_ids; + } + if ($connected_account_ids !== null) { + $request_payload["connected_account_ids"] = $connected_account_ids; + } + if ($user_identity_ids !== null) { + $request_payload["user_identity_ids"] = $user_identity_ids; + } + if ($expires_at !== null) { + $request_payload["expires_at"] = $expires_at; + } + + $res = $this->seam->client->post("/client_sessions/create", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return ClientSession::from_json($json->client_session); + } + + public function delete(string $client_session_id): void + { + $request_payload = []; + + if ($client_session_id !== null) { + $request_payload["client_session_id"] = $client_session_id; + } + + $this->seam->client->post("/client_sessions/delete", [ + "json" => (object) $request_payload, + ]); + } + + public function get( + ?string $client_session_id = null, + ?string $user_identifier_key = null + ): ClientSession { + $request_payload = []; + + if ($client_session_id !== null) { + $request_payload["client_session_id"] = $client_session_id; + } + if ($user_identifier_key !== null) { + $request_payload["user_identifier_key"] = $user_identifier_key; + } + + $res = $this->seam->client->post("/client_sessions/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return ClientSession::from_json($json->client_session); + } + + public function get_or_create( + ?string $user_identifier_key = null, + ?array $connect_webview_ids = null, + ?array $connected_account_ids = null, + ?array $user_identity_ids = null, + ?string $expires_at = null + ): ClientSession { + $request_payload = []; + + if ($user_identifier_key !== null) { + $request_payload["user_identifier_key"] = $user_identifier_key; + } + if ($connect_webview_ids !== null) { + $request_payload["connect_webview_ids"] = $connect_webview_ids; + } + if ($connected_account_ids !== null) { + $request_payload["connected_account_ids"] = $connected_account_ids; + } + if ($user_identity_ids !== null) { + $request_payload["user_identity_ids"] = $user_identity_ids; + } + if ($expires_at !== null) { + $request_payload["expires_at"] = $expires_at; + } + + $res = $this->seam->client->post("/client_sessions/get_or_create", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return ClientSession::from_json($json->client_session); + } + + public function grant_access( + ?string $client_session_id = null, + ?string $user_identifier_key = null, + ?array $connected_account_ids = null, + ?array $connect_webview_ids = null, + ?array $user_identity_ids = null + ): void { + $request_payload = []; + + if ($client_session_id !== null) { + $request_payload["client_session_id"] = $client_session_id; + } + if ($user_identifier_key !== null) { + $request_payload["user_identifier_key"] = $user_identifier_key; + } + if ($connected_account_ids !== null) { + $request_payload["connected_account_ids"] = $connected_account_ids; + } + if ($connect_webview_ids !== null) { + $request_payload["connect_webview_ids"] = $connect_webview_ids; + } + if ($user_identity_ids !== null) { + $request_payload["user_identity_ids"] = $user_identity_ids; + } + + $this->seam->client->post("/client_sessions/grant_access", [ + "json" => (object) $request_payload, + ]); + } + + public function list( + ?string $client_session_id = null, + ?string $user_identifier_key = null, + ?string $connect_webview_id = null, + ?bool $without_user_identifier_key = null, + ?string $user_identity_id = null + ): array { + $request_payload = []; + + if ($client_session_id !== null) { + $request_payload["client_session_id"] = $client_session_id; + } + if ($user_identifier_key !== null) { + $request_payload["user_identifier_key"] = $user_identifier_key; + } + if ($connect_webview_id !== null) { + $request_payload["connect_webview_id"] = $connect_webview_id; + } + if ($without_user_identifier_key !== null) { + $request_payload[ + "without_user_identifier_key" + ] = $without_user_identifier_key; + } + if ($user_identity_id !== null) { + $request_payload["user_identity_id"] = $user_identity_id; + } + + $res = $this->seam->client->post("/client_sessions/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => ClientSession::from_json($r), + $json->client_sessions + ); + } + + public function revoke(string $client_session_id): void + { + $request_payload = []; + + if ($client_session_id !== null) { + $request_payload["client_session_id"] = $client_session_id; + } + + $this->seam->client->post("/client_sessions/revoke", [ + "json" => (object) $request_payload, + ]); + } +} diff --git a/src/Routes/Clients/ConnectWebviews.php b/src/Routes/Clients/ConnectWebviews.php new file mode 100644 index 00000000..37389a0a --- /dev/null +++ b/src/Routes/Clients/ConnectWebviews.php @@ -0,0 +1,124 @@ +seam = $seam; + } + + public function create( + ?string $device_selection_mode = null, + ?string $custom_redirect_url = null, + ?string $custom_redirect_failure_url = null, + ?array $accepted_providers = null, + ?string $provider_category = null, + mixed $custom_metadata = null, + ?bool $automatically_manage_new_devices = null, + ?bool $wait_for_device_creation = null + ): ConnectWebview { + $request_payload = []; + + if ($device_selection_mode !== null) { + $request_payload["device_selection_mode"] = $device_selection_mode; + } + if ($custom_redirect_url !== null) { + $request_payload["custom_redirect_url"] = $custom_redirect_url; + } + if ($custom_redirect_failure_url !== null) { + $request_payload[ + "custom_redirect_failure_url" + ] = $custom_redirect_failure_url; + } + if ($accepted_providers !== null) { + $request_payload["accepted_providers"] = $accepted_providers; + } + if ($provider_category !== null) { + $request_payload["provider_category"] = $provider_category; + } + if ($custom_metadata !== null) { + $request_payload["custom_metadata"] = $custom_metadata; + } + if ($automatically_manage_new_devices !== null) { + $request_payload[ + "automatically_manage_new_devices" + ] = $automatically_manage_new_devices; + } + if ($wait_for_device_creation !== null) { + $request_payload[ + "wait_for_device_creation" + ] = $wait_for_device_creation; + } + + $res = $this->seam->client->post("/connect_webviews/create", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return ConnectWebview::from_json($json->connect_webview); + } + + public function delete(string $connect_webview_id): void + { + $request_payload = []; + + if ($connect_webview_id !== null) { + $request_payload["connect_webview_id"] = $connect_webview_id; + } + + $this->seam->client->post("/connect_webviews/delete", [ + "json" => (object) $request_payload, + ]); + } + + public function get(string $connect_webview_id): ConnectWebview + { + $request_payload = []; + + if ($connect_webview_id !== null) { + $request_payload["connect_webview_id"] = $connect_webview_id; + } + + $res = $this->seam->client->post("/connect_webviews/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return ConnectWebview::from_json($json->connect_webview); + } + + public function list( + ?string $user_identifier_key = null, + mixed $custom_metadata_has = null, + ?float $limit = null + ): array { + $request_payload = []; + + if ($user_identifier_key !== null) { + $request_payload["user_identifier_key"] = $user_identifier_key; + } + if ($custom_metadata_has !== null) { + $request_payload["custom_metadata_has"] = $custom_metadata_has; + } + if ($limit !== null) { + $request_payload["limit"] = $limit; + } + + $res = $this->seam->client->post("/connect_webviews/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => ConnectWebview::from_json($r), + $json->connect_webviews + ); + } +} diff --git a/src/Routes/Clients/ConnectedAccounts.php b/src/Routes/Clients/ConnectedAccounts.php new file mode 100644 index 00000000..b2738601 --- /dev/null +++ b/src/Routes/Clients/ConnectedAccounts.php @@ -0,0 +1,103 @@ +seam = $seam; + } + + public function delete( + string $connected_account_id, + ?bool $sync = null + ): void { + $request_payload = []; + + if ($connected_account_id !== null) { + $request_payload["connected_account_id"] = $connected_account_id; + } + if ($sync !== null) { + $request_payload["sync"] = $sync; + } + + $this->seam->client->post("/connected_accounts/delete", [ + "json" => (object) $request_payload, + ]); + } + + public function get( + ?string $connected_account_id = null, + ?string $email = null + ): ConnectedAccount { + $request_payload = []; + + if ($connected_account_id !== null) { + $request_payload["connected_account_id"] = $connected_account_id; + } + if ($email !== null) { + $request_payload["email"] = $email; + } + + $res = $this->seam->client->post("/connected_accounts/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return ConnectedAccount::from_json($json->connected_account); + } + + public function list( + ?string $user_identifier_key = null, + mixed $custom_metadata_has = null + ): array { + $request_payload = []; + + if ($user_identifier_key !== null) { + $request_payload["user_identifier_key"] = $user_identifier_key; + } + if ($custom_metadata_has !== null) { + $request_payload["custom_metadata_has"] = $custom_metadata_has; + } + + $res = $this->seam->client->post("/connected_accounts/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => ConnectedAccount::from_json($r), + $json->connected_accounts + ); + } + + public function update( + string $connected_account_id, + ?bool $automatically_manage_new_devices = null, + mixed $custom_metadata = null + ): void { + $request_payload = []; + + if ($connected_account_id !== null) { + $request_payload["connected_account_id"] = $connected_account_id; + } + if ($automatically_manage_new_devices !== null) { + $request_payload[ + "automatically_manage_new_devices" + ] = $automatically_manage_new_devices; + } + if ($custom_metadata !== null) { + $request_payload["custom_metadata"] = $custom_metadata; + } + + $this->seam->client->post("/connected_accounts/update", [ + "json" => (object) $request_payload, + ]); + } +} diff --git a/src/Routes/Clients/Devices.php b/src/Routes/Clients/Devices.php new file mode 100644 index 00000000..426d76ca --- /dev/null +++ b/src/Routes/Clients/Devices.php @@ -0,0 +1,158 @@ +seam = $seam; + $this->simulate = new DevicesSimulate($seam); + $this->unmanaged = new DevicesUnmanaged($seam); + } + + public function get(?string $device_id = null, ?string $name = null): Device + { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($name !== null) { + $request_payload["name"] = $name; + } + + $res = $this->seam->client->post("/devices/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return Device::from_json($json->device); + } + + public function list( + ?string $connected_account_id = null, + ?array $connected_account_ids = null, + ?string $connect_webview_id = null, + ?string $device_type = null, + ?array $device_types = null, + ?string $manufacturer = null, + ?array $device_ids = null, + ?float $limit = null, + ?string $created_before = null, + ?string $user_identifier_key = null, + mixed $custom_metadata_has = null, + ?array $include_if = null, + ?array $exclude_if = null, + ?string $unstable_location_id = null + ): array { + $request_payload = []; + + if ($connected_account_id !== null) { + $request_payload["connected_account_id"] = $connected_account_id; + } + if ($connected_account_ids !== null) { + $request_payload["connected_account_ids"] = $connected_account_ids; + } + if ($connect_webview_id !== null) { + $request_payload["connect_webview_id"] = $connect_webview_id; + } + if ($device_type !== null) { + $request_payload["device_type"] = $device_type; + } + if ($device_types !== null) { + $request_payload["device_types"] = $device_types; + } + if ($manufacturer !== null) { + $request_payload["manufacturer"] = $manufacturer; + } + if ($device_ids !== null) { + $request_payload["device_ids"] = $device_ids; + } + if ($limit !== null) { + $request_payload["limit"] = $limit; + } + if ($created_before !== null) { + $request_payload["created_before"] = $created_before; + } + if ($user_identifier_key !== null) { + $request_payload["user_identifier_key"] = $user_identifier_key; + } + if ($custom_metadata_has !== null) { + $request_payload["custom_metadata_has"] = $custom_metadata_has; + } + if ($include_if !== null) { + $request_payload["include_if"] = $include_if; + } + if ($exclude_if !== null) { + $request_payload["exclude_if"] = $exclude_if; + } + if ($unstable_location_id !== null) { + $request_payload["unstable_location_id"] = $unstable_location_id; + } + + $res = $this->seam->client->post("/devices/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map(fn($r) => Device::from_json($r), $json->devices); + } + + public function list_device_providers( + ?string $provider_category = null + ): array { + $request_payload = []; + + if ($provider_category !== null) { + $request_payload["provider_category"] = $provider_category; + } + + $res = $this->seam->client->post("/devices/list_device_providers", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => DeviceProvider::from_json($r), + $json->device_providers + ); + } + + public function update( + string $device_id, + mixed $properties = null, + ?string $name = null, + ?bool $is_managed = null, + mixed $custom_metadata = null + ): void { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($properties !== null) { + $request_payload["properties"] = $properties; + } + if ($name !== null) { + $request_payload["name"] = $name; + } + if ($is_managed !== null) { + $request_payload["is_managed"] = $is_managed; + } + if ($custom_metadata !== null) { + $request_payload["custom_metadata"] = $custom_metadata; + } + + $this->seam->client->post("/devices/update", [ + "json" => (object) $request_payload, + ]); + } +} diff --git a/src/Routes/Clients/DevicesSimulate.php b/src/Routes/Clients/DevicesSimulate.php new file mode 100644 index 00000000..afe36f86 --- /dev/null +++ b/src/Routes/Clients/DevicesSimulate.php @@ -0,0 +1,54 @@ +seam = $seam; + } + + public function connect(string $device_id): void + { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + + $this->seam->client->post("/devices/simulate/connect", [ + "json" => (object) $request_payload, + ]); + } + + public function disconnect(string $device_id): void + { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + + $this->seam->client->post("/devices/simulate/disconnect", [ + "json" => (object) $request_payload, + ]); + } + + public function remove(string $device_id): void + { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + + $this->seam->client->post("/devices/simulate/remove", [ + "json" => (object) $request_payload, + ]); + } +} diff --git a/src/Routes/Clients/DevicesUnmanaged.php b/src/Routes/Clients/DevicesUnmanaged.php new file mode 100644 index 00000000..76d7e559 --- /dev/null +++ b/src/Routes/Clients/DevicesUnmanaged.php @@ -0,0 +1,125 @@ +seam = $seam; + } + + public function get( + ?string $device_id = null, + ?string $name = null + ): UnmanagedDevice { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($name !== null) { + $request_payload["name"] = $name; + } + + $res = $this->seam->client->post("/devices/unmanaged/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return UnmanagedDevice::from_json($json->device); + } + + public function list( + ?string $connected_account_id = null, + ?array $connected_account_ids = null, + ?string $connect_webview_id = null, + ?string $device_type = null, + ?array $device_types = null, + ?string $manufacturer = null, + ?array $device_ids = null, + ?float $limit = null, + ?string $created_before = null, + ?string $user_identifier_key = null, + mixed $custom_metadata_has = null, + ?array $include_if = null, + ?array $exclude_if = null, + ?string $unstable_location_id = null + ): array { + $request_payload = []; + + if ($connected_account_id !== null) { + $request_payload["connected_account_id"] = $connected_account_id; + } + if ($connected_account_ids !== null) { + $request_payload["connected_account_ids"] = $connected_account_ids; + } + if ($connect_webview_id !== null) { + $request_payload["connect_webview_id"] = $connect_webview_id; + } + if ($device_type !== null) { + $request_payload["device_type"] = $device_type; + } + if ($device_types !== null) { + $request_payload["device_types"] = $device_types; + } + if ($manufacturer !== null) { + $request_payload["manufacturer"] = $manufacturer; + } + if ($device_ids !== null) { + $request_payload["device_ids"] = $device_ids; + } + if ($limit !== null) { + $request_payload["limit"] = $limit; + } + if ($created_before !== null) { + $request_payload["created_before"] = $created_before; + } + if ($user_identifier_key !== null) { + $request_payload["user_identifier_key"] = $user_identifier_key; + } + if ($custom_metadata_has !== null) { + $request_payload["custom_metadata_has"] = $custom_metadata_has; + } + if ($include_if !== null) { + $request_payload["include_if"] = $include_if; + } + if ($exclude_if !== null) { + $request_payload["exclude_if"] = $exclude_if; + } + if ($unstable_location_id !== null) { + $request_payload["unstable_location_id"] = $unstable_location_id; + } + + $res = $this->seam->client->post("/devices/unmanaged/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => UnmanagedDevice::from_json($r), + $json->devices + ); + } + + public function update(string $device_id, bool $is_managed): void + { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($is_managed !== null) { + $request_payload["is_managed"] = $is_managed; + } + + $this->seam->client->post("/devices/unmanaged/update", [ + "json" => (object) $request_payload, + ]); + } +} diff --git a/src/Routes/Clients/Events.php b/src/Routes/Clients/Events.php new file mode 100644 index 00000000..c1d11fd8 --- /dev/null +++ b/src/Routes/Clients/Events.php @@ -0,0 +1,114 @@ +seam = $seam; + } + + public function get( + ?string $event_id = null, + ?string $event_type = null, + ?string $device_id = null + ): Event { + $request_payload = []; + + if ($event_id !== null) { + $request_payload["event_id"] = $event_id; + } + if ($event_type !== null) { + $request_payload["event_type"] = $event_type; + } + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + + $res = $this->seam->client->post("/events/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return Event::from_json($json->event); + } + + public function list( + ?float $unstable_offset = null, + ?string $since = null, + ?array $between = null, + ?string $device_id = null, + ?array $device_ids = null, + ?string $acs_system_id = null, + ?array $acs_system_ids = null, + ?string $access_code_id = null, + ?array $access_code_ids = null, + ?string $event_type = null, + ?array $event_types = null, + ?string $connected_account_id = null, + ?string $connect_webview_id = null, + ?float $limit = null, + ?array $event_ids = null + ): array { + $request_payload = []; + + if ($unstable_offset !== null) { + $request_payload["unstable_offset"] = $unstable_offset; + } + if ($since !== null) { + $request_payload["since"] = $since; + } + if ($between !== null) { + $request_payload["between"] = $between; + } + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($device_ids !== null) { + $request_payload["device_ids"] = $device_ids; + } + if ($acs_system_id !== null) { + $request_payload["acs_system_id"] = $acs_system_id; + } + if ($acs_system_ids !== null) { + $request_payload["acs_system_ids"] = $acs_system_ids; + } + if ($access_code_id !== null) { + $request_payload["access_code_id"] = $access_code_id; + } + if ($access_code_ids !== null) { + $request_payload["access_code_ids"] = $access_code_ids; + } + if ($event_type !== null) { + $request_payload["event_type"] = $event_type; + } + if ($event_types !== null) { + $request_payload["event_types"] = $event_types; + } + if ($connected_account_id !== null) { + $request_payload["connected_account_id"] = $connected_account_id; + } + if ($connect_webview_id !== null) { + $request_payload["connect_webview_id"] = $connect_webview_id; + } + if ($limit !== null) { + $request_payload["limit"] = $limit; + } + if ($event_ids !== null) { + $request_payload["event_ids"] = $event_ids; + } + + $res = $this->seam->client->post("/events/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map(fn($r) => Event::from_json($r), $json->events); + } +} diff --git a/src/Routes/Clients/Locks.php b/src/Routes/Clients/Locks.php new file mode 100644 index 00000000..b10d2c50 --- /dev/null +++ b/src/Routes/Clients/Locks.php @@ -0,0 +1,165 @@ +seam = $seam; + } + + public function get(?string $device_id = null, ?string $name = null): Device + { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($name !== null) { + $request_payload["name"] = $name; + } + + $res = $this->seam->client->post("/locks/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return Device::from_json($json->device); + } + + public function list( + ?string $connected_account_id = null, + ?array $connected_account_ids = null, + ?string $connect_webview_id = null, + ?string $device_type = null, + ?array $device_types = null, + ?string $manufacturer = null, + ?array $device_ids = null, + ?float $limit = null, + ?string $created_before = null, + ?string $user_identifier_key = null, + mixed $custom_metadata_has = null, + ?array $include_if = null, + ?array $exclude_if = null, + ?string $unstable_location_id = null + ): array { + $request_payload = []; + + if ($connected_account_id !== null) { + $request_payload["connected_account_id"] = $connected_account_id; + } + if ($connected_account_ids !== null) { + $request_payload["connected_account_ids"] = $connected_account_ids; + } + if ($connect_webview_id !== null) { + $request_payload["connect_webview_id"] = $connect_webview_id; + } + if ($device_type !== null) { + $request_payload["device_type"] = $device_type; + } + if ($device_types !== null) { + $request_payload["device_types"] = $device_types; + } + if ($manufacturer !== null) { + $request_payload["manufacturer"] = $manufacturer; + } + if ($device_ids !== null) { + $request_payload["device_ids"] = $device_ids; + } + if ($limit !== null) { + $request_payload["limit"] = $limit; + } + if ($created_before !== null) { + $request_payload["created_before"] = $created_before; + } + if ($user_identifier_key !== null) { + $request_payload["user_identifier_key"] = $user_identifier_key; + } + if ($custom_metadata_has !== null) { + $request_payload["custom_metadata_has"] = $custom_metadata_has; + } + if ($include_if !== null) { + $request_payload["include_if"] = $include_if; + } + if ($exclude_if !== null) { + $request_payload["exclude_if"] = $exclude_if; + } + if ($unstable_location_id !== null) { + $request_payload["unstable_location_id"] = $unstable_location_id; + } + + $res = $this->seam->client->post("/locks/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map(fn($r) => Device::from_json($r), $json->devices); + } + + public function lock_door( + string $device_id, + ?bool $sync = null, + bool $wait_for_action_attempt = true + ): ActionAttempt { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($sync !== null) { + $request_payload["sync"] = $sync; + } + + $res = $this->seam->client->post("/locks/lock_door", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + if (!$wait_for_action_attempt) { + return ActionAttempt::from_json($json->action_attempt); + } + + $action_attempt = $this->seam->action_attempts->poll_until_ready( + $json->action_attempt->action_attempt_id + ); + + return $action_attempt; + } + + public function unlock_door( + string $device_id, + ?bool $sync = null, + bool $wait_for_action_attempt = true + ): ActionAttempt { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($sync !== null) { + $request_payload["sync"] = $sync; + } + + $res = $this->seam->client->post("/locks/unlock_door", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + if (!$wait_for_action_attempt) { + return ActionAttempt::from_json($json->action_attempt); + } + + $action_attempt = $this->seam->action_attempts->poll_until_ready( + $json->action_attempt->action_attempt_id + ); + + return $action_attempt; + } +} diff --git a/src/Routes/Clients/Networks.php b/src/Routes/Clients/Networks.php new file mode 100644 index 00000000..5812f44e --- /dev/null +++ b/src/Routes/Clients/Networks.php @@ -0,0 +1,44 @@ +seam = $seam; + } + + public function get(string $network_id): Network + { + $request_payload = []; + + if ($network_id !== null) { + $request_payload["network_id"] = $network_id; + } + + $res = $this->seam->client->post("/networks/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return Network::from_json($json->network); + } + + public function list(): array + { + $request_payload = []; + + $res = $this->seam->client->post("/networks/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map(fn($r) => Network::from_json($r), $json->networks); + } +} diff --git a/src/Routes/Clients/NoiseSensors.php b/src/Routes/Clients/NoiseSensors.php new file mode 100644 index 00000000..7c45fc77 --- /dev/null +++ b/src/Routes/Clients/NoiseSensors.php @@ -0,0 +1,88 @@ +seam = $seam; + $this->noise_thresholds = new NoiseSensorsNoiseThresholds($seam); + $this->simulate = new NoiseSensorsSimulate($seam); + } + + public function list( + ?string $connected_account_id = null, + ?array $connected_account_ids = null, + ?string $connect_webview_id = null, + ?string $device_type = null, + ?array $device_types = null, + ?string $manufacturer = null, + ?array $device_ids = null, + ?float $limit = null, + ?string $created_before = null, + ?string $user_identifier_key = null, + mixed $custom_metadata_has = null, + ?array $include_if = null, + ?array $exclude_if = null, + ?string $unstable_location_id = null + ): array { + $request_payload = []; + + if ($connected_account_id !== null) { + $request_payload["connected_account_id"] = $connected_account_id; + } + if ($connected_account_ids !== null) { + $request_payload["connected_account_ids"] = $connected_account_ids; + } + if ($connect_webview_id !== null) { + $request_payload["connect_webview_id"] = $connect_webview_id; + } + if ($device_type !== null) { + $request_payload["device_type"] = $device_type; + } + if ($device_types !== null) { + $request_payload["device_types"] = $device_types; + } + if ($manufacturer !== null) { + $request_payload["manufacturer"] = $manufacturer; + } + if ($device_ids !== null) { + $request_payload["device_ids"] = $device_ids; + } + if ($limit !== null) { + $request_payload["limit"] = $limit; + } + if ($created_before !== null) { + $request_payload["created_before"] = $created_before; + } + if ($user_identifier_key !== null) { + $request_payload["user_identifier_key"] = $user_identifier_key; + } + if ($custom_metadata_has !== null) { + $request_payload["custom_metadata_has"] = $custom_metadata_has; + } + if ($include_if !== null) { + $request_payload["include_if"] = $include_if; + } + if ($exclude_if !== null) { + $request_payload["exclude_if"] = $exclude_if; + } + if ($unstable_location_id !== null) { + $request_payload["unstable_location_id"] = $unstable_location_id; + } + + $res = $this->seam->client->post("/noise_sensors/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map(fn($r) => Device::from_json($r), $json->devices); + } +} diff --git a/src/Routes/Clients/NoiseSensorsNoiseThresholds.php b/src/Routes/Clients/NoiseSensorsNoiseThresholds.php new file mode 100644 index 00000000..3ab27a04 --- /dev/null +++ b/src/Routes/Clients/NoiseSensorsNoiseThresholds.php @@ -0,0 +1,166 @@ +seam = $seam; + } + + public function create( + string $device_id, + string $starts_daily_at, + string $ends_daily_at, + ?bool $sync = null, + ?string $name = null, + ?float $noise_threshold_decibels = null, + ?float $noise_threshold_nrs = null + ): NoiseThreshold { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($starts_daily_at !== null) { + $request_payload["starts_daily_at"] = $starts_daily_at; + } + if ($ends_daily_at !== null) { + $request_payload["ends_daily_at"] = $ends_daily_at; + } + if ($sync !== null) { + $request_payload["sync"] = $sync; + } + if ($name !== null) { + $request_payload["name"] = $name; + } + if ($noise_threshold_decibels !== null) { + $request_payload[ + "noise_threshold_decibels" + ] = $noise_threshold_decibels; + } + if ($noise_threshold_nrs !== null) { + $request_payload["noise_threshold_nrs"] = $noise_threshold_nrs; + } + + $res = $this->seam->client->post( + "/noise_sensors/noise_thresholds/create", + ["json" => (object) $request_payload] + ); + $json = json_decode($res->getBody()); + + return NoiseThreshold::from_json($json->noise_threshold); + } + + public function delete( + string $noise_threshold_id, + string $device_id, + ?bool $sync = null + ): void { + $request_payload = []; + + if ($noise_threshold_id !== null) { + $request_payload["noise_threshold_id"] = $noise_threshold_id; + } + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($sync !== null) { + $request_payload["sync"] = $sync; + } + + $this->seam->client->post("/noise_sensors/noise_thresholds/delete", [ + "json" => (object) $request_payload, + ]); + } + + public function get(string $noise_threshold_id): NoiseThreshold + { + $request_payload = []; + + if ($noise_threshold_id !== null) { + $request_payload["noise_threshold_id"] = $noise_threshold_id; + } + + $res = $this->seam->client->post( + "/noise_sensors/noise_thresholds/get", + ["json" => (object) $request_payload] + ); + $json = json_decode($res->getBody()); + + return NoiseThreshold::from_json($json->noise_threshold); + } + + public function list(string $device_id, ?bool $is_programmed = null): array + { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($is_programmed !== null) { + $request_payload["is_programmed"] = $is_programmed; + } + + $res = $this->seam->client->post( + "/noise_sensors/noise_thresholds/list", + ["json" => (object) $request_payload] + ); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => NoiseThreshold::from_json($r), + $json->noise_thresholds + ); + } + + public function update( + string $noise_threshold_id, + string $device_id, + ?bool $sync = null, + ?string $name = null, + ?string $starts_daily_at = null, + ?string $ends_daily_at = null, + ?float $noise_threshold_decibels = null, + ?float $noise_threshold_nrs = null + ): void { + $request_payload = []; + + if ($noise_threshold_id !== null) { + $request_payload["noise_threshold_id"] = $noise_threshold_id; + } + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($sync !== null) { + $request_payload["sync"] = $sync; + } + if ($name !== null) { + $request_payload["name"] = $name; + } + if ($starts_daily_at !== null) { + $request_payload["starts_daily_at"] = $starts_daily_at; + } + if ($ends_daily_at !== null) { + $request_payload["ends_daily_at"] = $ends_daily_at; + } + if ($noise_threshold_decibels !== null) { + $request_payload[ + "noise_threshold_decibels" + ] = $noise_threshold_decibels; + } + if ($noise_threshold_nrs !== null) { + $request_payload["noise_threshold_nrs"] = $noise_threshold_nrs; + } + + $this->seam->client->post("/noise_sensors/noise_thresholds/update", [ + "json" => (object) $request_payload, + ]); + } +} diff --git a/src/Routes/Clients/NoiseSensorsSimulate.php b/src/Routes/Clients/NoiseSensorsSimulate.php new file mode 100644 index 00000000..6141cdd6 --- /dev/null +++ b/src/Routes/Clients/NoiseSensorsSimulate.php @@ -0,0 +1,29 @@ +seam = $seam; + } + + public function trigger_noise_threshold(string $device_id): void + { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + + $this->seam->client->post( + "/noise_sensors/simulate/trigger_noise_threshold", + ["json" => (object) $request_payload] + ); + } +} diff --git a/src/Routes/Clients/Phones.php b/src/Routes/Clients/Phones.php new file mode 100644 index 00000000..2e9463f7 --- /dev/null +++ b/src/Routes/Clients/Phones.php @@ -0,0 +1,69 @@ +seam = $seam; + $this->simulate = new PhonesSimulate($seam); + } + + public function deactivate(string $device_id): void + { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + + $this->seam->client->post("/phones/deactivate", [ + "json" => (object) $request_payload, + ]); + } + + public function get(string $device_id): Phone + { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + + $res = $this->seam->client->post("/phones/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return Phone::from_json($json->phone); + } + + public function list( + ?string $owner_user_identity_id = null, + ?string $acs_credential_id = null + ): array { + $request_payload = []; + + if ($owner_user_identity_id !== null) { + $request_payload[ + "owner_user_identity_id" + ] = $owner_user_identity_id; + } + if ($acs_credential_id !== null) { + $request_payload["acs_credential_id"] = $acs_credential_id; + } + + $res = $this->seam->client->post("/phones/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map(fn($r) => Phone::from_json($r), $json->phones); + } +} diff --git a/src/Routes/Clients/PhonesSimulate.php b/src/Routes/Clients/PhonesSimulate.php new file mode 100644 index 00000000..a3cd5cba --- /dev/null +++ b/src/Routes/Clients/PhonesSimulate.php @@ -0,0 +1,48 @@ +seam = $seam; + } + + public function create_sandbox_phone( + string $user_identity_id, + ?string $custom_sdk_installation_id = null, + mixed $phone_metadata = null, + mixed $assa_abloy_metadata = null + ): Phone { + $request_payload = []; + + if ($user_identity_id !== null) { + $request_payload["user_identity_id"] = $user_identity_id; + } + if ($custom_sdk_installation_id !== null) { + $request_payload[ + "custom_sdk_installation_id" + ] = $custom_sdk_installation_id; + } + if ($phone_metadata !== null) { + $request_payload["phone_metadata"] = $phone_metadata; + } + if ($assa_abloy_metadata !== null) { + $request_payload["assa_abloy_metadata"] = $assa_abloy_metadata; + } + + $res = $this->seam->client->post( + "/phones/simulate/create_sandbox_phone", + ["json" => (object) $request_payload] + ); + $json = json_decode($res->getBody()); + + return Phone::from_json($json->phone); + } +} diff --git a/src/Routes/Clients/Thermostats.php b/src/Routes/Clients/Thermostats.php new file mode 100644 index 00000000..48baeaa2 --- /dev/null +++ b/src/Routes/Clients/Thermostats.php @@ -0,0 +1,570 @@ +seam = $seam; + $this->schedules = new ThermostatsSchedules($seam); + $this->simulate = new ThermostatsSimulate($seam); + } + + public function activate_climate_preset( + string $device_id, + string $climate_preset_key, + bool $wait_for_action_attempt = true + ): ActionAttempt { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($climate_preset_key !== null) { + $request_payload["climate_preset_key"] = $climate_preset_key; + } + + $res = $this->seam->client->post( + "/thermostats/activate_climate_preset", + ["json" => (object) $request_payload] + ); + $json = json_decode($res->getBody()); + + if (!$wait_for_action_attempt) { + return ActionAttempt::from_json($json->action_attempt); + } + + $action_attempt = $this->seam->action_attempts->poll_until_ready( + $json->action_attempt->action_attempt_id + ); + + return $action_attempt; + } + + public function cool( + string $device_id, + ?float $cooling_set_point_celsius = null, + ?float $cooling_set_point_fahrenheit = null, + ?bool $sync = null, + bool $wait_for_action_attempt = true + ): ActionAttempt { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($cooling_set_point_celsius !== null) { + $request_payload[ + "cooling_set_point_celsius" + ] = $cooling_set_point_celsius; + } + if ($cooling_set_point_fahrenheit !== null) { + $request_payload[ + "cooling_set_point_fahrenheit" + ] = $cooling_set_point_fahrenheit; + } + if ($sync !== null) { + $request_payload["sync"] = $sync; + } + + $res = $this->seam->client->post("/thermostats/cool", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + if (!$wait_for_action_attempt) { + return ActionAttempt::from_json($json->action_attempt); + } + + $action_attempt = $this->seam->action_attempts->poll_until_ready( + $json->action_attempt->action_attempt_id + ); + + return $action_attempt; + } + + public function create_climate_preset( + string $device_id, + string $climate_preset_key, + ?bool $manual_override_allowed = null, + ?string $name = null, + ?string $fan_mode_setting = null, + ?string $hvac_mode_setting = null, + ?float $cooling_set_point_celsius = null, + ?float $heating_set_point_celsius = null, + ?float $cooling_set_point_fahrenheit = null, + ?float $heating_set_point_fahrenheit = null + ): void { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($climate_preset_key !== null) { + $request_payload["climate_preset_key"] = $climate_preset_key; + } + if ($manual_override_allowed !== null) { + $request_payload[ + "manual_override_allowed" + ] = $manual_override_allowed; + } + if ($name !== null) { + $request_payload["name"] = $name; + } + if ($fan_mode_setting !== null) { + $request_payload["fan_mode_setting"] = $fan_mode_setting; + } + if ($hvac_mode_setting !== null) { + $request_payload["hvac_mode_setting"] = $hvac_mode_setting; + } + if ($cooling_set_point_celsius !== null) { + $request_payload[ + "cooling_set_point_celsius" + ] = $cooling_set_point_celsius; + } + if ($heating_set_point_celsius !== null) { + $request_payload[ + "heating_set_point_celsius" + ] = $heating_set_point_celsius; + } + if ($cooling_set_point_fahrenheit !== null) { + $request_payload[ + "cooling_set_point_fahrenheit" + ] = $cooling_set_point_fahrenheit; + } + if ($heating_set_point_fahrenheit !== null) { + $request_payload[ + "heating_set_point_fahrenheit" + ] = $heating_set_point_fahrenheit; + } + + $this->seam->client->post("/thermostats/create_climate_preset", [ + "json" => (object) $request_payload, + ]); + } + + public function delete_climate_preset( + string $device_id, + string $climate_preset_key + ): void { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($climate_preset_key !== null) { + $request_payload["climate_preset_key"] = $climate_preset_key; + } + + $this->seam->client->post("/thermostats/delete_climate_preset", [ + "json" => (object) $request_payload, + ]); + } + + public function heat( + string $device_id, + ?float $heating_set_point_celsius = null, + ?float $heating_set_point_fahrenheit = null, + ?bool $sync = null, + bool $wait_for_action_attempt = true + ): ActionAttempt { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($heating_set_point_celsius !== null) { + $request_payload[ + "heating_set_point_celsius" + ] = $heating_set_point_celsius; + } + if ($heating_set_point_fahrenheit !== null) { + $request_payload[ + "heating_set_point_fahrenheit" + ] = $heating_set_point_fahrenheit; + } + if ($sync !== null) { + $request_payload["sync"] = $sync; + } + + $res = $this->seam->client->post("/thermostats/heat", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + if (!$wait_for_action_attempt) { + return ActionAttempt::from_json($json->action_attempt); + } + + $action_attempt = $this->seam->action_attempts->poll_until_ready( + $json->action_attempt->action_attempt_id + ); + + return $action_attempt; + } + + public function heat_cool( + string $device_id, + ?float $heating_set_point_celsius = null, + ?float $heating_set_point_fahrenheit = null, + ?float $cooling_set_point_celsius = null, + ?float $cooling_set_point_fahrenheit = null, + ?bool $sync = null, + bool $wait_for_action_attempt = true + ): ActionAttempt { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($heating_set_point_celsius !== null) { + $request_payload[ + "heating_set_point_celsius" + ] = $heating_set_point_celsius; + } + if ($heating_set_point_fahrenheit !== null) { + $request_payload[ + "heating_set_point_fahrenheit" + ] = $heating_set_point_fahrenheit; + } + if ($cooling_set_point_celsius !== null) { + $request_payload[ + "cooling_set_point_celsius" + ] = $cooling_set_point_celsius; + } + if ($cooling_set_point_fahrenheit !== null) { + $request_payload[ + "cooling_set_point_fahrenheit" + ] = $cooling_set_point_fahrenheit; + } + if ($sync !== null) { + $request_payload["sync"] = $sync; + } + + $res = $this->seam->client->post("/thermostats/heat_cool", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + if (!$wait_for_action_attempt) { + return ActionAttempt::from_json($json->action_attempt); + } + + $action_attempt = $this->seam->action_attempts->poll_until_ready( + $json->action_attempt->action_attempt_id + ); + + return $action_attempt; + } + + public function list( + ?string $connected_account_id = null, + ?array $connected_account_ids = null, + ?string $connect_webview_id = null, + ?string $device_type = null, + ?array $device_types = null, + ?string $manufacturer = null, + ?array $device_ids = null, + ?float $limit = null, + ?string $created_before = null, + ?string $user_identifier_key = null, + mixed $custom_metadata_has = null, + ?array $include_if = null, + ?array $exclude_if = null, + ?string $unstable_location_id = null + ): array { + $request_payload = []; + + if ($connected_account_id !== null) { + $request_payload["connected_account_id"] = $connected_account_id; + } + if ($connected_account_ids !== null) { + $request_payload["connected_account_ids"] = $connected_account_ids; + } + if ($connect_webview_id !== null) { + $request_payload["connect_webview_id"] = $connect_webview_id; + } + if ($device_type !== null) { + $request_payload["device_type"] = $device_type; + } + if ($device_types !== null) { + $request_payload["device_types"] = $device_types; + } + if ($manufacturer !== null) { + $request_payload["manufacturer"] = $manufacturer; + } + if ($device_ids !== null) { + $request_payload["device_ids"] = $device_ids; + } + if ($limit !== null) { + $request_payload["limit"] = $limit; + } + if ($created_before !== null) { + $request_payload["created_before"] = $created_before; + } + if ($user_identifier_key !== null) { + $request_payload["user_identifier_key"] = $user_identifier_key; + } + if ($custom_metadata_has !== null) { + $request_payload["custom_metadata_has"] = $custom_metadata_has; + } + if ($include_if !== null) { + $request_payload["include_if"] = $include_if; + } + if ($exclude_if !== null) { + $request_payload["exclude_if"] = $exclude_if; + } + if ($unstable_location_id !== null) { + $request_payload["unstable_location_id"] = $unstable_location_id; + } + + $res = $this->seam->client->post("/thermostats/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map(fn($r) => Device::from_json($r), $json->devices); + } + + public function off( + string $device_id, + ?bool $sync = null, + bool $wait_for_action_attempt = true + ): ActionAttempt { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($sync !== null) { + $request_payload["sync"] = $sync; + } + + $res = $this->seam->client->post("/thermostats/off", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + if (!$wait_for_action_attempt) { + return ActionAttempt::from_json($json->action_attempt); + } + + $action_attempt = $this->seam->action_attempts->poll_until_ready( + $json->action_attempt->action_attempt_id + ); + + return $action_attempt; + } + + public function set_fallback_climate_preset( + string $device_id, + string $climate_preset_key + ): void { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($climate_preset_key !== null) { + $request_payload["climate_preset_key"] = $climate_preset_key; + } + + $this->seam->client->post("/thermostats/set_fallback_climate_preset", [ + "json" => (object) $request_payload, + ]); + } + + public function set_fan_mode( + string $device_id, + ?string $fan_mode = null, + ?string $fan_mode_setting = null, + ?bool $sync = null, + bool $wait_for_action_attempt = true + ): ActionAttempt { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($fan_mode !== null) { + $request_payload["fan_mode"] = $fan_mode; + } + if ($fan_mode_setting !== null) { + $request_payload["fan_mode_setting"] = $fan_mode_setting; + } + if ($sync !== null) { + $request_payload["sync"] = $sync; + } + + $res = $this->seam->client->post("/thermostats/set_fan_mode", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + if (!$wait_for_action_attempt) { + return ActionAttempt::from_json($json->action_attempt); + } + + $action_attempt = $this->seam->action_attempts->poll_until_ready( + $json->action_attempt->action_attempt_id + ); + + return $action_attempt; + } + + public function set_hvac_mode( + string $hvac_mode_setting, + string $device_id, + ?float $cooling_set_point_celsius = null, + ?float $cooling_set_point_fahrenheit = null, + ?float $heating_set_point_celsius = null, + ?float $heating_set_point_fahrenheit = null, + bool $wait_for_action_attempt = true + ): ActionAttempt { + $request_payload = []; + + if ($hvac_mode_setting !== null) { + $request_payload["hvac_mode_setting"] = $hvac_mode_setting; + } + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($cooling_set_point_celsius !== null) { + $request_payload[ + "cooling_set_point_celsius" + ] = $cooling_set_point_celsius; + } + if ($cooling_set_point_fahrenheit !== null) { + $request_payload[ + "cooling_set_point_fahrenheit" + ] = $cooling_set_point_fahrenheit; + } + if ($heating_set_point_celsius !== null) { + $request_payload[ + "heating_set_point_celsius" + ] = $heating_set_point_celsius; + } + if ($heating_set_point_fahrenheit !== null) { + $request_payload[ + "heating_set_point_fahrenheit" + ] = $heating_set_point_fahrenheit; + } + + $res = $this->seam->client->post("/thermostats/set_hvac_mode", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + if (!$wait_for_action_attempt) { + return ActionAttempt::from_json($json->action_attempt); + } + + $action_attempt = $this->seam->action_attempts->poll_until_ready( + $json->action_attempt->action_attempt_id + ); + + return $action_attempt; + } + + public function set_temperature_threshold( + string $device_id, + ?float $lower_limit_celsius = null, + ?float $lower_limit_fahrenheit = null, + ?float $upper_limit_celsius = null, + ?float $upper_limit_fahrenheit = null + ): void { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($lower_limit_celsius !== null) { + $request_payload["lower_limit_celsius"] = $lower_limit_celsius; + } + if ($lower_limit_fahrenheit !== null) { + $request_payload[ + "lower_limit_fahrenheit" + ] = $lower_limit_fahrenheit; + } + if ($upper_limit_celsius !== null) { + $request_payload["upper_limit_celsius"] = $upper_limit_celsius; + } + if ($upper_limit_fahrenheit !== null) { + $request_payload[ + "upper_limit_fahrenheit" + ] = $upper_limit_fahrenheit; + } + + $this->seam->client->post("/thermostats/set_temperature_threshold", [ + "json" => (object) $request_payload, + ]); + } + + public function update_climate_preset( + string $device_id, + string $climate_preset_key, + bool $manual_override_allowed, + ?string $name = null, + ?string $fan_mode_setting = null, + ?string $hvac_mode_setting = null, + ?float $cooling_set_point_celsius = null, + ?float $heating_set_point_celsius = null, + ?float $cooling_set_point_fahrenheit = null, + ?float $heating_set_point_fahrenheit = null + ): void { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($climate_preset_key !== null) { + $request_payload["climate_preset_key"] = $climate_preset_key; + } + if ($manual_override_allowed !== null) { + $request_payload[ + "manual_override_allowed" + ] = $manual_override_allowed; + } + if ($name !== null) { + $request_payload["name"] = $name; + } + if ($fan_mode_setting !== null) { + $request_payload["fan_mode_setting"] = $fan_mode_setting; + } + if ($hvac_mode_setting !== null) { + $request_payload["hvac_mode_setting"] = $hvac_mode_setting; + } + if ($cooling_set_point_celsius !== null) { + $request_payload[ + "cooling_set_point_celsius" + ] = $cooling_set_point_celsius; + } + if ($heating_set_point_celsius !== null) { + $request_payload[ + "heating_set_point_celsius" + ] = $heating_set_point_celsius; + } + if ($cooling_set_point_fahrenheit !== null) { + $request_payload[ + "cooling_set_point_fahrenheit" + ] = $cooling_set_point_fahrenheit; + } + if ($heating_set_point_fahrenheit !== null) { + $request_payload[ + "heating_set_point_fahrenheit" + ] = $heating_set_point_fahrenheit; + } + + $this->seam->client->post("/thermostats/update_climate_preset", [ + "json" => (object) $request_payload, + ]); + } +} diff --git a/src/Routes/Clients/ThermostatsSchedules.php b/src/Routes/Clients/ThermostatsSchedules.php new file mode 100644 index 00000000..220e205c --- /dev/null +++ b/src/Routes/Clients/ThermostatsSchedules.php @@ -0,0 +1,158 @@ +seam = $seam; + } + + public function create( + string $device_id, + string $climate_preset_key, + string $starts_at, + string $ends_at, + ?string $name = null, + mixed $max_override_period_minutes = null, + ?bool $is_override_allowed = null + ): ThermostatSchedule { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($climate_preset_key !== null) { + $request_payload["climate_preset_key"] = $climate_preset_key; + } + if ($starts_at !== null) { + $request_payload["starts_at"] = $starts_at; + } + if ($ends_at !== null) { + $request_payload["ends_at"] = $ends_at; + } + if ($name !== null) { + $request_payload["name"] = $name; + } + if ($max_override_period_minutes !== null) { + $request_payload[ + "max_override_period_minutes" + ] = $max_override_period_minutes; + } + if ($is_override_allowed !== null) { + $request_payload["is_override_allowed"] = $is_override_allowed; + } + + $res = $this->seam->client->post("/thermostats/schedules/create", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return ThermostatSchedule::from_json($json->thermostat_schedule); + } + + public function delete(string $thermostat_schedule_id): void + { + $request_payload = []; + + if ($thermostat_schedule_id !== null) { + $request_payload[ + "thermostat_schedule_id" + ] = $thermostat_schedule_id; + } + + $this->seam->client->post("/thermostats/schedules/delete", [ + "json" => (object) $request_payload, + ]); + } + + public function get(string $thermostat_schedule_id): ThermostatSchedule + { + $request_payload = []; + + if ($thermostat_schedule_id !== null) { + $request_payload[ + "thermostat_schedule_id" + ] = $thermostat_schedule_id; + } + + $res = $this->seam->client->post("/thermostats/schedules/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return ThermostatSchedule::from_json($json->thermostat_schedule); + } + + public function list( + string $device_id, + ?string $user_identifier_key = null + ): array { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($user_identifier_key !== null) { + $request_payload["user_identifier_key"] = $user_identifier_key; + } + + $res = $this->seam->client->post("/thermostats/schedules/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => ThermostatSchedule::from_json($r), + $json->thermostat_schedules + ); + } + + public function update( + string $thermostat_schedule_id, + ?string $name = null, + ?string $climate_preset_key = null, + mixed $max_override_period_minutes = null, + ?string $starts_at = null, + ?string $ends_at = null, + ?bool $is_override_allowed = null + ): void { + $request_payload = []; + + if ($thermostat_schedule_id !== null) { + $request_payload[ + "thermostat_schedule_id" + ] = $thermostat_schedule_id; + } + if ($name !== null) { + $request_payload["name"] = $name; + } + if ($climate_preset_key !== null) { + $request_payload["climate_preset_key"] = $climate_preset_key; + } + if ($max_override_period_minutes !== null) { + $request_payload[ + "max_override_period_minutes" + ] = $max_override_period_minutes; + } + if ($starts_at !== null) { + $request_payload["starts_at"] = $starts_at; + } + if ($ends_at !== null) { + $request_payload["ends_at"] = $ends_at; + } + if ($is_override_allowed !== null) { + $request_payload["is_override_allowed"] = $is_override_allowed; + } + + $this->seam->client->post("/thermostats/schedules/update", [ + "json" => (object) $request_payload, + ]); + } +} diff --git a/src/Routes/Clients/ThermostatsSimulate.php b/src/Routes/Clients/ThermostatsSimulate.php new file mode 100644 index 00000000..c4aa487d --- /dev/null +++ b/src/Routes/Clients/ThermostatsSimulate.php @@ -0,0 +1,81 @@ +seam = $seam; + } + + public function hvac_mode_adjusted( + string $hvac_mode, + string $device_id, + ?float $cooling_set_point_celsius = null, + ?float $cooling_set_point_fahrenheit = null, + ?float $heating_set_point_celsius = null, + ?float $heating_set_point_fahrenheit = null + ): void { + $request_payload = []; + + if ($hvac_mode !== null) { + $request_payload["hvac_mode"] = $hvac_mode; + } + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($cooling_set_point_celsius !== null) { + $request_payload[ + "cooling_set_point_celsius" + ] = $cooling_set_point_celsius; + } + if ($cooling_set_point_fahrenheit !== null) { + $request_payload[ + "cooling_set_point_fahrenheit" + ] = $cooling_set_point_fahrenheit; + } + if ($heating_set_point_celsius !== null) { + $request_payload[ + "heating_set_point_celsius" + ] = $heating_set_point_celsius; + } + if ($heating_set_point_fahrenheit !== null) { + $request_payload[ + "heating_set_point_fahrenheit" + ] = $heating_set_point_fahrenheit; + } + + $this->seam->client->post("/thermostats/simulate/hvac_mode_adjusted", [ + "json" => (object) $request_payload, + ]); + } + + public function temperature_reached( + string $device_id, + ?float $temperature_celsius = null, + ?float $temperature_fahrenheit = null + ): void { + $request_payload = []; + + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + if ($temperature_celsius !== null) { + $request_payload["temperature_celsius"] = $temperature_celsius; + } + if ($temperature_fahrenheit !== null) { + $request_payload[ + "temperature_fahrenheit" + ] = $temperature_fahrenheit; + } + + $this->seam->client->post("/thermostats/simulate/temperature_reached", [ + "json" => (object) $request_payload, + ]); + } +} diff --git a/src/Routes/Clients/UserIdentities.php b/src/Routes/Clients/UserIdentities.php new file mode 100644 index 00000000..87d7bfcc --- /dev/null +++ b/src/Routes/Clients/UserIdentities.php @@ -0,0 +1,261 @@ +seam = $seam; + $this->enrollment_automations = new UserIdentitiesEnrollmentAutomations( + $seam + ); + } + + public function add_acs_user( + string $user_identity_id, + string $acs_user_id + ): void { + $request_payload = []; + + if ($user_identity_id !== null) { + $request_payload["user_identity_id"] = $user_identity_id; + } + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + + $this->seam->client->post("/user_identities/add_acs_user", [ + "json" => (object) $request_payload, + ]); + } + + public function create( + ?string $user_identity_key = null, + ?string $email_address = null, + ?string $phone_number = null, + ?string $full_name = null + ): UserIdentity { + $request_payload = []; + + if ($user_identity_key !== null) { + $request_payload["user_identity_key"] = $user_identity_key; + } + if ($email_address !== null) { + $request_payload["email_address"] = $email_address; + } + if ($phone_number !== null) { + $request_payload["phone_number"] = $phone_number; + } + if ($full_name !== null) { + $request_payload["full_name"] = $full_name; + } + + $res = $this->seam->client->post("/user_identities/create", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return UserIdentity::from_json($json->user_identity); + } + + public function delete(string $user_identity_id): void + { + $request_payload = []; + + if ($user_identity_id !== null) { + $request_payload["user_identity_id"] = $user_identity_id; + } + + $this->seam->client->post("/user_identities/delete", [ + "json" => (object) $request_payload, + ]); + } + + public function get( + ?string $user_identity_id = null, + ?string $user_identity_key = null + ): UserIdentity { + $request_payload = []; + + if ($user_identity_id !== null) { + $request_payload["user_identity_id"] = $user_identity_id; + } + if ($user_identity_key !== null) { + $request_payload["user_identity_key"] = $user_identity_key; + } + + $res = $this->seam->client->post("/user_identities/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return UserIdentity::from_json($json->user_identity); + } + + public function grant_access_to_device( + string $user_identity_id, + string $device_id + ): void { + $request_payload = []; + + if ($user_identity_id !== null) { + $request_payload["user_identity_id"] = $user_identity_id; + } + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + + $this->seam->client->post("/user_identities/grant_access_to_device", [ + "json" => (object) $request_payload, + ]); + } + + public function list( + ?string $credential_manager_acs_system_id = null + ): array { + $request_payload = []; + + if ($credential_manager_acs_system_id !== null) { + $request_payload[ + "credential_manager_acs_system_id" + ] = $credential_manager_acs_system_id; + } + + $res = $this->seam->client->post("/user_identities/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => UserIdentity::from_json($r), + $json->user_identities + ); + } + + public function list_accessible_devices(string $user_identity_id): array + { + $request_payload = []; + + if ($user_identity_id !== null) { + $request_payload["user_identity_id"] = $user_identity_id; + } + + $res = $this->seam->client->post( + "/user_identities/list_accessible_devices", + ["json" => (object) $request_payload] + ); + $json = json_decode($res->getBody()); + + return array_map(fn($r) => Device::from_json($r), $json->devices); + } + + public function list_acs_systems(string $user_identity_id): array + { + $request_payload = []; + + if ($user_identity_id !== null) { + $request_payload["user_identity_id"] = $user_identity_id; + } + + $res = $this->seam->client->post("/user_identities/list_acs_systems", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => AcsSystem::from_json($r), + $json->acs_systems + ); + } + + public function list_acs_users(string $user_identity_id): array + { + $request_payload = []; + + if ($user_identity_id !== null) { + $request_payload["user_identity_id"] = $user_identity_id; + } + + $res = $this->seam->client->post("/user_identities/list_acs_users", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map(fn($r) => AcsUser::from_json($r), $json->acs_users); + } + + public function remove_acs_user( + string $user_identity_id, + string $acs_user_id + ): void { + $request_payload = []; + + if ($user_identity_id !== null) { + $request_payload["user_identity_id"] = $user_identity_id; + } + if ($acs_user_id !== null) { + $request_payload["acs_user_id"] = $acs_user_id; + } + + $this->seam->client->post("/user_identities/remove_acs_user", [ + "json" => (object) $request_payload, + ]); + } + + public function revoke_access_to_device( + string $user_identity_id, + string $device_id + ): void { + $request_payload = []; + + if ($user_identity_id !== null) { + $request_payload["user_identity_id"] = $user_identity_id; + } + if ($device_id !== null) { + $request_payload["device_id"] = $device_id; + } + + $this->seam->client->post("/user_identities/revoke_access_to_device", [ + "json" => (object) $request_payload, + ]); + } + + public function update( + string $user_identity_id, + ?string $user_identity_key = null, + ?string $email_address = null, + ?string $phone_number = null, + ?string $full_name = null + ): void { + $request_payload = []; + + if ($user_identity_id !== null) { + $request_payload["user_identity_id"] = $user_identity_id; + } + if ($user_identity_key !== null) { + $request_payload["user_identity_key"] = $user_identity_key; + } + if ($email_address !== null) { + $request_payload["email_address"] = $email_address; + } + if ($phone_number !== null) { + $request_payload["phone_number"] = $phone_number; + } + if ($full_name !== null) { + $request_payload["full_name"] = $full_name; + } + + $this->seam->client->post("/user_identities/update", [ + "json" => (object) $request_payload, + ]); + } +} diff --git a/src/Routes/Clients/UserIdentitiesEnrollmentAutomations.php b/src/Routes/Clients/UserIdentitiesEnrollmentAutomations.php new file mode 100644 index 00000000..fb489190 --- /dev/null +++ b/src/Routes/Clients/UserIdentitiesEnrollmentAutomations.php @@ -0,0 +1,110 @@ +seam = $seam; + } + + public function delete(string $enrollment_automation_id): void + { + $request_payload = []; + + if ($enrollment_automation_id !== null) { + $request_payload[ + "enrollment_automation_id" + ] = $enrollment_automation_id; + } + + $this->seam->client->post( + "/user_identities/enrollment_automations/delete", + ["json" => (object) $request_payload] + ); + } + + public function get(string $enrollment_automation_id): EnrollmentAutomation + { + $request_payload = []; + + if ($enrollment_automation_id !== null) { + $request_payload[ + "enrollment_automation_id" + ] = $enrollment_automation_id; + } + + $res = $this->seam->client->post( + "/user_identities/enrollment_automations/get", + ["json" => (object) $request_payload] + ); + $json = json_decode($res->getBody()); + + return EnrollmentAutomation::from_json($json->enrollment_automation); + } + + public function launch( + string $user_identity_id, + string $credential_manager_acs_system_id, + ?string $acs_credential_pool_id = null, + ?bool $create_credential_manager_user = null, + ?string $credential_manager_acs_user_id = null + ): void { + $request_payload = []; + + if ($user_identity_id !== null) { + $request_payload["user_identity_id"] = $user_identity_id; + } + if ($credential_manager_acs_system_id !== null) { + $request_payload[ + "credential_manager_acs_system_id" + ] = $credential_manager_acs_system_id; + } + if ($acs_credential_pool_id !== null) { + $request_payload[ + "acs_credential_pool_id" + ] = $acs_credential_pool_id; + } + if ($create_credential_manager_user !== null) { + $request_payload[ + "create_credential_manager_user" + ] = $create_credential_manager_user; + } + if ($credential_manager_acs_user_id !== null) { + $request_payload[ + "credential_manager_acs_user_id" + ] = $credential_manager_acs_user_id; + } + + $this->seam->client->post( + "/user_identities/enrollment_automations/launch", + ["json" => (object) $request_payload] + ); + } + + public function list(string $user_identity_id): array + { + $request_payload = []; + + if ($user_identity_id !== null) { + $request_payload["user_identity_id"] = $user_identity_id; + } + + $res = $this->seam->client->post( + "/user_identities/enrollment_automations/list", + ["json" => (object) $request_payload] + ); + $json = json_decode($res->getBody()); + + return array_map( + fn($r) => EnrollmentAutomation::from_json($r), + $json->enrollment_automations + ); + } +} diff --git a/src/Routes/Clients/Webhooks.php b/src/Routes/Clients/Webhooks.php new file mode 100644 index 00000000..d62014ae --- /dev/null +++ b/src/Routes/Clients/Webhooks.php @@ -0,0 +1,92 @@ +seam = $seam; + } + + public function create(string $url, ?array $event_types = null): Webhook + { + $request_payload = []; + + if ($url !== null) { + $request_payload["url"] = $url; + } + if ($event_types !== null) { + $request_payload["event_types"] = $event_types; + } + + $res = $this->seam->client->post("/webhooks/create", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return Webhook::from_json($json->webhook); + } + + public function delete(string $webhook_id): void + { + $request_payload = []; + + if ($webhook_id !== null) { + $request_payload["webhook_id"] = $webhook_id; + } + + $this->seam->client->post("/webhooks/delete", [ + "json" => (object) $request_payload, + ]); + } + + public function get(string $webhook_id): Webhook + { + $request_payload = []; + + if ($webhook_id !== null) { + $request_payload["webhook_id"] = $webhook_id; + } + + $res = $this->seam->client->post("/webhooks/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return Webhook::from_json($json->webhook); + } + + public function list(): array + { + $request_payload = []; + + $res = $this->seam->client->post("/webhooks/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map(fn($r) => Webhook::from_json($r), $json->webhooks); + } + + public function update(string $webhook_id, array $event_types): void + { + $request_payload = []; + + if ($webhook_id !== null) { + $request_payload["webhook_id"] = $webhook_id; + } + if ($event_types !== null) { + $request_payload["event_types"] = $event_types; + } + + $this->seam->client->post("/webhooks/update", [ + "json" => (object) $request_payload, + ]); + } +} diff --git a/src/Routes/Clients/Workspaces.php b/src/Routes/Clients/Workspaces.php new file mode 100644 index 00000000..640c2555 --- /dev/null +++ b/src/Routes/Clients/Workspaces.php @@ -0,0 +1,107 @@ +seam = $seam; + } + + public function create( + string $name, + ?string $company_name = null, + ?string $connect_partner_name = null, + ?bool $is_sandbox = null, + ?string $webview_primary_button_color = null, + ?string $webview_primary_button_text_color = null, + ?string $webview_logo_shape = null + ): Workspace { + $request_payload = []; + + if ($name !== null) { + $request_payload["name"] = $name; + } + if ($company_name !== null) { + $request_payload["company_name"] = $company_name; + } + if ($connect_partner_name !== null) { + $request_payload["connect_partner_name"] = $connect_partner_name; + } + if ($is_sandbox !== null) { + $request_payload["is_sandbox"] = $is_sandbox; + } + if ($webview_primary_button_color !== null) { + $request_payload[ + "webview_primary_button_color" + ] = $webview_primary_button_color; + } + if ($webview_primary_button_text_color !== null) { + $request_payload[ + "webview_primary_button_text_color" + ] = $webview_primary_button_text_color; + } + if ($webview_logo_shape !== null) { + $request_payload["webview_logo_shape"] = $webview_logo_shape; + } + + $res = $this->seam->client->post("/workspaces/create", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return Workspace::from_json($json->workspace); + } + + public function get(): Workspace + { + $request_payload = []; + + $res = $this->seam->client->post("/workspaces/get", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return Workspace::from_json($json->workspace); + } + + public function list(): array + { + $request_payload = []; + + $res = $this->seam->client->post("/workspaces/list", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + return array_map(fn($r) => Workspace::from_json($r), $json->workspaces); + } + + public function reset_sandbox( + bool $wait_for_action_attempt = true + ): ActionAttempt { + $request_payload = []; + + $res = $this->seam->client->post("/workspaces/reset_sandbox", [ + "json" => (object) $request_payload, + ]); + $json = json_decode($res->getBody()); + + if (!$wait_for_action_attempt) { + return ActionAttempt::from_json($json->action_attempt); + } + + $action_attempt = $this->seam->action_attempts->poll_until_ready( + $json->action_attempt->action_attempt_id + ); + + return $action_attempt; + } +} diff --git a/src/Objects/AccessCode.php b/src/Routes/Objects/AccessCode.php similarity index 98% rename from src/Objects/AccessCode.php rename to src/Routes/Objects/AccessCode.php index c775e831..00e5115b 100644 --- a/src/Objects/AccessCode.php +++ b/src/Routes/Objects/AccessCode.php @@ -1,6 +1,6 @@ access_codes = new AccessCodes($seam); + $this->acs = new Acs($seam); + $this->action_attempts = new ActionAttempts($seam); + $this->bridges = new Bridges($seam); + $this->client_sessions = new ClientSessions($seam); + $this->connect_webviews = new ConnectWebviews($seam); + $this->connected_accounts = new ConnectedAccounts($seam); + $this->devices = new Devices($seam); + $this->events = new Events($seam); + $this->locks = new Locks($seam); + $this->networks = new Networks($seam); + $this->noise_sensors = new NoiseSensors($seam); + $this->phones = new Phones($seam); + $this->thermostats = new Thermostats($seam); + $this->user_identities = new UserIdentities($seam); + $this->webhooks = new Webhooks($seam); + $this->workspaces = new Workspaces($seam); + } +} diff --git a/src/Seam.php b/src/Seam.php new file mode 100644 index 00000000..f1c8cb93 --- /dev/null +++ b/src/Seam.php @@ -0,0 +1,80 @@ +defaults = [ + "wait_for_action_attempt" => $wait_for_action_attempt, + ]; + + $this->client = + $client ?? + Http::createClient([ + "base_url" => $options["endpoint"], + "headers" => $options["headers"], + "guzzle_options" => $guzzle_options, + ]); + + $this->routes = new Routes($this); + } + + public function __get(string $name): mixed + { + return $this->routes->$name; + } + + public static function fromApiKey( + string $api_key, + ?string $endpoint = null, + bool $wait_for_action_attempt = true, + array $guzzle_options = [] + ): self { + return new self( + api_key: $api_key, + endpoint: $endpoint, + wait_for_action_attempt: $wait_for_action_attempt, + guzzle_options: $guzzle_options + ); + } + + public static function fromPersonalAccessToken( + string $personal_access_token, + string $workspace_id, + ?string $endpoint = null, + bool $wait_for_action_attempt = true, + array $guzzle_options = [] + ): self { + return new self( + personal_access_token: $personal_access_token, + workspace_id: $workspace_id, + endpoint: $endpoint, + wait_for_action_attempt: $wait_for_action_attempt, + guzzle_options: $guzzle_options + ); + } +} diff --git a/src/SeamClient.php b/src/SeamClient.php deleted file mode 100644 index 3af13b56..00000000 --- a/src/SeamClient.php +++ /dev/null @@ -1,5111 +0,0 @@ -api_key = $api_key ?: (getenv("SEAM_API_KEY") ?: null); - $seam_sdk_version = PackageVersion::get(); - $this->client = new HTTPClient([ - "base_uri" => $endpoint, - "timeout" => 60.0, - "headers" => [ - "Authorization" => "Bearer " . $this->api_key, - "User-Agent" => "Seam PHP Client " . $seam_sdk_version, - "seam-sdk-name" => "seamapi/php", - "seam-sdk-version" => $seam_sdk_version, - "seam-lts-version" => $this->ltsVersion, - ], - "http_errors" => $throw_http_errors, - ]); - $this->access_codes = new AccessCodesClient($this); - $this->acs = new AcsClient($this); - $this->action_attempts = new ActionAttemptsClient($this); - $this->bridges = new BridgesClient($this); - $this->client_sessions = new ClientSessionsClient($this); - $this->connect_webviews = new ConnectWebviewsClient($this); - $this->connected_accounts = new ConnectedAccountsClient($this); - $this->devices = new DevicesClient($this); - $this->events = new EventsClient($this); - $this->locks = new LocksClient($this); - $this->networks = new NetworksClient($this); - $this->noise_sensors = new NoiseSensorsClient($this); - $this->phones = new PhonesClient($this); - $this->thermostats = new ThermostatsClient($this); - $this->user_identities = new UserIdentitiesClient($this); - $this->webhooks = new WebhooksClient($this); - $this->workspaces = new WorkspacesClient($this); - } - - public function request( - $method, - $path, - $json = null, - $query = null, - $inner_object = null - ) { - $options = [ - "json" => $json, - "query" => $query, - ]; - $options = array_filter($options, fn($option) => $option !== null); - - // TODO handle request errors - $response = $this->client->request($method, $path, $options); - $status_code = $response->getStatusCode(); - $request_id = $response->getHeaderLine("seam-request-id"); - - $res_json = null; - try { - $res_json = json_decode($response->getBody()); - } catch (Exception $ignoreError) { - } - - if ($status_code >= 400) { - if ($status_code === 401) { - throw new HttpUnauthorizedError($request_id); - } - - if (($res_json->error ?? null) != null) { - if ($res_json->error->type === "invalid_input") { - throw new HttpInvalidInputError( - $res_json->error, - $status_code, - $request_id - ); - } - - throw new HttpApiError( - $res_json->error, - $status_code, - $request_id - ); - } - - throw GuzzleHttpExceptionRequestException::create( - new GuzzleHttpPsr7Request($method, $path), - $response - ); - } - - return $inner_object ? $res_json->$inner_object : $res_json; - } -} - -class AccessCodesClient -{ - private SeamClient $seam; - public AccessCodesSimulateClient $simulate; - public AccessCodesUnmanagedClient $unmanaged; - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - $this->simulate = new AccessCodesSimulateClient($seam); - $this->unmanaged = new AccessCodesUnmanagedClient($seam); - } - - public function create( - string $device_id, - bool $allow_external_modification = null, - bool $attempt_for_offline_device = null, - string $code = null, - string $common_code_key = null, - string $ends_at = null, - bool $is_external_modification_allowed = null, - bool $is_offline_access_code = null, - bool $is_one_time_use = null, - string $max_time_rounding = null, - string $name = null, - bool $prefer_native_scheduling = null, - float $preferred_code_length = null, - string $starts_at = null, - bool $sync = null, - bool $use_backup_access_code_pool = null, - bool $use_offline_access_code = null - ): AccessCode { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($allow_external_modification !== null) { - $request_payload[ - "allow_external_modification" - ] = $allow_external_modification; - } - if ($attempt_for_offline_device !== null) { - $request_payload[ - "attempt_for_offline_device" - ] = $attempt_for_offline_device; - } - if ($code !== null) { - $request_payload["code"] = $code; - } - if ($common_code_key !== null) { - $request_payload["common_code_key"] = $common_code_key; - } - if ($ends_at !== null) { - $request_payload["ends_at"] = $ends_at; - } - if ($is_external_modification_allowed !== null) { - $request_payload[ - "is_external_modification_allowed" - ] = $is_external_modification_allowed; - } - if ($is_offline_access_code !== null) { - $request_payload[ - "is_offline_access_code" - ] = $is_offline_access_code; - } - if ($is_one_time_use !== null) { - $request_payload["is_one_time_use"] = $is_one_time_use; - } - if ($max_time_rounding !== null) { - $request_payload["max_time_rounding"] = $max_time_rounding; - } - if ($name !== null) { - $request_payload["name"] = $name; - } - if ($prefer_native_scheduling !== null) { - $request_payload[ - "prefer_native_scheduling" - ] = $prefer_native_scheduling; - } - if ($preferred_code_length !== null) { - $request_payload["preferred_code_length"] = $preferred_code_length; - } - if ($starts_at !== null) { - $request_payload["starts_at"] = $starts_at; - } - if ($sync !== null) { - $request_payload["sync"] = $sync; - } - if ($use_backup_access_code_pool !== null) { - $request_payload[ - "use_backup_access_code_pool" - ] = $use_backup_access_code_pool; - } - if ($use_offline_access_code !== null) { - $request_payload[ - "use_offline_access_code" - ] = $use_offline_access_code; - } - - $res = $this->seam->request( - "POST", - "/access_codes/create", - json: (object) $request_payload, - inner_object: "access_code" - ); - - return AccessCode::from_json($res); - } - - public function create_multiple( - array $device_ids, - bool $allow_external_modification = null, - bool $attempt_for_offline_device = null, - string $behavior_when_code_cannot_be_shared = null, - string $code = null, - string $ends_at = null, - bool $is_external_modification_allowed = null, - bool $is_offline_access_code = null, - bool $is_one_time_use = null, - string $max_time_rounding = null, - string $name = null, - bool $prefer_native_scheduling = null, - float $preferred_code_length = null, - string $starts_at = null, - bool $use_backup_access_code_pool = null, - bool $use_offline_access_code = null - ): array { - $request_payload = []; - - if ($device_ids !== null) { - $request_payload["device_ids"] = $device_ids; - } - if ($allow_external_modification !== null) { - $request_payload[ - "allow_external_modification" - ] = $allow_external_modification; - } - if ($attempt_for_offline_device !== null) { - $request_payload[ - "attempt_for_offline_device" - ] = $attempt_for_offline_device; - } - if ($behavior_when_code_cannot_be_shared !== null) { - $request_payload[ - "behavior_when_code_cannot_be_shared" - ] = $behavior_when_code_cannot_be_shared; - } - if ($code !== null) { - $request_payload["code"] = $code; - } - if ($ends_at !== null) { - $request_payload["ends_at"] = $ends_at; - } - if ($is_external_modification_allowed !== null) { - $request_payload[ - "is_external_modification_allowed" - ] = $is_external_modification_allowed; - } - if ($is_offline_access_code !== null) { - $request_payload[ - "is_offline_access_code" - ] = $is_offline_access_code; - } - if ($is_one_time_use !== null) { - $request_payload["is_one_time_use"] = $is_one_time_use; - } - if ($max_time_rounding !== null) { - $request_payload["max_time_rounding"] = $max_time_rounding; - } - if ($name !== null) { - $request_payload["name"] = $name; - } - if ($prefer_native_scheduling !== null) { - $request_payload[ - "prefer_native_scheduling" - ] = $prefer_native_scheduling; - } - if ($preferred_code_length !== null) { - $request_payload["preferred_code_length"] = $preferred_code_length; - } - if ($starts_at !== null) { - $request_payload["starts_at"] = $starts_at; - } - if ($use_backup_access_code_pool !== null) { - $request_payload[ - "use_backup_access_code_pool" - ] = $use_backup_access_code_pool; - } - if ($use_offline_access_code !== null) { - $request_payload[ - "use_offline_access_code" - ] = $use_offline_access_code; - } - - $res = $this->seam->request( - "POST", - "/access_codes/create_multiple", - json: (object) $request_payload, - inner_object: "access_codes" - ); - - return array_map(fn($r) => AccessCode::from_json($r), $res); - } - - public function delete( - string $access_code_id, - string $device_id = null, - bool $sync = null - ): void { - $request_payload = []; - - if ($access_code_id !== null) { - $request_payload["access_code_id"] = $access_code_id; - } - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($sync !== null) { - $request_payload["sync"] = $sync; - } - - $this->seam->request( - "POST", - "/access_codes/delete", - json: (object) $request_payload - ); - } - - public function generate_code(string $device_id): AccessCode - { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - - $res = $this->seam->request( - "POST", - "/access_codes/generate_code", - json: (object) $request_payload, - inner_object: "generated_code" - ); - - return AccessCode::from_json($res); - } - - public function get( - string $access_code_id = null, - string $code = null, - string $device_id = null - ): AccessCode { - $request_payload = []; - - if ($access_code_id !== null) { - $request_payload["access_code_id"] = $access_code_id; - } - if ($code !== null) { - $request_payload["code"] = $code; - } - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - - $res = $this->seam->request( - "POST", - "/access_codes/get", - json: (object) $request_payload, - inner_object: "access_code" - ); - - return AccessCode::from_json($res); - } - - public function list( - array $access_code_ids = null, - string $device_id = null, - string $user_identifier_key = null - ): array { - $request_payload = []; - - if ($access_code_ids !== null) { - $request_payload["access_code_ids"] = $access_code_ids; - } - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($user_identifier_key !== null) { - $request_payload["user_identifier_key"] = $user_identifier_key; - } - - $res = $this->seam->request( - "POST", - "/access_codes/list", - json: (object) $request_payload, - inner_object: "access_codes" - ); - - return array_map(fn($r) => AccessCode::from_json($r), $res); - } - - public function pull_backup_access_code(string $access_code_id): AccessCode - { - $request_payload = []; - - if ($access_code_id !== null) { - $request_payload["access_code_id"] = $access_code_id; - } - - $res = $this->seam->request( - "POST", - "/access_codes/pull_backup_access_code", - json: (object) $request_payload, - inner_object: "access_code" - ); - - return AccessCode::from_json($res); - } - - public function update( - string $access_code_id, - bool $allow_external_modification = null, - bool $attempt_for_offline_device = null, - string $code = null, - string $device_id = null, - string $ends_at = null, - bool $is_external_modification_allowed = null, - bool $is_managed = null, - bool $is_offline_access_code = null, - bool $is_one_time_use = null, - string $max_time_rounding = null, - string $name = null, - bool $prefer_native_scheduling = null, - float $preferred_code_length = null, - string $starts_at = null, - bool $sync = null, - string $type = null, - bool $use_backup_access_code_pool = null, - bool $use_offline_access_code = null - ): void { - $request_payload = []; - - if ($access_code_id !== null) { - $request_payload["access_code_id"] = $access_code_id; - } - if ($allow_external_modification !== null) { - $request_payload[ - "allow_external_modification" - ] = $allow_external_modification; - } - if ($attempt_for_offline_device !== null) { - $request_payload[ - "attempt_for_offline_device" - ] = $attempt_for_offline_device; - } - if ($code !== null) { - $request_payload["code"] = $code; - } - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($ends_at !== null) { - $request_payload["ends_at"] = $ends_at; - } - if ($is_external_modification_allowed !== null) { - $request_payload[ - "is_external_modification_allowed" - ] = $is_external_modification_allowed; - } - if ($is_managed !== null) { - $request_payload["is_managed"] = $is_managed; - } - if ($is_offline_access_code !== null) { - $request_payload[ - "is_offline_access_code" - ] = $is_offline_access_code; - } - if ($is_one_time_use !== null) { - $request_payload["is_one_time_use"] = $is_one_time_use; - } - if ($max_time_rounding !== null) { - $request_payload["max_time_rounding"] = $max_time_rounding; - } - if ($name !== null) { - $request_payload["name"] = $name; - } - if ($prefer_native_scheduling !== null) { - $request_payload[ - "prefer_native_scheduling" - ] = $prefer_native_scheduling; - } - if ($preferred_code_length !== null) { - $request_payload["preferred_code_length"] = $preferred_code_length; - } - if ($starts_at !== null) { - $request_payload["starts_at"] = $starts_at; - } - if ($sync !== null) { - $request_payload["sync"] = $sync; - } - if ($type !== null) { - $request_payload["type"] = $type; - } - if ($use_backup_access_code_pool !== null) { - $request_payload[ - "use_backup_access_code_pool" - ] = $use_backup_access_code_pool; - } - if ($use_offline_access_code !== null) { - $request_payload[ - "use_offline_access_code" - ] = $use_offline_access_code; - } - - $this->seam->request( - "POST", - "/access_codes/update", - json: (object) $request_payload - ); - } - - public function update_multiple( - string $common_code_key, - string $ends_at = null, - string $name = null, - string $starts_at = null - ): void { - $request_payload = []; - - if ($common_code_key !== null) { - $request_payload["common_code_key"] = $common_code_key; - } - if ($ends_at !== null) { - $request_payload["ends_at"] = $ends_at; - } - if ($name !== null) { - $request_payload["name"] = $name; - } - if ($starts_at !== null) { - $request_payload["starts_at"] = $starts_at; - } - - $this->seam->request( - "POST", - "/access_codes/update_multiple", - json: (object) $request_payload - ); - } -} - -class AccessCodesSimulateClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function create_unmanaged_access_code( - string $code, - string $device_id, - string $name - ): UnmanagedAccessCode { - $request_payload = []; - - if ($code !== null) { - $request_payload["code"] = $code; - } - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($name !== null) { - $request_payload["name"] = $name; - } - - $res = $this->seam->request( - "POST", - "/access_codes/simulate/create_unmanaged_access_code", - json: (object) $request_payload, - inner_object: "access_code" - ); - - return UnmanagedAccessCode::from_json($res); - } -} - -class AccessCodesUnmanagedClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function convert_to_managed( - string $access_code_id, - bool $allow_external_modification = null, - bool $force = null, - bool $is_external_modification_allowed = null, - bool $sync = null - ): void { - $request_payload = []; - - if ($access_code_id !== null) { - $request_payload["access_code_id"] = $access_code_id; - } - if ($allow_external_modification !== null) { - $request_payload[ - "allow_external_modification" - ] = $allow_external_modification; - } - if ($force !== null) { - $request_payload["force"] = $force; - } - if ($is_external_modification_allowed !== null) { - $request_payload[ - "is_external_modification_allowed" - ] = $is_external_modification_allowed; - } - if ($sync !== null) { - $request_payload["sync"] = $sync; - } - - $this->seam->request( - "POST", - "/access_codes/unmanaged/convert_to_managed", - json: (object) $request_payload - ); - } - - public function delete(string $access_code_id, bool $sync = null): void - { - $request_payload = []; - - if ($access_code_id !== null) { - $request_payload["access_code_id"] = $access_code_id; - } - if ($sync !== null) { - $request_payload["sync"] = $sync; - } - - $this->seam->request( - "POST", - "/access_codes/unmanaged/delete", - json: (object) $request_payload - ); - } - - public function get( - string $access_code_id = null, - string $code = null, - string $device_id = null - ): UnmanagedAccessCode { - $request_payload = []; - - if ($access_code_id !== null) { - $request_payload["access_code_id"] = $access_code_id; - } - if ($code !== null) { - $request_payload["code"] = $code; - } - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - - $res = $this->seam->request( - "POST", - "/access_codes/unmanaged/get", - json: (object) $request_payload, - inner_object: "access_code" - ); - - return UnmanagedAccessCode::from_json($res); - } - - public function list( - string $device_id, - string $user_identifier_key = null - ): array { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($user_identifier_key !== null) { - $request_payload["user_identifier_key"] = $user_identifier_key; - } - - $res = $this->seam->request( - "POST", - "/access_codes/unmanaged/list", - json: (object) $request_payload, - inner_object: "access_codes" - ); - - return array_map(fn($r) => UnmanagedAccessCode::from_json($r), $res); - } - - public function update( - string $access_code_id, - bool $is_managed, - bool $allow_external_modification = null, - bool $force = null, - bool $is_external_modification_allowed = null - ): void { - $request_payload = []; - - if ($access_code_id !== null) { - $request_payload["access_code_id"] = $access_code_id; - } - if ($is_managed !== null) { - $request_payload["is_managed"] = $is_managed; - } - if ($allow_external_modification !== null) { - $request_payload[ - "allow_external_modification" - ] = $allow_external_modification; - } - if ($force !== null) { - $request_payload["force"] = $force; - } - if ($is_external_modification_allowed !== null) { - $request_payload[ - "is_external_modification_allowed" - ] = $is_external_modification_allowed; - } - - $this->seam->request( - "POST", - "/access_codes/unmanaged/update", - json: (object) $request_payload - ); - } -} - -class AcsAccessGroupsClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function add_user( - string $acs_access_group_id, - string $acs_user_id - ): void { - $request_payload = []; - - if ($acs_access_group_id !== null) { - $request_payload["acs_access_group_id"] = $acs_access_group_id; - } - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - - $this->seam->request( - "POST", - "/acs/access_groups/add_user", - json: (object) $request_payload - ); - } - - public function get(string $acs_access_group_id): AcsAccessGroup - { - $request_payload = []; - - if ($acs_access_group_id !== null) { - $request_payload["acs_access_group_id"] = $acs_access_group_id; - } - - $res = $this->seam->request( - "POST", - "/acs/access_groups/get", - json: (object) $request_payload, - inner_object: "acs_access_group" - ); - - return AcsAccessGroup::from_json($res); - } - - public function list( - string $acs_system_id = null, - string $acs_user_id = null - ): array { - $request_payload = []; - - if ($acs_system_id !== null) { - $request_payload["acs_system_id"] = $acs_system_id; - } - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - - $res = $this->seam->request( - "POST", - "/acs/access_groups/list", - json: (object) $request_payload, - inner_object: "acs_access_groups" - ); - - return array_map(fn($r) => AcsAccessGroup::from_json($r), $res); - } - - public function list_accessible_entrances( - string $acs_access_group_id - ): array { - $request_payload = []; - - if ($acs_access_group_id !== null) { - $request_payload["acs_access_group_id"] = $acs_access_group_id; - } - - $res = $this->seam->request( - "POST", - "/acs/access_groups/list_accessible_entrances", - json: (object) $request_payload, - inner_object: "acs_entrances" - ); - - return array_map(fn($r) => AcsEntrance::from_json($r), $res); - } - - public function list_users(string $acs_access_group_id): array - { - $request_payload = []; - - if ($acs_access_group_id !== null) { - $request_payload["acs_access_group_id"] = $acs_access_group_id; - } - - $res = $this->seam->request( - "POST", - "/acs/access_groups/list_users", - json: (object) $request_payload, - inner_object: "acs_users" - ); - - return array_map(fn($r) => AcsUser::from_json($r), $res); - } - - public function remove_user( - string $acs_access_group_id, - string $acs_user_id - ): void { - $request_payload = []; - - if ($acs_access_group_id !== null) { - $request_payload["acs_access_group_id"] = $acs_access_group_id; - } - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - - $this->seam->request( - "POST", - "/acs/access_groups/remove_user", - json: (object) $request_payload - ); - } -} - -class AcsClient -{ - private SeamClient $seam; - public AcsAccessGroupsClient $access_groups; - public AcsCredentialPoolsClient $credential_pools; - public AcsCredentialProvisioningAutomationsClient $credential_provisioning_automations; - public AcsCredentialsClient $credentials; - public AcsEncodersClient $encoders; - public AcsEntrancesClient $entrances; - public AcsSystemsClient $systems; - public AcsUsersClient $users; - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - $this->access_groups = new AcsAccessGroupsClient($seam); - $this->credential_pools = new AcsCredentialPoolsClient($seam); - $this->credential_provisioning_automations = new AcsCredentialProvisioningAutomationsClient( - $seam - ); - $this->credentials = new AcsCredentialsClient($seam); - $this->encoders = new AcsEncodersClient($seam); - $this->entrances = new AcsEntrancesClient($seam); - $this->systems = new AcsSystemsClient($seam); - $this->users = new AcsUsersClient($seam); - } -} - -class AcsAccessGroupsUnmanagedClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function get(string $acs_access_group_id): UnmanagedAcsAccessGroup - { - $request_payload = []; - - if ($acs_access_group_id !== null) { - $request_payload["acs_access_group_id"] = $acs_access_group_id; - } - - $res = $this->seam->request( - "POST", - "/acs/access_groups/unmanaged/get", - json: (object) $request_payload, - inner_object: "acs_access_group" - ); - - return UnmanagedAcsAccessGroup::from_json($res); - } - - public function list( - string $acs_system_id = null, - string $acs_user_id = null - ): array { - $request_payload = []; - - if ($acs_system_id !== null) { - $request_payload["acs_system_id"] = $acs_system_id; - } - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - - $res = $this->seam->request( - "POST", - "/acs/access_groups/unmanaged/list", - json: (object) $request_payload, - inner_object: "acs_access_groups" - ); - - return array_map( - fn($r) => UnmanagedAcsAccessGroup::from_json($r), - $res - ); - } -} - -class AcsCredentialPoolsClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function list(string $acs_system_id): array - { - $request_payload = []; - - if ($acs_system_id !== null) { - $request_payload["acs_system_id"] = $acs_system_id; - } - - $res = $this->seam->request( - "POST", - "/acs/credential_pools/list", - json: (object) $request_payload, - inner_object: "acs_credential_pools" - ); - - return array_map(fn($r) => AcsCredentialPool::from_json($r), $res); - } -} - -class AcsCredentialProvisioningAutomationsClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function launch( - string $credential_manager_acs_system_id, - string $user_identity_id, - string $acs_credential_pool_id = null, - bool $create_credential_manager_user = null, - string $credential_manager_acs_user_id = null - ): AcsCredentialProvisioningAutomation { - $request_payload = []; - - if ($credential_manager_acs_system_id !== null) { - $request_payload[ - "credential_manager_acs_system_id" - ] = $credential_manager_acs_system_id; - } - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - if ($acs_credential_pool_id !== null) { - $request_payload[ - "acs_credential_pool_id" - ] = $acs_credential_pool_id; - } - if ($create_credential_manager_user !== null) { - $request_payload[ - "create_credential_manager_user" - ] = $create_credential_manager_user; - } - if ($credential_manager_acs_user_id !== null) { - $request_payload[ - "credential_manager_acs_user_id" - ] = $credential_manager_acs_user_id; - } - - $res = $this->seam->request( - "POST", - "/acs/credential_provisioning_automations/launch", - json: (object) $request_payload, - inner_object: "acs_credential_provisioning_automation" - ); - - return AcsCredentialProvisioningAutomation::from_json($res); - } -} - -class AcsCredentialsClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function assign(string $acs_credential_id, string $acs_user_id): void - { - $request_payload = []; - - if ($acs_credential_id !== null) { - $request_payload["acs_credential_id"] = $acs_credential_id; - } - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - - $this->seam->request( - "POST", - "/acs/credentials/assign", - json: (object) $request_payload - ); - } - - public function create( - string $access_method, - string $acs_user_id, - array $allowed_acs_entrance_ids = null, - mixed $assa_abloy_vostio_metadata = null, - string $code = null, - string $credential_manager_acs_system_id = null, - string $ends_at = null, - bool $is_multi_phone_sync_credential = null, - mixed $salto_space_metadata = null, - string $starts_at = null, - mixed $visionline_metadata = null - ): AcsCredential { - $request_payload = []; - - if ($access_method !== null) { - $request_payload["access_method"] = $access_method; - } - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - if ($allowed_acs_entrance_ids !== null) { - $request_payload[ - "allowed_acs_entrance_ids" - ] = $allowed_acs_entrance_ids; - } - if ($assa_abloy_vostio_metadata !== null) { - $request_payload[ - "assa_abloy_vostio_metadata" - ] = $assa_abloy_vostio_metadata; - } - if ($code !== null) { - $request_payload["code"] = $code; - } - if ($credential_manager_acs_system_id !== null) { - $request_payload[ - "credential_manager_acs_system_id" - ] = $credential_manager_acs_system_id; - } - if ($ends_at !== null) { - $request_payload["ends_at"] = $ends_at; - } - if ($is_multi_phone_sync_credential !== null) { - $request_payload[ - "is_multi_phone_sync_credential" - ] = $is_multi_phone_sync_credential; - } - if ($salto_space_metadata !== null) { - $request_payload["salto_space_metadata"] = $salto_space_metadata; - } - if ($starts_at !== null) { - $request_payload["starts_at"] = $starts_at; - } - if ($visionline_metadata !== null) { - $request_payload["visionline_metadata"] = $visionline_metadata; - } - - $res = $this->seam->request( - "POST", - "/acs/credentials/create", - json: (object) $request_payload, - inner_object: "acs_credential" - ); - - return AcsCredential::from_json($res); - } - - public function create_offline_code( - string $acs_user_id, - string $allowed_acs_entrance_id, - string $ends_at = null, - bool $is_one_time_use = null, - string $starts_at = null - ): AcsCredential { - $request_payload = []; - - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - if ($allowed_acs_entrance_id !== null) { - $request_payload[ - "allowed_acs_entrance_id" - ] = $allowed_acs_entrance_id; - } - if ($ends_at !== null) { - $request_payload["ends_at"] = $ends_at; - } - if ($is_one_time_use !== null) { - $request_payload["is_one_time_use"] = $is_one_time_use; - } - if ($starts_at !== null) { - $request_payload["starts_at"] = $starts_at; - } - - $res = $this->seam->request( - "POST", - "/acs/credentials/create_offline_code", - json: (object) $request_payload, - inner_object: "acs_credential" - ); - - return AcsCredential::from_json($res); - } - - public function delete(string $acs_credential_id): void - { - $request_payload = []; - - if ($acs_credential_id !== null) { - $request_payload["acs_credential_id"] = $acs_credential_id; - } - - $this->seam->request( - "POST", - "/acs/credentials/delete", - json: (object) $request_payload - ); - } - - public function get(string $acs_credential_id): AcsCredential - { - $request_payload = []; - - if ($acs_credential_id !== null) { - $request_payload["acs_credential_id"] = $acs_credential_id; - } - - $res = $this->seam->request( - "POST", - "/acs/credentials/get", - json: (object) $request_payload, - inner_object: "acs_credential" - ); - - return AcsCredential::from_json($res); - } - - public function list( - string $acs_user_id = null, - string $acs_system_id = null, - string $user_identity_id = null, - string $created_before = null, - bool $is_multi_phone_sync_credential = null, - float $limit = null - ): array { - $request_payload = []; - - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - if ($acs_system_id !== null) { - $request_payload["acs_system_id"] = $acs_system_id; - } - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - if ($created_before !== null) { - $request_payload["created_before"] = $created_before; - } - if ($is_multi_phone_sync_credential !== null) { - $request_payload[ - "is_multi_phone_sync_credential" - ] = $is_multi_phone_sync_credential; - } - if ($limit !== null) { - $request_payload["limit"] = $limit; - } - - $res = $this->seam->request( - "POST", - "/acs/credentials/list", - json: (object) $request_payload, - inner_object: "acs_credentials" - ); - - return array_map(fn($r) => AcsCredential::from_json($r), $res); - } - - public function list_accessible_entrances(string $acs_credential_id): array - { - $request_payload = []; - - if ($acs_credential_id !== null) { - $request_payload["acs_credential_id"] = $acs_credential_id; - } - - $res = $this->seam->request( - "POST", - "/acs/credentials/list_accessible_entrances", - json: (object) $request_payload, - inner_object: "acs_entrances" - ); - - return array_map(fn($r) => AcsEntrance::from_json($r), $res); - } - - public function unassign( - string $acs_credential_id, - string $acs_user_id - ): void { - $request_payload = []; - - if ($acs_credential_id !== null) { - $request_payload["acs_credential_id"] = $acs_credential_id; - } - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - - $this->seam->request( - "POST", - "/acs/credentials/unassign", - json: (object) $request_payload - ); - } - - public function update( - string $acs_credential_id, - string $code = null, - string $ends_at = null - ): void { - $request_payload = []; - - if ($acs_credential_id !== null) { - $request_payload["acs_credential_id"] = $acs_credential_id; - } - if ($code !== null) { - $request_payload["code"] = $code; - } - if ($ends_at !== null) { - $request_payload["ends_at"] = $ends_at; - } - - $this->seam->request( - "POST", - "/acs/credentials/update", - json: (object) $request_payload - ); - } -} - -class AcsCredentialsUnmanagedClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function get(string $acs_credential_id): UnmanagedAcsCredential - { - $request_payload = []; - - if ($acs_credential_id !== null) { - $request_payload["acs_credential_id"] = $acs_credential_id; - } - - $res = $this->seam->request( - "POST", - "/acs/credentials/unmanaged/get", - json: (object) $request_payload, - inner_object: "acs_credential" - ); - - return UnmanagedAcsCredential::from_json($res); - } - - public function list( - string $acs_user_id = null, - string $acs_system_id = null, - string $user_identity_id = null - ): array { - $request_payload = []; - - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - if ($acs_system_id !== null) { - $request_payload["acs_system_id"] = $acs_system_id; - } - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - - $res = $this->seam->request( - "POST", - "/acs/credentials/unmanaged/list", - json: (object) $request_payload, - inner_object: "acs_credentials" - ); - - return array_map(fn($r) => UnmanagedAcsCredential::from_json($r), $res); - } -} - -class AcsEncodersClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function encode_credential( - string $acs_credential_id, - string $acs_encoder_id, - bool $wait_for_action_attempt = true - ): ActionAttempt { - $request_payload = []; - - if ($acs_credential_id !== null) { - $request_payload["acs_credential_id"] = $acs_credential_id; - } - if ($acs_encoder_id !== null) { - $request_payload["acs_encoder_id"] = $acs_encoder_id; - } - - $res = $this->seam->request( - "POST", - "/acs/encoders/encode_credential", - json: (object) $request_payload, - inner_object: "action_attempt" - ); - - if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); - } - - $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id - ); - - return $action_attempt; - } - - public function list( - string $acs_system_id = null, - float $limit = null, - array $acs_system_ids = null, - array $acs_encoder_ids = null - ): array { - $request_payload = []; - - if ($acs_system_id !== null) { - $request_payload["acs_system_id"] = $acs_system_id; - } - if ($limit !== null) { - $request_payload["limit"] = $limit; - } - if ($acs_system_ids !== null) { - $request_payload["acs_system_ids"] = $acs_system_ids; - } - if ($acs_encoder_ids !== null) { - $request_payload["acs_encoder_ids"] = $acs_encoder_ids; - } - - $res = $this->seam->request( - "POST", - "/acs/encoders/list", - json: (object) $request_payload, - inner_object: "acs_encoders" - ); - - return array_map(fn($r) => AcsEncoder::from_json($r), $res); - } - - public function scan_credential( - string $acs_encoder_id, - bool $wait_for_action_attempt = true - ): ActionAttempt { - $request_payload = []; - - if ($acs_encoder_id !== null) { - $request_payload["acs_encoder_id"] = $acs_encoder_id; - } - - $res = $this->seam->request( - "POST", - "/acs/encoders/scan_credential", - json: (object) $request_payload, - inner_object: "action_attempt" - ); - - if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); - } - - $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id - ); - - return $action_attempt; - } -} - -class AcsEncodersSimulateClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function next_credential_encode_will_fail( - string $acs_encoder_id, - string $error_code = null, - string $acs_credential_id = null - ): void { - $request_payload = []; - - if ($acs_encoder_id !== null) { - $request_payload["acs_encoder_id"] = $acs_encoder_id; - } - if ($error_code !== null) { - $request_payload["error_code"] = $error_code; - } - if ($acs_credential_id !== null) { - $request_payload["acs_credential_id"] = $acs_credential_id; - } - - $this->seam->request( - "POST", - "/acs/encoders/simulate/next_credential_encode_will_fail", - json: (object) $request_payload - ); - } - - public function next_credential_encode_will_succeed( - string $acs_encoder_id, - string $scenario = null - ): void { - $request_payload = []; - - if ($acs_encoder_id !== null) { - $request_payload["acs_encoder_id"] = $acs_encoder_id; - } - if ($scenario !== null) { - $request_payload["scenario"] = $scenario; - } - - $this->seam->request( - "POST", - "/acs/encoders/simulate/next_credential_encode_will_succeed", - json: (object) $request_payload - ); - } - - public function next_credential_scan_will_fail( - string $acs_encoder_id, - string $error_code = null, - string $acs_credential_id_on_seam = null - ): void { - $request_payload = []; - - if ($acs_encoder_id !== null) { - $request_payload["acs_encoder_id"] = $acs_encoder_id; - } - if ($error_code !== null) { - $request_payload["error_code"] = $error_code; - } - if ($acs_credential_id_on_seam !== null) { - $request_payload[ - "acs_credential_id_on_seam" - ] = $acs_credential_id_on_seam; - } - - $this->seam->request( - "POST", - "/acs/encoders/simulate/next_credential_scan_will_fail", - json: (object) $request_payload - ); - } - - public function next_credential_scan_will_succeed( - string $acs_encoder_id, - string $acs_credential_id_on_seam = null, - string $scenario = null - ): void { - $request_payload = []; - - if ($acs_encoder_id !== null) { - $request_payload["acs_encoder_id"] = $acs_encoder_id; - } - if ($acs_credential_id_on_seam !== null) { - $request_payload[ - "acs_credential_id_on_seam" - ] = $acs_credential_id_on_seam; - } - if ($scenario !== null) { - $request_payload["scenario"] = $scenario; - } - - $this->seam->request( - "POST", - "/acs/encoders/simulate/next_credential_scan_will_succeed", - json: (object) $request_payload - ); - } -} - -class AcsEntrancesClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function get(string $acs_entrance_id): AcsEntrance - { - $request_payload = []; - - if ($acs_entrance_id !== null) { - $request_payload["acs_entrance_id"] = $acs_entrance_id; - } - - $res = $this->seam->request( - "POST", - "/acs/entrances/get", - json: (object) $request_payload, - inner_object: "acs_entrance" - ); - - return AcsEntrance::from_json($res); - } - - public function grant_access( - string $acs_entrance_id, - string $acs_user_id - ): void { - $request_payload = []; - - if ($acs_entrance_id !== null) { - $request_payload["acs_entrance_id"] = $acs_entrance_id; - } - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - - $this->seam->request( - "POST", - "/acs/entrances/grant_access", - json: (object) $request_payload - ); - } - - public function list( - string $acs_credential_id = null, - string $acs_system_id = null - ): array { - $request_payload = []; - - if ($acs_credential_id !== null) { - $request_payload["acs_credential_id"] = $acs_credential_id; - } - if ($acs_system_id !== null) { - $request_payload["acs_system_id"] = $acs_system_id; - } - - $res = $this->seam->request( - "POST", - "/acs/entrances/list", - json: (object) $request_payload, - inner_object: "acs_entrances" - ); - - return array_map(fn($r) => AcsEntrance::from_json($r), $res); - } - - public function list_credentials_with_access( - string $acs_entrance_id, - array $include_if = null - ): array { - $request_payload = []; - - if ($acs_entrance_id !== null) { - $request_payload["acs_entrance_id"] = $acs_entrance_id; - } - if ($include_if !== null) { - $request_payload["include_if"] = $include_if; - } - - $res = $this->seam->request( - "POST", - "/acs/entrances/list_credentials_with_access", - json: (object) $request_payload, - inner_object: "acs_credentials" - ); - - return array_map(fn($r) => AcsCredential::from_json($r), $res); - } -} - -class AcsSystemsClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function get(string $acs_system_id): AcsSystem - { - $request_payload = []; - - if ($acs_system_id !== null) { - $request_payload["acs_system_id"] = $acs_system_id; - } - - $res = $this->seam->request( - "POST", - "/acs/systems/get", - json: (object) $request_payload, - inner_object: "acs_system" - ); - - return AcsSystem::from_json($res); - } - - public function list(string $connected_account_id = null): array - { - $request_payload = []; - - if ($connected_account_id !== null) { - $request_payload["connected_account_id"] = $connected_account_id; - } - - $res = $this->seam->request( - "POST", - "/acs/systems/list", - json: (object) $request_payload, - inner_object: "acs_systems" - ); - - return array_map(fn($r) => AcsSystem::from_json($r), $res); - } - - public function list_compatible_credential_manager_acs_systems( - string $acs_system_id - ): array { - $request_payload = []; - - if ($acs_system_id !== null) { - $request_payload["acs_system_id"] = $acs_system_id; - } - - $res = $this->seam->request( - "POST", - "/acs/systems/list_compatible_credential_manager_acs_systems", - json: (object) $request_payload, - inner_object: "acs_systems" - ); - - return array_map(fn($r) => AcsSystem::from_json($r), $res); - } -} - -class AcsUsersClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function add_to_access_group( - string $acs_access_group_id, - string $acs_user_id - ): void { - $request_payload = []; - - if ($acs_access_group_id !== null) { - $request_payload["acs_access_group_id"] = $acs_access_group_id; - } - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - - $this->seam->request( - "POST", - "/acs/users/add_to_access_group", - json: (object) $request_payload - ); - } - - public function create( - string $acs_system_id, - string $full_name, - mixed $access_schedule = null, - array $acs_access_group_ids = null, - string $email = null, - string $email_address = null, - string $phone_number = null, - string $user_identity_id = null - ): AcsUser { - $request_payload = []; - - if ($acs_system_id !== null) { - $request_payload["acs_system_id"] = $acs_system_id; - } - if ($full_name !== null) { - $request_payload["full_name"] = $full_name; - } - if ($access_schedule !== null) { - $request_payload["access_schedule"] = $access_schedule; - } - if ($acs_access_group_ids !== null) { - $request_payload["acs_access_group_ids"] = $acs_access_group_ids; - } - if ($email !== null) { - $request_payload["email"] = $email; - } - if ($email_address !== null) { - $request_payload["email_address"] = $email_address; - } - if ($phone_number !== null) { - $request_payload["phone_number"] = $phone_number; - } - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - - $res = $this->seam->request( - "POST", - "/acs/users/create", - json: (object) $request_payload, - inner_object: "acs_user" - ); - - return AcsUser::from_json($res); - } - - public function delete(string $acs_user_id): void - { - $request_payload = []; - - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - - $this->seam->request( - "POST", - "/acs/users/delete", - json: (object) $request_payload - ); - } - - public function get(string $acs_user_id): AcsUser - { - $request_payload = []; - - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - - $res = $this->seam->request( - "POST", - "/acs/users/get", - json: (object) $request_payload, - inner_object: "acs_user" - ); - - return AcsUser::from_json($res); - } - - public function list( - string $acs_system_id = null, - string $created_before = null, - float $limit = null, - string $user_identity_email_address = null, - string $user_identity_id = null, - string $user_identity_phone_number = null - ): array { - $request_payload = []; - - if ($acs_system_id !== null) { - $request_payload["acs_system_id"] = $acs_system_id; - } - if ($created_before !== null) { - $request_payload["created_before"] = $created_before; - } - if ($limit !== null) { - $request_payload["limit"] = $limit; - } - if ($user_identity_email_address !== null) { - $request_payload[ - "user_identity_email_address" - ] = $user_identity_email_address; - } - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - if ($user_identity_phone_number !== null) { - $request_payload[ - "user_identity_phone_number" - ] = $user_identity_phone_number; - } - - $res = $this->seam->request( - "POST", - "/acs/users/list", - json: (object) $request_payload, - inner_object: "acs_users" - ); - - return array_map(fn($r) => AcsUser::from_json($r), $res); - } - - public function list_accessible_entrances(string $acs_user_id): array - { - $request_payload = []; - - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - - $res = $this->seam->request( - "POST", - "/acs/users/list_accessible_entrances", - json: (object) $request_payload, - inner_object: "acs_entrances" - ); - - return array_map(fn($r) => AcsEntrance::from_json($r), $res); - } - - public function remove_from_access_group( - string $acs_access_group_id, - string $acs_user_id - ): void { - $request_payload = []; - - if ($acs_access_group_id !== null) { - $request_payload["acs_access_group_id"] = $acs_access_group_id; - } - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - - $this->seam->request( - "POST", - "/acs/users/remove_from_access_group", - json: (object) $request_payload - ); - } - - public function revoke_access_to_all_entrances(string $acs_user_id): void - { - $request_payload = []; - - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - - $this->seam->request( - "POST", - "/acs/users/revoke_access_to_all_entrances", - json: (object) $request_payload - ); - } - - public function suspend(string $acs_user_id): void - { - $request_payload = []; - - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - - $this->seam->request( - "POST", - "/acs/users/suspend", - json: (object) $request_payload - ); - } - - public function unsuspend(string $acs_user_id): void - { - $request_payload = []; - - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - - $this->seam->request( - "POST", - "/acs/users/unsuspend", - json: (object) $request_payload - ); - } - - public function update( - string $acs_user_id, - mixed $access_schedule = null, - string $email = null, - string $email_address = null, - string $full_name = null, - string $hid_acs_system_id = null, - string $phone_number = null - ): void { - $request_payload = []; - - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - if ($access_schedule !== null) { - $request_payload["access_schedule"] = $access_schedule; - } - if ($email !== null) { - $request_payload["email"] = $email; - } - if ($email_address !== null) { - $request_payload["email_address"] = $email_address; - } - if ($full_name !== null) { - $request_payload["full_name"] = $full_name; - } - if ($hid_acs_system_id !== null) { - $request_payload["hid_acs_system_id"] = $hid_acs_system_id; - } - if ($phone_number !== null) { - $request_payload["phone_number"] = $phone_number; - } - - $this->seam->request( - "POST", - "/acs/users/update", - json: (object) $request_payload - ); - } -} - -class AcsUsersUnmanagedClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function get(string $acs_user_id): UnmanagedAcsUser - { - $request_payload = []; - - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - - $res = $this->seam->request( - "POST", - "/acs/users/unmanaged/get", - json: (object) $request_payload, - inner_object: "acs_user" - ); - - return UnmanagedAcsUser::from_json($res); - } - - public function list( - string $acs_system_id = null, - float $limit = null, - string $user_identity_email_address = null, - string $user_identity_id = null, - string $user_identity_phone_number = null - ): array { - $request_payload = []; - - if ($acs_system_id !== null) { - $request_payload["acs_system_id"] = $acs_system_id; - } - if ($limit !== null) { - $request_payload["limit"] = $limit; - } - if ($user_identity_email_address !== null) { - $request_payload[ - "user_identity_email_address" - ] = $user_identity_email_address; - } - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - if ($user_identity_phone_number !== null) { - $request_payload[ - "user_identity_phone_number" - ] = $user_identity_phone_number; - } - - $res = $this->seam->request( - "POST", - "/acs/users/unmanaged/list", - json: (object) $request_payload, - inner_object: "acs_users" - ); - - return array_map(fn($r) => UnmanagedAcsUser::from_json($r), $res); - } -} - -class ActionAttemptsClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function get(string $action_attempt_id): ActionAttempt - { - $request_payload = []; - - if ($action_attempt_id !== null) { - $request_payload["action_attempt_id"] = $action_attempt_id; - } - - $res = $this->seam->request( - "POST", - "/action_attempts/get", - json: (object) $request_payload, - inner_object: "action_attempt" - ); - - return ActionAttempt::from_json($res); - } - - public function list(array $action_attempt_ids): array - { - $request_payload = []; - - if ($action_attempt_ids !== null) { - $request_payload["action_attempt_ids"] = $action_attempt_ids; - } - - $res = $this->seam->request( - "POST", - "/action_attempts/list", - json: (object) $request_payload, - inner_object: "action_attempts" - ); - - return array_map(fn($r) => ActionAttempt::from_json($r), $res); - } - public function poll_until_ready( - string $action_attempt_id, - float $timeout = 20.0 - ): ActionAttempt { - $seam = $this->seam; - $time_waiting = 0.0; - $polling_interval = 0.4; - $action_attempt = $seam->action_attempts->get($action_attempt_id); - - while ($action_attempt->status == "pending") { - $action_attempt = $seam->action_attempts->get( - $action_attempt->action_attempt_id - ); - if ($time_waiting > $timeout) { - throw new ActionAttemptTimeoutError($action_attempt, $timeout); - } - $time_waiting += $polling_interval; - usleep($polling_interval * 1000000); - } - - if ($action_attempt->status == "error") { - throw new ActionAttemptFailedError($action_attempt); - } - - return $action_attempt; - } -} - -class BridgesClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function get(string $bridge_id): void - { - $request_payload = []; - - if ($bridge_id !== null) { - $request_payload["bridge_id"] = $bridge_id; - } - - $this->seam->request( - "POST", - "/bridges/get", - json: (object) $request_payload, - inner_object: "bridge" - ); - } - - public function list(): void - { - $request_payload = []; - - $this->seam->request( - "POST", - "/bridges/list", - json: (object) $request_payload, - inner_object: "bridges" - ); - } -} - -class ClientSessionsClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function create( - array $connect_webview_ids = null, - array $connected_account_ids = null, - string $expires_at = null, - string $user_identifier_key = null, - array $user_identity_ids = null - ): ClientSession { - $request_payload = []; - - if ($connect_webview_ids !== null) { - $request_payload["connect_webview_ids"] = $connect_webview_ids; - } - if ($connected_account_ids !== null) { - $request_payload["connected_account_ids"] = $connected_account_ids; - } - if ($expires_at !== null) { - $request_payload["expires_at"] = $expires_at; - } - if ($user_identifier_key !== null) { - $request_payload["user_identifier_key"] = $user_identifier_key; - } - if ($user_identity_ids !== null) { - $request_payload["user_identity_ids"] = $user_identity_ids; - } - - $res = $this->seam->request( - "POST", - "/client_sessions/create", - json: (object) $request_payload, - inner_object: "client_session" - ); - - return ClientSession::from_json($res); - } - - public function delete(string $client_session_id): void - { - $request_payload = []; - - if ($client_session_id !== null) { - $request_payload["client_session_id"] = $client_session_id; - } - - $this->seam->request( - "POST", - "/client_sessions/delete", - json: (object) $request_payload - ); - } - - public function get( - string $client_session_id = null, - string $user_identifier_key = null - ): ClientSession { - $request_payload = []; - - if ($client_session_id !== null) { - $request_payload["client_session_id"] = $client_session_id; - } - if ($user_identifier_key !== null) { - $request_payload["user_identifier_key"] = $user_identifier_key; - } - - $res = $this->seam->request( - "POST", - "/client_sessions/get", - json: (object) $request_payload, - inner_object: "client_session" - ); - - return ClientSession::from_json($res); - } - - public function get_or_create( - array $connect_webview_ids = null, - array $connected_account_ids = null, - string $expires_at = null, - string $user_identifier_key = null, - array $user_identity_ids = null - ): ClientSession { - $request_payload = []; - - if ($connect_webview_ids !== null) { - $request_payload["connect_webview_ids"] = $connect_webview_ids; - } - if ($connected_account_ids !== null) { - $request_payload["connected_account_ids"] = $connected_account_ids; - } - if ($expires_at !== null) { - $request_payload["expires_at"] = $expires_at; - } - if ($user_identifier_key !== null) { - $request_payload["user_identifier_key"] = $user_identifier_key; - } - if ($user_identity_ids !== null) { - $request_payload["user_identity_ids"] = $user_identity_ids; - } - - $res = $this->seam->request( - "POST", - "/client_sessions/get_or_create", - json: (object) $request_payload, - inner_object: "client_session" - ); - - return ClientSession::from_json($res); - } - - public function grant_access( - string $client_session_id = null, - array $connect_webview_ids = null, - array $connected_account_ids = null, - string $user_identifier_key = null, - array $user_identity_ids = null - ): void { - $request_payload = []; - - if ($client_session_id !== null) { - $request_payload["client_session_id"] = $client_session_id; - } - if ($connect_webview_ids !== null) { - $request_payload["connect_webview_ids"] = $connect_webview_ids; - } - if ($connected_account_ids !== null) { - $request_payload["connected_account_ids"] = $connected_account_ids; - } - if ($user_identifier_key !== null) { - $request_payload["user_identifier_key"] = $user_identifier_key; - } - if ($user_identity_ids !== null) { - $request_payload["user_identity_ids"] = $user_identity_ids; - } - - $this->seam->request( - "POST", - "/client_sessions/grant_access", - json: (object) $request_payload - ); - } - - public function list( - string $client_session_id = null, - string $connect_webview_id = null, - string $user_identifier_key = null, - string $user_identity_id = null, - bool $without_user_identifier_key = null - ): array { - $request_payload = []; - - if ($client_session_id !== null) { - $request_payload["client_session_id"] = $client_session_id; - } - if ($connect_webview_id !== null) { - $request_payload["connect_webview_id"] = $connect_webview_id; - } - if ($user_identifier_key !== null) { - $request_payload["user_identifier_key"] = $user_identifier_key; - } - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - if ($without_user_identifier_key !== null) { - $request_payload[ - "without_user_identifier_key" - ] = $without_user_identifier_key; - } - - $res = $this->seam->request( - "POST", - "/client_sessions/list", - json: (object) $request_payload, - inner_object: "client_sessions" - ); - - return array_map(fn($r) => ClientSession::from_json($r), $res); - } - - public function revoke(string $client_session_id): void - { - $request_payload = []; - - if ($client_session_id !== null) { - $request_payload["client_session_id"] = $client_session_id; - } - - $this->seam->request( - "POST", - "/client_sessions/revoke", - json: (object) $request_payload - ); - } -} - -class ConnectWebviewsClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function create( - array $accepted_providers = null, - bool $automatically_manage_new_devices = null, - mixed $custom_metadata = null, - string $custom_redirect_failure_url = null, - string $custom_redirect_url = null, - string $device_selection_mode = null, - string $provider_category = null, - bool $wait_for_device_creation = null - ): ConnectWebview { - $request_payload = []; - - if ($accepted_providers !== null) { - $request_payload["accepted_providers"] = $accepted_providers; - } - if ($automatically_manage_new_devices !== null) { - $request_payload[ - "automatically_manage_new_devices" - ] = $automatically_manage_new_devices; - } - if ($custom_metadata !== null) { - $request_payload["custom_metadata"] = $custom_metadata; - } - if ($custom_redirect_failure_url !== null) { - $request_payload[ - "custom_redirect_failure_url" - ] = $custom_redirect_failure_url; - } - if ($custom_redirect_url !== null) { - $request_payload["custom_redirect_url"] = $custom_redirect_url; - } - if ($device_selection_mode !== null) { - $request_payload["device_selection_mode"] = $device_selection_mode; - } - if ($provider_category !== null) { - $request_payload["provider_category"] = $provider_category; - } - if ($wait_for_device_creation !== null) { - $request_payload[ - "wait_for_device_creation" - ] = $wait_for_device_creation; - } - - $res = $this->seam->request( - "POST", - "/connect_webviews/create", - json: (object) $request_payload, - inner_object: "connect_webview" - ); - - return ConnectWebview::from_json($res); - } - - public function delete(string $connect_webview_id): void - { - $request_payload = []; - - if ($connect_webview_id !== null) { - $request_payload["connect_webview_id"] = $connect_webview_id; - } - - $this->seam->request( - "POST", - "/connect_webviews/delete", - json: (object) $request_payload - ); - } - - public function get(string $connect_webview_id): ConnectWebview - { - $request_payload = []; - - if ($connect_webview_id !== null) { - $request_payload["connect_webview_id"] = $connect_webview_id; - } - - $res = $this->seam->request( - "POST", - "/connect_webviews/get", - json: (object) $request_payload, - inner_object: "connect_webview" - ); - - return ConnectWebview::from_json($res); - } - - public function list( - mixed $custom_metadata_has = null, - float $limit = null, - string $user_identifier_key = null - ): array { - $request_payload = []; - - if ($custom_metadata_has !== null) { - $request_payload["custom_metadata_has"] = $custom_metadata_has; - } - if ($limit !== null) { - $request_payload["limit"] = $limit; - } - if ($user_identifier_key !== null) { - $request_payload["user_identifier_key"] = $user_identifier_key; - } - - $res = $this->seam->request( - "POST", - "/connect_webviews/list", - json: (object) $request_payload, - inner_object: "connect_webviews" - ); - - return array_map(fn($r) => ConnectWebview::from_json($r), $res); - } -} - -class ConnectedAccountsClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function delete( - string $connected_account_id, - bool $sync = null - ): void { - $request_payload = []; - - if ($connected_account_id !== null) { - $request_payload["connected_account_id"] = $connected_account_id; - } - if ($sync !== null) { - $request_payload["sync"] = $sync; - } - - $this->seam->request( - "POST", - "/connected_accounts/delete", - json: (object) $request_payload - ); - } - - public function get( - string $connected_account_id = null, - string $email = null - ): ConnectedAccount { - $request_payload = []; - - if ($connected_account_id !== null) { - $request_payload["connected_account_id"] = $connected_account_id; - } - if ($email !== null) { - $request_payload["email"] = $email; - } - - $res = $this->seam->request( - "POST", - "/connected_accounts/get", - json: (object) $request_payload, - inner_object: "connected_account" - ); - - return ConnectedAccount::from_json($res); - } - - public function list( - mixed $custom_metadata_has = null, - string $user_identifier_key = null - ): array { - $request_payload = []; - - if ($custom_metadata_has !== null) { - $request_payload["custom_metadata_has"] = $custom_metadata_has; - } - if ($user_identifier_key !== null) { - $request_payload["user_identifier_key"] = $user_identifier_key; - } - - $res = $this->seam->request( - "POST", - "/connected_accounts/list", - json: (object) $request_payload, - inner_object: "connected_accounts" - ); - - return array_map(fn($r) => ConnectedAccount::from_json($r), $res); - } - - public function update( - string $connected_account_id, - bool $automatically_manage_new_devices = null, - mixed $custom_metadata = null - ): void { - $request_payload = []; - - if ($connected_account_id !== null) { - $request_payload["connected_account_id"] = $connected_account_id; - } - if ($automatically_manage_new_devices !== null) { - $request_payload[ - "automatically_manage_new_devices" - ] = $automatically_manage_new_devices; - } - if ($custom_metadata !== null) { - $request_payload["custom_metadata"] = $custom_metadata; - } - - $this->seam->request( - "POST", - "/connected_accounts/update", - json: (object) $request_payload - ); - } -} - -class DevicesClient -{ - private SeamClient $seam; - public DevicesSimulateClient $simulate; - public DevicesUnmanagedClient $unmanaged; - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - $this->simulate = new DevicesSimulateClient($seam); - $this->unmanaged = new DevicesUnmanagedClient($seam); - } - - public function delete(string $device_id): void - { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - - $this->seam->request( - "POST", - "/devices/delete", - json: (object) $request_payload - ); - } - - public function get(string $device_id = null, string $name = null): Device - { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($name !== null) { - $request_payload["name"] = $name; - } - - $res = $this->seam->request( - "POST", - "/devices/get", - json: (object) $request_payload, - inner_object: "device" - ); - - return Device::from_json($res); - } - - public function list( - string $connect_webview_id = null, - string $connected_account_id = null, - array $connected_account_ids = null, - string $created_before = null, - mixed $custom_metadata_has = null, - array $device_ids = null, - string $device_type = null, - array $device_types = null, - array $exclude_if = null, - array $include_if = null, - float $limit = null, - string $manufacturer = null, - string $user_identifier_key = null - ): array { - $request_payload = []; - - if ($connect_webview_id !== null) { - $request_payload["connect_webview_id"] = $connect_webview_id; - } - if ($connected_account_id !== null) { - $request_payload["connected_account_id"] = $connected_account_id; - } - if ($connected_account_ids !== null) { - $request_payload["connected_account_ids"] = $connected_account_ids; - } - if ($created_before !== null) { - $request_payload["created_before"] = $created_before; - } - if ($custom_metadata_has !== null) { - $request_payload["custom_metadata_has"] = $custom_metadata_has; - } - if ($device_ids !== null) { - $request_payload["device_ids"] = $device_ids; - } - if ($device_type !== null) { - $request_payload["device_type"] = $device_type; - } - if ($device_types !== null) { - $request_payload["device_types"] = $device_types; - } - if ($exclude_if !== null) { - $request_payload["exclude_if"] = $exclude_if; - } - if ($include_if !== null) { - $request_payload["include_if"] = $include_if; - } - if ($limit !== null) { - $request_payload["limit"] = $limit; - } - if ($manufacturer !== null) { - $request_payload["manufacturer"] = $manufacturer; - } - if ($user_identifier_key !== null) { - $request_payload["user_identifier_key"] = $user_identifier_key; - } - - $res = $this->seam->request( - "POST", - "/devices/list", - json: (object) $request_payload, - inner_object: "devices" - ); - - return array_map(fn($r) => Device::from_json($r), $res); - } - - public function list_device_providers( - string $provider_category = null - ): array { - $request_payload = []; - - if ($provider_category !== null) { - $request_payload["provider_category"] = $provider_category; - } - - $res = $this->seam->request( - "POST", - "/devices/list_device_providers", - json: (object) $request_payload, - inner_object: "device_providers" - ); - - return array_map(fn($r) => DeviceProvider::from_json($r), $res); - } - - public function update( - string $device_id, - mixed $custom_metadata = null, - bool $is_managed = null, - string $name = null, - mixed $properties = null - ): void { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($custom_metadata !== null) { - $request_payload["custom_metadata"] = $custom_metadata; - } - if ($is_managed !== null) { - $request_payload["is_managed"] = $is_managed; - } - if ($name !== null) { - $request_payload["name"] = $name; - } - if ($properties !== null) { - $request_payload["properties"] = $properties; - } - - $this->seam->request( - "POST", - "/devices/update", - json: (object) $request_payload - ); - } -} - -class DevicesSimulateClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function connect(string $device_id): void - { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - - $this->seam->request( - "POST", - "/devices/simulate/connect", - json: (object) $request_payload - ); - } - - public function disconnect(string $device_id): void - { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - - $this->seam->request( - "POST", - "/devices/simulate/disconnect", - json: (object) $request_payload - ); - } - - public function remove(string $device_id): void - { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - - $this->seam->request( - "POST", - "/devices/simulate/remove", - json: (object) $request_payload - ); - } -} - -class DevicesUnmanagedClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function get( - string $device_id = null, - string $name = null - ): UnmanagedDevice { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($name !== null) { - $request_payload["name"] = $name; - } - - $res = $this->seam->request( - "POST", - "/devices/unmanaged/get", - json: (object) $request_payload, - inner_object: "device" - ); - - return UnmanagedDevice::from_json($res); - } - - public function list( - string $connect_webview_id = null, - string $connected_account_id = null, - array $connected_account_ids = null, - string $created_before = null, - mixed $custom_metadata_has = null, - array $device_ids = null, - string $device_type = null, - array $device_types = null, - array $exclude_if = null, - array $include_if = null, - float $limit = null, - string $manufacturer = null, - string $user_identifier_key = null - ): array { - $request_payload = []; - - if ($connect_webview_id !== null) { - $request_payload["connect_webview_id"] = $connect_webview_id; - } - if ($connected_account_id !== null) { - $request_payload["connected_account_id"] = $connected_account_id; - } - if ($connected_account_ids !== null) { - $request_payload["connected_account_ids"] = $connected_account_ids; - } - if ($created_before !== null) { - $request_payload["created_before"] = $created_before; - } - if ($custom_metadata_has !== null) { - $request_payload["custom_metadata_has"] = $custom_metadata_has; - } - if ($device_ids !== null) { - $request_payload["device_ids"] = $device_ids; - } - if ($device_type !== null) { - $request_payload["device_type"] = $device_type; - } - if ($device_types !== null) { - $request_payload["device_types"] = $device_types; - } - if ($exclude_if !== null) { - $request_payload["exclude_if"] = $exclude_if; - } - if ($include_if !== null) { - $request_payload["include_if"] = $include_if; - } - if ($limit !== null) { - $request_payload["limit"] = $limit; - } - if ($manufacturer !== null) { - $request_payload["manufacturer"] = $manufacturer; - } - if ($user_identifier_key !== null) { - $request_payload["user_identifier_key"] = $user_identifier_key; - } - - $res = $this->seam->request( - "POST", - "/devices/unmanaged/list", - json: (object) $request_payload, - inner_object: "devices" - ); - - return array_map(fn($r) => UnmanagedDevice::from_json($r), $res); - } - - public function update(string $device_id, bool $is_managed): void - { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($is_managed !== null) { - $request_payload["is_managed"] = $is_managed; - } - - $this->seam->request( - "POST", - "/devices/unmanaged/update", - json: (object) $request_payload - ); - } -} - -class EventsClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function get( - string $device_id = null, - string $event_id = null, - string $event_type = null - ): Event { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($event_id !== null) { - $request_payload["event_id"] = $event_id; - } - if ($event_type !== null) { - $request_payload["event_type"] = $event_type; - } - - $res = $this->seam->request( - "POST", - "/events/get", - json: (object) $request_payload, - inner_object: "event" - ); - - return Event::from_json($res); - } - - public function list( - string $access_code_id = null, - array $access_code_ids = null, - string $acs_system_id = null, - array $acs_system_ids = null, - array $between = null, - string $connect_webview_id = null, - string $connected_account_id = null, - string $device_id = null, - array $device_ids = null, - string $event_type = null, - array $event_types = null, - float $limit = null, - string $since = null, - float $unstable_offset = null - ): array { - $request_payload = []; - - if ($access_code_id !== null) { - $request_payload["access_code_id"] = $access_code_id; - } - if ($access_code_ids !== null) { - $request_payload["access_code_ids"] = $access_code_ids; - } - if ($acs_system_id !== null) { - $request_payload["acs_system_id"] = $acs_system_id; - } - if ($acs_system_ids !== null) { - $request_payload["acs_system_ids"] = $acs_system_ids; - } - if ($between !== null) { - $request_payload["between"] = $between; - } - if ($connect_webview_id !== null) { - $request_payload["connect_webview_id"] = $connect_webview_id; - } - if ($connected_account_id !== null) { - $request_payload["connected_account_id"] = $connected_account_id; - } - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($device_ids !== null) { - $request_payload["device_ids"] = $device_ids; - } - if ($event_type !== null) { - $request_payload["event_type"] = $event_type; - } - if ($event_types !== null) { - $request_payload["event_types"] = $event_types; - } - if ($limit !== null) { - $request_payload["limit"] = $limit; - } - if ($since !== null) { - $request_payload["since"] = $since; - } - if ($unstable_offset !== null) { - $request_payload["unstable_offset"] = $unstable_offset; - } - - $res = $this->seam->request( - "POST", - "/events/list", - json: (object) $request_payload, - inner_object: "events" - ); - - return array_map(fn($r) => Event::from_json($r), $res); - } -} - -class LocksClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function get(string $device_id = null, string $name = null): Device - { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($name !== null) { - $request_payload["name"] = $name; - } - - $res = $this->seam->request( - "POST", - "/locks/get", - json: (object) $request_payload, - inner_object: "device" - ); - - return Device::from_json($res); - } - - public function list( - string $connect_webview_id = null, - string $connected_account_id = null, - array $connected_account_ids = null, - string $created_before = null, - mixed $custom_metadata_has = null, - array $device_ids = null, - string $device_type = null, - array $device_types = null, - array $exclude_if = null, - array $include_if = null, - float $limit = null, - string $manufacturer = null, - string $user_identifier_key = null - ): array { - $request_payload = []; - - if ($connect_webview_id !== null) { - $request_payload["connect_webview_id"] = $connect_webview_id; - } - if ($connected_account_id !== null) { - $request_payload["connected_account_id"] = $connected_account_id; - } - if ($connected_account_ids !== null) { - $request_payload["connected_account_ids"] = $connected_account_ids; - } - if ($created_before !== null) { - $request_payload["created_before"] = $created_before; - } - if ($custom_metadata_has !== null) { - $request_payload["custom_metadata_has"] = $custom_metadata_has; - } - if ($device_ids !== null) { - $request_payload["device_ids"] = $device_ids; - } - if ($device_type !== null) { - $request_payload["device_type"] = $device_type; - } - if ($device_types !== null) { - $request_payload["device_types"] = $device_types; - } - if ($exclude_if !== null) { - $request_payload["exclude_if"] = $exclude_if; - } - if ($include_if !== null) { - $request_payload["include_if"] = $include_if; - } - if ($limit !== null) { - $request_payload["limit"] = $limit; - } - if ($manufacturer !== null) { - $request_payload["manufacturer"] = $manufacturer; - } - if ($user_identifier_key !== null) { - $request_payload["user_identifier_key"] = $user_identifier_key; - } - - $res = $this->seam->request( - "POST", - "/locks/list", - json: (object) $request_payload, - inner_object: "devices" - ); - - return array_map(fn($r) => Device::from_json($r), $res); - } - - public function lock_door( - string $device_id, - bool $sync = null, - bool $wait_for_action_attempt = true - ): ActionAttempt { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($sync !== null) { - $request_payload["sync"] = $sync; - } - - $res = $this->seam->request( - "POST", - "/locks/lock_door", - json: (object) $request_payload, - inner_object: "action_attempt" - ); - - if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); - } - - $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id - ); - - return $action_attempt; - } - - public function unlock_door( - string $device_id, - bool $sync = null, - bool $wait_for_action_attempt = true - ): ActionAttempt { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($sync !== null) { - $request_payload["sync"] = $sync; - } - - $res = $this->seam->request( - "POST", - "/locks/unlock_door", - json: (object) $request_payload, - inner_object: "action_attempt" - ); - - if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); - } - - $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id - ); - - return $action_attempt; - } -} - -class NetworksClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function get(string $network_id): Network - { - $request_payload = []; - - if ($network_id !== null) { - $request_payload["network_id"] = $network_id; - } - - $res = $this->seam->request( - "POST", - "/networks/get", - json: (object) $request_payload, - inner_object: "network" - ); - - return Network::from_json($res); - } - - public function list(): array - { - $request_payload = []; - - $res = $this->seam->request( - "POST", - "/networks/list", - json: (object) $request_payload, - inner_object: "networks" - ); - - return array_map(fn($r) => Network::from_json($r), $res); - } -} - -class NoiseSensorsClient -{ - private SeamClient $seam; - public NoiseSensorsNoiseThresholdsClient $noise_thresholds; - public NoiseSensorsSimulateClient $simulate; - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - $this->noise_thresholds = new NoiseSensorsNoiseThresholdsClient($seam); - $this->simulate = new NoiseSensorsSimulateClient($seam); - } - - public function list( - string $connect_webview_id = null, - string $connected_account_id = null, - array $connected_account_ids = null, - string $created_before = null, - mixed $custom_metadata_has = null, - array $device_ids = null, - string $device_type = null, - array $device_types = null, - array $exclude_if = null, - array $include_if = null, - float $limit = null, - string $manufacturer = null, - string $user_identifier_key = null - ): array { - $request_payload = []; - - if ($connect_webview_id !== null) { - $request_payload["connect_webview_id"] = $connect_webview_id; - } - if ($connected_account_id !== null) { - $request_payload["connected_account_id"] = $connected_account_id; - } - if ($connected_account_ids !== null) { - $request_payload["connected_account_ids"] = $connected_account_ids; - } - if ($created_before !== null) { - $request_payload["created_before"] = $created_before; - } - if ($custom_metadata_has !== null) { - $request_payload["custom_metadata_has"] = $custom_metadata_has; - } - if ($device_ids !== null) { - $request_payload["device_ids"] = $device_ids; - } - if ($device_type !== null) { - $request_payload["device_type"] = $device_type; - } - if ($device_types !== null) { - $request_payload["device_types"] = $device_types; - } - if ($exclude_if !== null) { - $request_payload["exclude_if"] = $exclude_if; - } - if ($include_if !== null) { - $request_payload["include_if"] = $include_if; - } - if ($limit !== null) { - $request_payload["limit"] = $limit; - } - if ($manufacturer !== null) { - $request_payload["manufacturer"] = $manufacturer; - } - if ($user_identifier_key !== null) { - $request_payload["user_identifier_key"] = $user_identifier_key; - } - - $res = $this->seam->request( - "POST", - "/noise_sensors/list", - json: (object) $request_payload, - inner_object: "devices" - ); - - return array_map(fn($r) => Device::from_json($r), $res); - } -} - -class NoiseSensorsNoiseThresholdsClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function create( - string $device_id, - string $ends_daily_at, - string $starts_daily_at, - string $name = null, - float $noise_threshold_decibels = null, - float $noise_threshold_nrs = null, - bool $sync = null - ): NoiseThreshold { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($ends_daily_at !== null) { - $request_payload["ends_daily_at"] = $ends_daily_at; - } - if ($starts_daily_at !== null) { - $request_payload["starts_daily_at"] = $starts_daily_at; - } - if ($name !== null) { - $request_payload["name"] = $name; - } - if ($noise_threshold_decibels !== null) { - $request_payload[ - "noise_threshold_decibels" - ] = $noise_threshold_decibels; - } - if ($noise_threshold_nrs !== null) { - $request_payload["noise_threshold_nrs"] = $noise_threshold_nrs; - } - if ($sync !== null) { - $request_payload["sync"] = $sync; - } - - $res = $this->seam->request( - "POST", - "/noise_sensors/noise_thresholds/create", - json: (object) $request_payload, - inner_object: "noise_threshold" - ); - - return NoiseThreshold::from_json($res); - } - - public function delete( - string $device_id, - string $noise_threshold_id, - bool $sync = null - ): void { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($noise_threshold_id !== null) { - $request_payload["noise_threshold_id"] = $noise_threshold_id; - } - if ($sync !== null) { - $request_payload["sync"] = $sync; - } - - $this->seam->request( - "POST", - "/noise_sensors/noise_thresholds/delete", - json: (object) $request_payload - ); - } - - public function get(string $noise_threshold_id): NoiseThreshold - { - $request_payload = []; - - if ($noise_threshold_id !== null) { - $request_payload["noise_threshold_id"] = $noise_threshold_id; - } - - $res = $this->seam->request( - "POST", - "/noise_sensors/noise_thresholds/get", - json: (object) $request_payload, - inner_object: "noise_threshold" - ); - - return NoiseThreshold::from_json($res); - } - - public function list(string $device_id, bool $is_programmed = null): array - { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($is_programmed !== null) { - $request_payload["is_programmed"] = $is_programmed; - } - - $res = $this->seam->request( - "POST", - "/noise_sensors/noise_thresholds/list", - json: (object) $request_payload, - inner_object: "noise_thresholds" - ); - - return array_map(fn($r) => NoiseThreshold::from_json($r), $res); - } - - public function update( - string $device_id, - string $noise_threshold_id, - string $ends_daily_at = null, - string $name = null, - float $noise_threshold_decibels = null, - float $noise_threshold_nrs = null, - string $starts_daily_at = null, - bool $sync = null - ): void { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($noise_threshold_id !== null) { - $request_payload["noise_threshold_id"] = $noise_threshold_id; - } - if ($ends_daily_at !== null) { - $request_payload["ends_daily_at"] = $ends_daily_at; - } - if ($name !== null) { - $request_payload["name"] = $name; - } - if ($noise_threshold_decibels !== null) { - $request_payload[ - "noise_threshold_decibels" - ] = $noise_threshold_decibels; - } - if ($noise_threshold_nrs !== null) { - $request_payload["noise_threshold_nrs"] = $noise_threshold_nrs; - } - if ($starts_daily_at !== null) { - $request_payload["starts_daily_at"] = $starts_daily_at; - } - if ($sync !== null) { - $request_payload["sync"] = $sync; - } - - $this->seam->request( - "POST", - "/noise_sensors/noise_thresholds/update", - json: (object) $request_payload - ); - } -} - -class NoiseSensorsSimulateClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function trigger_noise_threshold(string $device_id): void - { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - - $this->seam->request( - "POST", - "/noise_sensors/simulate/trigger_noise_threshold", - json: (object) $request_payload - ); - } -} - -class PhonesClient -{ - private SeamClient $seam; - public PhonesSimulateClient $simulate; - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - $this->simulate = new PhonesSimulateClient($seam); - } - - public function deactivate(string $device_id): void - { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - - $this->seam->request( - "POST", - "/phones/deactivate", - json: (object) $request_payload - ); - } - - public function get(string $device_id): Phone - { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - - $res = $this->seam->request( - "POST", - "/phones/get", - json: (object) $request_payload, - inner_object: "phone" - ); - - return Phone::from_json($res); - } - - public function list( - string $acs_credential_id = null, - string $owner_user_identity_id = null - ): array { - $request_payload = []; - - if ($acs_credential_id !== null) { - $request_payload["acs_credential_id"] = $acs_credential_id; - } - if ($owner_user_identity_id !== null) { - $request_payload[ - "owner_user_identity_id" - ] = $owner_user_identity_id; - } - - $res = $this->seam->request( - "POST", - "/phones/list", - json: (object) $request_payload, - inner_object: "phones" - ); - - return array_map(fn($r) => Phone::from_json($r), $res); - } -} - -class PhonesSimulateClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function create_sandbox_phone( - string $user_identity_id, - mixed $assa_abloy_metadata = null, - string $custom_sdk_installation_id = null, - mixed $phone_metadata = null - ): Phone { - $request_payload = []; - - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - if ($assa_abloy_metadata !== null) { - $request_payload["assa_abloy_metadata"] = $assa_abloy_metadata; - } - if ($custom_sdk_installation_id !== null) { - $request_payload[ - "custom_sdk_installation_id" - ] = $custom_sdk_installation_id; - } - if ($phone_metadata !== null) { - $request_payload["phone_metadata"] = $phone_metadata; - } - - $res = $this->seam->request( - "POST", - "/phones/simulate/create_sandbox_phone", - json: (object) $request_payload, - inner_object: "phone" - ); - - return Phone::from_json($res); - } -} - -class ThermostatsClient -{ - private SeamClient $seam; - public ThermostatsSchedulesClient $schedules; - public ThermostatsSimulateClient $simulate; - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - $this->schedules = new ThermostatsSchedulesClient($seam); - $this->simulate = new ThermostatsSimulateClient($seam); - } - - public function activate_climate_preset( - string $climate_preset_key, - string $device_id, - bool $wait_for_action_attempt = true - ): ActionAttempt { - $request_payload = []; - - if ($climate_preset_key !== null) { - $request_payload["climate_preset_key"] = $climate_preset_key; - } - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - - $res = $this->seam->request( - "POST", - "/thermostats/activate_climate_preset", - json: (object) $request_payload, - inner_object: "action_attempt" - ); - - if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); - } - - $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id - ); - - return $action_attempt; - } - - public function cool( - string $device_id, - float $cooling_set_point_celsius = null, - float $cooling_set_point_fahrenheit = null, - bool $sync = null, - bool $wait_for_action_attempt = true - ): ActionAttempt { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($cooling_set_point_celsius !== null) { - $request_payload[ - "cooling_set_point_celsius" - ] = $cooling_set_point_celsius; - } - if ($cooling_set_point_fahrenheit !== null) { - $request_payload[ - "cooling_set_point_fahrenheit" - ] = $cooling_set_point_fahrenheit; - } - if ($sync !== null) { - $request_payload["sync"] = $sync; - } - - $res = $this->seam->request( - "POST", - "/thermostats/cool", - json: (object) $request_payload, - inner_object: "action_attempt" - ); - - if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); - } - - $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id - ); - - return $action_attempt; - } - - public function create_climate_preset( - string $climate_preset_key, - string $device_id, - float $cooling_set_point_celsius = null, - float $cooling_set_point_fahrenheit = null, - string $fan_mode_setting = null, - float $heating_set_point_celsius = null, - float $heating_set_point_fahrenheit = null, - string $hvac_mode_setting = null, - bool $manual_override_allowed = null, - string $name = null - ): void { - $request_payload = []; - - if ($climate_preset_key !== null) { - $request_payload["climate_preset_key"] = $climate_preset_key; - } - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($cooling_set_point_celsius !== null) { - $request_payload[ - "cooling_set_point_celsius" - ] = $cooling_set_point_celsius; - } - if ($cooling_set_point_fahrenheit !== null) { - $request_payload[ - "cooling_set_point_fahrenheit" - ] = $cooling_set_point_fahrenheit; - } - if ($fan_mode_setting !== null) { - $request_payload["fan_mode_setting"] = $fan_mode_setting; - } - if ($heating_set_point_celsius !== null) { - $request_payload[ - "heating_set_point_celsius" - ] = $heating_set_point_celsius; - } - if ($heating_set_point_fahrenheit !== null) { - $request_payload[ - "heating_set_point_fahrenheit" - ] = $heating_set_point_fahrenheit; - } - if ($hvac_mode_setting !== null) { - $request_payload["hvac_mode_setting"] = $hvac_mode_setting; - } - if ($manual_override_allowed !== null) { - $request_payload[ - "manual_override_allowed" - ] = $manual_override_allowed; - } - if ($name !== null) { - $request_payload["name"] = $name; - } - - $this->seam->request( - "POST", - "/thermostats/create_climate_preset", - json: (object) $request_payload - ); - } - - public function delete_climate_preset( - string $climate_preset_key, - string $device_id - ): void { - $request_payload = []; - - if ($climate_preset_key !== null) { - $request_payload["climate_preset_key"] = $climate_preset_key; - } - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - - $this->seam->request( - "POST", - "/thermostats/delete_climate_preset", - json: (object) $request_payload - ); - } - - public function get(string $device_id = null, string $name = null): Device - { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($name !== null) { - $request_payload["name"] = $name; - } - - $res = $this->seam->request( - "POST", - "/thermostats/get", - json: (object) $request_payload, - inner_object: "thermostat" - ); - - return Device::from_json($res); - } - - public function heat( - string $device_id, - float $heating_set_point_celsius = null, - float $heating_set_point_fahrenheit = null, - bool $sync = null, - bool $wait_for_action_attempt = true - ): ActionAttempt { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($heating_set_point_celsius !== null) { - $request_payload[ - "heating_set_point_celsius" - ] = $heating_set_point_celsius; - } - if ($heating_set_point_fahrenheit !== null) { - $request_payload[ - "heating_set_point_fahrenheit" - ] = $heating_set_point_fahrenheit; - } - if ($sync !== null) { - $request_payload["sync"] = $sync; - } - - $res = $this->seam->request( - "POST", - "/thermostats/heat", - json: (object) $request_payload, - inner_object: "action_attempt" - ); - - if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); - } - - $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id - ); - - return $action_attempt; - } - - public function heat_cool( - string $device_id, - float $cooling_set_point_celsius = null, - float $cooling_set_point_fahrenheit = null, - float $heating_set_point_celsius = null, - float $heating_set_point_fahrenheit = null, - bool $sync = null, - bool $wait_for_action_attempt = true - ): ActionAttempt { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($cooling_set_point_celsius !== null) { - $request_payload[ - "cooling_set_point_celsius" - ] = $cooling_set_point_celsius; - } - if ($cooling_set_point_fahrenheit !== null) { - $request_payload[ - "cooling_set_point_fahrenheit" - ] = $cooling_set_point_fahrenheit; - } - if ($heating_set_point_celsius !== null) { - $request_payload[ - "heating_set_point_celsius" - ] = $heating_set_point_celsius; - } - if ($heating_set_point_fahrenheit !== null) { - $request_payload[ - "heating_set_point_fahrenheit" - ] = $heating_set_point_fahrenheit; - } - if ($sync !== null) { - $request_payload["sync"] = $sync; - } - - $res = $this->seam->request( - "POST", - "/thermostats/heat_cool", - json: (object) $request_payload, - inner_object: "action_attempt" - ); - - if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); - } - - $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id - ); - - return $action_attempt; - } - - public function list( - string $connect_webview_id = null, - string $connected_account_id = null, - array $connected_account_ids = null, - string $created_before = null, - mixed $custom_metadata_has = null, - array $device_ids = null, - string $device_type = null, - array $device_types = null, - array $exclude_if = null, - array $include_if = null, - float $limit = null, - string $manufacturer = null, - string $user_identifier_key = null - ): array { - $request_payload = []; - - if ($connect_webview_id !== null) { - $request_payload["connect_webview_id"] = $connect_webview_id; - } - if ($connected_account_id !== null) { - $request_payload["connected_account_id"] = $connected_account_id; - } - if ($connected_account_ids !== null) { - $request_payload["connected_account_ids"] = $connected_account_ids; - } - if ($created_before !== null) { - $request_payload["created_before"] = $created_before; - } - if ($custom_metadata_has !== null) { - $request_payload["custom_metadata_has"] = $custom_metadata_has; - } - if ($device_ids !== null) { - $request_payload["device_ids"] = $device_ids; - } - if ($device_type !== null) { - $request_payload["device_type"] = $device_type; - } - if ($device_types !== null) { - $request_payload["device_types"] = $device_types; - } - if ($exclude_if !== null) { - $request_payload["exclude_if"] = $exclude_if; - } - if ($include_if !== null) { - $request_payload["include_if"] = $include_if; - } - if ($limit !== null) { - $request_payload["limit"] = $limit; - } - if ($manufacturer !== null) { - $request_payload["manufacturer"] = $manufacturer; - } - if ($user_identifier_key !== null) { - $request_payload["user_identifier_key"] = $user_identifier_key; - } - - $res = $this->seam->request( - "POST", - "/thermostats/list", - json: (object) $request_payload, - inner_object: "devices" - ); - - return array_map(fn($r) => Device::from_json($r), $res); - } - - public function off( - string $device_id, - bool $sync = null, - bool $wait_for_action_attempt = true - ): ActionAttempt { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($sync !== null) { - $request_payload["sync"] = $sync; - } - - $res = $this->seam->request( - "POST", - "/thermostats/off", - json: (object) $request_payload, - inner_object: "action_attempt" - ); - - if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); - } - - $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id - ); - - return $action_attempt; - } - - public function set_fallback_climate_preset( - string $climate_preset_key, - string $device_id - ): void { - $request_payload = []; - - if ($climate_preset_key !== null) { - $request_payload["climate_preset_key"] = $climate_preset_key; - } - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - - $this->seam->request( - "POST", - "/thermostats/set_fallback_climate_preset", - json: (object) $request_payload - ); - } - - public function set_fan_mode( - string $device_id, - string $fan_mode = null, - string $fan_mode_setting = null, - bool $sync = null, - bool $wait_for_action_attempt = true - ): ActionAttempt { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($fan_mode !== null) { - $request_payload["fan_mode"] = $fan_mode; - } - if ($fan_mode_setting !== null) { - $request_payload["fan_mode_setting"] = $fan_mode_setting; - } - if ($sync !== null) { - $request_payload["sync"] = $sync; - } - - $res = $this->seam->request( - "POST", - "/thermostats/set_fan_mode", - json: (object) $request_payload, - inner_object: "action_attempt" - ); - - if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); - } - - $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id - ); - - return $action_attempt; - } - - public function set_hvac_mode( - string $device_id, - string $hvac_mode_setting, - float $cooling_set_point_celsius = null, - float $cooling_set_point_fahrenheit = null, - float $heating_set_point_celsius = null, - float $heating_set_point_fahrenheit = null, - bool $wait_for_action_attempt = true - ): ActionAttempt { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($hvac_mode_setting !== null) { - $request_payload["hvac_mode_setting"] = $hvac_mode_setting; - } - if ($cooling_set_point_celsius !== null) { - $request_payload[ - "cooling_set_point_celsius" - ] = $cooling_set_point_celsius; - } - if ($cooling_set_point_fahrenheit !== null) { - $request_payload[ - "cooling_set_point_fahrenheit" - ] = $cooling_set_point_fahrenheit; - } - if ($heating_set_point_celsius !== null) { - $request_payload[ - "heating_set_point_celsius" - ] = $heating_set_point_celsius; - } - if ($heating_set_point_fahrenheit !== null) { - $request_payload[ - "heating_set_point_fahrenheit" - ] = $heating_set_point_fahrenheit; - } - - $res = $this->seam->request( - "POST", - "/thermostats/set_hvac_mode", - json: (object) $request_payload, - inner_object: "action_attempt" - ); - - if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); - } - - $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id - ); - - return $action_attempt; - } - - public function set_temperature_threshold( - string $device_id, - float $lower_limit_celsius = null, - float $lower_limit_fahrenheit = null, - float $upper_limit_celsius = null, - float $upper_limit_fahrenheit = null - ): void { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($lower_limit_celsius !== null) { - $request_payload["lower_limit_celsius"] = $lower_limit_celsius; - } - if ($lower_limit_fahrenheit !== null) { - $request_payload[ - "lower_limit_fahrenheit" - ] = $lower_limit_fahrenheit; - } - if ($upper_limit_celsius !== null) { - $request_payload["upper_limit_celsius"] = $upper_limit_celsius; - } - if ($upper_limit_fahrenheit !== null) { - $request_payload[ - "upper_limit_fahrenheit" - ] = $upper_limit_fahrenheit; - } - - $this->seam->request( - "POST", - "/thermostats/set_temperature_threshold", - json: (object) $request_payload - ); - } - - public function update_climate_preset( - string $climate_preset_key, - string $device_id, - bool $manual_override_allowed, - float $cooling_set_point_celsius = null, - float $cooling_set_point_fahrenheit = null, - string $fan_mode_setting = null, - float $heating_set_point_celsius = null, - float $heating_set_point_fahrenheit = null, - string $hvac_mode_setting = null, - string $name = null - ): void { - $request_payload = []; - - if ($climate_preset_key !== null) { - $request_payload["climate_preset_key"] = $climate_preset_key; - } - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($manual_override_allowed !== null) { - $request_payload[ - "manual_override_allowed" - ] = $manual_override_allowed; - } - if ($cooling_set_point_celsius !== null) { - $request_payload[ - "cooling_set_point_celsius" - ] = $cooling_set_point_celsius; - } - if ($cooling_set_point_fahrenheit !== null) { - $request_payload[ - "cooling_set_point_fahrenheit" - ] = $cooling_set_point_fahrenheit; - } - if ($fan_mode_setting !== null) { - $request_payload["fan_mode_setting"] = $fan_mode_setting; - } - if ($heating_set_point_celsius !== null) { - $request_payload[ - "heating_set_point_celsius" - ] = $heating_set_point_celsius; - } - if ($heating_set_point_fahrenheit !== null) { - $request_payload[ - "heating_set_point_fahrenheit" - ] = $heating_set_point_fahrenheit; - } - if ($hvac_mode_setting !== null) { - $request_payload["hvac_mode_setting"] = $hvac_mode_setting; - } - if ($name !== null) { - $request_payload["name"] = $name; - } - - $this->seam->request( - "POST", - "/thermostats/update_climate_preset", - json: (object) $request_payload - ); - } -} - -class ThermostatsSchedulesClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function create( - string $climate_preset_key, - string $device_id, - string $ends_at, - string $starts_at, - bool $is_override_allowed = null, - mixed $max_override_period_minutes = null, - string $name = null - ): ThermostatSchedule { - $request_payload = []; - - if ($climate_preset_key !== null) { - $request_payload["climate_preset_key"] = $climate_preset_key; - } - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($ends_at !== null) { - $request_payload["ends_at"] = $ends_at; - } - if ($starts_at !== null) { - $request_payload["starts_at"] = $starts_at; - } - if ($is_override_allowed !== null) { - $request_payload["is_override_allowed"] = $is_override_allowed; - } - if ($max_override_period_minutes !== null) { - $request_payload[ - "max_override_period_minutes" - ] = $max_override_period_minutes; - } - if ($name !== null) { - $request_payload["name"] = $name; - } - - $res = $this->seam->request( - "POST", - "/thermostats/schedules/create", - json: (object) $request_payload, - inner_object: "thermostat_schedule" - ); - - return ThermostatSchedule::from_json($res); - } - - public function delete(string $thermostat_schedule_id): void - { - $request_payload = []; - - if ($thermostat_schedule_id !== null) { - $request_payload[ - "thermostat_schedule_id" - ] = $thermostat_schedule_id; - } - - $this->seam->request( - "POST", - "/thermostats/schedules/delete", - json: (object) $request_payload - ); - } - - public function get(string $thermostat_schedule_id): ThermostatSchedule - { - $request_payload = []; - - if ($thermostat_schedule_id !== null) { - $request_payload[ - "thermostat_schedule_id" - ] = $thermostat_schedule_id; - } - - $res = $this->seam->request( - "POST", - "/thermostats/schedules/get", - json: (object) $request_payload, - inner_object: "thermostat_schedule" - ); - - return ThermostatSchedule::from_json($res); - } - - public function list( - string $device_id, - string $user_identifier_key = null - ): array { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($user_identifier_key !== null) { - $request_payload["user_identifier_key"] = $user_identifier_key; - } - - $res = $this->seam->request( - "POST", - "/thermostats/schedules/list", - json: (object) $request_payload, - inner_object: "thermostat_schedules" - ); - - return array_map(fn($r) => ThermostatSchedule::from_json($r), $res); - } - - public function update( - string $thermostat_schedule_id, - string $climate_preset_key = null, - string $ends_at = null, - bool $is_override_allowed = null, - mixed $max_override_period_minutes = null, - string $name = null, - string $starts_at = null - ): void { - $request_payload = []; - - if ($thermostat_schedule_id !== null) { - $request_payload[ - "thermostat_schedule_id" - ] = $thermostat_schedule_id; - } - if ($climate_preset_key !== null) { - $request_payload["climate_preset_key"] = $climate_preset_key; - } - if ($ends_at !== null) { - $request_payload["ends_at"] = $ends_at; - } - if ($is_override_allowed !== null) { - $request_payload["is_override_allowed"] = $is_override_allowed; - } - if ($max_override_period_minutes !== null) { - $request_payload[ - "max_override_period_minutes" - ] = $max_override_period_minutes; - } - if ($name !== null) { - $request_payload["name"] = $name; - } - if ($starts_at !== null) { - $request_payload["starts_at"] = $starts_at; - } - - $this->seam->request( - "POST", - "/thermostats/schedules/update", - json: (object) $request_payload - ); - } -} - -class ThermostatsSimulateClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function hvac_mode_adjusted( - string $device_id, - string $hvac_mode, - float $cooling_set_point_celsius = null, - float $cooling_set_point_fahrenheit = null, - float $heating_set_point_celsius = null, - float $heating_set_point_fahrenheit = null - ): void { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($hvac_mode !== null) { - $request_payload["hvac_mode"] = $hvac_mode; - } - if ($cooling_set_point_celsius !== null) { - $request_payload[ - "cooling_set_point_celsius" - ] = $cooling_set_point_celsius; - } - if ($cooling_set_point_fahrenheit !== null) { - $request_payload[ - "cooling_set_point_fahrenheit" - ] = $cooling_set_point_fahrenheit; - } - if ($heating_set_point_celsius !== null) { - $request_payload[ - "heating_set_point_celsius" - ] = $heating_set_point_celsius; - } - if ($heating_set_point_fahrenheit !== null) { - $request_payload[ - "heating_set_point_fahrenheit" - ] = $heating_set_point_fahrenheit; - } - - $this->seam->request( - "POST", - "/thermostats/simulate/hvac_mode_adjusted", - json: (object) $request_payload - ); - } - - public function temperature_reached( - string $device_id, - float $temperature_celsius = null, - float $temperature_fahrenheit = null - ): void { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($temperature_celsius !== null) { - $request_payload["temperature_celsius"] = $temperature_celsius; - } - if ($temperature_fahrenheit !== null) { - $request_payload[ - "temperature_fahrenheit" - ] = $temperature_fahrenheit; - } - - $this->seam->request( - "POST", - "/thermostats/simulate/temperature_reached", - json: (object) $request_payload - ); - } -} - -class UserIdentitiesClient -{ - private SeamClient $seam; - public UserIdentitiesEnrollmentAutomationsClient $enrollment_automations; - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - $this->enrollment_automations = new UserIdentitiesEnrollmentAutomationsClient( - $seam - ); - } - - public function add_acs_user( - string $acs_user_id, - string $user_identity_id - ): void { - $request_payload = []; - - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - - $this->seam->request( - "POST", - "/user_identities/add_acs_user", - json: (object) $request_payload - ); - } - - public function create( - string $email_address = null, - string $full_name = null, - string $phone_number = null, - string $user_identity_key = null - ): UserIdentity { - $request_payload = []; - - if ($email_address !== null) { - $request_payload["email_address"] = $email_address; - } - if ($full_name !== null) { - $request_payload["full_name"] = $full_name; - } - if ($phone_number !== null) { - $request_payload["phone_number"] = $phone_number; - } - if ($user_identity_key !== null) { - $request_payload["user_identity_key"] = $user_identity_key; - } - - $res = $this->seam->request( - "POST", - "/user_identities/create", - json: (object) $request_payload, - inner_object: "user_identity" - ); - - return UserIdentity::from_json($res); - } - - public function delete(string $user_identity_id): void - { - $request_payload = []; - - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - - $this->seam->request( - "POST", - "/user_identities/delete", - json: (object) $request_payload - ); - } - - public function get( - string $user_identity_id = null, - string $user_identity_key = null - ): UserIdentity { - $request_payload = []; - - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - if ($user_identity_key !== null) { - $request_payload["user_identity_key"] = $user_identity_key; - } - - $res = $this->seam->request( - "POST", - "/user_identities/get", - json: (object) $request_payload, - inner_object: "user_identity" - ); - - return UserIdentity::from_json($res); - } - - public function grant_access_to_device( - string $device_id, - string $user_identity_id - ): void { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - - $this->seam->request( - "POST", - "/user_identities/grant_access_to_device", - json: (object) $request_payload - ); - } - - public function list(string $credential_manager_acs_system_id = null): array - { - $request_payload = []; - - if ($credential_manager_acs_system_id !== null) { - $request_payload[ - "credential_manager_acs_system_id" - ] = $credential_manager_acs_system_id; - } - - $res = $this->seam->request( - "POST", - "/user_identities/list", - json: (object) $request_payload, - inner_object: "user_identities" - ); - - return array_map(fn($r) => UserIdentity::from_json($r), $res); - } - - public function list_accessible_devices(string $user_identity_id): array - { - $request_payload = []; - - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - - $res = $this->seam->request( - "POST", - "/user_identities/list_accessible_devices", - json: (object) $request_payload, - inner_object: "devices" - ); - - return array_map(fn($r) => Device::from_json($r), $res); - } - - public function list_acs_systems(string $user_identity_id): array - { - $request_payload = []; - - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - - $res = $this->seam->request( - "POST", - "/user_identities/list_acs_systems", - json: (object) $request_payload, - inner_object: "acs_systems" - ); - - return array_map(fn($r) => AcsSystem::from_json($r), $res); - } - - public function list_acs_users(string $user_identity_id): array - { - $request_payload = []; - - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - - $res = $this->seam->request( - "POST", - "/user_identities/list_acs_users", - json: (object) $request_payload, - inner_object: "acs_users" - ); - - return array_map(fn($r) => AcsUser::from_json($r), $res); - } - - public function remove_acs_user( - string $acs_user_id, - string $user_identity_id - ): void { - $request_payload = []; - - if ($acs_user_id !== null) { - $request_payload["acs_user_id"] = $acs_user_id; - } - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - - $this->seam->request( - "POST", - "/user_identities/remove_acs_user", - json: (object) $request_payload - ); - } - - public function revoke_access_to_device( - string $device_id, - string $user_identity_id - ): void { - $request_payload = []; - - if ($device_id !== null) { - $request_payload["device_id"] = $device_id; - } - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - - $this->seam->request( - "POST", - "/user_identities/revoke_access_to_device", - json: (object) $request_payload - ); - } - - public function update( - string $user_identity_id, - string $email_address = null, - string $full_name = null, - string $phone_number = null, - string $user_identity_key = null - ): void { - $request_payload = []; - - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - if ($email_address !== null) { - $request_payload["email_address"] = $email_address; - } - if ($full_name !== null) { - $request_payload["full_name"] = $full_name; - } - if ($phone_number !== null) { - $request_payload["phone_number"] = $phone_number; - } - if ($user_identity_key !== null) { - $request_payload["user_identity_key"] = $user_identity_key; - } - - $this->seam->request( - "POST", - "/user_identities/update", - json: (object) $request_payload - ); - } -} - -class UserIdentitiesEnrollmentAutomationsClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function delete(string $enrollment_automation_id): void - { - $request_payload = []; - - if ($enrollment_automation_id !== null) { - $request_payload[ - "enrollment_automation_id" - ] = $enrollment_automation_id; - } - - $this->seam->request( - "POST", - "/user_identities/enrollment_automations/delete", - json: (object) $request_payload - ); - } - - public function get(string $enrollment_automation_id): EnrollmentAutomation - { - $request_payload = []; - - if ($enrollment_automation_id !== null) { - $request_payload[ - "enrollment_automation_id" - ] = $enrollment_automation_id; - } - - $res = $this->seam->request( - "POST", - "/user_identities/enrollment_automations/get", - json: (object) $request_payload, - inner_object: "enrollment_automation" - ); - - return EnrollmentAutomation::from_json($res); - } - - public function launch( - string $credential_manager_acs_system_id, - string $user_identity_id, - string $acs_credential_pool_id = null, - bool $create_credential_manager_user = null, - string $credential_manager_acs_user_id = null - ): void { - $request_payload = []; - - if ($credential_manager_acs_system_id !== null) { - $request_payload[ - "credential_manager_acs_system_id" - ] = $credential_manager_acs_system_id; - } - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - if ($acs_credential_pool_id !== null) { - $request_payload[ - "acs_credential_pool_id" - ] = $acs_credential_pool_id; - } - if ($create_credential_manager_user !== null) { - $request_payload[ - "create_credential_manager_user" - ] = $create_credential_manager_user; - } - if ($credential_manager_acs_user_id !== null) { - $request_payload[ - "credential_manager_acs_user_id" - ] = $credential_manager_acs_user_id; - } - - $this->seam->request( - "POST", - "/user_identities/enrollment_automations/launch", - json: (object) $request_payload, - inner_object: "enrollment_automation" - ); - } - - public function list(string $user_identity_id): array - { - $request_payload = []; - - if ($user_identity_id !== null) { - $request_payload["user_identity_id"] = $user_identity_id; - } - - $res = $this->seam->request( - "POST", - "/user_identities/enrollment_automations/list", - json: (object) $request_payload, - inner_object: "enrollment_automations" - ); - - return array_map(fn($r) => EnrollmentAutomation::from_json($r), $res); - } -} - -class WebhooksClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function create(string $url, array $event_types = null): Webhook - { - $request_payload = []; - - if ($url !== null) { - $request_payload["url"] = $url; - } - if ($event_types !== null) { - $request_payload["event_types"] = $event_types; - } - - $res = $this->seam->request( - "POST", - "/webhooks/create", - json: (object) $request_payload, - inner_object: "webhook" - ); - - return Webhook::from_json($res); - } - - public function delete(string $webhook_id): void - { - $request_payload = []; - - if ($webhook_id !== null) { - $request_payload["webhook_id"] = $webhook_id; - } - - $this->seam->request( - "POST", - "/webhooks/delete", - json: (object) $request_payload - ); - } - - public function get(string $webhook_id): Webhook - { - $request_payload = []; - - if ($webhook_id !== null) { - $request_payload["webhook_id"] = $webhook_id; - } - - $res = $this->seam->request( - "POST", - "/webhooks/get", - json: (object) $request_payload, - inner_object: "webhook" - ); - - return Webhook::from_json($res); - } - - public function list(): array - { - $request_payload = []; - - $res = $this->seam->request( - "POST", - "/webhooks/list", - json: (object) $request_payload, - inner_object: "webhooks" - ); - - return array_map(fn($r) => Webhook::from_json($r), $res); - } - - public function update(array $event_types, string $webhook_id): void - { - $request_payload = []; - - if ($event_types !== null) { - $request_payload["event_types"] = $event_types; - } - if ($webhook_id !== null) { - $request_payload["webhook_id"] = $webhook_id; - } - - $this->seam->request( - "POST", - "/webhooks/update", - json: (object) $request_payload - ); - } -} - -class WorkspacesClient -{ - private SeamClient $seam; - - public function __construct(SeamClient $seam) - { - $this->seam = $seam; - } - - public function create( - string $name, - string $company_name = null, - string $connect_partner_name = null, - bool $is_sandbox = null, - string $webview_logo_shape = null, - string $webview_primary_button_color = null, - string $webview_primary_button_text_color = null - ): Workspace { - $request_payload = []; - - if ($name !== null) { - $request_payload["name"] = $name; - } - if ($company_name !== null) { - $request_payload["company_name"] = $company_name; - } - if ($connect_partner_name !== null) { - $request_payload["connect_partner_name"] = $connect_partner_name; - } - if ($is_sandbox !== null) { - $request_payload["is_sandbox"] = $is_sandbox; - } - if ($webview_logo_shape !== null) { - $request_payload["webview_logo_shape"] = $webview_logo_shape; - } - if ($webview_primary_button_color !== null) { - $request_payload[ - "webview_primary_button_color" - ] = $webview_primary_button_color; - } - if ($webview_primary_button_text_color !== null) { - $request_payload[ - "webview_primary_button_text_color" - ] = $webview_primary_button_text_color; - } - - $res = $this->seam->request( - "POST", - "/workspaces/create", - json: (object) $request_payload, - inner_object: "workspace" - ); - - return Workspace::from_json($res); - } - - public function get(): Workspace - { - $request_payload = []; - - $res = $this->seam->request( - "POST", - "/workspaces/get", - json: (object) $request_payload, - inner_object: "workspace" - ); - - return Workspace::from_json($res); - } - - public function list(): array - { - $request_payload = []; - - $res = $this->seam->request( - "POST", - "/workspaces/list", - json: (object) $request_payload, - inner_object: "workspaces" - ); - - return array_map(fn($r) => Workspace::from_json($r), $res); - } - - public function reset_sandbox( - bool $wait_for_action_attempt = true - ): ActionAttempt { - $request_payload = []; - - $res = $this->seam->request( - "POST", - "/workspaces/reset_sandbox", - json: (object) $request_payload, - inner_object: "action_attempt" - ); - - if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); - } - - $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id - ); - - return $action_attempt; - } -} diff --git a/tests/ActionAttemptsTest.php b/tests/ActionAttemptsTest.php index d6c45d7e..2c78174d 100644 --- a/tests/ActionAttemptsTest.php +++ b/tests/ActionAttemptsTest.php @@ -43,18 +43,16 @@ public function testFailedActionAttempt(): void $this->assertEquals("pending", $action_attempt->status); - $seam->request( - "POST", - "/_fake/update_action_attempt", - json: [ + $seam->client->post("/_fake/update_action_attempt", [ + "json" => [ "action_attempt_id" => $action_attempt->action_attempt_id, "status" => "error", "error" => [ "message" => "Failed", "type" => "failed_attempt", ], - ] - ); + ], + ]); try { $seam->action_attempts->poll_until_ready( @@ -84,14 +82,12 @@ public function testTimeoutActionAttempt(): void $this->assertEquals("pending", $action_attempt->status); - $seam->request( - "POST", - "/_fake/update_action_attempt", - json: [ + $seam->client->post("/_fake/update_action_attempt", [ + "json" => [ "action_attempt_id" => $action_attempt->action_attempt_id, "status" => "pending", - ] - ); + ], + ]); try { $seam->action_attempts->poll_until_ready( diff --git a/tests/DevicesTest.php b/tests/DevicesTest.php index eff72cd4..6a3156f5 100644 --- a/tests/DevicesTest.php +++ b/tests/DevicesTest.php @@ -41,17 +41,6 @@ public function testGetAndListDevices(): void $device = $seam->devices->get(name: $device_name); $this->assertTrue($device->properties->manufacturer === $manufacturer); - $seam->devices->delete(device_id: $device_id); - try { - $seam->devices->get(device_id: $device_id); - - $this->fail("Expected the device to be deleted"); - } catch (\Seam\HttpApiError $exception) { - $this->assertTrue( - str_contains($exception->getErrorCode(), "device_not_found") - ); - } - $stable_device_providers = $seam->devices->list_device_providers( provider_category: "stable" ); diff --git a/tests/Fixture.php b/tests/Fixture.php index 4d9efd54..e2a4a03a 100644 --- a/tests/Fixture.php +++ b/tests/Fixture.php @@ -2,7 +2,7 @@ namespace Tests; -use Seam\SeamClient; +use Seam\Seam; final class Fixture { @@ -17,7 +17,7 @@ public static function getTestServer() $api_url = "https://{$random_string}.fakeseamconnect.seam.vc"; $api_key = "seam_apikey1_token"; - $seam = new SeamClient($api_key, $api_url); + $seam = new Seam(api_key: $api_key, endpoint: $api_url); return $seam; } diff --git a/tests/HttpErrorTest.php b/tests/HttpErrorTest.php index 184aba3f..c57469fd 100644 --- a/tests/HttpErrorTest.php +++ b/tests/HttpErrorTest.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use Seam\Seam; use PHPUnit\Framework\TestCase; use Tests\Fixture; @@ -12,13 +13,11 @@ public function testInvalidInputError(): void $seam = Fixture::getTestServer(); try { - $seam->request( - "POST", - "/devices/list", - json: [ + $seam->client->post("/devices/list", [ + "json" => [ "device_ids" => 1234, - ] - ); + ], + ]); $this->fail("Expected InvalidInputError"); } catch (\Seam\HttpInvalidInputError $e) { $this->assertEquals(400, $e->getStatusCode()); @@ -34,8 +33,8 @@ public function testInvalidInputError(): void public function testUnauthorizedError(): void { $test_server = Fixture::getTestServer(); - $seam = new \Seam\SeamClient( - "invalid_api_key", + $seam = new Seam( + "seam_invalid_api_key", $test_server->client->getConfig("base_uri")->__toString() ); @@ -65,9 +64,9 @@ public function testNonSeamError(): void { $seam = Fixture::getTestServer(); - $seam = new \Seam\SeamClient( + $seam = new Seam( "seam_apikey1_token", - "https://nonexistent.example.com" + endpoint: "https://nonexistent.example.com" ); try {