1use super::{Client, Context, DEFAULT_TIMEOUT_SECS, Error, System};
2use crate::client::Format;
3use std::sync::Arc;
4use std::time::Duration;
5
6#[derive(Clone)]
7pub struct Node {
8 client: Client,
9 pub(crate) system: System,
10 pub id: String,
11}
12
13impl Node {
14 pub(crate) fn new(client: Client, system: System, id: String) -> Self {
15 Self { client, system, id }
16 }
17
18 pub fn context(&self, id: &str, name: &str) -> Result<Arc<Context>, Error> {
19 let args = vec![
20 self.system.id.to_string(),
21 self.id.clone(),
22 id.to_string(),
23 name.to_string(),
24 ];
25 let mut client = self.client.clone();
26 let transaction = client.send(Format::Json, "contexts", &args)?;
27 let _res = client.wait_for_response(transaction, Duration::from_secs(DEFAULT_TIMEOUT_SECS))?;
28 Ok(Arc::new(Context::new(client, self.clone(), id.to_string())))
29 }
30}