namecom
ModuleThe Name.com registrar, over its Core API.
Contents
use utopia_domains::registrar::namecom::NameCom;Rust
pub struct NameComThe Name.com registrar, over its Core API with HTTP basic authentication.
Availability is asked 50 domains per request; each answer carries the
prices too, so with a cache a following Adapter::price for the same
domain needs no request.
Rust
use std::sync::Arc;
use utopia_domains::registrar::{NameCom, Registrar};
use utopia_domains::transport::{Request, Response, Transport, TransportError};
use utopia_domains::BoxFuture;
/// Answers every request with the same recorded response.
struct Recorded(&'static str);
impl Transport for Recorded {
fn send<'a>(&'a self, request: Request) -> BoxFuture<'a, Result<Response, TransportError>> {
assert_eq!(request.url, "https://api.name.com/core/v1/domains/example.com:getAuthCode");
Box::pin(async move { Ok(Response { status: 200, headers: vec![], body: self.0.into() }) })
}
}
let adapter = NameCom::new("user", "token", "api.name.com", Some(Arc::new(Recorded(r#"{"authCode":"x1y2"}"#))));
let registrar = Registrar::new(adapter);
let code = tokio::runtime::Runtime::new()?.block_on(registrar.auth_code("example.com"))?;
assert_eq!(code, "x1y2");Also implements
Debug.