Skip to content

Commit

Permalink
added urls to contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
anewton1998 committed Sep 5, 2024
1 parent 59d690e commit 9d2820f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
3 changes: 2 additions & 1 deletion icann-rdap-client/src/md/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ impl ToMd for Entity {
.and_data_ul(&"Languages", contact.langs)
.and_data_ul(&"Phones", contact.phones)
.and_data_ul(&"Emails", contact.emails)
.and_data_ul(&"Web Contact", contact.contact_uris);
.and_data_ul(&"Web Contact", contact.contact_uris)
.and_data_ul(&"URLs", contact.urls);
table = contact.postal_addresses.add_to_mptable(table, params);
table = contact.name_parts.add_to_mptable(table, params)
}
Expand Down
17 changes: 15 additions & 2 deletions icann-rdap-common/src/contact/from_vcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl Contact {
.and_postal_addresses(vcard.find_properties("adr").get_postal_addresses())
.and_name_parts(vcard.find_property("n").get_name_parts())
.and_contact_uris(vcard.find_properties("contact-uri").get_texts())
.and_urls(vcard.find_properties("url").get_texts())
.build();

contact.is_non_empty().then_some(contact)
Expand Down Expand Up @@ -526,11 +527,13 @@ mod tests {
],
["tz", {},
"utc-offset", "-05:00"],
["url", { "type":"home" },
"uri", "https://example.org"],
["contact-uri", {},
"uri",
"https://example.com/contact-form"
],
["url", {},
"uri",
"https://example.com/some-url"
]
]
]
Expand Down Expand Up @@ -697,5 +700,15 @@ mod tests {
.expect("contact-uris empty"),
"https://example.com/contact-form"
);

// urls
assert_eq!(
actual
.urls
.expect("no urls")
.first()
.expect("urls are empty"),
"https://example.com/some-url"
);
}
}
4 changes: 4 additions & 0 deletions icann-rdap-common/src/contact/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ pub struct Contact {

/// Contact URIs.
pub contact_uris: Option<Vec<String>>,

/// URLs
pub urls: Option<Vec<String>>,
}

impl Contact {
Expand All @@ -154,6 +157,7 @@ impl Contact {
|| self.emails.is_some()
|| self.phones.is_some()
|| self.contact_uris.is_some()
|| self.urls.is_some()
}

/// Set the set of emails.
Expand Down
8 changes: 8 additions & 0 deletions icann-rdap-common/src/contact/to_vcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ impl Contact {
}
}

if let Some(urls) = &self.urls {
for url in urls {
vcard.push(json!(["url", {}, "uri", url]));
}
}

// return the vcard array
vec![Value::String("vcard".to_string()), Value::from(vcard)]
}
Expand Down Expand Up @@ -275,6 +281,7 @@ mod tests {
.contexts(vec!["work".to_string()])
.email("[email protected]")
.build()])
.urls(vec!["https://example.com/some-url".to_string()])
.build();

// WHEN
Expand All @@ -292,5 +299,6 @@ mod tests {
assert_eq!(contact.phones, actual.phones);
assert_eq!(contact.emails, actual.emails);
assert_eq!(contact.contact_uris, actual.contact_uris);
assert_eq!(contact.urls, actual.urls);
}
}

0 comments on commit 9d2820f

Please sign in to comment.