diff --git a/README.md b/README.md index dd85a49f..2ca38f9f 100644 --- a/README.md +++ b/README.md @@ -11,32 +11,32 @@ $seam = new Seam\SeamClient("YOUR_API_KEY"); # Create a Connect Webview to login to a provider $connect_webview = $seam->connect_webviews->create( - accepted_providers: ["august"] + accepted_providers: ["august"] ); print "Please Login at this url: " . $connect_webview->url; # Poll until connect webview is completed while (true) { - $connect_webview = $seam->connect_webviews->get( - $connect_webview->connect_webview_id - ); - if ($connect_webview->status == "authorized") { - break; - } else { - sleep(1); - } + $connect_webview = $seam->connect_webviews->get( + $connect_webview->connect_webview_id + ); + if ($connect_webview->status == "authorized") { + break; + } else { + sleep(1); + } } $connected_account = $seam->connected_accounts->get( - $connect_webview->connected_account_id + $connect_webview->connected_account_id ); print "Looks like you connected with " . - json_encode($connected_account->user_identifier); + json_encode($connected_account->user_identifier); $devices = $seam->devices->list( - connected_account_id: $connected_account->connected_account_id + connected_account_id: $connected_account->connected_account_id ); print "You have " . count($devices) . " devices"; @@ -55,9 +55,9 @@ $updated_device->properties->locked; // false # Create an access code on a device $access_code = $seam->access_codes->create( - device_id: $device_id, - code: "1234", - name: "Test Code" + device_id: $device_id, + code: "1234", + name: "Test Code" ); # Check the status of an access code @@ -66,6 +66,93 @@ $access_code->status; // 'setting' (it will go to 'set' when active on the devic $seam->access_codes->delete($access_code->access_code_id); ``` +### Pagination + +Some Seam API endpoints that return lists of resources support pagination. +Use the `Paginator` class to fetch and process resources across multiple pages. + +#### Manually fetch pages with the next_page_cursor + +```php +$pages = $seam->createPaginator( + fn($params) => $seam->connected_accounts->list(...$params), + ["limit" => 2] +); + +[$connectedAccounts, $pagination] = $pages->firstPage(); + +if ($pagination->has_next_page) { + [$moreConnectedAccounts] = $pages->nextPage($pagination->next_page_cursor); +} +``` + +#### Resume pagination + +Get the first page on initial load: + +```php +$params = ["limit" => 20]; + +$pages = $seam->createPaginator( + fn($p) => $seam->connected_accounts->list(...$p), + $params +); + +[$connectedAccounts, $pagination] = $pages->firstPage(); + +// Store pagination state for later use +file_put_contents( + "/tmp/seam_connected_accounts_list.json", + json_encode([$params, $pagination]) +); +``` + +Get the next page at a later time: + +```php +$stored_data = json_decode( + file_get_contents("/tmp/seam_connected_accounts_list.json") ?: "[]", + false +); + +$params = $stored_data[0] ?? []; +$pagination = + $stored_data[1] ?? + (object) ["has_next_page" => false, "next_page_cursor" => null]; + +if ($pagination->has_next_page) { + $pages = $seam->createPaginator( + fn($p) => $seam->connected_accounts->list(...$p), + $params + ); + [$moreConnectedAccounts] = $pages->nextPage($pagination->next_page_cursor); +} +``` + +#### Iterate over all resources + +```php +$pages = $seam->createPaginator( + fn($p) => $seam->connected_accounts->list(...$p), + ["limit" => 20] +); + +foreach ($pages->flatten() as $connectedAccount) { + print $connectedAccount->account_type_display_name . "\n"; +} +``` + +#### Return all resources across all pages as an array + +```php +$pages = $seam->createPaginator( + fn($p) => $seam->connected_accounts->list(...$p), + ["limit" => 20] +); + +$connectedAccounts = $pages->flattenToArray(); +``` + ## Installation To install the latest version of the automatically generated SDK, run: @@ -87,4 +174,4 @@ If you want to install our previous handwritten version, run: ### Running Tests -You'll need to export `SEAM_API_KEY` to a sandbox workspace API key. +You'll need to export `SEAM_API_KEY` to a sandbox workspace API key. \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 9f9b1ab4..7c22fff3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,8 +10,8 @@ "license": "MIT", "devDependencies": { "@prettier/plugin-php": "^0.22.1", - "@seamapi/nextlove-sdk-generator": "1.15.8", - "@seamapi/types": "1.351.1", + "@seamapi/nextlove-sdk-generator": "1.18.0", + "@seamapi/types": "1.377.0", "del": "^7.1.0", "prettier": "^3.0.0" } @@ -434,9 +434,9 @@ } }, "node_modules/@seamapi/nextlove-sdk-generator": { - "version": "1.15.8", - "resolved": "https://registry.npmjs.org/@seamapi/nextlove-sdk-generator/-/nextlove-sdk-generator-1.15.8.tgz", - "integrity": "sha512-Q2v5p5BmK45/Qm6LpwUe3c2s6zzgUum9VOxnQU0K9CO3n23KaJf1X2M/sU6mRedAGh+JJsgmXLePtj21hhPZZg==", + "version": "1.18.0", + "resolved": "https://registry.npmjs.org/@seamapi/nextlove-sdk-generator/-/nextlove-sdk-generator-1.18.0.tgz", + "integrity": "sha512-lINrwlr3pJUWawFvEXezY89VxS4mafgkqeBGTiLRZSXTDLzqEl8QD6UKN0CHKirwHCjPFj8MUsGDyz7pCzbCmQ==", "dev": true, "dependencies": { "@nodelib/fs.walk": "^2.0.0", @@ -455,17 +455,16 @@ } }, "node_modules/@seamapi/types": { - "version": "1.351.1", - "resolved": "https://registry.npmjs.org/@seamapi/types/-/types-1.351.1.tgz", - "integrity": "sha512-zqgGhSUs1EpNAxSAuDPq0jQNifMJua+lX5jviFtC7RSxjqGIP47oBtW76OxFHOnJK9FyIk4vYE583ioBzIPzOg==", + "version": "1.377.0", + "resolved": "https://registry.npmjs.org/@seamapi/types/-/types-1.377.0.tgz", + "integrity": "sha512-EOdujTToK8AxrMn7TSL3Ju4X+3GeHB8RsrF4M8w5aIGjyOzJzPcxOMJHlhfCzB+x5A6r3VA50FIOsB8U9KmFiw==", "dev": true, - "license": "MIT", "engines": { "node": ">=18.12.0", "npm": ">= 9.0.0" }, "peerDependencies": { - "zod": "^3.21.4" + "zod": "^3.24.0" } }, "node_modules/aggregate-error": { @@ -1608,9 +1607,9 @@ } }, "node_modules/zod": { - "version": "3.22.4", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.22.4.tgz", - "integrity": "sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==", + "version": "3.24.2", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.24.2.tgz", + "integrity": "sha512-lY7CDW43ECgW9u1TcT3IoXHflywfVqDYze4waEz812jR/bZ8FHDsl7pFQoSZTz5N+2NqRXs8GBwnAwo3ZNxqhQ==", "dev": true, "peer": true, "funding": { diff --git a/package.json b/package.json index 6220dbda..2f11a833 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,8 @@ }, "devDependencies": { "@prettier/plugin-php": "^0.22.1", - "@seamapi/nextlove-sdk-generator": "1.15.8", - "@seamapi/types": "1.351.1", + "@seamapi/nextlove-sdk-generator": "1.18.0", + "@seamapi/types": "1.377.0", "del": "^7.1.0", "prettier": "^3.0.0" } diff --git a/src/Objects/AccessCodeErrors.php b/src/Objects/AccessCodeErrors.php index f267c8fb..8f17847f 100644 --- a/src/Objects/AccessCodeErrors.php +++ b/src/Objects/AccessCodeErrors.php @@ -14,6 +14,7 @@ public static function from_json(mixed $json): AccessCodeErrors|null message: $json->message, created_at: $json->created_at ?? null, is_access_code_error: $json->is_access_code_error ?? null, + is_bridge_error: $json->is_bridge_error ?? null, is_connected_account_error: $json->is_connected_account_error ?? null, is_device_error: $json->is_device_error ?? null @@ -25,6 +26,7 @@ public function __construct( public string $message, public string|null $created_at, public bool|null $is_access_code_error, + public bool|null $is_bridge_error, public bool|null $is_connected_account_error, public bool|null $is_device_error ) { diff --git a/src/Objects/AcsSystem.php b/src/Objects/AcsSystem.php index a874ff1f..95c5b818 100644 --- a/src/Objects/AcsSystem.php +++ b/src/Objects/AcsSystem.php @@ -28,6 +28,8 @@ public static function from_json(mixed $json): AcsSystem|null $json->warnings ?? [] ), workspace_id: $json->workspace_id, + acs_access_group_count: $json->acs_access_group_count ?? null, + acs_user_count: $json->acs_user_count ?? null, can_add_acs_users_to_acs_access_groups: $json->can_add_acs_users_to_acs_access_groups ?? null, can_automate_enrollment: $json->can_automate_enrollment ?? null, @@ -63,6 +65,8 @@ public function __construct( public string $name, public array $warnings, public string $workspace_id, + public float|null $acs_access_group_count, + public float|null $acs_user_count, public bool|null $can_add_acs_users_to_acs_access_groups, public bool|null $can_automate_enrollment, public bool|null $can_create_acs_access_groups, diff --git a/src/Objects/AcsSystemErrors.php b/src/Objects/AcsSystemErrors.php index 3f6889b2..70924d88 100644 --- a/src/Objects/AcsSystemErrors.php +++ b/src/Objects/AcsSystemErrors.php @@ -12,14 +12,16 @@ public static function from_json(mixed $json): AcsSystemErrors|null return new self( created_at: $json->created_at, error_code: $json->error_code, - message: $json->message + message: $json->message, + is_bridge_error: $json->is_bridge_error ?? null ); } public function __construct( public string $created_at, public string $error_code, - public string $message + public string $message, + public bool|null $is_bridge_error ) { } } diff --git a/src/Objects/AcsUser.php b/src/Objects/AcsUser.php index 08608dfd..b3746fb7 100644 --- a/src/Objects/AcsUser.php +++ b/src/Objects/AcsUser.php @@ -35,6 +35,10 @@ public static function from_json(mixed $json): AcsUser|null full_name: $json->full_name ?? null, hid_acs_system_id: $json->hid_acs_system_id ?? null, is_suspended: $json->is_suspended ?? null, + pending_mutations: array_map( + fn($p) => AcsUserPendingMutations::from_json($p), + $json->pending_mutations ?? [] + ), phone_number: $json->phone_number ?? null, user_identity_id: $json->user_identity_id ?? null, is_latest_desired_state_synced_with_provider: $json->is_latest_desired_state_synced_with_provider ?? @@ -66,6 +70,7 @@ public function __construct( public string|null $full_name, public string|null $hid_acs_system_id, public bool|null $is_suspended, + public array|null $pending_mutations, public string|null $phone_number, public string|null $user_identity_id, public bool|null $is_latest_desired_state_synced_with_provider, diff --git a/src/Objects/AcsUserFrom.php b/src/Objects/AcsUserFrom.php new file mode 100644 index 00000000..bcc98a3e --- /dev/null +++ b/src/Objects/AcsUserFrom.php @@ -0,0 +1,20 @@ +acs_access_group_id ?? null + ); + } + + public function __construct(public string|null $acs_access_group_id) + { + } +} diff --git a/src/Objects/AcsUserPendingMutations.php b/src/Objects/AcsUserPendingMutations.php new file mode 100644 index 00000000..22a42feb --- /dev/null +++ b/src/Objects/AcsUserPendingMutations.php @@ -0,0 +1,29 @@ +created_at, + mutation_code: $json->mutation_code, + from: isset($json->from) + ? AcsUserFrom::from_json($json->from) + : null, + to: isset($json->to) ? AcsUserTo::from_json($json->to) : null + ); + } + + public function __construct( + public string $created_at, + public string $mutation_code, + public AcsUserFrom|null $from, + public AcsUserTo|null $to + ) { + } +} diff --git a/src/Objects/AcsUserTo.php b/src/Objects/AcsUserTo.php new file mode 100644 index 00000000..f55db154 --- /dev/null +++ b/src/Objects/AcsUserTo.php @@ -0,0 +1,20 @@ +acs_access_group_id ?? null + ); + } + + public function __construct(public string|null $acs_access_group_id) + { + } +} diff --git a/src/Objects/ConnectedAccountErrors.php b/src/Objects/ConnectedAccountErrors.php index c721eb03..4f5f5965 100644 --- a/src/Objects/ConnectedAccountErrors.php +++ b/src/Objects/ConnectedAccountErrors.php @@ -10,18 +10,27 @@ public static function from_json(mixed $json): ConnectedAccountErrors|null return null; } return new self( + created_at: $json->created_at, error_code: $json->error_code, - is_connected_account_error: $json->is_connected_account_error, message: $json->message, - created_at: $json->created_at ?? null + is_bridge_error: $json->is_bridge_error ?? null, + is_connected_account_error: $json->is_connected_account_error ?? + null, + salto_ks_metadata: isset($json->salto_ks_metadata) + ? ConnectedAccountSaltoKsMetadata::from_json( + $json->salto_ks_metadata + ) + : null ); } public function __construct( + public string $created_at, public string $error_code, - public bool $is_connected_account_error, public string $message, - public string|null $created_at + public bool|null $is_bridge_error, + public bool|null $is_connected_account_error, + public ConnectedAccountSaltoKsMetadata|null $salto_ks_metadata ) { } } diff --git a/src/Objects/ConnectedAccountSaltoKsMetadata.php b/src/Objects/ConnectedAccountSaltoKsMetadata.php new file mode 100644 index 00000000..57fb5ef1 --- /dev/null +++ b/src/Objects/ConnectedAccountSaltoKsMetadata.php @@ -0,0 +1,24 @@ + ConnectedAccountSites::from_json($s), + $json->sites ?? [] + ) + ); + } + + public function __construct(public array $sites) + { + } +} diff --git a/src/Objects/ConnectedAccountSites.php b/src/Objects/ConnectedAccountSites.php new file mode 100644 index 00000000..1e2d116f --- /dev/null +++ b/src/Objects/ConnectedAccountSites.php @@ -0,0 +1,27 @@ +site_id, + site_name: $json->site_name, + site_user_subscription_limit: $json->site_user_subscription_limit, + subscribed_site_user_count: $json->subscribed_site_user_count + ); + } + + public function __construct( + public string $site_id, + public string $site_name, + public mixed $site_user_subscription_limit, + public mixed $subscribed_site_user_count + ) { + } +} diff --git a/src/Objects/ConnectedAccountWarnings.php b/src/Objects/ConnectedAccountWarnings.php index 43e69bd8..d97c7661 100644 --- a/src/Objects/ConnectedAccountWarnings.php +++ b/src/Objects/ConnectedAccountWarnings.php @@ -10,16 +10,22 @@ public static function from_json(mixed $json): ConnectedAccountWarnings|null return null; } return new self( + created_at: $json->created_at, message: $json->message, warning_code: $json->warning_code, - created_at: $json->created_at ?? null + salto_ks_metadata: isset($json->salto_ks_metadata) + ? ConnectedAccountSaltoKsMetadata::from_json( + $json->salto_ks_metadata + ) + : null ); } public function __construct( + public string $created_at, public string $message, public string $warning_code, - public string|null $created_at + public ConnectedAccountSaltoKsMetadata|null $salto_ks_metadata ) { } } diff --git a/src/Objects/DeviceErrors.php b/src/Objects/DeviceErrors.php index ecd009fa..166b6f9a 100644 --- a/src/Objects/DeviceErrors.php +++ b/src/Objects/DeviceErrors.php @@ -10,9 +10,10 @@ public static function from_json(mixed $json): DeviceErrors|null return null; } return new self( + created_at: $json->created_at, error_code: $json->error_code, message: $json->message, - created_at: $json->created_at ?? null, + is_bridge_error: $json->is_bridge_error ?? null, is_connected_account_error: $json->is_connected_account_error ?? null, is_device_error: $json->is_device_error ?? null @@ -20,9 +21,10 @@ public static function from_json(mixed $json): DeviceErrors|null } public function __construct( + public string $created_at, public string $error_code, public string $message, - public string|null $created_at, + public bool|null $is_bridge_error, public bool|null $is_connected_account_error, public bool|null $is_device_error ) { diff --git a/src/Objects/DeviceFeatures.php b/src/Objects/DeviceFeatures.php index b4c81580..98708fa7 100644 --- a/src/Objects/DeviceFeatures.php +++ b/src/Objects/DeviceFeatures.php @@ -14,7 +14,8 @@ public static function from_json(mixed $json): DeviceFeatures|null lock_command: $json->lock_command, passcode: $json->passcode, passcode_management: $json->passcode_management, - unlock_via_gateway: $json->unlock_via_gateway + unlock_via_gateway: $json->unlock_via_gateway, + wifi: $json->wifi ); } @@ -23,7 +24,8 @@ public function __construct( public bool $lock_command, public bool $passcode, public bool $passcode_management, - public bool $unlock_via_gateway + public bool $unlock_via_gateway, + public bool $wifi ) { } } diff --git a/src/Objects/DeviceProperties.php b/src/Objects/DeviceProperties.php index 9a32e4e3..3eb6aefe 100644 --- a/src/Objects/DeviceProperties.php +++ b/src/Objects/DeviceProperties.php @@ -198,6 +198,9 @@ public static function from_json(mixed $json): DeviceProperties|null $json->seam_bridge_metadata ) : null, + sensi_metadata: isset($json->sensi_metadata) + ? DeviceSensiMetadata::from_json($json->sensi_metadata) + : null, serial_number: $json->serial_number ?? null, smartthings_metadata: isset($json->smartthings_metadata) ? DeviceSmartthingsMetadata::from_json( @@ -313,6 +316,7 @@ public function __construct( public DeviceSaltoSpaceCredentialServiceMetadata|null $salto_space_credential_service_metadata, public DeviceSchlageMetadata|null $schlage_metadata, public DeviceSeamBridgeMetadata|null $seam_bridge_metadata, + public DeviceSensiMetadata|null $sensi_metadata, public string|null $serial_number, public DeviceSmartthingsMetadata|null $smartthings_metadata, public array|null $supported_code_lengths, diff --git a/src/Objects/DeviceSensiMetadata.php b/src/Objects/DeviceSensiMetadata.php new file mode 100644 index 00000000..aace90a0 --- /dev/null +++ b/src/Objects/DeviceSensiMetadata.php @@ -0,0 +1,25 @@ +device_id, + device_name: $json->device_name, + product_type: $json->product_type + ); + } + + public function __construct( + public string $device_id, + public string $device_name, + public string $product_type + ) { + } +} diff --git a/src/Objects/DeviceWarnings.php b/src/Objects/DeviceWarnings.php index fa29faf0..db5e7aa8 100644 --- a/src/Objects/DeviceWarnings.php +++ b/src/Objects/DeviceWarnings.php @@ -10,16 +10,16 @@ public static function from_json(mixed $json): DeviceWarnings|null return null; } return new self( + created_at: $json->created_at, message: $json->message, - warning_code: $json->warning_code, - created_at: $json->created_at ?? null + warning_code: $json->warning_code ); } public function __construct( + public string $created_at, public string $message, - public string $warning_code, - public string|null $created_at + public string $warning_code ) { } } diff --git a/src/Objects/Event.php b/src/Objects/Event.php index 5a1030e6..be37a1c6 100644 --- a/src/Objects/Event.php +++ b/src/Objects/Event.php @@ -14,6 +14,7 @@ public static function from_json(mixed $json): Event|null acs_access_group_id: $json->acs_access_group_id ?? null, acs_credential_id: $json->acs_credential_id ?? null, acs_encoder_id: $json->acs_encoder_id ?? null, + acs_entrance_id: $json->acs_entrance_id ?? null, acs_system_id: $json->acs_system_id ?? null, acs_user_id: $json->acs_user_id ?? null, action_attempt_id: $json->action_attempt_id ?? null, @@ -34,6 +35,7 @@ public static function from_json(mixed $json): Event|null desired_temperature_fahrenheit: $json->desired_temperature_fahrenheit ?? null, device_id: $json->device_id ?? null, + device_name: $json->device_name ?? null, enrollment_automation_id: $json->enrollment_automation_id ?? null, error_code: $json->error_code ?? null, event_id: $json->event_id ?? null, @@ -71,6 +73,7 @@ public function __construct( public string|null $acs_access_group_id, public string|null $acs_credential_id, public string|null $acs_encoder_id, + public string|null $acs_entrance_id, public string|null $acs_system_id, public string|null $acs_user_id, public string|null $action_attempt_id, @@ -88,6 +91,7 @@ public function __construct( public float|null $desired_temperature_celsius, public float|null $desired_temperature_fahrenheit, public string|null $device_id, + public string|null $device_name, public string|null $enrollment_automation_id, public string|null $error_code, public string|null $event_id, diff --git a/src/Objects/Pagination.php b/src/Objects/Pagination.php new file mode 100644 index 00000000..58e41e44 --- /dev/null +++ b/src/Objects/Pagination.php @@ -0,0 +1,25 @@ +has_next_page, + next_page_cursor: $json->next_page_cursor ?? null, + next_page_url: $json->next_page_url ?? null + ); + } + + public function __construct( + public bool $has_next_page, + public string|null $next_page_cursor, + public string|null $next_page_url + ) { + } +} diff --git a/src/Objects/UnmanagedAccessCodeErrors.php b/src/Objects/UnmanagedAccessCodeErrors.php index 7240b0e2..e7f4d4cb 100644 --- a/src/Objects/UnmanagedAccessCodeErrors.php +++ b/src/Objects/UnmanagedAccessCodeErrors.php @@ -15,6 +15,7 @@ public static function from_json( message: $json->message, created_at: $json->created_at ?? null, is_access_code_error: $json->is_access_code_error ?? null, + is_bridge_error: $json->is_bridge_error ?? null, is_connected_account_error: $json->is_connected_account_error ?? null, is_device_error: $json->is_device_error ?? null @@ -26,6 +27,7 @@ public function __construct( public string $message, public string|null $created_at, public bool|null $is_access_code_error, + public bool|null $is_bridge_error, public bool|null $is_connected_account_error, public bool|null $is_device_error ) { diff --git a/src/Objects/UnmanagedAcsUser.php b/src/Objects/UnmanagedAcsUser.php index 5e938fdc..ae8cde13 100644 --- a/src/Objects/UnmanagedAcsUser.php +++ b/src/Objects/UnmanagedAcsUser.php @@ -37,6 +37,10 @@ public static function from_json(mixed $json): UnmanagedAcsUser|null full_name: $json->full_name ?? null, hid_acs_system_id: $json->hid_acs_system_id ?? null, is_suspended: $json->is_suspended ?? null, + pending_mutations: array_map( + fn($p) => UnmanagedAcsUserPendingMutations::from_json($p), + $json->pending_mutations ?? [] + ), phone_number: $json->phone_number ?? null, user_identity_id: $json->user_identity_id ?? null, is_latest_desired_state_synced_with_provider: $json->is_latest_desired_state_synced_with_provider ?? @@ -68,6 +72,7 @@ public function __construct( public string|null $full_name, public string|null $hid_acs_system_id, public bool|null $is_suspended, + public array|null $pending_mutations, public string|null $phone_number, public string|null $user_identity_id, public bool|null $is_latest_desired_state_synced_with_provider, diff --git a/src/Objects/UnmanagedAcsUserFrom.php b/src/Objects/UnmanagedAcsUserFrom.php new file mode 100644 index 00000000..47a251a0 --- /dev/null +++ b/src/Objects/UnmanagedAcsUserFrom.php @@ -0,0 +1,20 @@ +acs_access_group_id ?? null + ); + } + + public function __construct(public string|null $acs_access_group_id) + { + } +} diff --git a/src/Objects/UnmanagedAcsUserPendingMutations.php b/src/Objects/UnmanagedAcsUserPendingMutations.php new file mode 100644 index 00000000..b1469cbb --- /dev/null +++ b/src/Objects/UnmanagedAcsUserPendingMutations.php @@ -0,0 +1,32 @@ +created_at, + mutation_code: $json->mutation_code, + from: isset($json->from) + ? UnmanagedAcsUserFrom::from_json($json->from) + : null, + to: isset($json->to) + ? UnmanagedAcsUserTo::from_json($json->to) + : null + ); + } + + public function __construct( + public string $created_at, + public string $mutation_code, + public UnmanagedAcsUserFrom|null $from, + public UnmanagedAcsUserTo|null $to + ) { + } +} diff --git a/src/Objects/UnmanagedAcsUserTo.php b/src/Objects/UnmanagedAcsUserTo.php new file mode 100644 index 00000000..d2eb20ee --- /dev/null +++ b/src/Objects/UnmanagedAcsUserTo.php @@ -0,0 +1,20 @@ +acs_access_group_id ?? null + ); + } + + public function __construct(public string|null $acs_access_group_id) + { + } +} diff --git a/src/Objects/UnmanagedDeviceErrors.php b/src/Objects/UnmanagedDeviceErrors.php index 0b0f12a2..37c0b465 100644 --- a/src/Objects/UnmanagedDeviceErrors.php +++ b/src/Objects/UnmanagedDeviceErrors.php @@ -10,9 +10,10 @@ public static function from_json(mixed $json): UnmanagedDeviceErrors|null return null; } return new self( + created_at: $json->created_at, error_code: $json->error_code, message: $json->message, - created_at: $json->created_at ?? null, + is_bridge_error: $json->is_bridge_error ?? null, is_connected_account_error: $json->is_connected_account_error ?? null, is_device_error: $json->is_device_error ?? null @@ -20,9 +21,10 @@ public static function from_json(mixed $json): UnmanagedDeviceErrors|null } public function __construct( + public string $created_at, public string $error_code, public string $message, - public string|null $created_at, + public bool|null $is_bridge_error, public bool|null $is_connected_account_error, public bool|null $is_device_error ) { diff --git a/src/Objects/UnmanagedDeviceWarnings.php b/src/Objects/UnmanagedDeviceWarnings.php index 84cc664f..c7cbe962 100644 --- a/src/Objects/UnmanagedDeviceWarnings.php +++ b/src/Objects/UnmanagedDeviceWarnings.php @@ -10,16 +10,16 @@ public static function from_json(mixed $json): UnmanagedDeviceWarnings|null return null; } return new self( + created_at: $json->created_at, message: $json->message, - warning_code: $json->warning_code, - created_at: $json->created_at ?? null + warning_code: $json->warning_code ); } public function __construct( + public string $created_at, public string $message, - public string $warning_code, - public string|null $created_at + public string $warning_code ) { } } diff --git a/src/Objects/Workspace.php b/src/Objects/Workspace.php index 9ac24e25..a48dc00b 100644 --- a/src/Objects/Workspace.php +++ b/src/Objects/Workspace.php @@ -12,6 +12,7 @@ public static function from_json(mixed $json): Workspace|null return new self( company_name: $json->company_name, is_sandbox: $json->is_sandbox, + is_suspended: $json->is_suspended, name: $json->name, workspace_id: $json->workspace_id, connect_partner_name: $json->connect_partner_name ?? null @@ -21,6 +22,7 @@ public static function from_json(mixed $json): Workspace|null public function __construct( public string $company_name, public bool $is_sandbox, + public bool $is_suspended, public string $name, public string $workspace_id, public string|null $connect_partner_name diff --git a/src/Paginator.php b/src/Paginator.php new file mode 100644 index 00000000..42526658 --- /dev/null +++ b/src/Paginator.php @@ -0,0 +1,89 @@ +callable = $callable; + $this->params = $params; + } + + public function firstPage(): array + { + $callable = $this->callable; + $params = $this->params; + + $params["on_response"] = fn($response) => $this->cachePagination( + $response, + self::FIRST_PAGE + ); + + $data = $callable($params); + + return [$data, $this->pagination_cache[self::FIRST_PAGE]]; + } + + public function nextPage(string $next_page_cursor): array + { + $callable = $this->callable; + $params = $this->params; + + $params["page_cursor"] = $next_page_cursor; + $params["on_response"] = fn($response) => $this->cachePagination( + $response, + $next_page_cursor + ); + + $data = $callable($params); + + return [$data, $this->pagination_cache[$next_page_cursor]]; + } + + private function cachePagination($response, $next_page_cursor) + { + $this->pagination_cache[$next_page_cursor] = $response->pagination; + } + + public function flattenToArray(): array + { + $items = []; + + [$response, $pagination] = $this->firstPage(); + $items = array_merge($items, $response); + + while ($pagination->has_next_page) { + [$response, $pagination] = $this->nextPage( + $pagination->next_page_cursor + ); + $items = array_merge($items, $response); + } + + return $items; + } + + public function flatten() + { + [$current, $pagination] = $this->firstPage(); + + foreach ($current as $item) { + yield $item; + } + + while ($pagination->has_next_page) { + [$current, $pagination] = $this->nextPage( + $pagination->next_page_cursor + ); + + foreach ($current as $item) { + yield $item; + } + } + } +} diff --git a/src/SeamClient.php b/src/SeamClient.php index 3af13b56..df6389ac 100644 --- a/src/SeamClient.php +++ b/src/SeamClient.php @@ -21,6 +21,7 @@ use Seam\Objects\Event; use Seam\Objects\Network; use Seam\Objects\NoiseThreshold; +use Seam\Objects\Pagination; use Seam\Objects\Phone; use Seam\Objects\ThermostatSchedule; use Seam\Objects\UnmanagedAccessCode; @@ -105,13 +106,8 @@ public function __construct( $this->workspaces = new WorkspacesClient($this); } - public function request( - $method, - $path, - $json = null, - $query = null, - $inner_object = null - ) { + public function request($method, $path, $json = null, $query = null) + { $options = [ "json" => $json, "query" => $query, @@ -156,7 +152,12 @@ public function request( ); } - return $inner_object ? $res_json->$inner_object : $res_json; + return $res_json; + } + + public function createPaginator($request, $params = []) + { + return new Paginator($request, $params); } } @@ -174,22 +175,22 @@ public function __construct(SeamClient $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 + ?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 = []; @@ -262,30 +263,29 @@ public function create( $res = $this->seam->request( "POST", "/access_codes/create", - json: (object) $request_payload, - inner_object: "access_code" + json: (object) $request_payload ); - return AccessCode::from_json($res); + return AccessCode::from_json($res->access_code); } 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 + ?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 = []; @@ -357,17 +357,19 @@ public function create_multiple( $res = $this->seam->request( "POST", "/access_codes/create_multiple", - json: (object) $request_payload, - inner_object: "access_codes" + json: (object) $request_payload ); - return array_map(fn($r) => AccessCode::from_json($r), $res); + return array_map( + fn($r) => AccessCode::from_json($r), + $res->access_codes + ); } public function delete( string $access_code_id, - string $device_id = null, - bool $sync = null + ?string $device_id = null, + ?bool $sync = null ): void { $request_payload = []; @@ -399,17 +401,16 @@ public function generate_code(string $device_id): AccessCode $res = $this->seam->request( "POST", "/access_codes/generate_code", - json: (object) $request_payload, - inner_object: "generated_code" + json: (object) $request_payload ); - return AccessCode::from_json($res); + return AccessCode::from_json($res->generated_code); } public function get( - string $access_code_id = null, - string $code = null, - string $device_id = null + ?string $access_code_id = null, + ?string $code = null, + ?string $device_id = null ): AccessCode { $request_payload = []; @@ -426,17 +427,17 @@ public function get( $res = $this->seam->request( "POST", "/access_codes/get", - json: (object) $request_payload, - inner_object: "access_code" + json: (object) $request_payload ); - return AccessCode::from_json($res); + return AccessCode::from_json($res->access_code); } public function list( - array $access_code_ids = null, - string $device_id = null, - string $user_identifier_key = null + ?array $access_code_ids = null, + ?string $device_id = null, + ?string $user_identifier_key = null, + ?callable $on_response = null ): array { $request_payload = []; @@ -453,11 +454,17 @@ public function list( $res = $this->seam->request( "POST", "/access_codes/list", - json: (object) $request_payload, - inner_object: "access_codes" + json: (object) $request_payload ); - return array_map(fn($r) => AccessCode::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map( + fn($r) => AccessCode::from_json($r), + $res->access_codes + ); } public function pull_backup_access_code(string $access_code_id): AccessCode @@ -471,33 +478,32 @@ public function pull_backup_access_code(string $access_code_id): AccessCode $res = $this->seam->request( "POST", "/access_codes/pull_backup_access_code", - json: (object) $request_payload, - inner_object: "access_code" + json: (object) $request_payload ); - return AccessCode::from_json($res); + return AccessCode::from_json($res->access_code); } 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 + ?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 = []; @@ -582,9 +588,9 @@ public function update( public function update_multiple( string $common_code_key, - string $ends_at = null, - string $name = null, - string $starts_at = null + ?string $ends_at = null, + ?string $name = null, + ?string $starts_at = null ): void { $request_payload = []; @@ -638,11 +644,10 @@ public function create_unmanaged_access_code( $res = $this->seam->request( "POST", "/access_codes/simulate/create_unmanaged_access_code", - json: (object) $request_payload, - inner_object: "access_code" + json: (object) $request_payload ); - return UnmanagedAccessCode::from_json($res); + return UnmanagedAccessCode::from_json($res->access_code); } } @@ -657,10 +662,10 @@ public function __construct(SeamClient $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 + ?bool $allow_external_modification = null, + ?bool $force = null, + ?bool $is_external_modification_allowed = null, + ?bool $sync = null ): void { $request_payload = []; @@ -691,7 +696,7 @@ public function convert_to_managed( ); } - public function delete(string $access_code_id, bool $sync = null): void + public function delete(string $access_code_id, ?bool $sync = null): void { $request_payload = []; @@ -710,9 +715,9 @@ public function delete(string $access_code_id, bool $sync = null): void } public function get( - string $access_code_id = null, - string $code = null, - string $device_id = null + ?string $access_code_id = null, + ?string $code = null, + ?string $device_id = null ): UnmanagedAccessCode { $request_payload = []; @@ -729,16 +734,16 @@ public function get( $res = $this->seam->request( "POST", "/access_codes/unmanaged/get", - json: (object) $request_payload, - inner_object: "access_code" + json: (object) $request_payload ); - return UnmanagedAccessCode::from_json($res); + return UnmanagedAccessCode::from_json($res->access_code); } public function list( string $device_id, - string $user_identifier_key = null + ?string $user_identifier_key = null, + ?callable $on_response = null ): array { $request_payload = []; @@ -752,19 +757,25 @@ public function list( $res = $this->seam->request( "POST", "/access_codes/unmanaged/list", - json: (object) $request_payload, - inner_object: "access_codes" + json: (object) $request_payload ); - return array_map(fn($r) => UnmanagedAccessCode::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map( + fn($r) => UnmanagedAccessCode::from_json($r), + $res->access_codes + ); } public function update( string $access_code_id, bool $is_managed, - bool $allow_external_modification = null, - bool $force = null, - bool $is_external_modification_allowed = null + ?bool $allow_external_modification = null, + ?bool $force = null, + ?bool $is_external_modification_allowed = null ): void { $request_payload = []; @@ -836,16 +847,16 @@ public function get(string $acs_access_group_id): AcsAccessGroup $res = $this->seam->request( "POST", "/acs/access_groups/get", - json: (object) $request_payload, - inner_object: "acs_access_group" + json: (object) $request_payload ); - return AcsAccessGroup::from_json($res); + return AcsAccessGroup::from_json($res->acs_access_group); } public function list( - string $acs_system_id = null, - string $acs_user_id = null + ?string $acs_system_id = null, + ?string $acs_user_id = null, + ?callable $on_response = null ): array { $request_payload = []; @@ -859,11 +870,17 @@ public function list( $res = $this->seam->request( "POST", "/acs/access_groups/list", - json: (object) $request_payload, - inner_object: "acs_access_groups" + json: (object) $request_payload ); - return array_map(fn($r) => AcsAccessGroup::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map( + fn($r) => AcsAccessGroup::from_json($r), + $res->acs_access_groups + ); } public function list_accessible_entrances( @@ -878,11 +895,13 @@ public function list_accessible_entrances( $res = $this->seam->request( "POST", "/acs/access_groups/list_accessible_entrances", - json: (object) $request_payload, - inner_object: "acs_entrances" + json: (object) $request_payload ); - return array_map(fn($r) => AcsEntrance::from_json($r), $res); + return array_map( + fn($r) => AcsEntrance::from_json($r), + $res->acs_entrances + ); } public function list_users(string $acs_access_group_id): array @@ -896,11 +915,10 @@ public function list_users(string $acs_access_group_id): array $res = $this->seam->request( "POST", "/acs/access_groups/list_users", - json: (object) $request_payload, - inner_object: "acs_users" + json: (object) $request_payload ); - return array_map(fn($r) => AcsUser::from_json($r), $res); + return array_map(fn($r) => AcsUser::from_json($r), $res->acs_users); } public function remove_user( @@ -928,8 +946,6 @@ 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; @@ -939,10 +955,6 @@ 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); @@ -951,141 +963,6 @@ public function __construct(SeamClient $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; @@ -1116,14 +993,14 @@ public function assign(string $acs_credential_id, string $acs_user_id): void public function create( string $access_method, string $acs_user_id, - array $allowed_acs_entrance_ids = null, + ?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, + ?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, + ?string $starts_at = null, mixed $visionline_metadata = null ): AcsCredential { $request_payload = []; @@ -1173,48 +1050,10 @@ public function create( $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" + json: (object) $request_payload ); - return AcsCredential::from_json($res); + return AcsCredential::from_json($res->acs_credential); } public function delete(string $acs_credential_id): void @@ -1243,20 +1082,20 @@ public function get(string $acs_credential_id): AcsCredential $res = $this->seam->request( "POST", "/acs/credentials/get", - json: (object) $request_payload, - inner_object: "acs_credential" + json: (object) $request_payload ); - return AcsCredential::from_json($res); + return AcsCredential::from_json($res->acs_credential); } 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 + ?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, + ?callable $on_response = null ): array { $request_payload = []; @@ -1284,11 +1123,17 @@ public function list( $res = $this->seam->request( "POST", "/acs/credentials/list", - json: (object) $request_payload, - inner_object: "acs_credentials" + json: (object) $request_payload ); - return array_map(fn($r) => AcsCredential::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map( + fn($r) => AcsCredential::from_json($r), + $res->acs_credentials + ); } public function list_accessible_entrances(string $acs_credential_id): array @@ -1302,11 +1147,13 @@ public function list_accessible_entrances(string $acs_credential_id): array $res = $this->seam->request( "POST", "/acs/credentials/list_accessible_entrances", - json: (object) $request_payload, - inner_object: "acs_entrances" + json: (object) $request_payload ); - return array_map(fn($r) => AcsEntrance::from_json($r), $res); + return array_map( + fn($r) => AcsEntrance::from_json($r), + $res->acs_entrances + ); } public function unassign( @@ -1331,8 +1178,8 @@ public function unassign( public function update( string $acs_credential_id, - string $code = null, - string $ends_at = null + ?string $code = null, + ?string $ends_at = null ): void { $request_payload = []; @@ -1354,61 +1201,6 @@ public function update( } } -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; @@ -1435,26 +1227,26 @@ public function encode_credential( $res = $this->seam->request( "POST", "/acs/encoders/encode_credential", - json: (object) $request_payload, - inner_object: "action_attempt" + json: (object) $request_payload ); if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); + return ActionAttempt::from_json($res->action_attempt); } $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id + $res->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 + ?string $acs_system_id = null, + ?float $limit = null, + ?array $acs_system_ids = null, + ?array $acs_encoder_ids = null, + ?callable $on_response = null ): array { $request_payload = []; @@ -1474,11 +1266,17 @@ public function list( $res = $this->seam->request( "POST", "/acs/encoders/list", - json: (object) $request_payload, - inner_object: "acs_encoders" + json: (object) $request_payload ); - return array_map(fn($r) => AcsEncoder::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map( + fn($r) => AcsEncoder::from_json($r), + $res->acs_encoders + ); } public function scan_credential( @@ -1494,16 +1292,15 @@ public function scan_credential( $res = $this->seam->request( "POST", "/acs/encoders/scan_credential", - json: (object) $request_payload, - inner_object: "action_attempt" + json: (object) $request_payload ); if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); + return ActionAttempt::from_json($res->action_attempt); } $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id + $res->action_attempt->action_attempt_id ); return $action_attempt; @@ -1521,8 +1318,8 @@ public function __construct(SeamClient $seam) public function next_credential_encode_will_fail( string $acs_encoder_id, - string $error_code = null, - string $acs_credential_id = null + ?string $error_code = null, + ?string $acs_credential_id = null ): void { $request_payload = []; @@ -1545,7 +1342,7 @@ public function next_credential_encode_will_fail( public function next_credential_encode_will_succeed( string $acs_encoder_id, - string $scenario = null + ?string $scenario = null ): void { $request_payload = []; @@ -1565,8 +1362,8 @@ public function next_credential_encode_will_succeed( public function next_credential_scan_will_fail( string $acs_encoder_id, - string $error_code = null, - string $acs_credential_id_on_seam = null + ?string $error_code = null, + ?string $acs_credential_id_on_seam = null ): void { $request_payload = []; @@ -1591,8 +1388,8 @@ public function next_credential_scan_will_fail( public function next_credential_scan_will_succeed( string $acs_encoder_id, - string $acs_credential_id_on_seam = null, - string $scenario = null + ?string $acs_credential_id_on_seam = null, + ?string $scenario = null ): void { $request_payload = []; @@ -1636,11 +1433,10 @@ public function get(string $acs_entrance_id): AcsEntrance $res = $this->seam->request( "POST", "/acs/entrances/get", - json: (object) $request_payload, - inner_object: "acs_entrance" + json: (object) $request_payload ); - return AcsEntrance::from_json($res); + return AcsEntrance::from_json($res->acs_entrance); } public function grant_access( @@ -1664,8 +1460,9 @@ public function grant_access( } public function list( - string $acs_credential_id = null, - string $acs_system_id = null + ?string $acs_credential_id = null, + ?string $acs_system_id = null, + ?callable $on_response = null ): array { $request_payload = []; @@ -1679,16 +1476,22 @@ public function list( $res = $this->seam->request( "POST", "/acs/entrances/list", - json: (object) $request_payload, - inner_object: "acs_entrances" + json: (object) $request_payload ); - return array_map(fn($r) => AcsEntrance::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map( + fn($r) => AcsEntrance::from_json($r), + $res->acs_entrances + ); } public function list_credentials_with_access( string $acs_entrance_id, - array $include_if = null + ?array $include_if = null ): array { $request_payload = []; @@ -1702,11 +1505,13 @@ public function list_credentials_with_access( $res = $this->seam->request( "POST", "/acs/entrances/list_credentials_with_access", - json: (object) $request_payload, - inner_object: "acs_credentials" + json: (object) $request_payload ); - return array_map(fn($r) => AcsCredential::from_json($r), $res); + return array_map( + fn($r) => AcsCredential::from_json($r), + $res->acs_credentials + ); } } @@ -1730,15 +1535,16 @@ public function get(string $acs_system_id): AcsSystem $res = $this->seam->request( "POST", "/acs/systems/get", - json: (object) $request_payload, - inner_object: "acs_system" + json: (object) $request_payload ); - return AcsSystem::from_json($res); + return AcsSystem::from_json($res->acs_system); } - public function list(string $connected_account_id = null): array - { + public function list( + ?string $connected_account_id = null, + ?callable $on_response = null + ): array { $request_payload = []; if ($connected_account_id !== null) { @@ -1748,11 +1554,14 @@ public function list(string $connected_account_id = null): array $res = $this->seam->request( "POST", "/acs/systems/list", - json: (object) $request_payload, - inner_object: "acs_systems" + json: (object) $request_payload ); - return array_map(fn($r) => AcsSystem::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map(fn($r) => AcsSystem::from_json($r), $res->acs_systems); } public function list_compatible_credential_manager_acs_systems( @@ -1767,11 +1576,10 @@ public function list_compatible_credential_manager_acs_systems( $res = $this->seam->request( "POST", "/acs/systems/list_compatible_credential_manager_acs_systems", - json: (object) $request_payload, - inner_object: "acs_systems" + json: (object) $request_payload ); - return array_map(fn($r) => AcsSystem::from_json($r), $res); + return array_map(fn($r) => AcsSystem::from_json($r), $res->acs_systems); } } @@ -1808,11 +1616,11 @@ 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 + ?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 = []; @@ -1844,11 +1652,10 @@ public function create( $res = $this->seam->request( "POST", "/acs/users/create", - json: (object) $request_payload, - inner_object: "acs_user" + json: (object) $request_payload ); - return AcsUser::from_json($res); + return AcsUser::from_json($res->acs_user); } public function delete(string $acs_user_id): void @@ -1877,20 +1684,22 @@ public function get(string $acs_user_id): AcsUser $res = $this->seam->request( "POST", "/acs/users/get", - json: (object) $request_payload, - inner_object: "acs_user" + json: (object) $request_payload ); - return AcsUser::from_json($res); + return AcsUser::from_json($res->acs_user); } 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 + ?string $acs_system_id = null, + ?string $created_before = null, + mixed $limit = null, + ?string $page_cursor = null, + ?string $search = null, + ?string $user_identity_email_address = null, + ?string $user_identity_id = null, + ?string $user_identity_phone_number = null, + ?callable $on_response = null ): array { $request_payload = []; @@ -1903,6 +1712,12 @@ public function list( if ($limit !== null) { $request_payload["limit"] = $limit; } + if ($page_cursor !== null) { + $request_payload["page_cursor"] = $page_cursor; + } + if ($search !== null) { + $request_payload["search"] = $search; + } if ($user_identity_email_address !== null) { $request_payload[ "user_identity_email_address" @@ -1920,11 +1735,14 @@ public function list( $res = $this->seam->request( "POST", "/acs/users/list", - json: (object) $request_payload, - inner_object: "acs_users" + json: (object) $request_payload ); - return array_map(fn($r) => AcsUser::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map(fn($r) => AcsUser::from_json($r), $res->acs_users); } public function list_accessible_entrances(string $acs_user_id): array @@ -1938,11 +1756,13 @@ public function list_accessible_entrances(string $acs_user_id): array $res = $this->seam->request( "POST", "/acs/users/list_accessible_entrances", - json: (object) $request_payload, - inner_object: "acs_entrances" + json: (object) $request_payload ); - return array_map(fn($r) => AcsEntrance::from_json($r), $res); + return array_map( + fn($r) => AcsEntrance::from_json($r), + $res->acs_entrances + ); } public function remove_from_access_group( @@ -2013,11 +1833,11 @@ public function unsuspend(string $acs_user_id): void 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 + ?string $email = null, + ?string $email_address = null, + ?string $full_name = null, + ?string $hid_acs_system_id = null, + ?string $phone_number = null ): void { $request_payload = []; @@ -2051,73 +1871,6 @@ public function update( } } -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; @@ -2138,15 +1891,16 @@ public function get(string $action_attempt_id): ActionAttempt $res = $this->seam->request( "POST", "/action_attempts/get", - json: (object) $request_payload, - inner_object: "action_attempt" + json: (object) $request_payload ); - return ActionAttempt::from_json($res); + return ActionAttempt::from_json($res->action_attempt); } - public function list(array $action_attempt_ids): array - { + public function list( + array $action_attempt_ids, + ?callable $on_response = null + ): array { $request_payload = []; if ($action_attempt_ids !== null) { @@ -2156,11 +1910,17 @@ public function list(array $action_attempt_ids): array $res = $this->seam->request( "POST", "/action_attempts/list", - json: (object) $request_payload, - inner_object: "action_attempts" + json: (object) $request_payload ); - return array_map(fn($r) => ActionAttempt::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map( + fn($r) => ActionAttempt::from_json($r), + $res->action_attempts + ); } public function poll_until_ready( string $action_attempt_id, @@ -2210,21 +1970,13 @@ public function get(string $bridge_id): void $this->seam->request( "POST", "/bridges/get", - json: (object) $request_payload, - inner_object: "bridge" + json: (object) $request_payload ); } public function list(): void { - $request_payload = []; - - $this->seam->request( - "POST", - "/bridges/list", - json: (object) $request_payload, - inner_object: "bridges" - ); + $this->seam->request("POST", "/bridges/list"); } } @@ -2238,11 +1990,11 @@ public function __construct(SeamClient $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 + ?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 = []; @@ -2265,11 +2017,10 @@ public function create( $res = $this->seam->request( "POST", "/client_sessions/create", - json: (object) $request_payload, - inner_object: "client_session" + json: (object) $request_payload ); - return ClientSession::from_json($res); + return ClientSession::from_json($res->client_session); } public function delete(string $client_session_id): void @@ -2288,8 +2039,8 @@ public function delete(string $client_session_id): void } public function get( - string $client_session_id = null, - string $user_identifier_key = null + ?string $client_session_id = null, + ?string $user_identifier_key = null ): ClientSession { $request_payload = []; @@ -2303,19 +2054,18 @@ public function get( $res = $this->seam->request( "POST", "/client_sessions/get", - json: (object) $request_payload, - inner_object: "client_session" + json: (object) $request_payload ); - return ClientSession::from_json($res); + return ClientSession::from_json($res->client_session); } 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 + ?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 = []; @@ -2338,19 +2088,18 @@ public function get_or_create( $res = $this->seam->request( "POST", "/client_sessions/get_or_create", - json: (object) $request_payload, - inner_object: "client_session" + json: (object) $request_payload ); - return ClientSession::from_json($res); + return ClientSession::from_json($res->client_session); } 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 + ?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 = []; @@ -2378,11 +2127,12 @@ public function grant_access( } 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 + ?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, + ?callable $on_response = null ): array { $request_payload = []; @@ -2407,11 +2157,17 @@ public function list( $res = $this->seam->request( "POST", "/client_sessions/list", - json: (object) $request_payload, - inner_object: "client_sessions" + json: (object) $request_payload ); - return array_map(fn($r) => ClientSession::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map( + fn($r) => ClientSession::from_json($r), + $res->client_sessions + ); } public function revoke(string $client_session_id): void @@ -2440,14 +2196,14 @@ public function __construct(SeamClient $seam) } public function create( - array $accepted_providers = null, - bool $automatically_manage_new_devices = null, + ?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 + ?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 = []; @@ -2485,11 +2241,10 @@ public function create( $res = $this->seam->request( "POST", "/connect_webviews/create", - json: (object) $request_payload, - inner_object: "connect_webview" + json: (object) $request_payload ); - return ConnectWebview::from_json($res); + return ConnectWebview::from_json($res->connect_webview); } public function delete(string $connect_webview_id): void @@ -2518,17 +2273,17 @@ public function get(string $connect_webview_id): ConnectWebview $res = $this->seam->request( "POST", "/connect_webviews/get", - json: (object) $request_payload, - inner_object: "connect_webview" + json: (object) $request_payload ); - return ConnectWebview::from_json($res); + return ConnectWebview::from_json($res->connect_webview); } public function list( mixed $custom_metadata_has = null, - float $limit = null, - string $user_identifier_key = null + ?float $limit = null, + ?string $user_identifier_key = null, + ?callable $on_response = null ): array { $request_payload = []; @@ -2545,11 +2300,17 @@ public function list( $res = $this->seam->request( "POST", "/connect_webviews/list", - json: (object) $request_payload, - inner_object: "connect_webviews" + json: (object) $request_payload ); - return array_map(fn($r) => ConnectWebview::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map( + fn($r) => ConnectWebview::from_json($r), + $res->connect_webviews + ); } } @@ -2564,7 +2325,7 @@ public function __construct(SeamClient $seam) public function delete( string $connected_account_id, - bool $sync = null + ?bool $sync = null ): void { $request_payload = []; @@ -2583,8 +2344,8 @@ public function delete( } public function get( - string $connected_account_id = null, - string $email = null + ?string $connected_account_id = null, + ?string $email = null ): ConnectedAccount { $request_payload = []; @@ -2598,22 +2359,30 @@ public function get( $res = $this->seam->request( "POST", "/connected_accounts/get", - json: (object) $request_payload, - inner_object: "connected_account" + json: (object) $request_payload ); - return ConnectedAccount::from_json($res); + return ConnectedAccount::from_json($res->connected_account); } public function list( mixed $custom_metadata_has = null, - string $user_identifier_key = null + mixed $limit = null, + ?string $page_cursor = null, + ?string $user_identifier_key = null, + ?callable $on_response = 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 ($page_cursor !== null) { + $request_payload["page_cursor"] = $page_cursor; + } if ($user_identifier_key !== null) { $request_payload["user_identifier_key"] = $user_identifier_key; } @@ -2621,16 +2390,22 @@ public function list( $res = $this->seam->request( "POST", "/connected_accounts/list", - json: (object) $request_payload, - inner_object: "connected_accounts" + json: (object) $request_payload ); - return array_map(fn($r) => ConnectedAccount::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map( + fn($r) => ConnectedAccount::from_json($r), + $res->connected_accounts + ); } public function update( string $connected_account_id, - bool $automatically_manage_new_devices = null, + ?bool $automatically_manage_new_devices = null, mixed $custom_metadata = null ): void { $request_payload = []; @@ -2667,22 +2442,7 @@ public function __construct(SeamClient $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 + public function get(?string $device_id = null, ?string $name = null): Device { $request_payload = []; @@ -2696,27 +2456,28 @@ public function get(string $device_id = null, string $name = null): Device $res = $this->seam->request( "POST", "/devices/get", - json: (object) $request_payload, - inner_object: "device" + json: (object) $request_payload ); - return Device::from_json($res); + return Device::from_json($res->device); } public function list( - string $connect_webview_id = null, - string $connected_account_id = null, - array $connected_account_ids = null, - string $created_before = null, + ?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 $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 $unstable_location_id = null, + ?string $user_identifier_key = null, + ?callable $on_response = null ): array { $request_payload = []; @@ -2756,6 +2517,9 @@ public function list( if ($manufacturer !== null) { $request_payload["manufacturer"] = $manufacturer; } + if ($unstable_location_id !== null) { + $request_payload["unstable_location_id"] = $unstable_location_id; + } if ($user_identifier_key !== null) { $request_payload["user_identifier_key"] = $user_identifier_key; } @@ -2763,15 +2527,18 @@ public function list( $res = $this->seam->request( "POST", "/devices/list", - json: (object) $request_payload, - inner_object: "devices" + json: (object) $request_payload ); - return array_map(fn($r) => Device::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map(fn($r) => Device::from_json($r), $res->devices); } public function list_device_providers( - string $provider_category = null + ?string $provider_category = null ): array { $request_payload = []; @@ -2782,18 +2549,20 @@ public function list_device_providers( $res = $this->seam->request( "POST", "/devices/list_device_providers", - json: (object) $request_payload, - inner_object: "device_providers" + json: (object) $request_payload ); - return array_map(fn($r) => DeviceProvider::from_json($r), $res); + return array_map( + fn($r) => DeviceProvider::from_json($r), + $res->device_providers + ); } public function update( string $device_id, mixed $custom_metadata = null, - bool $is_managed = null, - string $name = null, + ?bool $is_managed = null, + ?string $name = null, mixed $properties = null ): void { $request_payload = []; @@ -2887,8 +2656,8 @@ public function __construct(SeamClient $seam) } public function get( - string $device_id = null, - string $name = null + ?string $device_id = null, + ?string $name = null ): UnmanagedDevice { $request_payload = []; @@ -2902,27 +2671,28 @@ public function get( $res = $this->seam->request( "POST", "/devices/unmanaged/get", - json: (object) $request_payload, - inner_object: "device" + json: (object) $request_payload ); - return UnmanagedDevice::from_json($res); + return UnmanagedDevice::from_json($res->device); } public function list( - string $connect_webview_id = null, - string $connected_account_id = null, - array $connected_account_ids = null, - string $created_before = null, + ?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 $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 $unstable_location_id = null, + ?string $user_identifier_key = null, + ?callable $on_response = null ): array { $request_payload = []; @@ -2962,6 +2732,9 @@ public function list( if ($manufacturer !== null) { $request_payload["manufacturer"] = $manufacturer; } + if ($unstable_location_id !== null) { + $request_payload["unstable_location_id"] = $unstable_location_id; + } if ($user_identifier_key !== null) { $request_payload["user_identifier_key"] = $user_identifier_key; } @@ -2969,11 +2742,17 @@ public function list( $res = $this->seam->request( "POST", "/devices/unmanaged/list", - json: (object) $request_payload, - inner_object: "devices" + json: (object) $request_payload ); - return array_map(fn($r) => UnmanagedDevice::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map( + fn($r) => UnmanagedDevice::from_json($r), + $res->devices + ); } public function update(string $device_id, bool $is_managed): void @@ -3005,9 +2784,9 @@ public function __construct(SeamClient $seam) } public function get( - string $device_id = null, - string $event_id = null, - string $event_type = null + ?string $device_id = null, + ?string $event_id = null, + ?string $event_type = null ): Event { $request_payload = []; @@ -3024,28 +2803,29 @@ public function get( $res = $this->seam->request( "POST", "/events/get", - json: (object) $request_payload, - inner_object: "event" + json: (object) $request_payload ); - return Event::from_json($res); + return Event::from_json($res->event); } 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 + ?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, + ?array $event_ids = null, + ?string $event_type = null, + ?array $event_types = null, + ?float $limit = null, + ?string $since = null, + ?float $unstable_offset = null, + ?callable $on_response = null ): array { $request_payload = []; @@ -3076,6 +2856,9 @@ public function list( if ($device_ids !== null) { $request_payload["device_ids"] = $device_ids; } + if ($event_ids !== null) { + $request_payload["event_ids"] = $event_ids; + } if ($event_type !== null) { $request_payload["event_type"] = $event_type; } @@ -3095,11 +2878,14 @@ public function list( $res = $this->seam->request( "POST", "/events/list", - json: (object) $request_payload, - inner_object: "events" + json: (object) $request_payload ); - return array_map(fn($r) => Event::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map(fn($r) => Event::from_json($r), $res->events); } } @@ -3112,7 +2898,7 @@ public function __construct(SeamClient $seam) $this->seam = $seam; } - public function get(string $device_id = null, string $name = null): Device + public function get(?string $device_id = null, ?string $name = null): Device { $request_payload = []; @@ -3126,27 +2912,28 @@ public function get(string $device_id = null, string $name = null): Device $res = $this->seam->request( "POST", "/locks/get", - json: (object) $request_payload, - inner_object: "device" + json: (object) $request_payload ); - return Device::from_json($res); + return Device::from_json($res->device); } public function list( - string $connect_webview_id = null, - string $connected_account_id = null, - array $connected_account_ids = null, - string $created_before = null, + ?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 $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 $unstable_location_id = null, + ?string $user_identifier_key = null, + ?callable $on_response = null ): array { $request_payload = []; @@ -3186,6 +2973,9 @@ public function list( if ($manufacturer !== null) { $request_payload["manufacturer"] = $manufacturer; } + if ($unstable_location_id !== null) { + $request_payload["unstable_location_id"] = $unstable_location_id; + } if ($user_identifier_key !== null) { $request_payload["user_identifier_key"] = $user_identifier_key; } @@ -3193,16 +2983,19 @@ public function list( $res = $this->seam->request( "POST", "/locks/list", - json: (object) $request_payload, - inner_object: "devices" + json: (object) $request_payload ); - return array_map(fn($r) => Device::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map(fn($r) => Device::from_json($r), $res->devices); } public function lock_door( string $device_id, - bool $sync = null, + ?bool $sync = null, bool $wait_for_action_attempt = true ): ActionAttempt { $request_payload = []; @@ -3217,16 +3010,15 @@ public function lock_door( $res = $this->seam->request( "POST", "/locks/lock_door", - json: (object) $request_payload, - inner_object: "action_attempt" + json: (object) $request_payload ); if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); + return ActionAttempt::from_json($res->action_attempt); } $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id + $res->action_attempt->action_attempt_id ); return $action_attempt; @@ -3234,7 +3026,7 @@ public function lock_door( public function unlock_door( string $device_id, - bool $sync = null, + ?bool $sync = null, bool $wait_for_action_attempt = true ): ActionAttempt { $request_payload = []; @@ -3249,16 +3041,15 @@ public function unlock_door( $res = $this->seam->request( "POST", "/locks/unlock_door", - json: (object) $request_payload, - inner_object: "action_attempt" + json: (object) $request_payload ); if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); + return ActionAttempt::from_json($res->action_attempt); } $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id + $res->action_attempt->action_attempt_id ); return $action_attempt; @@ -3285,25 +3076,21 @@ public function get(string $network_id): Network $res = $this->seam->request( "POST", "/networks/get", - json: (object) $request_payload, - inner_object: "network" + json: (object) $request_payload ); - return Network::from_json($res); + return Network::from_json($res->network); } - public function list(): array + public function list(?callable $on_response = null): array { - $request_payload = []; + $res = $this->seam->request("POST", "/networks/list"); - $res = $this->seam->request( - "POST", - "/networks/list", - json: (object) $request_payload, - inner_object: "networks" - ); + if ($on_response !== null) { + $on_response($res); + } - return array_map(fn($r) => Network::from_json($r), $res); + return array_map(fn($r) => Network::from_json($r), $res->networks); } } @@ -3320,19 +3107,21 @@ public function __construct(SeamClient $seam) } public function list( - string $connect_webview_id = null, - string $connected_account_id = null, - array $connected_account_ids = null, - string $created_before = null, + ?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 $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 $unstable_location_id = null, + ?string $user_identifier_key = null, + ?callable $on_response = null ): array { $request_payload = []; @@ -3372,6 +3161,9 @@ public function list( if ($manufacturer !== null) { $request_payload["manufacturer"] = $manufacturer; } + if ($unstable_location_id !== null) { + $request_payload["unstable_location_id"] = $unstable_location_id; + } if ($user_identifier_key !== null) { $request_payload["user_identifier_key"] = $user_identifier_key; } @@ -3379,11 +3171,14 @@ public function list( $res = $this->seam->request( "POST", "/noise_sensors/list", - json: (object) $request_payload, - inner_object: "devices" + json: (object) $request_payload ); - return array_map(fn($r) => Device::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map(fn($r) => Device::from_json($r), $res->devices); } } @@ -3400,10 +3195,10 @@ 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 + ?string $name = null, + ?float $noise_threshold_decibels = null, + ?float $noise_threshold_nrs = null, + ?bool $sync = null ): NoiseThreshold { $request_payload = []; @@ -3434,17 +3229,16 @@ public function create( $res = $this->seam->request( "POST", "/noise_sensors/noise_thresholds/create", - json: (object) $request_payload, - inner_object: "noise_threshold" + json: (object) $request_payload ); - return NoiseThreshold::from_json($res); + return NoiseThreshold::from_json($res->noise_threshold); } public function delete( string $device_id, string $noise_threshold_id, - bool $sync = null + ?bool $sync = null ): void { $request_payload = []; @@ -3476,15 +3270,17 @@ public function get(string $noise_threshold_id): NoiseThreshold $res = $this->seam->request( "POST", "/noise_sensors/noise_thresholds/get", - json: (object) $request_payload, - inner_object: "noise_threshold" + json: (object) $request_payload ); - return NoiseThreshold::from_json($res); + return NoiseThreshold::from_json($res->noise_threshold); } - public function list(string $device_id, bool $is_programmed = null): array - { + public function list( + string $device_id, + ?bool $is_programmed = null, + ?callable $on_response = null + ): array { $request_payload = []; if ($device_id !== null) { @@ -3497,22 +3293,28 @@ public function list(string $device_id, bool $is_programmed = null): array $res = $this->seam->request( "POST", "/noise_sensors/noise_thresholds/list", - json: (object) $request_payload, - inner_object: "noise_thresholds" + json: (object) $request_payload ); - return array_map(fn($r) => NoiseThreshold::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map( + fn($r) => NoiseThreshold::from_json($r), + $res->noise_thresholds + ); } 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 + ?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 = []; @@ -3612,16 +3414,16 @@ public function get(string $device_id): Phone $res = $this->seam->request( "POST", "/phones/get", - json: (object) $request_payload, - inner_object: "phone" + json: (object) $request_payload ); - return Phone::from_json($res); + return Phone::from_json($res->phone); } public function list( - string $acs_credential_id = null, - string $owner_user_identity_id = null + ?string $acs_credential_id = null, + ?string $owner_user_identity_id = null, + ?callable $on_response = null ): array { $request_payload = []; @@ -3637,11 +3439,14 @@ public function list( $res = $this->seam->request( "POST", "/phones/list", - json: (object) $request_payload, - inner_object: "phones" + json: (object) $request_payload ); - return array_map(fn($r) => Phone::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map(fn($r) => Phone::from_json($r), $res->phones); } } @@ -3657,7 +3462,7 @@ public function __construct(SeamClient $seam) public function create_sandbox_phone( string $user_identity_id, mixed $assa_abloy_metadata = null, - string $custom_sdk_installation_id = null, + ?string $custom_sdk_installation_id = null, mixed $phone_metadata = null ): Phone { $request_payload = []; @@ -3680,11 +3485,10 @@ public function create_sandbox_phone( $res = $this->seam->request( "POST", "/phones/simulate/create_sandbox_phone", - json: (object) $request_payload, - inner_object: "phone" + json: (object) $request_payload ); - return Phone::from_json($res); + return Phone::from_json($res->phone); } } @@ -3717,16 +3521,15 @@ public function activate_climate_preset( $res = $this->seam->request( "POST", "/thermostats/activate_climate_preset", - json: (object) $request_payload, - inner_object: "action_attempt" + json: (object) $request_payload ); if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); + return ActionAttempt::from_json($res->action_attempt); } $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id + $res->action_attempt->action_attempt_id ); return $action_attempt; @@ -3734,9 +3537,9 @@ public function activate_climate_preset( public function cool( string $device_id, - float $cooling_set_point_celsius = null, - float $cooling_set_point_fahrenheit = null, - bool $sync = 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 = []; @@ -3761,16 +3564,15 @@ public function cool( $res = $this->seam->request( "POST", "/thermostats/cool", - json: (object) $request_payload, - inner_object: "action_attempt" + json: (object) $request_payload ); if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); + return ActionAttempt::from_json($res->action_attempt); } $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id + $res->action_attempt->action_attempt_id ); return $action_attempt; @@ -3779,14 +3581,14 @@ public function cool( 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 + ?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 = []; @@ -3858,32 +3660,11 @@ public function delete_climate_preset( ); } - 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, + ?float $heating_set_point_celsius = null, + ?float $heating_set_point_fahrenheit = null, + ?bool $sync = null, bool $wait_for_action_attempt = true ): ActionAttempt { $request_payload = []; @@ -3908,16 +3689,15 @@ public function heat( $res = $this->seam->request( "POST", "/thermostats/heat", - json: (object) $request_payload, - inner_object: "action_attempt" + json: (object) $request_payload ); if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); + return ActionAttempt::from_json($res->action_attempt); } $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id + $res->action_attempt->action_attempt_id ); return $action_attempt; @@ -3925,11 +3705,11 @@ public function heat( 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, + ?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 = []; @@ -3964,35 +3744,36 @@ public function heat_cool( $res = $this->seam->request( "POST", "/thermostats/heat_cool", - json: (object) $request_payload, - inner_object: "action_attempt" + json: (object) $request_payload ); if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); + return ActionAttempt::from_json($res->action_attempt); } $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id + $res->action_attempt->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, + ?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 $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 $unstable_location_id = null, + ?string $user_identifier_key = null, + ?callable $on_response = null ): array { $request_payload = []; @@ -4032,6 +3813,9 @@ public function list( if ($manufacturer !== null) { $request_payload["manufacturer"] = $manufacturer; } + if ($unstable_location_id !== null) { + $request_payload["unstable_location_id"] = $unstable_location_id; + } if ($user_identifier_key !== null) { $request_payload["user_identifier_key"] = $user_identifier_key; } @@ -4039,16 +3823,19 @@ public function list( $res = $this->seam->request( "POST", "/thermostats/list", - json: (object) $request_payload, - inner_object: "devices" + json: (object) $request_payload ); - return array_map(fn($r) => Device::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map(fn($r) => Device::from_json($r), $res->devices); } public function off( string $device_id, - bool $sync = null, + ?bool $sync = null, bool $wait_for_action_attempt = true ): ActionAttempt { $request_payload = []; @@ -4063,16 +3850,15 @@ public function off( $res = $this->seam->request( "POST", "/thermostats/off", - json: (object) $request_payload, - inner_object: "action_attempt" + json: (object) $request_payload ); if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); + return ActionAttempt::from_json($res->action_attempt); } $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id + $res->action_attempt->action_attempt_id ); return $action_attempt; @@ -4100,9 +3886,9 @@ public function set_fallback_climate_preset( public function set_fan_mode( string $device_id, - string $fan_mode = null, - string $fan_mode_setting = null, - bool $sync = null, + ?string $fan_mode = null, + ?string $fan_mode_setting = null, + ?bool $sync = null, bool $wait_for_action_attempt = true ): ActionAttempt { $request_payload = []; @@ -4123,16 +3909,15 @@ public function set_fan_mode( $res = $this->seam->request( "POST", "/thermostats/set_fan_mode", - json: (object) $request_payload, - inner_object: "action_attempt" + json: (object) $request_payload ); if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); + return ActionAttempt::from_json($res->action_attempt); } $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id + $res->action_attempt->action_attempt_id ); return $action_attempt; @@ -4141,10 +3926,10 @@ public function set_fan_mode( 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, + ?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 = []; @@ -4179,16 +3964,15 @@ public function set_hvac_mode( $res = $this->seam->request( "POST", "/thermostats/set_hvac_mode", - json: (object) $request_payload, - inner_object: "action_attempt" + json: (object) $request_payload ); if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); + return ActionAttempt::from_json($res->action_attempt); } $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id + $res->action_attempt->action_attempt_id ); return $action_attempt; @@ -4196,10 +3980,10 @@ public function set_hvac_mode( 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 + ?float $lower_limit_celsius = null, + ?float $lower_limit_fahrenheit = null, + ?float $upper_limit_celsius = null, + ?float $upper_limit_fahrenheit = null ): void { $request_payload = []; @@ -4234,13 +4018,13 @@ 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 + ?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 = []; @@ -4307,9 +4091,9 @@ public function create( string $device_id, string $ends_at, string $starts_at, - bool $is_override_allowed = null, + ?bool $is_override_allowed = null, mixed $max_override_period_minutes = null, - string $name = null + ?string $name = null ): ThermostatSchedule { $request_payload = []; @@ -4340,11 +4124,10 @@ public function create( $res = $this->seam->request( "POST", "/thermostats/schedules/create", - json: (object) $request_payload, - inner_object: "thermostat_schedule" + json: (object) $request_payload ); - return ThermostatSchedule::from_json($res); + return ThermostatSchedule::from_json($res->thermostat_schedule); } public function delete(string $thermostat_schedule_id): void @@ -4377,16 +4160,16 @@ public function get(string $thermostat_schedule_id): ThermostatSchedule $res = $this->seam->request( "POST", "/thermostats/schedules/get", - json: (object) $request_payload, - inner_object: "thermostat_schedule" + json: (object) $request_payload ); - return ThermostatSchedule::from_json($res); + return ThermostatSchedule::from_json($res->thermostat_schedule); } public function list( string $device_id, - string $user_identifier_key = null + ?string $user_identifier_key = null, + ?callable $on_response = null ): array { $request_payload = []; @@ -4400,21 +4183,27 @@ public function list( $res = $this->seam->request( "POST", "/thermostats/schedules/list", - json: (object) $request_payload, - inner_object: "thermostat_schedules" + json: (object) $request_payload ); - return array_map(fn($r) => ThermostatSchedule::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map( + fn($r) => ThermostatSchedule::from_json($r), + $res->thermostat_schedules + ); } public function update( string $thermostat_schedule_id, - string $climate_preset_key = null, - string $ends_at = null, - bool $is_override_allowed = null, + ?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 + ?string $name = null, + ?string $starts_at = null ): void { $request_payload = []; @@ -4464,10 +4253,10 @@ public function __construct(SeamClient $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 + ?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 = []; @@ -4507,8 +4296,8 @@ public function hvac_mode_adjusted( public function temperature_reached( string $device_id, - float $temperature_celsius = null, - float $temperature_fahrenheit = null + ?float $temperature_celsius = null, + ?float $temperature_fahrenheit = null ): void { $request_payload = []; @@ -4565,10 +4354,10 @@ public function add_acs_user( } public function create( - string $email_address = null, - string $full_name = null, - string $phone_number = null, - string $user_identity_key = null + ?string $email_address = null, + ?string $full_name = null, + ?string $phone_number = null, + ?string $user_identity_key = null ): UserIdentity { $request_payload = []; @@ -4588,11 +4377,10 @@ public function create( $res = $this->seam->request( "POST", "/user_identities/create", - json: (object) $request_payload, - inner_object: "user_identity" + json: (object) $request_payload ); - return UserIdentity::from_json($res); + return UserIdentity::from_json($res->user_identity); } public function delete(string $user_identity_id): void @@ -4611,8 +4399,8 @@ public function delete(string $user_identity_id): void } public function get( - string $user_identity_id = null, - string $user_identity_key = null + ?string $user_identity_id = null, + ?string $user_identity_key = null ): UserIdentity { $request_payload = []; @@ -4626,11 +4414,10 @@ public function get( $res = $this->seam->request( "POST", "/user_identities/get", - json: (object) $request_payload, - inner_object: "user_identity" + json: (object) $request_payload ); - return UserIdentity::from_json($res); + return UserIdentity::from_json($res->user_identity); } public function grant_access_to_device( @@ -4653,8 +4440,10 @@ public function grant_access_to_device( ); } - public function list(string $credential_manager_acs_system_id = null): array - { + public function list( + ?string $credential_manager_acs_system_id = null, + ?callable $on_response = null + ): array { $request_payload = []; if ($credential_manager_acs_system_id !== null) { @@ -4666,11 +4455,17 @@ public function list(string $credential_manager_acs_system_id = null): array $res = $this->seam->request( "POST", "/user_identities/list", - json: (object) $request_payload, - inner_object: "user_identities" + json: (object) $request_payload ); - return array_map(fn($r) => UserIdentity::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map( + fn($r) => UserIdentity::from_json($r), + $res->user_identities + ); } public function list_accessible_devices(string $user_identity_id): array @@ -4684,11 +4479,10 @@ public function list_accessible_devices(string $user_identity_id): array $res = $this->seam->request( "POST", "/user_identities/list_accessible_devices", - json: (object) $request_payload, - inner_object: "devices" + json: (object) $request_payload ); - return array_map(fn($r) => Device::from_json($r), $res); + return array_map(fn($r) => Device::from_json($r), $res->devices); } public function list_acs_systems(string $user_identity_id): array @@ -4702,11 +4496,10 @@ public function list_acs_systems(string $user_identity_id): array $res = $this->seam->request( "POST", "/user_identities/list_acs_systems", - json: (object) $request_payload, - inner_object: "acs_systems" + json: (object) $request_payload ); - return array_map(fn($r) => AcsSystem::from_json($r), $res); + return array_map(fn($r) => AcsSystem::from_json($r), $res->acs_systems); } public function list_acs_users(string $user_identity_id): array @@ -4720,11 +4513,10 @@ public function list_acs_users(string $user_identity_id): array $res = $this->seam->request( "POST", "/user_identities/list_acs_users", - json: (object) $request_payload, - inner_object: "acs_users" + json: (object) $request_payload ); - return array_map(fn($r) => AcsUser::from_json($r), $res); + return array_map(fn($r) => AcsUser::from_json($r), $res->acs_users); } public function remove_acs_user( @@ -4769,10 +4561,10 @@ public function revoke_access_to_device( public function update( string $user_identity_id, - string $email_address = null, - string $full_name = null, - string $phone_number = null, - string $user_identity_key = null + ?string $email_address = null, + ?string $full_name = null, + ?string $phone_number = null, + ?string $user_identity_key = null ): void { $request_payload = []; @@ -4839,19 +4631,18 @@ public function get(string $enrollment_automation_id): EnrollmentAutomation $res = $this->seam->request( "POST", "/user_identities/enrollment_automations/get", - json: (object) $request_payload, - inner_object: "enrollment_automation" + json: (object) $request_payload ); - return EnrollmentAutomation::from_json($res); + return EnrollmentAutomation::from_json($res->enrollment_automation); } 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 + ?string $acs_credential_pool_id = null, + ?bool $create_credential_manager_user = null, + ?string $credential_manager_acs_user_id = null ): void { $request_payload = []; @@ -4882,13 +4673,14 @@ public function launch( $this->seam->request( "POST", "/user_identities/enrollment_automations/launch", - json: (object) $request_payload, - inner_object: "enrollment_automation" + json: (object) $request_payload ); } - public function list(string $user_identity_id): array - { + public function list( + string $user_identity_id, + ?callable $on_response = null + ): array { $request_payload = []; if ($user_identity_id !== null) { @@ -4898,11 +4690,17 @@ public function list(string $user_identity_id): array $res = $this->seam->request( "POST", "/user_identities/enrollment_automations/list", - json: (object) $request_payload, - inner_object: "enrollment_automations" + json: (object) $request_payload ); - return array_map(fn($r) => EnrollmentAutomation::from_json($r), $res); + if ($on_response !== null) { + $on_response($res); + } + + return array_map( + fn($r) => EnrollmentAutomation::from_json($r), + $res->enrollment_automations + ); } } @@ -4915,7 +4713,7 @@ public function __construct(SeamClient $seam) $this->seam = $seam; } - public function create(string $url, array $event_types = null): Webhook + public function create(string $url, ?array $event_types = null): Webhook { $request_payload = []; @@ -4929,11 +4727,10 @@ public function create(string $url, array $event_types = null): Webhook $res = $this->seam->request( "POST", "/webhooks/create", - json: (object) $request_payload, - inner_object: "webhook" + json: (object) $request_payload ); - return Webhook::from_json($res); + return Webhook::from_json($res->webhook); } public function delete(string $webhook_id): void @@ -4962,25 +4759,21 @@ public function get(string $webhook_id): Webhook $res = $this->seam->request( "POST", "/webhooks/get", - json: (object) $request_payload, - inner_object: "webhook" + json: (object) $request_payload ); - return Webhook::from_json($res); + return Webhook::from_json($res->webhook); } - public function list(): array + public function list(?callable $on_response = null): array { - $request_payload = []; + $res = $this->seam->request("POST", "/webhooks/list"); - $res = $this->seam->request( - "POST", - "/webhooks/list", - json: (object) $request_payload, - inner_object: "webhooks" - ); + if ($on_response !== null) { + $on_response($res); + } - return array_map(fn($r) => Webhook::from_json($r), $res); + return array_map(fn($r) => Webhook::from_json($r), $res->webhooks); } public function update(array $event_types, string $webhook_id): void @@ -5013,12 +4806,13 @@ public function __construct(SeamClient $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 + ?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, + ?string $webview_success_message = null ): Workspace { $request_payload = []; @@ -5047,63 +4841,50 @@ public function create( "webview_primary_button_text_color" ] = $webview_primary_button_text_color; } + if ($webview_success_message !== null) { + $request_payload[ + "webview_success_message" + ] = $webview_success_message; + } $res = $this->seam->request( "POST", "/workspaces/create", - json: (object) $request_payload, - inner_object: "workspace" + json: (object) $request_payload ); - return Workspace::from_json($res); + return Workspace::from_json($res->workspace); } public function get(): Workspace { - $request_payload = []; - - $res = $this->seam->request( - "POST", - "/workspaces/get", - json: (object) $request_payload, - inner_object: "workspace" - ); + $res = $this->seam->request("POST", "/workspaces/get"); - return Workspace::from_json($res); + return Workspace::from_json($res->workspace); } - public function list(): array + public function list(?callable $on_response = null): array { - $request_payload = []; + $res = $this->seam->request("POST", "/workspaces/list"); - $res = $this->seam->request( - "POST", - "/workspaces/list", - json: (object) $request_payload, - inner_object: "workspaces" - ); + if ($on_response !== null) { + $on_response($res); + } - return array_map(fn($r) => Workspace::from_json($r), $res); + return array_map(fn($r) => Workspace::from_json($r), $res->workspaces); } 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" - ); + $res = $this->seam->request("POST", "/workspaces/reset_sandbox"); if (!$wait_for_action_attempt) { - return ActionAttempt::from_json($res); + return ActionAttempt::from_json($res->action_attempt); } $action_attempt = $this->seam->action_attempts->poll_until_ready( - $res->action_attempt_id + $res->action_attempt->action_attempt_id ); return $action_attempt; 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/PaginatorTest.php b/tests/PaginatorTest.php new file mode 100644 index 00000000..7866deba --- /dev/null +++ b/tests/PaginatorTest.php @@ -0,0 +1,82 @@ +createPaginator( + fn($params) => $seam->connected_accounts->list(...$params), + ["limit" => 2] + ); + [$connectedAccounts, $pagination] = $pages->firstPage(); + + $this->assertTrue(count($connectedAccounts) == 2); + $this->assertTrue($pagination->has_next_page); + $this->assertTrue($pagination->next_page_cursor !== null); + $this->assertTrue($pagination->next_page_url !== null); + } + + public function testPaginatorNextPage(): void + { + $seam = Fixture::getTestServer(); + + $pages = $seam->createPaginator( + fn($params) => $seam->connected_accounts->list(...$params), + ["limit" => 2] + ); + [$connectedAccounts, $pagination] = $pages->firstPage(); + + $this->assertTrue(count($connectedAccounts) == 2); + $this->assertTrue($pagination->has_next_page); + + [$moreConnectedAccounts] = $pages->nextPage( + $pagination->next_page_cursor + ); + + $this->assertTrue(count($moreConnectedAccounts) == 1); + } + + public function testPaginatorFlattenToArray(): void + { + $seam = Fixture::getTestServer(); + + $allConnectedAccounts = $seam->connected_accounts->list(); + + $pages = $seam->createPaginator( + fn($params) => $seam->connected_accounts->list(...$params), + ["limit" => 1] + ); + $devices = $pages->flattenToArray(); + + $this->assertTrue(count($devices) > 1); + $this->assertTrue(count($devices) == count($allConnectedAccounts)); + } + + public function testPaginatorFlatten(): void + { + $seam = Fixture::getTestServer(); + + $allConnectedAccounts = $seam->connected_accounts->list(); + $pages = $seam->createPaginator( + fn($params) => $seam->connected_accounts->list(...$params), + ["limit" => 1] + ); + + $connectedAccounts = []; + foreach ($pages->flatten() as $connectedAccount) { + $connectedAccounts[] = $connectedAccount; + } + $this->assertTrue(count($connectedAccounts) > 1); + $this->assertTrue( + count($connectedAccounts) == count($allConnectedAccounts) + ); + } +}