@@ -11,32 +11,32 @@ $seam = new Seam\SeamClient("YOUR_API_KEY");
1111
1212# Create a Connect Webview to login to a provider
1313$connect_webview = $seam->connect_webviews->create(
14- accepted_providers: ["august"]
14+ accepted_providers: ["august"]
1515);
1616
1717print "Please Login at this url: " . $connect_webview->url;
1818
1919# Poll until connect webview is completed
2020while (true) {
21- $connect_webview = $seam->connect_webviews->get(
22- $connect_webview->connect_webview_id
23- );
24- if ($connect_webview->status == "authorized") {
25- break;
26- } else {
27- sleep(1);
28- }
21+ $connect_webview = $seam->connect_webviews->get(
22+ $connect_webview->connect_webview_id
23+ );
24+ if ($connect_webview->status == "authorized") {
25+ break;
26+ } else {
27+ sleep(1);
28+ }
2929}
3030
3131$connected_account = $seam->connected_accounts->get(
32- $connect_webview->connected_account_id
32+ $connect_webview->connected_account_id
3333);
3434
3535print "Looks like you connected with " .
36- json_encode($connected_account->user_identifier);
36+ json_encode($connected_account->user_identifier);
3737
3838$devices = $seam->devices->list(
39- connected_account_id: $connected_account->connected_account_id
39+ connected_account_id: $connected_account->connected_account_id
4040);
4141
4242print "You have " . count($devices) . " devices";
@@ -55,9 +55,9 @@ $updated_device->properties->locked; // false
5555
5656# Create an access code on a device
5757$access_code = $seam->access_codes->create(
58- device_id: $device_id,
59- code: "1234",
60- name: "Test Code"
58+ device_id: $device_id,
59+ code: "1234",
60+ name: "Test Code"
6161);
6262
6363# 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
6666$seam->access_codes->delete($access_code->access_code_id);
6767```
6868
69+ ### Pagination
70+
71+ Some Seam API endpoints that return lists of resources support pagination.
72+ Use the ` Paginator ` class to fetch and process resources across multiple pages.
73+
74+ #### Manually fetch pages with the next_page_cursor
75+
76+ ``` php
77+ $pages = $seam->createPaginator(
78+ fn($params) => $seam->connected_accounts->list(...$params),
79+ ["limit" => 2]
80+ );
81+
82+ [$connectedAccounts, $pagination] = $pages->firstPage();
83+
84+ if ($pagination->has_next_page) {
85+ [$moreConnectedAccounts] = $pages->nextPage($pagination->next_page_cursor);
86+ }
87+ ```
88+
89+ #### Resume pagination
90+
91+ Get the first page on initial load:
92+
93+ ``` php
94+ $params = ["limit" => 20];
95+
96+ $pages = $seam->createPaginator(
97+ fn($p) => $seam->connected_accounts->list(...$p),
98+ $params
99+ );
100+
101+ [$connectedAccounts, $pagination] = $pages->firstPage();
102+
103+ // Store pagination state for later use
104+ file_put_contents(
105+ "/tmp/seam_connected_accounts_list.json",
106+ json_encode([$params, $pagination])
107+ );
108+ ```
109+
110+ Get the next page at a later time:
111+
112+ ``` php
113+ $stored_data = json_decode(
114+ file_get_contents("/tmp/seam_connected_accounts_list.json") ?: "[]",
115+ false
116+ );
117+
118+ $params = $stored_data[0] ?? [];
119+ $pagination =
120+ $stored_data[1] ??
121+ (object) ["has_next_page" => false, "next_page_cursor" => null];
122+
123+ if ($pagination->has_next_page) {
124+ $pages = $seam->createPaginator(
125+ fn($p) => $seam->connected_accounts->list(...$p),
126+ $params
127+ );
128+ [$moreConnectedAccounts] = $pages->nextPage($pagination->next_page_cursor);
129+ }
130+ ```
131+
132+ #### Iterate over all resources
133+
134+ ``` php
135+ $pages = $seam->createPaginator(
136+ fn($p) => $seam->connected_accounts->list(...$p),
137+ ["limit" => 20]
138+ );
139+
140+ foreach ($pages->flatten() as $connectedAccount) {
141+ print $connectedAccount->account_type_display_name . "\n";
142+ }
143+ ```
144+
145+ #### Return all resources across all pages as an array
146+
147+ ``` php
148+ $pages = $seam->createPaginator(
149+ fn($p) => $seam->connected_accounts->list(...$p),
150+ ["limit" => 20]
151+ );
152+
153+ $connectedAccounts = $pages->flattenToArray();
154+ ```
155+
69156## Installation
70157
71158To install the latest version of the automatically generated SDK, run:
@@ -87,4 +174,4 @@ If you want to install our previous handwritten version, run:
87174
88175### Running Tests
89176
90- You'll need to export ` SEAM_API_KEY ` to a sandbox workspace API key.
177+ You'll need to export ` SEAM_API_KEY ` to a sandbox workspace API key.
0 commit comments