From b0da37bb1e2e8b50e7e638dc7a56c1f99cf8d967 Mon Sep 17 00:00:00 2001 From: Ritesh Chitlangi Date: Wed, 21 Jul 2021 00:43:13 +0800 Subject: [PATCH] added contact check call --- examples/client.rs | 26 ++++++++++++++++---- src/connection.rs | 4 ++-- src/epp/object.rs | 2 +- src/epp/request.rs | 23 +++++++++--------- src/epp/request/contact.rs | 47 +++++++++++++++++++++++++++++++++++++ src/epp/request/domain.rs | 6 ++--- src/epp/response.rs | 1 + src/epp/response/contact.rs | 32 +++++++++++++++++++++++++ src/epp/response/domain.rs | 8 +------ 9 files changed, 120 insertions(+), 29 deletions(-) create mode 100644 src/epp/request/contact.rs create mode 100644 src/epp/response/contact.rs diff --git a/examples/client.rs b/examples/client.rs index d660e1b..2fb6e88 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -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::response; +use epp_client::{epp::request::generate_client_tr_id, connection::EppClient, connection, epp::xml::EppXml, epp::response::EppGreeting}; +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::(&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::(&contact_check).await.unwrap(); +} #[tokio::main] async fn main() { @@ -13,8 +30,7 @@ async fn main() { Err(e) => panic!("Error: {}", e) }; - let domains = vec!["eppdev.com", "hexonet.net"]; - let domain_check = domain::DomainCheck::epp_new(domains, generate_client_tr_id("eppdev").unwrap().as_str()); + check_domains(&client); - let response = client.transact::(&domain_check).await.unwrap(); + check_contacts(&mut client).await; } diff --git a/src/connection.rs b/src/connection.rs index d9447a2..e54ee5e 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -144,7 +144,7 @@ impl EppClient { }; 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::(&login_request).await?; @@ -177,7 +177,7 @@ impl EppClient { pub async fn logout(&mut self) { 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::(&epp_logout).await; } diff --git a/src/epp/object.rs b/src/epp/object.rs index dde2e3f..9eb347a 100644 --- a/src/epp/object.rs +++ b/src/epp/object.rs @@ -84,7 +84,7 @@ pub struct Services { } impl EppObject { - pub fn new(data: T) -> EppObject { + pub fn build(data: T) -> EppObject { EppObject { data: data, xmlns: EPP_XMLNS.to_string(), diff --git a/src/epp/request.rs b/src/epp/request.rs index 59e9601..b500692 100644 --- a/src/epp/request.rs +++ b/src/epp/request.rs @@ -1,3 +1,4 @@ +pub mod contact; pub mod domain; use serde::{Deserialize, Serialize}; @@ -29,9 +30,9 @@ impl ElementName for Hello { } } -impl Hello { - pub fn epp_new() -> EppHello { - EppObject::new(Hello {}) +impl EppHello { + pub fn new() -> EppHello { + EppObject::build(Hello {}) } } @@ -53,8 +54,8 @@ impl ElementName for Login { } } -impl Login { - pub fn epp_new(username: &str, password: &str, client_tr_id: &str) -> EppLogin { +impl EppLogin { + pub fn new(username: &str, password: &str, client_tr_id: &str) -> EppLogin { let login = Login { username: username.to_string_value(), password: password.to_string_value(), @@ -76,18 +77,18 @@ impl Login { }, }; - EppObject::new(Command:: { + EppObject::build(Command:: { command: login, client_tr_id: client_tr_id.to_string_value(), }) } pub fn set_options(&mut self, options: Options) { - self.options = options; + self.data.command.options = options; } 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")] pub struct Logout; -impl Logout { - pub fn epp_new(client_tr_id: &str) -> EppLogout { - EppObject::new(Command:: { +impl EppLogout { + pub fn new(client_tr_id: &str) -> EppLogout { + EppObject::build(Command:: { command: Logout, client_tr_id: client_tr_id.to_string_value(), }) diff --git a/src/epp/request/contact.rs b/src/epp/request/contact.rs new file mode 100644 index 0000000..4ce8d02 --- /dev/null +++ b/src/epp/request/contact.rs @@ -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>; + +#[derive(Serialize, Deserialize, Debug)] +pub struct ContactList { + pub xmlns: String, + #[serde(rename = "id")] + pub contact_ids: Vec, +} + +#[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::>(); + + let contact_check = ContactCheck { + list: ContactList { + xmlns: EPP_CONTACT_XMLNS.to_string(), + contact_ids: contact_ids, + }, + }; + + EppObject::build(Command:: { + command: contact_check, + client_tr_id: client_tr_id.to_string_value(), + }) + } +} diff --git a/src/epp/request/domain.rs b/src/epp/request/domain.rs index b7d0dae..b0123b0 100644 --- a/src/epp/request/domain.rs +++ b/src/epp/request/domain.rs @@ -25,8 +25,8 @@ impl ElementName for DomainCheck { } } -impl DomainCheck { - pub fn epp_new(domains: Vec<&str>, client_tr_id: &str) -> EppDomainCheck { +impl EppDomainCheck { + pub fn new(domains: Vec<&str>, client_tr_id: &str) -> EppDomainCheck { let domains = domains .iter() .filter_map(|d| Some(d.to_string_value())) @@ -39,7 +39,7 @@ impl DomainCheck { }, }; - EppObject::new(Command:: { + EppObject::build(Command:: { command: domain_check, client_tr_id: client_tr_id.to_string_value(), }) diff --git a/src/epp/response.rs b/src/epp/response.rs index 7d16254..f260544 100644 --- a/src/epp/response.rs +++ b/src/epp/response.rs @@ -1,3 +1,4 @@ +pub mod contact; pub mod domain; use serde::{Deserialize, Deserializer, Serialize}; diff --git a/src/epp/response/contact.rs b/src/epp/response/contact.rs new file mode 100644 index 0000000..789d7e0 --- /dev/null +++ b/src/epp/response/contact.rs @@ -0,0 +1,32 @@ +use serde::{Deserialize, Serialize}; + +use crate::epp::object::{EppObject, StringValue}; +use crate::epp::response::CommandResponse; + +pub type EppContactCheckResponse = EppObject>; + +#[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, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct ContactCheckData { + #[serde(rename = "cd")] + pub contact_list: Vec, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct ContactCheckResult { + #[serde(rename = "chkData")] + pub check_data: ContactCheckData, +} diff --git a/src/epp/response/domain.rs b/src/epp/response/domain.rs index c16ebbe..7212b50 100644 --- a/src/epp/response/domain.rs +++ b/src/epp/response/domain.rs @@ -5,18 +5,12 @@ use crate::epp::response::CommandResponse; pub type EppDomainCheckResponse = EppObject>; -#[derive(Serialize, Deserialize, Debug)] -pub enum Availability { - Unavailable, - Available, -} - #[derive(Serialize, Deserialize, Debug)] pub struct DomainCheck { #[serde(rename = "$value")] pub name: StringValue, #[serde(rename = "avail")] - pub avail: u16, + pub available: u16, } #[derive(Serialize, Deserialize, Debug)]