diff --git a/package-lock.json b/package-lock.json index 74399e7..2cd13f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MIT", "devDependencies": { "@prettier/plugin-php": "^0.22.1", - "@seamapi/nextlove-sdk-generator": "1.18.0", + "@seamapi/nextlove-sdk-generator": "1.18.1", "@seamapi/types": "1.384.0", "del": "^7.1.0", "prettier": "^3.0.0" @@ -434,10 +434,11 @@ } }, "node_modules/@seamapi/nextlove-sdk-generator": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/@seamapi/nextlove-sdk-generator/-/nextlove-sdk-generator-1.18.0.tgz", - "integrity": "sha512-lINrwlr3pJUWawFvEXezY89VxS4mafgkqeBGTiLRZSXTDLzqEl8QD6UKN0CHKirwHCjPFj8MUsGDyz7pCzbCmQ==", + "version": "1.18.1", + "resolved": "https://registry.npmjs.org/@seamapi/nextlove-sdk-generator/-/nextlove-sdk-generator-1.18.1.tgz", + "integrity": "sha512-TsK2AY2B/44JNEbWf30/UWfP7Y0T1bxZ3X6AH/buhUKHAzNfiipw133iAN2p6e2fu6sa9zbrjM1cmvwU+lDhiw==", "dev": true, + "license": "MIT", "dependencies": { "@nodelib/fs.walk": "^2.0.0", "axios": "^1.5.0", diff --git a/package.json b/package.json index 10d09e9..05d44e1 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ }, "devDependencies": { "@prettier/plugin-php": "^0.22.1", - "@seamapi/nextlove-sdk-generator": "1.18.0", + "@seamapi/nextlove-sdk-generator": "1.18.1", "@seamapi/types": "1.384.0", "del": "^7.1.0", "prettier": "^3.0.0" diff --git a/src/Paginator.php b/src/Paginator.php index 4252665..d28e834 100644 --- a/src/Paginator.php +++ b/src/Paginator.php @@ -4,20 +4,20 @@ class Paginator { - private $callable; + private $request; private $params; private $pagination_cache = []; private const FIRST_PAGE = "FIRST_PAGE"; - public function __construct(callable $callable, array $params = []) + public function __construct(callable $request, array $params = []) { - $this->callable = $callable; + $this->request = $request; $this->params = $params; } public function firstPage(): array { - $callable = $this->callable; + $request = $this->request; $params = $this->params; $params["on_response"] = fn($response) => $this->cachePagination( @@ -25,14 +25,20 @@ public function firstPage(): array self::FIRST_PAGE ); - $data = $callable($params); + $data = $request($params); return [$data, $this->pagination_cache[self::FIRST_PAGE]]; } public function nextPage(string $next_page_cursor): array { - $callable = $this->callable; + if ($next_page_cursor === null) { + throw new \InvalidArgumentException( + "Cannot get the next page with a null next_page_cursor" + ); + } + + $request = $this->request; $params = $this->params; $params["page_cursor"] = $next_page_cursor; @@ -41,7 +47,7 @@ public function nextPage(string $next_page_cursor): array $next_page_cursor ); - $data = $callable($params); + $data = $request($params); return [$data, $this->pagination_cache[$next_page_cursor]]; } diff --git a/src/SeamClient.php b/src/SeamClient.php index de8a7e4..9847684 100644 --- a/src/SeamClient.php +++ b/src/SeamClient.php @@ -437,8 +437,7 @@ public function get( public function list( ?array $access_code_ids = null, ?string $device_id = null, - ?string $user_identifier_key = null, - ?callable $on_response = null + ?string $user_identifier_key = null ): array { $request_payload = []; @@ -458,10 +457,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map( fn($r) => AccessCode::from_json($r), $res->access_codes @@ -743,8 +738,7 @@ public function get( public function list( string $device_id, - ?string $user_identifier_key = null, - ?callable $on_response = null + ?string $user_identifier_key = null ): array { $request_payload = []; @@ -761,10 +755,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map( fn($r) => UnmanagedAccessCode::from_json($r), $res->access_codes @@ -856,8 +846,7 @@ public function get(string $acs_access_group_id): AcsAccessGroup public function list( ?string $acs_system_id = null, - ?string $acs_user_id = null, - ?callable $on_response = null + ?string $acs_user_id = null ): array { $request_payload = []; @@ -874,10 +863,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map( fn($r) => AcsAccessGroup::from_json($r), $res->acs_access_groups @@ -1095,8 +1080,7 @@ public function list( ?string $user_identity_id = null, ?string $created_before = null, ?bool $is_multi_phone_sync_credential = null, - ?float $limit = null, - ?callable $on_response = null + ?float $limit = null ): array { $request_payload = []; @@ -1127,10 +1111,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map( fn($r) => AcsCredential::from_json($r), $res->acs_credentials @@ -1263,8 +1243,7 @@ public function list( ?string $acs_system_id = null, ?float $limit = null, ?array $acs_system_ids = null, - ?array $acs_encoder_ids = null, - ?callable $on_response = null + ?array $acs_encoder_ids = null ): array { $request_payload = []; @@ -1287,10 +1266,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map( fn($r) => AcsEncoder::from_json($r), $res->acs_encoders @@ -1479,8 +1454,7 @@ public function grant_access( public function list( ?string $acs_credential_id = null, - ?string $acs_system_id = null, - ?callable $on_response = null + ?string $acs_system_id = null ): array { $request_payload = []; @@ -1497,10 +1471,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map( fn($r) => AcsEntrance::from_json($r), $res->acs_entrances @@ -1559,10 +1529,8 @@ public function get(string $acs_system_id): AcsSystem return AcsSystem::from_json($res->acs_system); } - public function list( - ?string $connected_account_id = null, - ?callable $on_response = null - ): array { + public function list(?string $connected_account_id = null): array + { $request_payload = []; if ($connected_account_id !== null) { @@ -1575,10 +1543,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map(fn($r) => AcsSystem::from_json($r), $res->acs_systems); } @@ -1915,10 +1879,8 @@ public function get(string $action_attempt_id): ActionAttempt return ActionAttempt::from_json($res->action_attempt); } - public function list( - array $action_attempt_ids, - ?callable $on_response = null - ): array { + public function list(array $action_attempt_ids): array + { $request_payload = []; if ($action_attempt_ids !== null) { @@ -1931,10 +1893,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map( fn($r) => ActionAttempt::from_json($r), $res->action_attempts @@ -2149,8 +2107,7 @@ public function list( ?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 + ?bool $without_user_identifier_key = null ): array { $request_payload = []; @@ -2178,10 +2135,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map( fn($r) => ClientSession::from_json($r), $res->client_sessions @@ -2300,8 +2253,7 @@ public function get(string $connect_webview_id): ConnectWebview public function list( mixed $custom_metadata_has = null, ?float $limit = null, - ?string $user_identifier_key = null, - ?callable $on_response = null + ?string $user_identifier_key = null ): array { $request_payload = []; @@ -2321,10 +2273,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map( fn($r) => ConnectWebview::from_json($r), $res->connect_webviews @@ -2494,8 +2442,7 @@ public function list( ?float $limit = null, ?string $manufacturer = null, ?string $unstable_location_id = null, - ?string $user_identifier_key = null, - ?callable $on_response = null + ?string $user_identifier_key = null ): array { $request_payload = []; @@ -2548,10 +2495,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map(fn($r) => Device::from_json($r), $res->devices); } @@ -2709,8 +2652,7 @@ public function list( ?float $limit = null, ?string $manufacturer = null, ?string $unstable_location_id = null, - ?string $user_identifier_key = null, - ?callable $on_response = null + ?string $user_identifier_key = null ): array { $request_payload = []; @@ -2763,10 +2705,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map( fn($r) => UnmanagedDevice::from_json($r), $res->devices @@ -2842,8 +2780,7 @@ public function list( ?array $event_types = null, ?float $limit = null, ?string $since = null, - ?float $unstable_offset = null, - ?callable $on_response = null + ?float $unstable_offset = null ): array { $request_payload = []; @@ -2899,10 +2836,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map(fn($r) => Event::from_json($r), $res->events); } } @@ -2950,8 +2883,7 @@ public function list( ?float $limit = null, ?string $manufacturer = null, ?string $unstable_location_id = null, - ?string $user_identifier_key = null, - ?callable $on_response = null + ?string $user_identifier_key = null ): array { $request_payload = []; @@ -3004,10 +2936,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map(fn($r) => Device::from_json($r), $res->devices); } @@ -3100,14 +3028,10 @@ public function get(string $network_id): Network return Network::from_json($res->network); } - public function list(?callable $on_response = null): array + public function list(): array { $res = $this->seam->request("POST", "/networks/list"); - if ($on_response !== null) { - $on_response($res); - } - return array_map(fn($r) => Network::from_json($r), $res->networks); } } @@ -3138,8 +3062,7 @@ public function list( ?float $limit = null, ?string $manufacturer = null, ?string $unstable_location_id = null, - ?string $user_identifier_key = null, - ?callable $on_response = null + ?string $user_identifier_key = null ): array { $request_payload = []; @@ -3192,10 +3115,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map(fn($r) => Device::from_json($r), $res->devices); } } @@ -3294,11 +3213,8 @@ public function get(string $noise_threshold_id): NoiseThreshold return NoiseThreshold::from_json($res->noise_threshold); } - public function list( - string $device_id, - ?bool $is_programmed = null, - ?callable $on_response = null - ): array { + public function list(string $device_id, ?bool $is_programmed = null): array + { $request_payload = []; if ($device_id !== null) { @@ -3314,10 +3230,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map( fn($r) => NoiseThreshold::from_json($r), $res->noise_thresholds @@ -3440,8 +3352,7 @@ public function get(string $device_id): Phone public function list( ?string $acs_credential_id = null, - ?string $owner_user_identity_id = null, - ?callable $on_response = null + ?string $owner_user_identity_id = null ): array { $request_payload = []; @@ -3460,10 +3371,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map(fn($r) => Phone::from_json($r), $res->phones); } } @@ -3790,8 +3697,7 @@ public function list( ?float $limit = null, ?string $manufacturer = null, ?string $unstable_location_id = null, - ?string $user_identifier_key = null, - ?callable $on_response = null + ?string $user_identifier_key = null ): array { $request_payload = []; @@ -3844,10 +3750,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map(fn($r) => Device::from_json($r), $res->devices); } @@ -4186,8 +4088,7 @@ public function get(string $thermostat_schedule_id): ThermostatSchedule public function list( string $device_id, - ?string $user_identifier_key = null, - ?callable $on_response = null + ?string $user_identifier_key = null ): array { $request_payload = []; @@ -4204,10 +4105,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map( fn($r) => ThermostatSchedule::from_json($r), $res->thermostat_schedules @@ -4476,8 +4373,7 @@ public function grant_access_to_device( } public function list( - ?string $credential_manager_acs_system_id = null, - ?callable $on_response = null + ?string $credential_manager_acs_system_id = null ): array { $request_payload = []; @@ -4493,10 +4389,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map( fn($r) => UserIdentity::from_json($r), $res->user_identities @@ -4712,10 +4604,8 @@ public function launch( ); } - public function list( - string $user_identity_id, - ?callable $on_response = null - ): array { + public function list(string $user_identity_id): array + { $request_payload = []; if ($user_identity_id !== null) { @@ -4728,10 +4618,6 @@ public function list( json: (object) $request_payload ); - if ($on_response !== null) { - $on_response($res); - } - return array_map( fn($r) => EnrollmentAutomation::from_json($r), $res->enrollment_automations @@ -4800,14 +4686,10 @@ public function get(string $webhook_id): Webhook return Webhook::from_json($res->webhook); } - public function list(?callable $on_response = null): array + public function list(): array { $res = $this->seam->request("POST", "/webhooks/list"); - if ($on_response !== null) { - $on_response($res); - } - return array_map(fn($r) => Webhook::from_json($r), $res->webhooks); } @@ -4898,14 +4780,10 @@ public function get(): Workspace return Workspace::from_json($res->workspace); } - public function list(?callable $on_response = null): array + public function list(): array { $res = $this->seam->request("POST", "/workspaces/list"); - if ($on_response !== null) { - $on_response($res); - } - return array_map(fn($r) => Workspace::from_json($r), $res->workspaces); }