houseflow_api/
lib.rs

1#[cfg(feature = "admin")]
2mod admin;
3
4#[cfg(feature = "auth")]
5mod auth;
6
7#[cfg(feature = "auth")]
8mod fulfillment;
9
10#[cfg(feature = "auth")]
11pub use crate::fulfillment::FulfillmentError;
12
13#[cfg(feature = "auth")]
14pub use crate::auth::AuthError;
15
16#[cfg(any(feature = "auth", feature = "fulfillment", feature = "admin"))]
17use url::Url;
18
19#[derive(Debug, thiserror::Error)]
20#[non_exhaustive]
21pub enum Error {
22    #[error("error occured with sending request: `{0}`")]
23    ReqwestError(#[from] reqwest::Error),
24
25    #[cfg(feature = "auth")]
26    #[error("auth error: {0}")]
27    AuthError(#[from] AuthError),
28}
29
30#[derive(Debug, Clone)]
31pub struct HouseflowAPI {
32    #[cfg(feature = "auth")]
33    auth_url: Url,
34
35    #[cfg(feature = "fulfillment")]
36    fulfillment_url: Url,
37
38    #[cfg(feature = "admin")]
39    admin_url: Url,
40}
41
42impl HouseflowAPI {
43    pub fn new(#[allow(unused_variables)] server_address: std::net::SocketAddr) -> Self {
44        Self {
45            #[cfg(feature = "auth")]
46            auth_url: Url::parse(&format!("http://{}/auth/", server_address)).unwrap(),
47
48            #[cfg(feature = "fulfillment")]
49            fulfillment_url: Url::parse(&format!(
50                "http://{}/fulfillment/internal/",
51                server_address
52            ))
53            .unwrap(),
54
55            #[cfg(feature = "admin")]
56            admin_url: Url::parse(&format!("http://{}/admin/", server_address)).unwrap(),
57        }
58    }
59}