cognite/api/data_modeling/
streams.rs

1use crate::{
2    models::records::{ListStreamParams, RetrieveStreamParams, Stream, StreamWrite},
3    CogniteExternalId, Create, Items, List, Resource, WithBasePath,
4};
5
6pub type StreamsResource = Resource<Stream>;
7
8impl WithBasePath for StreamsResource {
9    const BASE_PATH: &'static str = "streams";
10}
11
12impl Create<StreamWrite, Stream> for StreamsResource {}
13impl List<ListStreamParams, Stream> for StreamsResource {}
14
15impl StreamsResource {
16    /// Retrieve a stream by its ID.
17    ///
18    /// # Arguments
19    ///
20    /// * `stream_id` - ID of the stream to retrieve.
21    pub async fn retrieve(
22        &self,
23        stream_id: &str,
24        include_statistics: bool,
25    ) -> crate::error::Result<Stream> {
26        self.api_client
27            .get_with_params(
28                &format!("{}/{}", Self::BASE_PATH, stream_id),
29                Some(RetrieveStreamParams {
30                    include_statistics: Some(include_statistics),
31                }),
32            )
33            .await
34    }
35
36    /// Delete a stream by its ID.
37    ///
38    /// # Arguments
39    ///
40    /// * `stream_ids` - IDs of the streams to delete.
41    pub async fn delete(&self, stream_ids: &[&str]) -> crate::error::Result<()> {
42        self.api_client
43            .post::<serde_json::Value, _>(
44                &format!("{}/delete", Self::BASE_PATH),
45                &Items::new(
46                    stream_ids
47                        .iter()
48                        .map(|id| CogniteExternalId {
49                            external_id: id.to_string(),
50                        })
51                        .collect::<Vec<_>>(),
52                ),
53            )
54            .await?;
55        Ok(())
56    }
57}