Skip to main content

apify_client/clients/
key_value_store_collection.rs

1//! Client for the key-value store collection (`/v2/key-value-stores`).
2
3use crate::clients::base::{get_or_create_named, list_resource, ResourceContext};
4use crate::common::{PaginationList, QueryParams, StorageListOptions};
5use crate::error::ApifyClientResult;
6use crate::http_client::HttpClient;
7use crate::models::KeyValueStore;
8
9/// Client for listing key-value stores and getting-or-creating one by name.
10#[derive(Debug, Clone)]
11pub struct KeyValueStoreCollectionClient {
12    ctx: ResourceContext,
13}
14
15impl KeyValueStoreCollectionClient {
16    pub(crate) fn new(http: HttpClient, base_url: &str) -> Self {
17        Self {
18            ctx: ResourceContext::collection(http, base_url, "key-value-stores"),
19        }
20    }
21
22    /// Lists key-value stores with offset/limit pagination, optionally filtering by
23    /// `unnamed`/`ownership`.
24    pub async fn list(
25        &self,
26        options: StorageListOptions,
27    ) -> ApifyClientResult<PaginationList<KeyValueStore>> {
28        let mut params = QueryParams::new();
29        options.apply(&mut params);
30        list_resource(&self.ctx, None, &params).await
31    }
32
33    /// Gets the store with the given `name`, creating it if it does not exist.
34    pub async fn get_or_create(&self, name: Option<&str>) -> ApifyClientResult<KeyValueStore> {
35        get_or_create_named(&self.ctx, name).await
36    }
37}