Skip to main content

onspring/endpoints/
apps.rs

1use reqwest::Method;
2
3use crate::client::OnspringClient;
4use crate::error::Result;
5use crate::models::{App, CollectionResponse, PagedResponse, PagingRequest};
6
7impl OnspringClient {
8  /// Gets all apps for the current client, with optional pagination.
9  pub async fn list_apps(&self, paging: Option<PagingRequest>) -> Result<PagedResponse<App>> {
10    let mut query = Vec::new();
11    if let Some(p) = paging {
12      query.push(("PageNumber", p.page_number.to_string()));
13      query.push(("PageSize", p.page_size.to_string()));
14    }
15    let query_refs: Vec<(&str, String)> = query.iter().map(|(k, v)| (*k, v.clone())).collect();
16    self
17      .request(Method::GET, "/Apps", &query_refs, Option::<&()>::None)
18      .await
19  }
20
21  /// Gets an app by its identifier.
22  pub async fn get_app(&self, app_id: i32) -> Result<App> {
23    let path = format!("/Apps/id/{}", app_id);
24    self
25      .request(Method::GET, &path, &[], Option::<&()>::None)
26      .await
27  }
28
29  /// Gets up to 100 apps by their identifiers.
30  pub async fn batch_get_apps(&self, ids: &[i32]) -> Result<CollectionResponse<App>> {
31    self
32      .request(Method::POST, "/Apps/batch-get", &[], Some(&ids))
33      .await
34  }
35}