Use country type from celes

This commit is contained in:
Dirkjan Ochtman 2021-12-02 10:41:52 +01:00 committed by masalachai
parent 609c327a95
commit 9f41f4263e
5 changed files with 28 additions and 11 deletions

View File

@ -11,6 +11,7 @@ repository = "https://github.com/masalachai/epp-client"
[dependencies]
epp-client-macros = { version = "0.1", path = "../epp-client-macros" }
celes = "2.1"
chrono = "0.4"
env_logger = "0.9"
log = "0.4"

View File

@ -1,6 +1,6 @@
//! Common data types included in EPP Requests and Responses
use std::fmt::Display;
use std::{fmt::Display, str::FromStr};
use epp_client_macros::ElementName;
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
@ -303,7 +303,26 @@ pub struct Address {
pub postal_code: StringValue,
/// The <cc> tag under <addr>
#[serde(rename = "contact:cc", alias = "cc")]
pub country_code: StringValue,
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
@ -379,7 +398,7 @@ impl Address {
city: &str,
province: &str,
postal_code: &str,
country_code: &str,
country: Country,
) -> Address {
let street = street.iter().map(|&s| s.into()).collect();
@ -388,7 +407,7 @@ impl Address {
city: city.into(),
province: province.into(),
postal_code: postal_code.into(),
country_code: country_code.into(),
country,
}
}
}

View File

@ -61,7 +61,7 @@ impl<E: EppExtension> EppRequest<E> for ContactCreate<E> {
///
/// // Create the address, postal_info, voice instances
/// let street = vec!["58", "Orchid Road"];
/// let address = Address::new(&street, "New York", "New York", "392374", "US");
/// let address = Address::new(&street, "New York", "New York", "392374", "US".parse().unwrap());
/// let postal_info = PostalInfo::new("int", "John Doe", "Acme Widgets", address);
/// let mut voice = Phone::new("+1.47237942");
/// voice.set_extension("123");

View File

@ -199,10 +199,7 @@ mod response {
result.info_data.postal_info.address.postal_code,
"392374".into()
);
assert_eq!(
result.info_data.postal_info.address.country_code,
"FR".into()
);
assert_eq!(result.info_data.postal_info.address.country.alpha2, "FR");
assert_eq!(result.info_data.voice.number, "+33.47237942".to_string());
assert_eq!(*voice_ext, "123".to_string());
assert_eq!(fax.number, "+33.86698799".to_string());

View File

@ -93,7 +93,7 @@ mod request {
let xml = get_xml("request/contact/create.xml").unwrap();
let street = &["58", "Orchid Road"];
let address = Address::new(street, "Paris", "Paris", "392374", "FR");
let address = Address::new(street, "Paris", "Paris", "392374", "FR".parse().unwrap());
let postal_info = PostalInfo::new("int", "John Doe", "Acme Widgets", address);
let mut voice = Phone::new("+33.47237942");
voice.set_extension("123");
@ -132,7 +132,7 @@ mod request {
let mut object = ContactUpdate::<NoExtension>::new("eppdev-contact-3");
let street = &["58", "Orchid Road"];
let address = Address::new(street, "Paris", "Paris", "392374", "FR");
let address = Address::new(street, "Paris", "Paris", "392374", "FR".parse().unwrap());
let postal_info = PostalInfo::new("loc", "John Doe", "Acme Widgets", address);
let voice = Phone::new("+33.47237942");