diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2022-10-21 17:15:01 +0200 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2022-10-21 17:15:01 +0200 |
commit | e332e9d4a468b3a97c4d8b91394070a5ac98c916 (patch) | |
tree | 3dca50ef631361605365baa4d22e22c025431e5b /src |
Initial commit
Diffstat (limited to 'src')
-rw-r--r-- | src/client.rs | 27 | ||||
-rw-r--r-- | src/error/mod.rs | 26 | ||||
-rw-r--r-- | src/lib.rs | 5 |
3 files changed, 58 insertions, 0 deletions
diff --git a/src/client.rs b/src/client.rs new file mode 100644 index 0000000..f0a06f3 --- /dev/null +++ b/src/client.rs @@ -0,0 +1,27 @@ +use crate::{Error, Result}; + +use reqwest::Url; + +/// The INWX environment to use. The Sandbox is good for testing +/// or debugging purposes. +pub enum Endpoint { + Production, + Sandbox, +} + +impl From<Endpoint> for &str { + fn from(endpoint: Endpoint) -> &'static str { + match endpoint { + Endpoint::Production => "https://api.domrobot.com/xmlrpc/", + Endpoint::Sandbox => "https://api.ote.domrobot.com/xmlrpc/", + } + } +} + +impl TryInto<Url> for Endpoint { + type Error = Error; + fn try_into(self) -> Result<Url> { + let url = Url::parse(self.into())?; + Ok(url) + } +} diff --git a/src/error/mod.rs b/src/error/mod.rs new file mode 100644 index 0000000..8c45015 --- /dev/null +++ b/src/error/mod.rs @@ -0,0 +1,26 @@ +use std::fmt; + +/// The Errors that may occur around Clients. +#[derive(Debug)] +pub enum Error { + ParseUrl(url::ParseError), +} + +impl std::error::Error for Error {} + +impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Error::ParseUrl(err) => write!(fmt, "can't parse Url: {}", err), + } + } +} + +impl From<url::ParseError> for Error { + fn from(err: url::ParseError) -> Self { + Self::ParseUrl(err) + } +} + +/// A `Result` alias where the `Err` case is `inwx::Error`. +pub type Result<T> = std::result::Result<T, Error>; diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..f4687c8 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,5 @@ +pub mod client; +pub mod error; + +pub use client::Endpoint; +pub use error::{Error, Result}; |