1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use serde_json::json;
pub use crate::api::{API, Texts, TextsBatch};
/// Workflow definition
pub struct Workflow {
api: API
}
/// Workflow implementation
impl Workflow {
/// Creates a Workflow instance.
///
pub fn new() -> Workflow {
Workflow {
api: API::new()
}
}
/// Creates a Workflow instance.
///
/// # Arguments
/// * `url` - API url
pub fn with_url(url: &str) -> Workflow {
Workflow {
api: API::with_url(url)
}
}
/// Creates a Workflow instance.
///
/// # Arguments
/// * `url` - API url
/// * `token` - API token
pub fn with_url_token(url: &str, token: &str) -> Workflow {
Workflow {
api: API::with_url_token(url, token)
}
}
/// Executes a named workflow using elements as input.
///
/// `name` workflow name
/// `elements` list of elements to run through workflow
pub async fn workflow(&self, name: &str, elements: &Vec<&str>) -> TextsBatch {
// Query parameters
let params = json!({
"name": name,
"elements": elements
});
// Execute API call
Ok(self.api.post("workflow", ¶ms).await?.json().await?)
}
}