#![deny(
missing_docs,
trivial_casts,
trivial_numeric_casts,
unused_extern_crates,
unused_import_braces,
unused_qualifications,
unused_results
)]
use clickonce::deploymentmanifest::DeploymentManifest;
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("HTTP error")]
HTTP(#[from] reqwest::Error),
#[error("XML error")]
XML(#[from] serde_xml_rs::Error),
#[error("Generic error {0}")]
Generic(String),
}
#[derive(Debug)]
pub struct MtgoApplication {
#[allow(dead_code)]
deployment_manifest: DeploymentManifest,
}
impl MtgoApplication {
pub async fn default() -> Result<Self, Error> {
Self::from_url("http://mtgoclientdepot.onlinegaming.wizards.com/MTGO.application").await
}
pub async fn from_url(url: &str) -> Result<Self, Error> {
let contents = reqwest::get(url).await?.text().await?;
Self::from_contents(&contents)
}
pub fn from_contents(contents: &str) -> Result<Self, Error> {
let deployment_manifest = serde_xml_rs::from_str(contents.trim_start_matches('\u{feff}'))?;
Ok(Self {
deployment_manifest,
})
}
}