Skip to main content

made_client/
artifacts.rs

1use made_proto::v1::{
2    ArtifactRecord, GetArtifactRequest, ListArtifactsRequest, ListArtifactsResponse,
3};
4
5use crate::{MadeClient, MadeClientError};
6
7impl MadeClient {
8    pub async fn get_artifact(
9        &self,
10        artifact_id: impl Into<String>,
11    ) -> Result<ArtifactRecord, MadeClientError> {
12        let response = self
13            .rpc()
14            .get_artifact(Self::request(
15                &self.context(),
16                "/underpass.made.v1.MadeService/GetArtifact",
17                GetArtifactRequest {
18                    artifact_id: artifact_id.into(),
19                },
20            ))
21            .await
22            .map_err(MadeClientError::from_status)?
23            .into_inner();
24        response.record.ok_or_else(|| {
25            MadeClientError::ProtocolViolation("get artifact response has no record".to_owned())
26        })
27    }
28
29    pub async fn list_artifacts(
30        &self,
31        cursor: Option<String>,
32        limit: u32,
33    ) -> Result<ListArtifactsResponse, MadeClientError> {
34        self.rpc()
35            .list_artifacts(Self::request(
36                &self.context(),
37                "/underpass.made.v1.MadeService/ListArtifacts",
38                ListArtifactsRequest { cursor, limit },
39            ))
40            .await
41            .map(tonic::Response::into_inner)
42            .map_err(MadeClientError::from_status)
43    }
44}