aboutsummaryrefslogtreecommitdiff
path: root/src/client.rs
blob: 3153254da7ea52539ade63e31343a749986dc917 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::{Error, Result};

use std::sync::Arc;

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)
    }
}

/// A synchronous client to make API calls with.
/// You do **not** need to wrap it in an `Arc` or `Rc`
/// because it already uses an `Arc` internally.
/// [`Rc`]: std::rc::Rc
pub struct Client {
    inner: Arc<ClientRef>,
}

impl Client {}

// The underlying data of a `Client`.
struct ClientRef {
    http: reqwest::Client,
}