akribes_sdk/sub/
drafts.rs1use std::sync::Arc;
2
3use crate::client::{AkribesClient, Inner};
4use crate::error::Result;
5use crate::models::*;
6
7#[derive(Clone, Debug)]
9pub struct DraftsClient {
10 pub(crate) inner: Arc<Inner>,
11 pub(crate) project_id: i64,
12}
13
14impl DraftsClient {
15 pub(crate) fn new(inner: Arc<Inner>, project_id: i64) -> Self {
16 Self { inner, project_id }
17 }
18
19 fn c(&self) -> AkribesClient {
20 AkribesClient {
21 inner: Arc::clone(&self.inner),
22 }
23 }
24
25 fn script_url(&self, name: &str) -> String {
26 format!(
27 "{}/projects/{}/scripts/{}",
28 self.inner.base_url,
29 self.project_id,
30 urlencoding::encode(name)
31 )
32 }
33
34 pub async fn get(&self, script_name: &str) -> Result<Option<Draft>> {
35 let url = format!("{}/draft", self.script_url(script_name));
36 self.c().get_opt(&url).await
37 }
38
39 pub async fn save(&self, script_name: &str, source: &str) -> Result<PutDraftResponse> {
40 let url = format!("{}/draft", self.script_url(script_name));
41 self.c().put_json(&url, &PutDraftRequest { source }).await
42 }
43}