#[allow(unused_imports)] use progenitor_client::{encode_path, RequestBuilderExt}; pub use progenitor_client::{ByteStream, Error, ResponseValue}; #[allow(unused_imports)] use reqwest::header::{HeaderMap, HeaderValue}; pub mod types { use serde::{Deserialize, Serialize}; #[allow(unused_imports)] use std::convert::TryFrom; #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct EnrolBody { pub host: String, pub key: String, } impl EnrolBody { pub fn builder() -> builder::EnrolBody { builder::EnrolBody::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct GlobalJobsResult { pub summary: Vec, } impl GlobalJobsResult { pub fn builder() -> builder::GlobalJobsResult { builder::GlobalJobsResult::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct OutputRecord { pub msg: String, pub stream: String, pub time: chrono::DateTime, } impl OutputRecord { pub fn builder() -> builder::OutputRecord { builder::OutputRecord::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct PingResult { pub host: String, pub ok: bool, } impl PingResult { pub fn builder() -> builder::PingResult { builder::PingResult::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct ReportFinishBody { pub duration_millis: usize, pub end_time: chrono::DateTime, pub exit_status: usize, pub id: ReportId, } impl ReportFinishBody { pub fn builder() -> builder::ReportFinishBody { builder::ReportFinishBody::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct ReportId { pub host: String, pub job: String, pub pid: u64, pub time: chrono::DateTime, pub uuid: String, } impl ReportId { pub fn builder() -> builder::ReportId { builder::ReportId::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct ReportOutputBody { pub id: ReportId, pub record: OutputRecord, } impl ReportOutputBody { pub fn builder() -> builder::ReportOutputBody { builder::ReportOutputBody::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct ReportResult { pub existed_already: bool, } impl ReportResult { pub fn builder() -> builder::ReportResult { builder::ReportResult::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct ReportStartBody { pub id: ReportId, pub script: String, pub start_time: chrono::DateTime, } impl ReportStartBody { pub fn builder() -> builder::ReportStartBody { builder::ReportStartBody::default() } } #[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)] pub struct ReportSummary { pub age_seconds: usize, pub duration_seconds: usize, pub host: String, pub job: String, pub status: usize, pub when: chrono::DateTime, } impl ReportSummary { pub fn builder() -> builder::ReportSummary { builder::ReportSummary::default() } } mod builder { pub struct EnrolBody { host: Result, key: Result, } impl Default for EnrolBody { fn default() -> Self { Self { host: Err("no value supplied for host".to_string()), key: Err("no value supplied for key".to_string()), } } } impl EnrolBody { pub fn host(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.host = value .try_into() .map_err(|e| format!("error converting supplied value for host: {}", e)); self } pub fn key(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.key = value .try_into() .map_err(|e| format!("error converting supplied value for key: {}", e)); self } } impl std::convert::TryFrom for super::EnrolBody { type Error = String; fn try_from(value: EnrolBody) -> Result { Ok(Self { host: value.host?, key: value.key?, }) } } pub struct GlobalJobsResult { summary: Result, String>, } impl Default for GlobalJobsResult { fn default() -> Self { Self { summary: Err("no value supplied for summary".to_string()), } } } impl GlobalJobsResult { pub fn summary(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.summary = value .try_into() .map_err(|e| format!("error converting supplied value for summary: {}", e)); self } } impl std::convert::TryFrom for super::GlobalJobsResult { type Error = String; fn try_from(value: GlobalJobsResult) -> Result { Ok(Self { summary: value.summary?, }) } } pub struct OutputRecord { msg: Result, stream: Result, time: Result, String>, } impl Default for OutputRecord { fn default() -> Self { Self { msg: Err("no value supplied for msg".to_string()), stream: Err("no value supplied for stream".to_string()), time: Err("no value supplied for time".to_string()), } } } impl OutputRecord { pub fn msg(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.msg = value .try_into() .map_err(|e| format!("error converting supplied value for msg: {}", e)); self } pub fn stream(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.stream = value .try_into() .map_err(|e| format!("error converting supplied value for stream: {}", e)); self } pub fn time(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.time = value .try_into() .map_err(|e| format!("error converting supplied value for time: {}", e)); self } } impl std::convert::TryFrom for super::OutputRecord { type Error = String; fn try_from(value: OutputRecord) -> Result { Ok(Self { msg: value.msg?, stream: value.stream?, time: value.time?, }) } } pub struct PingResult { host: Result, ok: Result, } impl Default for PingResult { fn default() -> Self { Self { host: Err("no value supplied for host".to_string()), ok: Err("no value supplied for ok".to_string()), } } } impl PingResult { pub fn host(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.host = value .try_into() .map_err(|e| format!("error converting supplied value for host: {}", e)); self } pub fn ok(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.ok = value .try_into() .map_err(|e| format!("error converting supplied value for ok: {}", e)); self } } impl std::convert::TryFrom for super::PingResult { type Error = String; fn try_from(value: PingResult) -> Result { Ok(Self { host: value.host?, ok: value.ok?, }) } } pub struct ReportFinishBody { duration_millis: Result, end_time: Result, String>, exit_status: Result, id: Result, } impl Default for ReportFinishBody { fn default() -> Self { Self { duration_millis: Err("no value supplied for duration_millis".to_string()), end_time: Err("no value supplied for end_time".to_string()), exit_status: Err("no value supplied for exit_status".to_string()), id: Err("no value supplied for id".to_string()), } } } impl ReportFinishBody { pub fn duration_millis(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.duration_millis = value.try_into().map_err(|e| { format!("error converting supplied value for duration_millis: {}", e) }); self } pub fn end_time(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.end_time = value .try_into() .map_err(|e| format!("error converting supplied value for end_time: {}", e)); self } pub fn exit_status(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.exit_status = value .try_into() .map_err(|e| format!("error converting supplied value for exit_status: {}", e)); self } pub fn id(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.id = value .try_into() .map_err(|e| format!("error converting supplied value for id: {}", e)); self } } impl std::convert::TryFrom for super::ReportFinishBody { type Error = String; fn try_from(value: ReportFinishBody) -> Result { Ok(Self { duration_millis: value.duration_millis?, end_time: value.end_time?, exit_status: value.exit_status?, id: value.id?, }) } } pub struct ReportId { host: Result, job: Result, pid: Result, time: Result, String>, uuid: Result, } impl Default for ReportId { fn default() -> Self { Self { host: Err("no value supplied for host".to_string()), job: Err("no value supplied for job".to_string()), pid: Err("no value supplied for pid".to_string()), time: Err("no value supplied for time".to_string()), uuid: Err("no value supplied for uuid".to_string()), } } } impl ReportId { pub fn host(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.host = value .try_into() .map_err(|e| format!("error converting supplied value for host: {}", e)); self } pub fn job(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.job = value .try_into() .map_err(|e| format!("error converting supplied value for job: {}", e)); self } pub fn pid(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.pid = value .try_into() .map_err(|e| format!("error converting supplied value for pid: {}", e)); self } pub fn time(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.time = value .try_into() .map_err(|e| format!("error converting supplied value for time: {}", e)); self } pub fn uuid(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.uuid = value .try_into() .map_err(|e| format!("error converting supplied value for uuid: {}", e)); self } } impl std::convert::TryFrom for super::ReportId { type Error = String; fn try_from(value: ReportId) -> Result { Ok(Self { host: value.host?, job: value.job?, pid: value.pid?, time: value.time?, uuid: value.uuid?, }) } } pub struct ReportOutputBody { id: Result, record: Result, } impl Default for ReportOutputBody { fn default() -> Self { Self { id: Err("no value supplied for id".to_string()), record: Err("no value supplied for record".to_string()), } } } impl ReportOutputBody { pub fn id(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.id = value .try_into() .map_err(|e| format!("error converting supplied value for id: {}", e)); self } pub fn record(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.record = value .try_into() .map_err(|e| format!("error converting supplied value for record: {}", e)); self } } impl std::convert::TryFrom for super::ReportOutputBody { type Error = String; fn try_from(value: ReportOutputBody) -> Result { Ok(Self { id: value.id?, record: value.record?, }) } } pub struct ReportResult { existed_already: Result, } impl Default for ReportResult { fn default() -> Self { Self { existed_already: Err("no value supplied for existed_already".to_string()), } } } impl ReportResult { pub fn existed_already(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.existed_already = value.try_into().map_err(|e| { format!("error converting supplied value for existed_already: {}", e) }); self } } impl std::convert::TryFrom for super::ReportResult { type Error = String; fn try_from(value: ReportResult) -> Result { Ok(Self { existed_already: value.existed_already?, }) } } pub struct ReportStartBody { id: Result, script: Result, start_time: Result, String>, } impl Default for ReportStartBody { fn default() -> Self { Self { id: Err("no value supplied for id".to_string()), script: Err("no value supplied for script".to_string()), start_time: Err("no value supplied for start_time".to_string()), } } } impl ReportStartBody { pub fn id(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.id = value .try_into() .map_err(|e| format!("error converting supplied value for id: {}", e)); self } pub fn script(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.script = value .try_into() .map_err(|e| format!("error converting supplied value for script: {}", e)); self } pub fn start_time(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.start_time = value .try_into() .map_err(|e| format!("error converting supplied value for start_time: {}", e)); self } } impl std::convert::TryFrom for super::ReportStartBody { type Error = String; fn try_from(value: ReportStartBody) -> Result { Ok(Self { id: value.id?, script: value.script?, start_time: value.start_time?, }) } } pub struct ReportSummary { age_seconds: Result, duration_seconds: Result, host: Result, job: Result, status: Result, when: Result, String>, } impl Default for ReportSummary { fn default() -> Self { Self { age_seconds: Err("no value supplied for age_seconds".to_string()), duration_seconds: Err("no value supplied for duration_seconds".to_string()), host: Err("no value supplied for host".to_string()), job: Err("no value supplied for job".to_string()), status: Err("no value supplied for status".to_string()), when: Err("no value supplied for when".to_string()), } } } impl ReportSummary { pub fn age_seconds(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.age_seconds = value .try_into() .map_err(|e| format!("error converting supplied value for age_seconds: {}", e)); self } pub fn duration_seconds(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.duration_seconds = value.try_into().map_err(|e| { format!( "error converting supplied value for duration_seconds: {}", e ) }); self } pub fn host(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.host = value .try_into() .map_err(|e| format!("error converting supplied value for host: {}", e)); self } pub fn job(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.job = value .try_into() .map_err(|e| format!("error converting supplied value for job: {}", e)); self } pub fn status(mut self, value: T) -> Self where T: std::convert::TryInto, T::Error: std::fmt::Display, { self.status = value .try_into() .map_err(|e| format!("error converting supplied value for status: {}", e)); self } pub fn when(mut self, value: T) -> Self where T: std::convert::TryInto>, T::Error: std::fmt::Display, { self.when = value .try_into() .map_err(|e| format!("error converting supplied value for when: {}", e)); self } } impl std::convert::TryFrom for super::ReportSummary { type Error = String; fn try_from(value: ReportSummary) -> Result { Ok(Self { age_seconds: value.age_seconds?, duration_seconds: value.duration_seconds?, host: value.host?, job: value.job?, status: value.status?, when: value.when?, }) } } } } #[derive(Clone, Debug)] ///Client for Keeper API /// ///report execution of cron jobs through a mechanism other than mail pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, } impl Client { /// Create a new client. /// /// `baseurl` is the base URL provided to the internal /// `reqwest::Client`, and should include a scheme and hostname, /// as well as port and a path stem if applicable. pub fn new(baseurl: &str) -> Self { let dur = std::time::Duration::from_secs(15); let client = reqwest::ClientBuilder::new() .connect_timeout(dur) .timeout(dur) .build() .unwrap(); Self::new_with_client(baseurl, client) } /// Construct a new client with an existing `reqwest::Client`, /// allowing more control over its configuration. /// /// `baseurl` is the base URL provided to the internal /// `reqwest::Client`, and should include a scheme and hostname, /// as well as port and a path stem if applicable. pub fn new_with_client(baseurl: &str, client: reqwest::Client) -> Self { Self { baseurl: baseurl.to_string(), client, } } /// Return the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } /// Return the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } } impl Client { ///Sends a `POST` request to `/enrol` /// ///Arguments: /// - `authorization`: Authorization header (bearer token) /// - `body` ///```ignore /// let response = client.enrol() /// .authorization(authorization) /// .body(body) /// .send() /// .await; /// ``` pub fn enrol(&self) -> builder::Enrol { builder::Enrol::new(self) } ///Sends a `GET` request to `/global/jobs` /// ///Arguments: /// - `authorization`: Authorization header (bearer token) ///```ignore /// let response = client.global_jobs() /// .authorization(authorization) /// .send() /// .await; /// ``` pub fn global_jobs(&self) -> builder::GlobalJobs { builder::GlobalJobs::new(self) } ///Sends a `GET` request to `/ping` /// ///Arguments: /// - `authorization`: Authorization header (bearer token) ///```ignore /// let response = client.ping() /// .authorization(authorization) /// .send() /// .await; /// ``` pub fn ping(&self) -> builder::Ping { builder::Ping::new(self) } ///Sends a `POST` request to `/report/finish` /// ///Arguments: /// - `authorization`: Authorization header (bearer token) /// - `body` ///```ignore /// let response = client.report_finish() /// .authorization(authorization) /// .body(body) /// .send() /// .await; /// ``` pub fn report_finish(&self) -> builder::ReportFinish { builder::ReportFinish::new(self) } ///Sends a `POST` request to `/report/output` /// ///Arguments: /// - `authorization`: Authorization header (bearer token) /// - `body` ///```ignore /// let response = client.report_output() /// .authorization(authorization) /// .body(body) /// .send() /// .await; /// ``` pub fn report_output(&self) -> builder::ReportOutput { builder::ReportOutput::new(self) } ///Sends a `POST` request to `/report/start` /// ///Arguments: /// - `authorization`: Authorization header (bearer token) /// - `body` ///```ignore /// let response = client.report_start() /// .authorization(authorization) /// .body(body) /// .send() /// .await; /// ``` pub fn report_start(&self) -> builder::ReportStart { builder::ReportStart::new(self) } } pub mod builder { use super::types; #[allow(unused_imports)] use super::{ encode_path, ByteStream, Error, HeaderMap, HeaderValue, RequestBuilderExt, ResponseValue, }; ///Builder for [`Client::enrol`] /// ///[`Client::enrol`]: super::Client::enrol #[derive(Debug, Clone)] pub struct Enrol<'a> { client: &'a super::Client, authorization: Result, body: Result, } impl<'a> Enrol<'a> { pub fn new(client: &'a super::Client) -> Self { Self { client, authorization: Err("authorization was not initialized".to_string()), body: Err("body was not initialized".to_string()), } } pub fn authorization(mut self, value: V) -> Self where V: std::convert::TryInto, { self.authorization = value .try_into() .map_err(|_| "conversion to `String` for authorization failed".to_string()); self } pub fn body(mut self, value: V) -> Self where V: std::convert::TryInto, { self.body = value .try_into() .map_err(|_| "conversion to `EnrolBody` for body failed".to_string()); self } ///Sends a `POST` request to `/enrol` pub async fn send(self) -> Result, Error<()>> { let Self { client, authorization, body, } = self; let authorization = authorization.map_err(Error::InvalidRequest)?; let body = body.map_err(Error::InvalidRequest)?; let url = format!("{}/enrol", client.baseurl,); let mut header_map = HeaderMap::with_capacity(1usize); header_map.append("Authorization", HeaderValue::try_from(authorization)?); let request = client .client .post(url) .json(&body) .headers(header_map) .build()?; let result = client.client.execute(request).await; let response = result?; match response.status().as_u16() { 201u16 => Ok(ResponseValue::empty(response)), _ => Err(Error::UnexpectedResponse(response)), } } } ///Builder for [`Client::global_jobs`] /// ///[`Client::global_jobs`]: super::Client::global_jobs #[derive(Debug, Clone)] pub struct GlobalJobs<'a> { client: &'a super::Client, authorization: Result, } impl<'a> GlobalJobs<'a> { pub fn new(client: &'a super::Client) -> Self { Self { client, authorization: Err("authorization was not initialized".to_string()), } } pub fn authorization(mut self, value: V) -> Self where V: std::convert::TryInto, { self.authorization = value .try_into() .map_err(|_| "conversion to `String` for authorization failed".to_string()); self } ///Sends a `GET` request to `/global/jobs` pub async fn send(self) -> Result, Error<()>> { let Self { client, authorization, } = self; let authorization = authorization.map_err(Error::InvalidRequest)?; let url = format!("{}/global/jobs", client.baseurl,); let mut header_map = HeaderMap::with_capacity(1usize); header_map.append("Authorization", HeaderValue::try_from(authorization)?); let request = client.client.get(url).headers(header_map).build()?; let result = client.client.execute(request).await; let response = result?; match response.status().as_u16() { 201u16 => ResponseValue::from_response(response).await, _ => Err(Error::UnexpectedResponse(response)), } } } ///Builder for [`Client::ping`] /// ///[`Client::ping`]: super::Client::ping #[derive(Debug, Clone)] pub struct Ping<'a> { client: &'a super::Client, authorization: Result, } impl<'a> Ping<'a> { pub fn new(client: &'a super::Client) -> Self { Self { client, authorization: Err("authorization was not initialized".to_string()), } } pub fn authorization(mut self, value: V) -> Self where V: std::convert::TryInto, { self.authorization = value .try_into() .map_err(|_| "conversion to `String` for authorization failed".to_string()); self } ///Sends a `GET` request to `/ping` pub async fn send(self) -> Result, Error<()>> { let Self { client, authorization, } = self; let authorization = authorization.map_err(Error::InvalidRequest)?; let url = format!("{}/ping", client.baseurl,); let mut header_map = HeaderMap::with_capacity(1usize); header_map.append("Authorization", HeaderValue::try_from(authorization)?); let request = client.client.get(url).headers(header_map).build()?; let result = client.client.execute(request).await; let response = result?; match response.status().as_u16() { 201u16 => ResponseValue::from_response(response).await, _ => Err(Error::UnexpectedResponse(response)), } } } ///Builder for [`Client::report_finish`] /// ///[`Client::report_finish`]: super::Client::report_finish #[derive(Debug, Clone)] pub struct ReportFinish<'a> { client: &'a super::Client, authorization: Result, body: Result, } impl<'a> ReportFinish<'a> { pub fn new(client: &'a super::Client) -> Self { Self { client, authorization: Err("authorization was not initialized".to_string()), body: Err("body was not initialized".to_string()), } } pub fn authorization(mut self, value: V) -> Self where V: std::convert::TryInto, { self.authorization = value .try_into() .map_err(|_| "conversion to `String` for authorization failed".to_string()); self } pub fn body(mut self, value: V) -> Self where V: std::convert::TryInto, { self.body = value .try_into() .map_err(|_| "conversion to `ReportFinishBody` for body failed".to_string()); self } ///Sends a `POST` request to `/report/finish` pub async fn send(self) -> Result, Error<()>> { let Self { client, authorization, body, } = self; let authorization = authorization.map_err(Error::InvalidRequest)?; let body = body.map_err(Error::InvalidRequest)?; let url = format!("{}/report/finish", client.baseurl,); let mut header_map = HeaderMap::with_capacity(1usize); header_map.append("Authorization", HeaderValue::try_from(authorization)?); let request = client .client .post(url) .json(&body) .headers(header_map) .build()?; let result = client.client.execute(request).await; let response = result?; match response.status().as_u16() { 201u16 => ResponseValue::from_response(response).await, _ => Err(Error::UnexpectedResponse(response)), } } } ///Builder for [`Client::report_output`] /// ///[`Client::report_output`]: super::Client::report_output #[derive(Debug, Clone)] pub struct ReportOutput<'a> { client: &'a super::Client, authorization: Result, body: Result, } impl<'a> ReportOutput<'a> { pub fn new(client: &'a super::Client) -> Self { Self { client, authorization: Err("authorization was not initialized".to_string()), body: Err("body was not initialized".to_string()), } } pub fn authorization(mut self, value: V) -> Self where V: std::convert::TryInto, { self.authorization = value .try_into() .map_err(|_| "conversion to `String` for authorization failed".to_string()); self } pub fn body(mut self, value: V) -> Self where V: std::convert::TryInto, { self.body = value .try_into() .map_err(|_| "conversion to `ReportOutputBody` for body failed".to_string()); self } ///Sends a `POST` request to `/report/output` pub async fn send(self) -> Result, Error<()>> { let Self { client, authorization, body, } = self; let authorization = authorization.map_err(Error::InvalidRequest)?; let body = body.map_err(Error::InvalidRequest)?; let url = format!("{}/report/output", client.baseurl,); let mut header_map = HeaderMap::with_capacity(1usize); header_map.append("Authorization", HeaderValue::try_from(authorization)?); let request = client .client .post(url) .json(&body) .headers(header_map) .build()?; let result = client.client.execute(request).await; let response = result?; match response.status().as_u16() { 201u16 => ResponseValue::from_response(response).await, _ => Err(Error::UnexpectedResponse(response)), } } } ///Builder for [`Client::report_start`] /// ///[`Client::report_start`]: super::Client::report_start #[derive(Debug, Clone)] pub struct ReportStart<'a> { client: &'a super::Client, authorization: Result, body: Result, } impl<'a> ReportStart<'a> { pub fn new(client: &'a super::Client) -> Self { Self { client, authorization: Err("authorization was not initialized".to_string()), body: Err("body was not initialized".to_string()), } } pub fn authorization(mut self, value: V) -> Self where V: std::convert::TryInto, { self.authorization = value .try_into() .map_err(|_| "conversion to `String` for authorization failed".to_string()); self } pub fn body(mut self, value: V) -> Self where V: std::convert::TryInto, { self.body = value .try_into() .map_err(|_| "conversion to `ReportStartBody` for body failed".to_string()); self } ///Sends a `POST` request to `/report/start` pub async fn send(self) -> Result, Error<()>> { let Self { client, authorization, body, } = self; let authorization = authorization.map_err(Error::InvalidRequest)?; let body = body.map_err(Error::InvalidRequest)?; let url = format!("{}/report/start", client.baseurl,); let mut header_map = HeaderMap::with_capacity(1usize); header_map.append("Authorization", HeaderValue::try_from(authorization)?); let request = client .client .post(url) .json(&body) .headers(header_map) .build()?; let result = client.client.execute(request).await; let response = result?; match response.status().as_u16() { 201u16 => ResponseValue::from_response(response).await, _ => Err(Error::UnexpectedResponse(response)), } } } } pub mod prelude { pub use self::super::Client; }