render_api/request/
create_job.rs

1use serde_json::json;
2use crate::model::*;
3use crate::RenderClient;
4use httpclient::InMemoryResponseExt;
5/**Create this with the associated client method.
6
7That method takes required values as arguments. Set optional values using builder methods on this struct.*/
8#[derive(Clone)]
9pub struct CreateJobRequest<'a> {
10    pub(crate) http_client: &'a RenderClient,
11    pub plan_id: Option<String>,
12    pub service_id: String,
13    pub start_command: Option<String>,
14}
15impl<'a> CreateJobRequest<'a> {
16    pub async fn send(self) -> ::httpclient::InMemoryResult<serde_json::Value> {
17        let mut r = self
18            .http_client
19            .client
20            .post(&format!("/services/{service_id}/jobs", service_id = self.service_id));
21        if let Some(ref unwrapped) = self.plan_id {
22            r = r.json(json!({ "planId" : unwrapped }));
23        }
24        if let Some(ref unwrapped) = self.start_command {
25            r = r.json(json!({ "startCommand" : unwrapped }));
26        }
27        r = self.http_client.authenticate(r);
28        let res = r.await?;
29        res.json().map_err(Into::into)
30    }
31    pub fn plan_id(mut self, plan_id: &str) -> Self {
32        self.plan_id = Some(plan_id.to_owned());
33        self
34    }
35    pub fn start_command(mut self, start_command: &str) -> Self {
36        self.start_command = Some(start_command.to_owned());
37        self
38    }
39}
40impl<'a> ::std::future::IntoFuture for CreateJobRequest<'a> {
41    type Output = httpclient::InMemoryResult<serde_json::Value>;
42    type IntoFuture = ::futures::future::BoxFuture<'a, Self::Output>;
43    fn into_future(self) -> Self::IntoFuture {
44        Box::pin(self.send())
45    }
46}