Use country type from celes
This commit is contained in:
parent
609c327a95
commit
9f41f4263e
|
@ -11,6 +11,7 @@ repository = "https://github.com/masalachai/epp-client"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
epp-client-macros = { version = "0.1", path = "../epp-client-macros" }
|
epp-client-macros = { version = "0.1", path = "../epp-client-macros" }
|
||||||
|
celes = "2.1"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
env_logger = "0.9"
|
env_logger = "0.9"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
|
@ -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;
|
use std::{fmt::Display, str::FromStr};
|
||||||
|
|
||||||
use epp_client_macros::ElementName;
|
use epp_client_macros::ElementName;
|
||||||
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
|
use serde::{ser::SerializeStruct, Deserialize, Serialize, Serializer};
|
||||||
|
@ -303,7 +303,26 @@ pub struct Address {
|
||||||
pub postal_code: StringValue,
|
pub postal_code: StringValue,
|
||||||
/// The <cc> tag under <addr>
|
/// The <cc> tag under <addr>
|
||||||
#[serde(rename = "contact:cc", alias = "cc")]
|
#[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 <postalInfo> type on contact transactions
|
/// The <postalInfo> type on contact transactions
|
||||||
|
@ -379,7 +398,7 @@ impl Address {
|
||||||
city: &str,
|
city: &str,
|
||||||
province: &str,
|
province: &str,
|
||||||
postal_code: &str,
|
postal_code: &str,
|
||||||
country_code: &str,
|
country: Country,
|
||||||
) -> Address {
|
) -> Address {
|
||||||
let street = street.iter().map(|&s| s.into()).collect();
|
let street = street.iter().map(|&s| s.into()).collect();
|
||||||
|
|
||||||
|
@ -388,7 +407,7 @@ impl Address {
|
||||||
city: city.into(),
|
city: city.into(),
|
||||||
province: province.into(),
|
province: province.into(),
|
||||||
postal_code: postal_code.into(),
|
postal_code: postal_code.into(),
|
||||||
country_code: country_code.into(),
|
country,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ impl<E: EppExtension> EppRequest<E> for ContactCreate<E> {
|
||||||
///
|
///
|
||||||
/// // Create the address, postal_info, voice instances
|
/// // Create the address, postal_info, voice instances
|
||||||
/// let street = vec!["58", "Orchid Road"];
|
/// 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 postal_info = PostalInfo::new("int", "John Doe", "Acme Widgets", address);
|
||||||
/// let mut voice = Phone::new("+1.47237942");
|
/// let mut voice = Phone::new("+1.47237942");
|
||||||
/// voice.set_extension("123");
|
/// voice.set_extension("123");
|
||||||
|
|
|
@ -199,10 +199,7 @@ mod response {
|
||||||
result.info_data.postal_info.address.postal_code,
|
result.info_data.postal_info.address.postal_code,
|
||||||
"392374".into()
|
"392374".into()
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(result.info_data.postal_info.address.country.alpha2, "FR");
|
||||||
result.info_data.postal_info.address.country_code,
|
|
||||||
"FR".into()
|
|
||||||
);
|
|
||||||
assert_eq!(result.info_data.voice.number, "+33.47237942".to_string());
|
assert_eq!(result.info_data.voice.number, "+33.47237942".to_string());
|
||||||
assert_eq!(*voice_ext, "123".to_string());
|
assert_eq!(*voice_ext, "123".to_string());
|
||||||
assert_eq!(fax.number, "+33.86698799".to_string());
|
assert_eq!(fax.number, "+33.86698799".to_string());
|
||||||
|
|
|
@ -93,7 +93,7 @@ mod request {
|
||||||
let xml = get_xml("request/contact/create.xml").unwrap();
|
let xml = get_xml("request/contact/create.xml").unwrap();
|
||||||
|
|
||||||
let street = &["58", "Orchid Road"];
|
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 postal_info = PostalInfo::new("int", "John Doe", "Acme Widgets", address);
|
||||||
let mut voice = Phone::new("+33.47237942");
|
let mut voice = Phone::new("+33.47237942");
|
||||||
voice.set_extension("123");
|
voice.set_extension("123");
|
||||||
|
@ -132,7 +132,7 @@ mod request {
|
||||||
let mut object = ContactUpdate::<NoExtension>::new("eppdev-contact-3");
|
let mut object = ContactUpdate::<NoExtension>::new("eppdev-contact-3");
|
||||||
|
|
||||||
let street = &["58", "Orchid Road"];
|
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 postal_info = PostalInfo::new("loc", "John Doe", "Acme Widgets", address);
|
||||||
let voice = Phone::new("+33.47237942");
|
let voice = Phone::new("+33.47237942");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue