Move contact-related types from common to contact

This commit is contained in:
Dirkjan Ochtman 2021-12-13 17:23:44 +01:00 committed by masalachai
parent 93f8e0e8c8
commit 3935413b70
5 changed files with 150 additions and 142 deletions

View File

@ -1,6 +1,6 @@
//! Common data types included in EPP Requests and Responses
use std::{fmt::Display, str::FromStr};
use std::fmt::Display;
use serde::{Deserialize, Serialize};
@ -122,138 +122,6 @@ pub struct ObjectStatus {
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 &lt;addr&gt; type on contact transactions
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Address {
/// The &lt;street&gt; tags under &lt;addr&gt;
#[serde(rename = "contact:street", alias = "street")]
pub street: Vec<StringValue>,
/// The &lt;city&gt; tag under &lt;addr&gt;
#[serde(rename = "contact:city", alias = "city")]
pub city: StringValue,
/// The &lt;sp&gt; tag under &lt;addr&gt;
#[serde(rename = "contact:sp", alias = "sp")]
pub province: StringValue,
/// The &lt;pc&gt; tag under &lt;addr&gt;
#[serde(rename = "contact:pc", alias = "pc")]
pub postal_code: StringValue,
/// The &lt;cc&gt; tag under &lt;addr&gt;
#[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 &lt;postalInfo&gt; type on contact transactions
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PostalInfo {
/// The 'type' attr on &lt;postalInfo&gt;
#[serde(rename = "type")]
pub info_type: String,
/// The &lt;name&gt; tag under &lt;postalInfo&gt;
#[serde(rename = "contact:name", alias = "name")]
pub name: StringValue,
/// The &lt;org&gt; tag under &lt;postalInfo&gt;
#[serde(rename = "contact:org", alias = "org")]
pub organization: StringValue,
/// The &lt;addr&gt; tag under &lt;postalInfo&gt;
#[serde(rename = "contact:addr", alias = "addr")]
pub address: Address,
}
/// The &lt;authInfo&gt; tag for domain and contact transactions
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ContactAuthInfo {
/// The &lt;pw&gt; tag under &lt;authInfo&gt;
#[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.
///
/// The rustls-pemfile crate can be used to parse a PEM file.

View File

@ -1,3 +1,9 @@
use std::str::FromStr;
use serde::{Deserialize, Serialize};
use crate::common::StringValue;
pub mod check;
pub mod create;
pub mod delete;
@ -5,3 +11,135 @@ pub mod info;
pub mod update;
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 &lt;authInfo&gt; tag for domain and contact transactions
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ContactAuthInfo {
/// The &lt;pw&gt; tag under &lt;authInfo&gt;
#[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 &lt;voice&gt; and &lt;fax&gt; types on domain transactions
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Phone {
/// The inner text on the &lt;voice&gt; and &lt;fax&gt; tags
#[serde(rename = "$value")]
pub number: String,
/// The value of the 'x' attr on &lt;voice&gt; and &lt;fax&gt; 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 &lt;addr&gt; type on contact transactions
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Address {
/// The &lt;street&gt; tags under &lt;addr&gt;
#[serde(rename = "contact:street", alias = "street")]
pub street: Vec<StringValue>,
/// The &lt;city&gt; tag under &lt;addr&gt;
#[serde(rename = "contact:city", alias = "city")]
pub city: StringValue,
/// The &lt;sp&gt; tag under &lt;addr&gt;
#[serde(rename = "contact:sp", alias = "sp")]
pub province: StringValue,
/// The &lt;pc&gt; tag under &lt;addr&gt;
#[serde(rename = "contact:pc", alias = "pc")]
pub postal_code: StringValue,
/// The &lt;cc&gt; tag under &lt;addr&gt;
#[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 &lt;postalInfo&gt; type on contact transactions
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PostalInfo {
/// The 'type' attr on &lt;postalInfo&gt;
#[serde(rename = "type")]
pub info_type: String,
/// The &lt;name&gt; tag under &lt;postalInfo&gt;
#[serde(rename = "contact:name", alias = "name")]
pub name: StringValue,
/// The &lt;org&gt; tag under &lt;postalInfo&gt;
#[serde(rename = "contact:org", alias = "org")]
pub organization: StringValue,
/// The &lt;addr&gt; tag under &lt;postalInfo&gt;
#[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,
}
}
}

View File

@ -1,7 +1,7 @@
//! Types for EPP contact create request
use super::XMLNS;
use crate::common::{ContactAuthInfo, NoExtension, Phone, PostalInfo, StringValue};
use super::{ContactAuthInfo, Phone, PostalInfo, XMLNS};
use crate::common::{NoExtension, StringValue};
use crate::request::{Command, Transaction};
use serde::{Deserialize, Serialize};
@ -101,7 +101,8 @@ pub struct ContactCreateResponse {
#[cfg(test)]
mod tests {
use super::{ContactCreate, Phone, PostalInfo};
use crate::common::{Address, NoExtension};
use crate::common::NoExtension;
use crate::contact::Address;
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};

View File

@ -1,7 +1,7 @@
//! Types for EPP contact info request
use super::XMLNS;
use crate::common::{ContactAuthInfo, NoExtension, ObjectStatus, Phone, PostalInfo, StringValue};
use super::{ContactAuthInfo, Phone, PostalInfo, XMLNS};
use crate::common::{NoExtension, ObjectStatus, StringValue};
use crate::request::{Command, Transaction};
use serde::{Deserialize, Serialize};

View File

@ -1,7 +1,7 @@
//! Types for EPP contact create request
use super::XMLNS;
use crate::common::{ContactAuthInfo, NoExtension, ObjectStatus, Phone, PostalInfo, StringValue};
use super::{ContactAuthInfo, Phone, PostalInfo, XMLNS};
use crate::common::{NoExtension, ObjectStatus, StringValue};
use crate::request::{Command, Transaction};
use serde::Serialize;
@ -107,8 +107,9 @@ pub struct ContactUpdate {
#[cfg(test)]
mod tests {
use super::ContactUpdate;
use crate::common::{Address, NoExtension, ObjectStatus, Phone, PostalInfo};
use super::{ContactUpdate, Phone, PostalInfo};
use crate::common::{NoExtension, ObjectStatus};
use crate::contact::Address;
use crate::request::Transaction;
use crate::tests::{get_xml, CLTRID, SUCCESS_MSG, SVTRID};