SDK de Rust
neivi-iqx-lookup — Cliente Rust para la API de IQX Lookup usando reqwest (blocking).
Instalación
Añade a tu Cargo.toml:
[dependencies]
neivi-iqx-lookup = "0.2.1"
Inicio Rápido
use iqx_lookup::IqxLookup;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = IqxLookup::builder()
.api_key("ALk-your-api-key")
.build()?;
// Validate an email
let email = client.validate_email("user@example.com")?;
println!("Valid format: {}", email.valid_format);
println!("Disposable: {}", email.disposable_email);
// Validate a phone number
let phone = client.validate_phone("+34912345678", Some("ES"))?;
println!("Valid: {}", phone.valid);
// Geolocate an IP
let ip = client.geolocate_ip(Some("8.8.8.8"))?;
println!("Country: {}", ip.country_name);
// Validate a VAT number
let vat = client.validate_vat("ES", "B87387775")?;
println!("Valid: {}", vat.valid);
// Parse a user-agent string
let ua = client.parse_user_agent(Some("Mozilla/5.0..."))?;
println!("Browser: {}", ua.browser_family);
Ok(())
}
Configuración
use std::time::Duration;
let client = IqxLookup::builder()
.api_key("ALk-your-api-key") // required
.base_url("https://api.iqxlookup.neivi.es") // optional
.timeout(Duration::from_secs(15)) // optional, default 10s
.build()?;
Referencia de la API
Todos los métodos devuelven Result<T, IqxLookupError>:
| Método | Retorna | Descripción |
|---|---|---|
validate_email(&self, address) | EmailValidationResult | Validación de formato de email, MX, desechable, proveedor gratuito |
validate_phone(&self, number, country_code) | PhoneValidationResult | Validación de teléfono (Option<&str>) |
geolocate_ip(&self, ip) | IpGeolocation | Geolocalización IP + ASN (None = IP del llamante) |
validate_vat(&self, country_code, number) | VatValidationResult | Validación de IVA UE vía VIES |
parse_user_agent(&self, ua) | UserAgentResult | Análisis de UA — navegador, SO, marca y modelo del dispositivo |
validate_iban(&self, iban) | IbanValidationResult | Estructura IBAN, suma de verificación, información del banco |
validate_bic(&self, bic) | BicValidationResult | Formato BIC/SWIFT, información de la institución |
lookup_dns(&self, domain, types) | DnsLookupResult | Registros DNS, seguridad SPF/DKIM/DMARC |
check_ssl(&self, domain) | SslCertificateResult | Certificado SSL, cadena, calificación |
analyze_password(&self, password) | PasswordStrengthResult | Puntuación de fortaleza, tiempo de descifrado, verificación de filtraciones |
validate_credit_card(&self, number) | CreditCardValidationResult | Verificación Luhn, red de tarjeta, consulta BIN |
last_rate_limit_info(&self) | Option<RateLimitInfo> | Límite de peticiones de la última respuesta |
Manejo de Errores
use iqx_lookup::IqxLookupError;
match client.validate_email("user@example.com") {
Ok(result) => println!("Valid: {}", result.valid_format),
Err(IqxLookupError::RateLimited { retry_after, .. }) => {
println!("Retry after: {}s", retry_after);
}
Err(IqxLookupError::Unauthorized { .. }) => {
println!("Check your API key");
}
Err(e) => eprintln!("Error: {}", e),
}
Variantes de Error
| Variante | Estado HTTP | Descripción |
|---|---|---|
Unauthorized | 401 | Falta la clave API |
Forbidden | 403 | Clave API inválida o inactiva |
NotFound | 404 | Recurso no encontrado |
RateLimited | 429 | Límite de peticiones excedido (con retry_after, limit, remaining, reset) |
ServiceUnavailable | 503 | Servicio no configurado |
Http | otro | Error HTTP genérico |
Request | — | Error de red/transporte |
Config | — | Error de configuración del builder |
Requisitos
- Rust 2021 edition
- Dependencias:
reqwest(blocking),serde,serde_json,thiserror