zero_bounce/utility/
mod.rs1use std::io::Error as IOError;
2
3pub mod structures;
4pub mod mock_constants;
5
6pub const CONTENT_TYPE_JSON: &str = "application/json";
7pub const CONTENT_TYPE_STREAM: &str = "application/octet-stream";
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum ApiBaseUrl {
12 Default,
14 USA,
16 EU,
18}
19
20impl ApiBaseUrl {
21 pub fn as_str(&self) -> &'static str {
23 match self {
24 ApiBaseUrl::Default => "https://api.zerobounce.net/v2/",
25 ApiBaseUrl::USA => "https://api-us.zerobounce.net/v2/",
26 ApiBaseUrl::EU => "https://api-eu.zerobounce.net/v2/",
27 }
28 }
29}
30
31impl From<ApiBaseUrl> for String {
32 fn from(url: ApiBaseUrl) -> Self {
33 url.as_str().to_string()
34 }
35}
36
37impl From<&ApiBaseUrl> for String {
38 fn from(url: &ApiBaseUrl) -> Self {
39 url.as_str().to_string()
40 }
41}
42
43pub const BULK_URI: &str = "https://bulkapi.zerobounce.net/v2";
44pub const ENDPOINT_CREDITS: &str = "/getcredits";
45pub const ENDPOINT_ACTIVITY_DATA: &str = "/activity";
46pub const ENDPOINT_VALIDATE: &str = "/validate";
47pub const ENDPOINT_API_USAGE: &str = "/getapiusage";
48pub const ENDPOINT_BATCH_VALIDATE: &str = "/validatebatch";
49pub const ENDPOINT_FILE_SEND: &str = "/sendfile";
50pub const ENDPOINT_FILE_STATUS: &str = "/filestatus";
51pub const ENDPOINT_FILE_RESULT: &str = "/getfile";
52pub const ENDPOINT_FILE_DELETE: &str = "/deletefile";
53pub const ENDPOINT_SCORING_SEND: &str = "/scoring/sendfile";
54pub const ENDPOINT_SCORING_STATUS: &str = "/scoring/filestatus";
55pub const ENDPOINT_SCORING_RESULT: &str = "/scoring/getfile";
56pub const ENDPOINT_SCORING_DELETE: &str = "/scoring/deletefile";
57pub const ENDPOINT_EMAIL_FINDER: &str = "/guessformat";
58
59pub const S_VALID: &str = "valid";
61pub const S_INVALID: &str = "invalid";
62pub const S_CATCH_ALL: &str = "catch-all";
63pub const S_UNKNOWN: &str = "unknown";
64pub const S_SPAMTRAP: &str = "spamtrap";
65pub const S_ABUSE: &str = "abuse";
66pub const S_DO_NOT_MAIL: &str = "do_not_mail";
67
68pub const SS_ANTISPAM_SYSTEM: &str = "antispam_system";
70pub const SS_GREYLISTED: &str = "greylisted";
71pub const SS_MAIL_SERVER_TEMPORARY_ERROR: &str = "mail_server_temporary_error";
72pub const SS_FORCIBLE_DISCONNECT: &str = "forcible_disconnect";
73pub const SS_MAIL_SERVER_DID_NOT_RESPOND: &str = "mail_server_did_not_respond";
74pub const SS_TIMEOUT_EXCEEDED: &str = "timeout_exceeded";
75pub const SS_FAILED_SMTP_CONNECTION: &str = "failed_smtp_connection";
76pub const SS_MAILBOX_QUOTA_EXCEEDED: &str = "mailbox_quota_exceeded";
77pub const SS_EXCEPTION_OCCURRED: &str = "exception_occurred";
78pub const SS_POSSIBLE_TRAP: &str = "possible_trap";
79pub const SS_ROLE_BASED: &str = "role_based";
80pub const SS_GLOBAL_SUPPRESSION: &str = "global_suppression";
81pub const SS_MAILBOX_NOT_FOUND: &str = "mailbox_not_found";
82pub const SS_NO_DNS_ENTRIES: &str = "no_dns_entries";
83pub const SS_FAILED_SYNTAX_CHECK: &str = "failed_syntax_check";
84pub const SS_POSSIBLE_TYPO: &str = "possible_typo";
85pub const SS_UNROUTABLE_IP_ADDRESS: &str = "unroutable_ip_address";
86pub const SS_LEADING_PERIOD_REMOVED: &str = "leading_period_removed";
87pub const SS_DOES_NOT_ACCEPT_MAIL: &str = "does_not_accept_mail";
88pub const SS_ALIAS_ADDRESS: &str = "alias_address";
89pub const SS_ROLE_BASED_CATCH_ALL: &str = "role_based_catch_all";
90pub const SS_DISPOSABLE: &str = "disposable";
91pub const SS_TOXIC: &str = "toxic";
92pub const SS_ACCEPT_ALL: &str = "accept_all";
93
94#[derive(Debug)]
95pub enum ZBError {
96 ExplicitError(String),
97 JsonError(serde_json::Error),
98 IntParseError(std::num::ParseIntError),
99 RequestError(reqwest::Error),
100 IOError(IOError),
101}
102
103pub type ZBResult<T> = Result<T, ZBError>;
104
105impl ZBError {
106 pub fn explicit(string: &str) -> ZBError {
107 ZBError::ExplicitError(string.to_string())
108 }
109}
110
111impl From<reqwest::Error> for ZBError {
117 fn from(value: reqwest::Error) -> ZBError {
118 ZBError::RequestError(value)
119 }
120}
121
122impl From<serde_json::Error> for ZBError {
127 fn from(value: serde_json::Error) -> ZBError {
128 ZBError::JsonError(value)
129 }
130}
131
132impl From<IOError> for ZBError {
133 fn from(value: IOError) -> Self {
134 ZBError::IOError(value)
135 }
136}