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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
use crate::client::OkaeriClient; use crate::OkaeriSdkError; use serde::Deserialize; use serde_json::json; use std::collections::HashMap; use std::env; use std::time::Duration; use url::Url; type Result<T> = std::result::Result<T, OkaeriSdkError>; #[allow(dead_code)] #[derive(Deserialize)] pub struct NoProxyAddressInfoGeneral { pub ip: String, pub asn: u64, pub provider: String, pub country: String, } #[allow(dead_code)] #[derive(Deserialize)] pub struct NoProxyAddressInfoRisks { pub total: u64, pub proxy: bool, pub country: bool, pub asn: bool, pub provider: bool, pub abuser: bool, } #[allow(dead_code)] #[derive(Deserialize)] pub struct NoProxyAddressInfoScore { pub noproxy: u64, pub abuseipdb: u64, } #[allow(dead_code)] #[derive(Deserialize)] pub struct NoProxyAddressInfoSuggestions { pub verify: bool, pub block: bool, } #[allow(dead_code)] #[derive(Deserialize)] pub struct NoProxyAddressInfo { pub general: NoProxyAddressInfoGeneral, pub risks: NoProxyAddressInfoRisks, pub score: NoProxyAddressInfoScore, pub suggestions: NoProxyAddressInfoSuggestions, } pub struct NoProxy { client: OkaeriClient, } impl NoProxy { pub fn new<S: Into<String>>(token: S) -> Result<Self> { NoProxy::new_with_config(token, None, None) } pub fn new_with_config<S: Into<String>>( token: S, base_url: Option<&str>, timeout: Option<Duration>, ) -> Result<Self> { let base_url = OkaeriClient::read_base_url( base_url, "https://noproxy-api.okaeri.eu", "OKAERI_SDK_NOPROXY_BASE_PATH", )?; let timeout = OkaeriClient::read_timeout(timeout, Duration::from_secs(5), "OKAERI_SDK_TIMEOUT")?; let headers = maplit::hashmap! { String::from("Authorization") => format!("Bearer {}", token.into()) }; let client = OkaeriClient::new(base_url, timeout, headers)?; Ok(NoProxy { client }) } pub async fn get_info(self, address: &str) -> Result<NoProxyAddressInfo> { self.client.get(format!("/v1/{}", address)).await } }