omg_api/
address.rs

1use clap::Subcommand;
2use serde::Deserialize;
3
4use crate::{get, get_auth};
5
6#[derive(Debug, Subcommand)]
7pub enum Address {
8    /// Get information about the availability of an address
9    #[clap(visible_aliases = &["a", "av"])]
10    IsAvailable {
11        /// Address to get availability of
12        address: String,
13    },
14    /// Get the expiration date for an address
15    #[clap(visible_aliases = &["e", "exp"])]
16    GetExpiry {
17        /// Address to get availability of
18        address: String,
19    },
20    /// Get limited (public) information about an address (no auth required)
21    #[clap(visible_aliases = &["pi", "pinfo"])]
22    GetPublicInfo {
23        /// Address to get availability of
24        address: String,
25    },
26    /// Get comprehensive information about an address
27    #[clap(visible_aliases = &["i", "info"])]
28    GetInfo {
29        /// Address to get availability of
30        address: String,
31    },
32}
33
34impl Address {
35    pub fn process(&self, api_key: &str) -> Result<AddressResponse, reqwest::Error> {
36        match self {
37            Address::IsAvailable { address } => Ok(AddressResponse::IsAvailable(get(&format!(
38                "address/{address}/availability"
39            ))?)),
40            Address::GetExpiry { address } => Ok(AddressResponse::GetExpiry(get(&format!(
41                "address/{address}/expiration"
42            ))?)),
43            Address::GetPublicInfo { address } => Ok(AddressResponse::GetPublicInfo(get(
44                &format!("address/{address}/info"),
45            )?)),
46            Address::GetInfo { address } => Ok(AddressResponse::GetInfo(get_auth(
47                api_key,
48                &format!("address/{address}/info"),
49            )?)),
50        }
51    }
52}
53
54structstruck::strike! {
55    #[strikethrough[allow(dead_code)]]
56    #[strikethrough[derive(Debug, Deserialize)]]
57    pub enum AddressResponse {
58        IsAvailable ( struct {
59            pub response: pub struct IsAvailableResponse {
60                pub address: String,
61                pub available: bool,
62            },
63        }),
64        GetExpiry ( struct {
65            pub response: pub struct GetExpiryResponse {
66                pub message: String,
67                pub expired: bool,
68            },
69        }),
70        GetPublicInfo ( struct {
71            pub response: pub struct GetPublicInfoResponse {
72                pub address: String,
73                pub message: String,
74                pub expiration: struct GetPublicInfoExpiration {
75                    pub expired: bool,
76                },
77                pub verification: struct GetPublicInfoVerification {
78                    pub verified: bool,
79                },
80            },
81        }),
82        GetInfo ( struct {
83            pub response: pub struct GetInfoResponse {
84                pub address: String,
85                pub message: String,
86                pub expiration: struct GetInfoExpiration {
87                    pub expired: bool,
88                    pub will_expire: bool,
89                    pub relative_time: String,
90                },
91                pub verification: struct GetInfoVerification {
92                    pub verified: bool,
93                },
94                pub owner: String,
95            }
96        }),
97    }
98}