diff --git a/src/common.rs b/src/common.rs index bb09e95..973b7f2 100644 --- a/src/common.rs +++ b/src/common.rs @@ -41,7 +41,7 @@ impl Extension for NoExtension { /// Type that represents the <name> tag for host check response #[derive(Deserialize, Debug)] -pub struct Available { +struct Available { /// The resource name #[serde(rename = "$value")] pub id: StringValue<'static>, @@ -52,7 +52,7 @@ pub struct Available { /// Type that represents the <cd> tag for domain check response #[derive(Deserialize, Debug)] -pub struct CheckResponseDataItem { +struct CheckResponseDataItem { /// Data under the <name> tag #[serde(rename = "name", alias = "id")] pub resource: Available, @@ -62,7 +62,7 @@ pub struct CheckResponseDataItem { /// Type that represents the <chkData> tag for host check response #[derive(Deserialize, Debug)] -pub struct CheckData { +struct CheckData { /// Data under the <cd> tag #[serde(rename = "cd")] pub list: Vec, @@ -70,12 +70,42 @@ pub struct CheckData { /// Type that represents the <resData> tag for host check response #[derive(Deserialize, Debug)] -pub struct CheckResponse { +struct DeserializedCheckResponse { /// Data under the <chkData> tag #[serde(rename = "chkData")] pub check_data: CheckData, } +#[derive(Debug)] +pub struct Checked { + pub id: String, + pub available: bool, + pub reason: Option, +} + +#[derive(Deserialize, Debug)] +#[serde(from = "DeserializedCheckResponse")] +pub struct CheckResponse { + pub list: Vec, +} + +impl From for CheckResponse { + fn from(rsp: DeserializedCheckResponse) -> Self { + Self { + list: rsp + .check_data + .list + .into_iter() + .map(|item| Checked { + id: item.resource.id.0.into_owned(), + available: item.resource.available, + reason: item.reason.map(|r| r.0.into_owned()), + }) + .collect(), + } + } +} + /// The