added contact check call
This commit is contained in:
parent
e879ce5d9a
commit
b0da37bb1e
|
@ -1,5 +1,22 @@
|
||||||
use epp_client::{epp::request, epp::request::generate_client_tr_id, epp::request::domain, connection, epp::xml::EppXml, epp::response::EppGreeting, epp::object::ElementName};
|
use epp_client::{epp::request::generate_client_tr_id, connection::EppClient, connection, epp::xml::EppXml, epp::response::EppGreeting};
|
||||||
use epp_client::epp::response;
|
use epp_client::epp::request::domain::EppDomainCheck;
|
||||||
|
use epp_client::epp::response::domain::EppDomainCheckResponse;
|
||||||
|
use epp_client::epp::request::contact::EppContactCheck;
|
||||||
|
use epp_client::epp::response::contact::EppContactCheckResponse;
|
||||||
|
|
||||||
|
async fn check_domains(client: &mut EppClient) {
|
||||||
|
let domains = vec!["eppdev.com", "hexonet.net"];
|
||||||
|
let domain_check = EppDomainCheck::new(domains, generate_client_tr_id("eppdev").unwrap().as_str());
|
||||||
|
|
||||||
|
client.transact::<EppDomainCheck, EppDomainCheckResponse>(&domain_check).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn check_contacts(client: &mut EppClient) {
|
||||||
|
let contacts = vec!["eppdev-contact-1", "eppdev-contact-2"];
|
||||||
|
let contact_check = EppContactCheck::new(contacts, generate_client_tr_id("eppdev").unwrap().as_str());
|
||||||
|
|
||||||
|
client.transact::<EppContactCheck, EppContactCheckResponse>(&contact_check).await.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
@ -13,8 +30,7 @@ async fn main() {
|
||||||
Err(e) => panic!("Error: {}", e)
|
Err(e) => panic!("Error: {}", e)
|
||||||
};
|
};
|
||||||
|
|
||||||
let domains = vec!["eppdev.com", "hexonet.net"];
|
check_domains(&client);
|
||||||
let domain_check = domain::DomainCheck::epp_new(domains, generate_client_tr_id("eppdev").unwrap().as_str());
|
|
||||||
|
|
||||||
let response = client.transact::<domain::EppDomainCheck, response::domain::EppDomainCheckResponse>(&domain_check).await.unwrap();
|
check_contacts(&mut client).await;
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ impl EppClient {
|
||||||
};
|
};
|
||||||
|
|
||||||
let client_tr_id = generate_client_tr_id(&client.credentials.0)?;
|
let client_tr_id = generate_client_tr_id(&client.credentials.0)?;
|
||||||
let login_request = Login::epp_new(&client.credentials.0, &client.credentials.1, client_tr_id.as_str());
|
let login_request = EppLogin::new(&client.credentials.0, &client.credentials.1, client_tr_id.as_str());
|
||||||
|
|
||||||
client.transact::<EppLogin, EppCommandResponse>(&login_request).await?;
|
client.transact::<EppLogin, EppCommandResponse>(&login_request).await?;
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ impl EppClient {
|
||||||
|
|
||||||
pub async fn logout(&mut self) {
|
pub async fn logout(&mut self) {
|
||||||
let client_tr_id = generate_client_tr_id(&self.credentials.0).unwrap();
|
let client_tr_id = generate_client_tr_id(&self.credentials.0).unwrap();
|
||||||
let epp_logout = Logout::epp_new(client_tr_id.as_str());
|
let epp_logout = EppLogout::new(client_tr_id.as_str());
|
||||||
|
|
||||||
self.transact::<EppLogout, EppCommandResponse>(&epp_logout).await;
|
self.transact::<EppLogout, EppCommandResponse>(&epp_logout).await;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ pub struct Services {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ElementName> EppObject<T> {
|
impl<T: ElementName> EppObject<T> {
|
||||||
pub fn new(data: T) -> EppObject<T> {
|
pub fn build(data: T) -> EppObject<T> {
|
||||||
EppObject {
|
EppObject {
|
||||||
data: data,
|
data: data,
|
||||||
xmlns: EPP_XMLNS.to_string(),
|
xmlns: EPP_XMLNS.to_string(),
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
pub mod contact;
|
||||||
pub mod domain;
|
pub mod domain;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -29,9 +30,9 @@ impl ElementName for Hello {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hello {
|
impl EppHello {
|
||||||
pub fn epp_new() -> EppHello {
|
pub fn new() -> EppHello {
|
||||||
EppObject::new(Hello {})
|
EppObject::build(Hello {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,8 +54,8 @@ impl ElementName for Login {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Login {
|
impl EppLogin {
|
||||||
pub fn epp_new(username: &str, password: &str, client_tr_id: &str) -> EppLogin {
|
pub fn new(username: &str, password: &str, client_tr_id: &str) -> EppLogin {
|
||||||
let login = Login {
|
let login = Login {
|
||||||
username: username.to_string_value(),
|
username: username.to_string_value(),
|
||||||
password: password.to_string_value(),
|
password: password.to_string_value(),
|
||||||
|
@ -76,18 +77,18 @@ impl Login {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
EppObject::new(Command::<Login> {
|
EppObject::build(Command::<Login> {
|
||||||
command: login,
|
command: login,
|
||||||
client_tr_id: client_tr_id.to_string_value(),
|
client_tr_id: client_tr_id.to_string_value(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_options(&mut self, options: Options) {
|
pub fn set_options(&mut self, options: Options) {
|
||||||
self.options = options;
|
self.data.command.options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_services(&mut self, services: Services) {
|
pub fn set_services(&mut self, services: Services) {
|
||||||
self.services = services;
|
self.data.command.services = services;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,9 +96,9 @@ impl Login {
|
||||||
#[serde(rename_all = "lowercase")]
|
#[serde(rename_all = "lowercase")]
|
||||||
pub struct Logout;
|
pub struct Logout;
|
||||||
|
|
||||||
impl Logout {
|
impl EppLogout {
|
||||||
pub fn epp_new(client_tr_id: &str) -> EppLogout {
|
pub fn new(client_tr_id: &str) -> EppLogout {
|
||||||
EppObject::new(Command::<Logout> {
|
EppObject::build(Command::<Logout> {
|
||||||
command: Logout,
|
command: Logout,
|
||||||
client_tr_id: client_tr_id.to_string_value(),
|
client_tr_id: client_tr_id.to_string_value(),
|
||||||
})
|
})
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
use crate::epp::command::Command;
|
||||||
|
use crate::epp::object::{ElementName, EppObject, StringValue, StringValueTrait};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
const EPP_CONTACT_XMLNS: &str = "urn:ietf:params:xml:ns:contact-1.0";
|
||||||
|
|
||||||
|
pub type EppContactCheck = EppObject<Command<ContactCheck>>;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct ContactList {
|
||||||
|
pub xmlns: String,
|
||||||
|
#[serde(rename = "id")]
|
||||||
|
pub contact_ids: Vec<StringValue>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct ContactCheck {
|
||||||
|
#[serde(rename = "check")]
|
||||||
|
list: ContactList,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ElementName for ContactCheck {
|
||||||
|
fn element_name(&self) -> &'static str {
|
||||||
|
"check"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EppContactCheck {
|
||||||
|
pub fn new(contact_ids: Vec<&str>, client_tr_id: &str) -> EppContactCheck {
|
||||||
|
let contact_ids = contact_ids
|
||||||
|
.iter()
|
||||||
|
.filter_map(|d| Some(d.to_string_value()))
|
||||||
|
.collect::<Vec<StringValue>>();
|
||||||
|
|
||||||
|
let contact_check = ContactCheck {
|
||||||
|
list: ContactList {
|
||||||
|
xmlns: EPP_CONTACT_XMLNS.to_string(),
|
||||||
|
contact_ids: contact_ids,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
EppObject::build(Command::<ContactCheck> {
|
||||||
|
command: contact_check,
|
||||||
|
client_tr_id: client_tr_id.to_string_value(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,8 +25,8 @@ impl ElementName for DomainCheck {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DomainCheck {
|
impl EppDomainCheck {
|
||||||
pub fn epp_new(domains: Vec<&str>, client_tr_id: &str) -> EppDomainCheck {
|
pub fn new(domains: Vec<&str>, client_tr_id: &str) -> EppDomainCheck {
|
||||||
let domains = domains
|
let domains = domains
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|d| Some(d.to_string_value()))
|
.filter_map(|d| Some(d.to_string_value()))
|
||||||
|
@ -39,7 +39,7 @@ impl DomainCheck {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
EppObject::new(Command::<DomainCheck> {
|
EppObject::build(Command::<DomainCheck> {
|
||||||
command: domain_check,
|
command: domain_check,
|
||||||
client_tr_id: client_tr_id.to_string_value(),
|
client_tr_id: client_tr_id.to_string_value(),
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
pub mod contact;
|
||||||
pub mod domain;
|
pub mod domain;
|
||||||
|
|
||||||
use serde::{Deserialize, Deserializer, Serialize};
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::epp::object::{EppObject, StringValue};
|
||||||
|
use crate::epp::response::CommandResponse;
|
||||||
|
|
||||||
|
pub type EppContactCheckResponse = EppObject<CommandResponse<ContactCheckResult>>;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct ContactCheck {
|
||||||
|
#[serde(rename = "$value")]
|
||||||
|
pub id: StringValue,
|
||||||
|
#[serde(rename = "avail")]
|
||||||
|
pub available: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct ContactCheckDataItem {
|
||||||
|
pub id: ContactCheck,
|
||||||
|
pub reason: Option<StringValue>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct ContactCheckData {
|
||||||
|
#[serde(rename = "cd")]
|
||||||
|
pub contact_list: Vec<ContactCheckDataItem>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct ContactCheckResult {
|
||||||
|
#[serde(rename = "chkData")]
|
||||||
|
pub check_data: ContactCheckData,
|
||||||
|
}
|
|
@ -5,18 +5,12 @@ use crate::epp::response::CommandResponse;
|
||||||
|
|
||||||
pub type EppDomainCheckResponse = EppObject<CommandResponse<DomainCheckResult>>;
|
pub type EppDomainCheckResponse = EppObject<CommandResponse<DomainCheckResult>>;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
pub enum Availability {
|
|
||||||
Unavailable,
|
|
||||||
Available,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct DomainCheck {
|
pub struct DomainCheck {
|
||||||
#[serde(rename = "$value")]
|
#[serde(rename = "$value")]
|
||||||
pub name: StringValue,
|
pub name: StringValue,
|
||||||
#[serde(rename = "avail")]
|
#[serde(rename = "avail")]
|
||||||
pub avail: u16,
|
pub available: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
|
Loading…
Reference in New Issue