msgraph_rs/
pagination.rs

1use serde_json::Value;
2use std::error::Error;
3
4pub fn fetch_all_pages(
5    client: &crate::client::GraphClient,
6    initial_response: Value,
7) -> Result<Value, Box<dyn Error>> {
8    let mut items = Vec::new();
9    let mut response = initial_response;
10
11    loop {
12        if let Some(value) = response.get("value") {
13            if let Some(array) = value.as_array() {
14                items.extend(array.clone());
15            }
16        }
17
18        if let Some(next_link) = response.get("@odata.nextLink") {
19            if let Some(next_url) = next_link.as_str() {
20                response = client
21                    .get_http_client() // Use getter for the HTTP client
22                    .get(next_url)
23                    .bearer_auth(client.get_access_token()) // Use getter for the access token
24                    .send()?
25                    .json()?;
26            } else {
27                break;
28            }
29        } else {
30            break;
31        }
32    }
33
34    Ok(serde_json::json!({ "value": items }))
35}