Move contact-related types from common to contact
This commit is contained in:
parent
93f8e0e8c8
commit
3935413b70
134
src/common.rs
134
src/common.rs
|
@ -1,6 +1,6 @@
|
||||||
//! Common data types included in EPP Requests and Responses
|
//! Common data types included in EPP Requests and Responses
|
||||||
|
|
||||||
use std::{fmt::Display, str::FromStr};
|
use std::fmt::Display;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -122,138 +122,6 @@ pub struct ObjectStatus {
|
||||||
pub status: String,
|
pub status: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The data for <voice> and <fax> types on domain transactions
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
||||||
pub struct Phone {
|
|
||||||
/// The inner text on the <voice> and <fax> tags
|
|
||||||
#[serde(rename = "$value")]
|
|
||||||
pub number: String,
|
|
||||||
/// The value of the 'x' attr on <voice> and <fax> tags
|
|
||||||
#[serde(rename = "x")]
|
|
||||||
pub extension: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The <addr> type on contact transactions
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
||||||
pub struct Address {
|
|
||||||
/// The <street> tags under <addr>
|
|
||||||
#[serde(rename = "contact:street", alias = "street")]
|
|
||||||
pub street: Vec<StringValue>,
|
|
||||||
/// The <city> tag under <addr>
|
|
||||||
#[serde(rename = "contact:city", alias = "city")]
|
|
||||||
pub city: StringValue,
|
|
||||||
/// The <sp> tag under <addr>
|
|
||||||
#[serde(rename = "contact:sp", alias = "sp")]
|
|
||||||
pub province: StringValue,
|
|
||||||
/// The <pc> tag under <addr>
|
|
||||||
#[serde(rename = "contact:pc", alias = "pc")]
|
|
||||||
pub postal_code: StringValue,
|
|
||||||
/// The <cc> tag under <addr>
|
|
||||||
#[serde(rename = "contact:cc", alias = "cc")]
|
|
||||||
pub country: Country,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
||||||
pub struct Country(celes::Country);
|
|
||||||
|
|
||||||
impl FromStr for Country {
|
|
||||||
type Err = <celes::Country as FromStr>::Err;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
Ok(Self(celes::Country::from_str(s)?))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::ops::Deref for Country {
|
|
||||||
type Target = celes::Country;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The <postalInfo> type on contact transactions
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
||||||
pub struct PostalInfo {
|
|
||||||
/// The 'type' attr on <postalInfo>
|
|
||||||
#[serde(rename = "type")]
|
|
||||||
pub info_type: String,
|
|
||||||
/// The <name> tag under <postalInfo>
|
|
||||||
#[serde(rename = "contact:name", alias = "name")]
|
|
||||||
pub name: StringValue,
|
|
||||||
/// The <org> tag under <postalInfo>
|
|
||||||
#[serde(rename = "contact:org", alias = "org")]
|
|
||||||
pub organization: StringValue,
|
|
||||||
/// The <addr> tag under <postalInfo>
|
|
||||||
#[serde(rename = "contact:addr", alias = "addr")]
|
|
||||||
pub address: Address,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The <authInfo> tag for domain and contact transactions
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
||||||
pub struct ContactAuthInfo {
|
|
||||||
/// The <pw> tag under <authInfo>
|
|
||||||
#[serde(rename = "contact:pw", alias = "pw")]
|
|
||||||
pub password: StringValue,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Phone {
|
|
||||||
/// Creates a new Phone instance with a given phone number
|
|
||||||
pub fn new(number: &str) -> Phone {
|
|
||||||
Phone {
|
|
||||||
extension: None,
|
|
||||||
number: number.to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the extension value of the Phone type
|
|
||||||
pub fn set_extension(&mut self, ext: &str) {
|
|
||||||
self.extension = Some(ext.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ContactAuthInfo {
|
|
||||||
/// Creates a ContactAuthInfo instance with the given password
|
|
||||||
pub fn new(password: &str) -> ContactAuthInfo {
|
|
||||||
ContactAuthInfo {
|
|
||||||
password: password.into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Address {
|
|
||||||
/// Creates a new Address instance
|
|
||||||
pub fn new(
|
|
||||||
street: &[&str],
|
|
||||||
city: &str,
|
|
||||||
province: &str,
|
|
||||||
postal_code: &str,
|
|
||||||
country: Country,
|
|
||||||
) -> Address {
|
|
||||||
let street = street.iter().map(|&s| s.into()).collect();
|
|
||||||
|
|
||||||
Address {
|
|
||||||
street,
|
|
||||||
city: city.into(),
|
|
||||||
province: province.into(),
|
|
||||||
postal_code: postal_code.into(),
|
|
||||||
country,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PostalInfo {
|
|
||||||
/// Creates a new PostalInfo instance
|
|
||||||
pub fn new(info_type: &str, name: &str, organization: &str, address: Address) -> PostalInfo {
|
|
||||||
PostalInfo {
|
|
||||||
info_type: info_type.to_string(),
|
|
||||||
name: name.into(),
|
|
||||||
organization: organization.into(),
|
|
||||||
address,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This type contains a single DER-encoded X.509 certificate.
|
/// This type contains a single DER-encoded X.509 certificate.
|
||||||
///
|
///
|
||||||
/// The rustls-pemfile crate can be used to parse a PEM file.
|
/// The rustls-pemfile crate can be used to parse a PEM file.
|
||||||
|
|
138
src/contact.rs
138
src/contact.rs
|
@ -1,3 +1,9 @@
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::common::StringValue;
|
||||||
|
|
||||||
pub mod check;
|
pub mod check;
|
||||||
pub mod create;
|
pub mod create;
|
||||||
pub mod delete;
|
pub mod delete;
|
||||||
|
@ -5,3 +11,135 @@ pub mod info;
|
||||||
pub mod update;
|
pub mod update;
|
||||||
|
|
||||||
pub const XMLNS: &str = "urn:ietf:params:xml:ns:contact-1.0";
|
pub const XMLNS: &str = "urn:ietf:params:xml:ns:contact-1.0";
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
pub struct Country(celes::Country);
|
||||||
|
|
||||||
|
impl FromStr for Country {
|
||||||
|
type Err = <celes::Country as FromStr>::Err;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
Ok(Self(celes::Country::from_str(s)?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::ops::Deref for Country {
|
||||||
|
type Target = celes::Country;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The <authInfo> tag for domain and contact transactions
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
pub struct ContactAuthInfo {
|
||||||
|
/// The <pw> tag under <authInfo>
|
||||||
|
#[serde(rename = "contact:pw", alias = "pw")]
|
||||||
|
pub password: StringValue,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ContactAuthInfo {
|
||||||
|
/// Creates a ContactAuthInfo instance with the given password
|
||||||
|
pub fn new(password: &str) -> ContactAuthInfo {
|
||||||
|
ContactAuthInfo {
|
||||||
|
password: password.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The data for <voice> and <fax> types on domain transactions
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
pub struct Phone {
|
||||||
|
/// The inner text on the <voice> and <fax> tags
|
||||||
|
#[serde(rename = "$value")]
|
||||||
|
pub number: String,
|
||||||
|
/// The value of the 'x' attr on <voice> and <fax> tags
|
||||||
|
#[serde(rename = "x")]
|
||||||
|
pub extension: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Phone {
|
||||||
|
/// Creates a new Phone instance with a given phone number
|
||||||
|
pub fn new(number: &str) -> Phone {
|
||||||
|
Phone {
|
||||||
|
extension: None,
|
||||||
|
number: number.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the extension value of the Phone type
|
||||||
|
pub fn set_extension(&mut self, ext: &str) {
|
||||||
|
self.extension = Some(ext.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The <addr> type on contact transactions
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
pub struct Address {
|
||||||
|
/// The <street> tags under <addr>
|
||||||
|
#[serde(rename = "contact:street", alias = "street")]
|
||||||
|
pub street: Vec<StringValue>,
|
||||||
|
/// The <city> tag under <addr>
|
||||||
|
#[serde(rename = "contact:city", alias = "city")]
|
||||||
|
pub city: StringValue,
|
||||||
|
/// The <sp> tag under <addr>
|
||||||
|
#[serde(rename = "contact:sp", alias = "sp")]
|
||||||
|
pub province: StringValue,
|
||||||
|
/// The <pc> tag under <addr>
|
||||||
|
#[serde(rename = "contact:pc", alias = "pc")]
|
||||||
|
pub postal_code: StringValue,
|
||||||
|
/// The <cc> tag under <addr>
|
||||||
|
#[serde(rename = "contact:cc", alias = "cc")]
|
||||||
|
pub country: Country,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Address {
|
||||||
|
/// Creates a new Address instance
|
||||||
|
pub fn new(
|
||||||
|
street: &[&str],
|
||||||
|
city: &str,
|
||||||
|
province: &str,
|
||||||
|
postal_code: &str,
|
||||||
|
country: Country,
|
||||||
|
) -> Address {
|
||||||
|
let street = street.iter().map(|&s| s.into()).collect();
|
||||||
|
|
||||||
|
Address {
|
||||||
|
street,
|
||||||
|
city: city.into(),
|
||||||
|
province: province.into(),
|
||||||
|
postal_code: postal_code.into(),
|
||||||
|
country,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The <postalInfo> type on contact transactions
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
pub struct PostalInfo {
|
||||||
|
/// The 'type' attr on <postalInfo>
|
||||||
|
#[serde(rename = "type")]
|
||||||
|
pub info_type: String,
|
||||||
|
/// The <name> tag under <postalInfo>
|
||||||
|
#[serde(rename = "contact:name", alias = "name")]
|
||||||
|
pub name: StringValue,
|
||||||
|
/// The <org> tag under <postalInfo>
|
||||||
|
#[serde(rename = "contact:org", alias = "org")]
|
||||||
|
pub organization: StringValue,
|
||||||
|
/// The <addr> tag under <postalInfo>
|
||||||
|
#[serde(rename = "contact:addr", alias = "addr")]
|
||||||
|
pub address: Address,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PostalInfo {
|
||||||
|
/// Creates a new PostalInfo instance
|
||||||
|
pub fn new(info_type: &str, name: &str, organization: &str, address: Address) -> PostalInfo {
|
||||||
|
PostalInfo {
|
||||||
|
info_type: info_type.to_string(),
|
||||||
|
name: name.into(),
|
||||||
|
organization: organization.into(),
|
||||||
|
address,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Types for EPP contact create request
|
//! Types for EPP contact create request
|
||||||
|
|
||||||
use super::XMLNS;
|
use super::{ContactAuthInfo, Phone, PostalInfo, XMLNS};
|
||||||
use crate::common::{ContactAuthInfo, NoExtension, Phone, PostalInfo, StringValue};
|
use crate::common::{NoExtension, StringValue};
|
||||||
use crate::request::{Command, Transaction};
|
use crate::request::{Command, Transaction};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -101,7 +101,8 @@ pub struct ContactCreateResponse {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{ContactCreate, Phone, PostalInfo};
|
use super::{ContactCreate, Phone, PostalInfo};
|
||||||
use crate::common::{Address, NoExtension};
|
use crate::common::NoExtension;
|
||||||
|
use crate::contact::Address;
|
||||||
use crate::request::Transaction;
|
use crate::request::Transaction;
|
||||||
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
|
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Types for EPP contact info request
|
//! Types for EPP contact info request
|
||||||
|
|
||||||
use super::XMLNS;
|
use super::{ContactAuthInfo, Phone, PostalInfo, XMLNS};
|
||||||
use crate::common::{ContactAuthInfo, NoExtension, ObjectStatus, Phone, PostalInfo, StringValue};
|
use crate::common::{NoExtension, ObjectStatus, StringValue};
|
||||||
use crate::request::{Command, Transaction};
|
use crate::request::{Command, Transaction};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Types for EPP contact create request
|
//! Types for EPP contact create request
|
||||||
|
|
||||||
use super::XMLNS;
|
use super::{ContactAuthInfo, Phone, PostalInfo, XMLNS};
|
||||||
use crate::common::{ContactAuthInfo, NoExtension, ObjectStatus, Phone, PostalInfo, StringValue};
|
use crate::common::{NoExtension, ObjectStatus, StringValue};
|
||||||
use crate::request::{Command, Transaction};
|
use crate::request::{Command, Transaction};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
@ -107,8 +107,9 @@ pub struct ContactUpdate {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::ContactUpdate;
|
use super::{ContactUpdate, Phone, PostalInfo};
|
||||||
use crate::common::{Address, NoExtension, ObjectStatus, Phone, PostalInfo};
|
use crate::common::{NoExtension, ObjectStatus};
|
||||||
|
use crate::contact::Address;
|
||||||
use crate::request::Transaction;
|
use crate::request::Transaction;
|
||||||
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
|
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue