cloudflare/framework/
mod.rs

1/*!
2This module controls how requests are sent to Cloudflare's API, and how responses are parsed from it.
3 */
4pub mod auth;
5pub mod client;
6pub mod endpoint;
7pub mod response;
8
9use serde::Serialize;
10
11#[derive(thiserror::Error, Debug)]
12/// Errors encountered while trying to connect to the Cloudflare API
13pub enum Error {
14    /// An error via the `reqwest` crate
15    #[error("Reqwest returned an error when connecting to the Cloudflare API: {0}")]
16    ReqwestError(#[from] reqwest::Error),
17}
18
19#[derive(Serialize, Clone, Debug)]
20pub enum OrderDirection {
21    #[serde(rename = "asc")]
22    Ascending,
23    #[serde(rename = "desc")]
24    Descending,
25}
26
27/// Used as a parameter to API calls that search for a resource (e.g. DNS records).
28/// Tells the API whether to return results that match all search requirements or at least one (any).
29#[derive(Serialize, Clone, Debug)]
30#[serde(rename_all = "lowercase")]
31pub enum SearchMatch {
32    /// Match all search requirements
33    All,
34    /// Match at least one search requirement
35    Any,
36}
37
38/// Which environment (host path) to use for API calls
39#[derive(Debug)]
40pub enum Environment {
41    /// The production endpoint: `https://api.cloudflare.com/client/v4`
42    Production,
43    /// A custom endpoint (for example, a `mockito` server)
44    Custom(String),
45}
46
47impl<'a> From<&'a Environment> for url::Url {
48    fn from(environment: &Environment) -> Self {
49        match environment {
50            Environment::Production => {
51                url::Url::parse("https://api.cloudflare.com/client/v4/").unwrap()
52            }
53            Environment::Custom(url) => url::Url::parse(url.as_str()).unwrap(),
54        }
55    }
56}