Skip to content

Commit e777428

Browse files
authored
Merge pull request #143 from icann/andy_dev
Multiple Issues
2 parents af6af2a + a705372 commit e777428

File tree

17 files changed

+649
-158
lines changed

17 files changed

+649
-158
lines changed

LICENSE-APACHE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
same "printed page" as the copyright notice for easier
188188
identification within third-party archives.
189189

190-
Copyright [yyyy] [name of copyright owner]
190+
Copyright 2025 Internet Corporation for Assigned Names and Numbers (ICANN)
191191

192192
Licensed under the Apache License, Version 2.0 (the "License");
193193
you may not use this file except in compliance with the License.

LICENSE-MIT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014-2016 Ning Sun and tojson_macros contributors
3+
Copyright (c) 2025 Internet Corporation for Assigned Names and Numbers (ICANN)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

icann-rdap-client/src/md/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,13 @@ pub(crate) fn events_to_table(
344344
) -> MultiPartTable {
345345
table = table.header_ref(&header_name.replace_md_chars());
346346
for event in events {
347+
let raw_event_date = event.event_date.to_owned().unwrap_or_default();
347348
let event_date = &event
348349
.event_date
349350
.to_owned()
350351
.unwrap_or("????".to_string())
351352
.format_date_time(params)
352-
.unwrap_or_default();
353+
.unwrap_or(format!("UKN FMT: {raw_event_date}"));
353354
let mut ul: Vec<&String> = vec![event_date];
354355
if let Some(event_actor) = &event.event_actor {
355356
ul.push(event_actor);

icann-rdap-common/src/contact/mod.rs

Lines changed: 204 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@
7676
//! ]"#;
7777
//!
7878
//! let data: Vec<Value> = serde_json::from_str(json).unwrap();
79-
//! let contact = Contact::from_vcard(&data);
79+
//! let contact = Contact::from_vcard(&data).unwrap();
80+
//!
81+
//! // use the getter functions to access the data.
82+
//! let kind = contact.kind();
83+
//! let email_addr = contact.emails().first().unwrap().email();
8084
//! ```
8185
8286
mod from_vcard;
@@ -249,6 +253,71 @@ impl Contact {
249253
self.postal_addresses = Some(vec![postal_address]);
250254
self
251255
}
256+
257+
/// Get the langs.
258+
pub fn langs(&self) -> &[Lang] {
259+
self.langs.as_deref().unwrap_or_default()
260+
}
261+
262+
/// Get the kind.
263+
pub fn kind(&self) -> Option<&str> {
264+
self.kind.as_deref()
265+
}
266+
267+
/// Get the full name.
268+
pub fn full_name(&self) -> Option<&str> {
269+
self.full_name.as_deref()
270+
}
271+
272+
/// Get the name parts.
273+
pub fn name_parts(&self) -> Option<&NameParts> {
274+
self.name_parts.as_ref()
275+
}
276+
277+
/// Get the nick names.
278+
pub fn nick_names(&self) -> &[String] {
279+
self.nick_names.as_deref().unwrap_or_default()
280+
}
281+
282+
/// Get the titles.
283+
pub fn titles(&self) -> &[String] {
284+
self.titles.as_deref().unwrap_or_default()
285+
}
286+
287+
/// Get the organizational roles.
288+
pub fn roles(&self) -> &[String] {
289+
self.roles.as_deref().unwrap_or_default()
290+
}
291+
292+
/// Get the organizational names.
293+
pub fn organizational_names(&self) -> &[String] {
294+
self.organization_names.as_deref().unwrap_or_default()
295+
}
296+
297+
/// Get the postal addresses.
298+
pub fn postal_addresses(&self) -> &[PostalAddress] {
299+
self.postal_addresses.as_deref().unwrap_or_default()
300+
}
301+
302+
/// Get the emails.
303+
pub fn emails(&self) -> &[Email] {
304+
self.emails.as_deref().unwrap_or_default()
305+
}
306+
307+
/// Get the phones.
308+
pub fn phones(&self) -> &[Phone] {
309+
self.phones.as_deref().unwrap_or_default()
310+
}
311+
312+
/// Get the contact uris.
313+
pub fn contact_uris(&self) -> &[String] {
314+
self.contact_uris.as_deref().unwrap_or_default()
315+
}
316+
317+
/// Get the URLs.
318+
pub fn urls(&self) -> &[String] {
319+
self.urls.as_deref().unwrap_or_default()
320+
}
252321
}
253322

254323
/// The language preference of the contact.
@@ -261,6 +330,18 @@ pub struct Lang {
261330
pub tag: String,
262331
}
263332

333+
impl Lang {
334+
/// Get the preference.
335+
pub fn preference(&self) -> Option<u64> {
336+
self.preference
337+
}
338+
339+
/// Get the RFC 5646 language tag.
340+
pub fn tag(&self) -> &str {
341+
self.tag.as_str()
342+
}
343+
}
344+
264345
impl Display for Lang {
265346
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
266347
if let Some(pref) = self.preference {
@@ -308,6 +389,31 @@ impl NameParts {
308389
suffixes: to_opt_vec(suffixes),
309390
}
310391
}
392+
393+
/// Get the name prefixes.
394+
pub fn prefixes(&self) -> &[String] {
395+
self.prefixes.as_deref().unwrap_or_default()
396+
}
397+
398+
/// Get the sur names.
399+
pub fn surnames(&self) -> &[String] {
400+
self.surnames.as_deref().unwrap_or_default()
401+
}
402+
403+
/// Get the middle names.
404+
pub fn middle_names(&self) -> &[String] {
405+
self.middle_names.as_deref().unwrap_or_default()
406+
}
407+
408+
/// Get the given names.
409+
pub fn given_names(&self) -> &[String] {
410+
self.given_names.as_deref().unwrap_or_default()
411+
}
412+
413+
/// Get the suffixes.
414+
pub fn suffixes(&self) -> &[String] {
415+
self.suffixes.as_deref().unwrap_or_default()
416+
}
311417
}
312418

313419
/// A postal address.
@@ -382,6 +488,68 @@ impl PostalAddress {
382488
postal_code,
383489
}
384490
}
491+
492+
/// Get the preference.
493+
pub fn preference(&self) -> Option<u64> {
494+
self.preference
495+
}
496+
497+
/// Get the contexts.
498+
pub fn contexts(&self) -> &[String] {
499+
self.contexts.as_deref().unwrap_or_default()
500+
}
501+
502+
/// Get the full address.
503+
///
504+
/// An unstructured address. An unstructured postal address is
505+
/// usually the complete postal address. That is, this string
506+
/// would contain the street address, country, region, postal code, etc...
507+
///
508+
/// Depending on how the postal address is given, it can either
509+
/// be structured or unstructured. If it is given as unstructured,
510+
/// then this value is populated.
511+
///
512+
/// It is possible that a single postal address is given as both,
513+
/// in which case this value is populated along with the other
514+
/// values of the postal address.
515+
pub fn full_address(&self) -> Option<&str> {
516+
self.full_address.as_deref()
517+
}
518+
519+
/// Get the street parts.
520+
pub fn street_parts(&self) -> &[String] {
521+
self.street_parts.as_deref().unwrap_or_default()
522+
}
523+
524+
/// Get the locality.
525+
pub fn locality(&self) -> Option<&str> {
526+
self.locality.as_deref()
527+
}
528+
529+
/// Get the region name.
530+
pub fn region_name(&self) -> Option<&str> {
531+
self.region_name.as_deref()
532+
}
533+
534+
/// Get the region code.
535+
pub fn region_code(&self) -> Option<&str> {
536+
self.region_code.as_deref()
537+
}
538+
539+
/// Get the country name.
540+
pub fn country_name(&self) -> Option<&str> {
541+
self.country_name.as_deref()
542+
}
543+
544+
/// Get the country code.
545+
pub fn country_code(&self) -> Option<&str> {
546+
self.country_code.as_deref()
547+
}
548+
549+
/// Get the postal code.
550+
pub fn postal_code(&self) -> Option<&str> {
551+
self.postal_code.as_deref()
552+
}
385553
}
386554

387555
/// Represents an email address.
@@ -407,6 +575,21 @@ impl Email {
407575
email,
408576
}
409577
}
578+
579+
/// Get the preference.
580+
pub fn preference(&self) -> Option<u64> {
581+
self.preference
582+
}
583+
584+
/// Get the contexts.
585+
pub fn contexts(&self) -> &[String] {
586+
self.contexts.as_deref().unwrap_or_default()
587+
}
588+
589+
/// Get the email address.
590+
pub fn email(&self) -> &str {
591+
self.email.as_str()
592+
}
410593
}
411594

412595
impl Display for Email {
@@ -459,6 +642,26 @@ impl Phone {
459642
features: to_opt_vec(features),
460643
}
461644
}
645+
646+
/// Get the preference.
647+
pub fn preference(&self) -> Option<u64> {
648+
self.preference
649+
}
650+
651+
/// Get the contexts.
652+
pub fn contexts(&self) -> &[String] {
653+
self.contexts.as_deref().unwrap_or_default()
654+
}
655+
656+
/// Get the phone number.
657+
pub fn phone(&self) -> &str {
658+
self.phone.as_str()
659+
}
660+
661+
/// Get the phone features.
662+
pub fn features(&self) -> &[String] {
663+
self.features.as_deref().unwrap_or_default()
664+
}
462665
}
463666

464667
impl Display for Phone {

icann-rdap-common/src/response/autnum.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ use super::{
4242
/// "endAutnum": 710
4343
/// }
4444
/// ```
45+
///
46+
/// Use the getter functions to get the autnum data.
47+
/// See [CommonFields] and [ObjectCommonFields] for common getter functions.
48+
/// ```rust
49+
/// # use icann_rdap_common::prelude::*;
50+
/// # let autnum = Autnum::builder()
51+
/// # .autnum_range(700..710) // the range of autnums
52+
/// # .handle("AS700-1")
53+
/// # .build();
54+
/// let start_autnum = autnum.start_autnum();
55+
/// let end_autnum = autnum.end_autnum();
56+
/// let handle = autnum.handle();
57+
/// ```
4558
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
4659
pub struct Autnum {
4760
#[serde(flatten)]
@@ -77,7 +90,7 @@ impl Autnum {
7790
/// use icann_rdap_common::prelude::*;
7891
///
7992
/// let autnum = Autnum::builder()
80-
/// .autnum_range(700..710)
93+
/// .autnum_range(700..710) //required for this builder
8194
/// .handle("AS700-1")
8295
/// .status("active")
8396
/// .build();

icann-rdap-common/src/response/common.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,25 @@ impl Common {
2626
}
2727
}
2828

29-
/// Empty Extensions.
30-
static EMPTY_EXTENSIONS: Vec<Extension> = vec![];
31-
/// Empty Notices.
32-
static EMPTY_NOTICES: Vec<Notice> = vec![];
33-
3429
/// Convience methods for fields in [Common].
3530
pub trait CommonFields {
3631
/// Getter for [Common].
3732
fn common(&self) -> &Common;
3833

39-
/// Getter for Vec of RDAP extensions.
40-
fn extensions(&self) -> &Vec<Extension> {
34+
/// Getter for the list of RDAP extensions.
35+
///
36+
/// In valid RDAP, this only appears on the top most object.
37+
fn extensions(&self) -> &[Extension] {
4138
self.common()
4239
.rdap_conformance
43-
.as_ref()
44-
.unwrap_or(&EMPTY_EXTENSIONS)
40+
.as_deref()
41+
.unwrap_or_default()
4542
}
4643

47-
/// Getter for Vec of Notices.
48-
fn notices(&self) -> &Vec<Notice> {
49-
self.common().notices.as_ref().unwrap_or(&EMPTY_NOTICES)
44+
/// Getter for the Notices.
45+
///
46+
/// In valid RDAP, this only appears on the top most object.
47+
fn notices(&self) -> &[Notice] {
48+
self.common().notices.as_deref().unwrap_or_default()
5049
}
5150
}

0 commit comments

Comments
 (0)