1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
// Copyright (C) 2019 University of Glasgow
// 
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions 
// are met:
// 
// 1. Redistributions of source code must retain the above copyright notice,
//    this list of conditions and the following disclaimer.
// 
// 2. Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// SPDX-License-Identifier: BSD-2-Clause

// This library contains code to interact with the IETF Datatracker
// (https://datatracker.ietf.org/release/about)
//
// The Datatracker API is at https://datatracker.ietf.org/api/v1 and is
// a REST API implemented using Django Tastypie (http://tastypieapi.org)
//
// It's possible to do time range queries on many of these values, for example:
//   https://datatracker.ietf.org/api/v1/person/person/?time__gt=2018-03-27T14:07:36
//
// See also:
//   https://datatracker.ietf.org/api/
//   https://trac.tools.ietf.org/tools/ietfdb/wiki/DatabaseSchemaDescription
//   https://trac.tools.ietf.org/tools/ietfdb/wiki/DatatrackerDrafts
//   RFC 6174 "Definition of IETF Working Group Document States"
//   RFC 6175 "Requirements to Extend the Datatracker for IETF Working Group Chairs and Authors"
//   RFC 6292 "Requirements for a Working Group Charter Tool"
//   RFC 6293 "Requirements for Internet-Draft Tracking by the IETF Community in the Datatracker"
//   RFC 6322 "Datatracker States and Annotations for the IAB, IRTF, and Independent Submission Streams"
//   RFC 6359 "Datatracker Extensions to Include IANA and RFC Editor Processing Information"
//   RFC 7760 "Statement of Work for Extensions to the IETF Datatracker for Author Statistics"

extern crate chrono;
extern crate reqwest;
extern crate serde;
extern crate serde_json;

use chrono::prelude::*;
use serde::{Deserialize, Deserializer};
use std::error;
use std::fmt;

// =================================================================================================================================
// Helper functions:

fn deserialize_time<'de, D>(deserializer: D) -> Result<DateTime<Utc>, D::Error>
    where D: Deserializer<'de>
{
    let s = String::deserialize(deserializer)?;
    Utc.datetime_from_str(&s, "%Y-%m-%dT%H:%M:%S%.f").map_err(serde::de::Error::custom)
}

// Generic types representing a paginated list of responses from the Datatracker:

#[derive(Deserialize, Debug)]
struct Meta {
    total_count : u32,
    limit       : u32,
    offset      : u32,
    previous    : Option<String>,
    next        : Option<String>
}

#[derive(Deserialize, Debug)]
struct Page<T> {
    meta        : Meta,
    objects     : Vec<T>
}

pub struct PaginatedList<'a, T> {
    iter : <Vec<T> as IntoIterator>::IntoIter,
    next : Option<String>,
    dt   : &'a Datatracker
}

impl<'a, T> PaginatedList<'a, T>
    where for<'de> T: Deserialize<'de>
{
    pub fn new(dt: &'a Datatracker, url : String) -> Result<Self, DatatrackerError> {
        let mut res = dt.connection.get(&url).send()?;
        let pl : Page<T> = res.json()?;

        Ok(Self {
            next : pl.meta.next.clone(),
            iter : pl.objects.into_iter(),
            dt   : dt
        })
    }

    fn try_next(&mut self) -> Result<Option<T>, DatatrackerError> {
        match self.iter.next() {
            Some(x) => {
                Ok(Some(x))
            }
            None => {
                match self.next.clone() {
                    Some(ref url_frag) => {
                        let url = format!("https://datatracker.ietf.org/{}", url_frag);
                        let mut res = self.dt.connection.get(&url).send()?;
                        let pl : Page<T> = res.json()?;
                        self.next = pl.meta.next.clone();
                        self.iter = pl.objects.into_iter();
                        self.try_next()
                    }
                    None => {
                        Ok(None)
                    }
                }
            }
        }
    }
}

impl<'a, T> Iterator for PaginatedList<'a, T>
    where for<'de> T: Deserialize<'de>
{
    type Item = Result<T, DatatrackerError>;

    fn next(&mut self) -> Option<Self::Item> {
        match self.try_next() {
            Ok(None)    => None,
            Ok(Some(x)) => Some(Ok(x)),
            Err(e)      => Some(Err(e))
        }
    }
}

// =================================================================================================================================
// IETF Datatracker types:

#[derive(Deserialize, Debug, Eq, PartialEq)]
pub struct EmailUri(String);

/// A mapping from email address to person in the IETF datatracker.
#[derive(Deserialize, Debug)]
pub struct Email {
    pub resource_uri : EmailUri,
    pub address      : String,
    pub person       : PersonUri,
    #[serde(deserialize_with="deserialize_time")]
    pub time         : DateTime<Utc>,
    pub origin       : String,
    pub primary      : bool,
    pub active       : bool
}

#[derive(Deserialize, Debug, Eq, PartialEq)]
pub struct HistoricalEmailUri(String);

#[derive(Deserialize, Debug)]
pub struct HistoricalEmail {
    // Fields common with Email:
    pub resource_uri          : HistoricalEmailUri,
    pub address               : String,
    pub person                : PersonUri,
    #[serde(deserialize_with="deserialize_time")]
    pub time                  : DateTime<Utc>,
    pub origin                : String,
    pub primary               : bool,
    pub active                : bool,
    // Fields recording the history:
    pub history_change_reason : Option<String>,
    pub history_user          : Option<String>,
    pub history_id            : u64,
    pub history_type          : String,
    #[serde(deserialize_with="deserialize_time")]
    pub history_date          : DateTime<Utc>
}


#[derive(Deserialize, Debug, Eq, PartialEq)]
pub struct PersonUri(String);

/// A person in the IETF datatracker.
#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct Person {
    pub id              : u64,
    pub resource_uri    : PersonUri,
    pub name            : String,
    pub name_from_draft : Option<String>,
    pub biography       : String,
    pub ascii           : String,
    pub ascii_short     : Option<String>,
    #[serde(deserialize_with="deserialize_time")]
    pub time            : DateTime<Utc>,
    pub photo           : Option<String>,  // Actually a URL
    pub photo_thumb     : Option<String>,  // Actually a URL
    pub user            : Option<String>,
    pub consent         : Option<bool>
}

#[derive(Deserialize, Debug, Eq, PartialEq)]
pub struct HistoricalPersonUri(String);

/// A historical person in the IETF datatracker.
#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct HistoricalPerson {
    // Fields common with Person:
    pub id                    : u64,
    pub resource_uri          : HistoricalPersonUri,
    pub name                  : String,
    pub name_from_draft       : String,
    pub biography             : String,
    pub ascii                 : String,
    pub ascii_short           : Option<String>,
    #[serde(deserialize_with="deserialize_time")]
    pub time                  : DateTime<Utc>,
    pub photo                 : Option<String>, // Actually a URL
    pub photo_thumb           : Option<String>, // Actually a URL
    pub user                  : String,
    pub consent               : Option<bool>,
    // Fields recording the history:
    pub history_change_reason : Option<String>,
    pub history_user          : String,
    pub history_type          : String,
    pub history_id            : u64,
    #[serde(deserialize_with="deserialize_time")]
    pub history_date          : DateTime<Utc>,
}

#[derive(Deserialize, Debug, Eq, PartialEq)]
pub struct PersonAliasUri(String);

/// An alias in the IETF datatracker.
#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct PersonAlias {
    pub id           : u64,
    pub resource_uri : PersonAliasUri,
    pub person       : PersonUri,
    pub name         : String,
}

// =================================================================================================================================
// The DatatrackerError type:

#[derive(Debug)]
pub enum DatatrackerError {
    NotFound,
    IoError(reqwest::Error)
}

impl fmt::Display for DatatrackerError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            DatatrackerError::NotFound => write!(f, "Not found"),
            DatatrackerError::IoError(ref e) => e.fmt(f)
        }
    }
}

impl error::Error for DatatrackerError {
    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
        match *self {
            DatatrackerError::NotFound => None,
            DatatrackerError::IoError(ref e) => Some(e)
        }
    }
}

impl From<reqwest::Error> for DatatrackerError {
    fn from(err: reqwest::Error) -> DatatrackerError {
        DatatrackerError::IoError(err)
    }
}

// =================================================================================================================================
// IETF Datatracker API:

pub struct Datatracker {
    connection : reqwest::Client
}

impl Datatracker {
    fn retrieve<T>(&self, url : &str) -> Result<T, DatatrackerError>
        where for<'de> T: Deserialize<'de> 
    {
        let mut res = self.connection.get(url).send()?;
        if res.status().is_success() {
            let res : T = res.json()?;
            Ok(res)
        } else {
            Err(DatatrackerError::NotFound)
        }
    }

    pub fn new() -> Self {
        Datatracker {
            connection : reqwest::Client::new()
        }
    }

    // ----------------------------------------------------------------------------------------------------------------------------
    // Datatracker API endpoints returning information about email addresses:
    // * https://datatracker.ietf.org/api/v1/person/email/csp@csperkins.org/
    // * https://datatracker.ietf.org/api/v1/person/historicalemail/

    /// Retrieve information about an email address.
    ///
    /// This returns the information held about a particular email address.
    /// If you want information about the person with a particular address,
    /// use `person_from_email()`.
    pub fn email(&self, email : &str) -> Result<Email, DatatrackerError> {
        let url = format!("https://datatracker.ietf.org/api/v1/person/email/{}/", email);
        self.retrieve::<Email>(&url)
    }

    pub fn email_history_for_address<'a>(&'a self, email : &'a str) -> Result<PaginatedList<HistoricalEmail>, DatatrackerError> {
        let url = format!("https://datatracker.ietf.org/api/v1/person/historicalemail/?address={}", email);
        PaginatedList::<'a, HistoricalEmail>::new(self, url)
    }

    pub fn email_history_for_person<'a>(&'a self, person : &'a Person) -> Result<PaginatedList<HistoricalEmail>, DatatrackerError> {
        let url = format!("https://datatracker.ietf.org/api/v1/person/historicalemail/?person={}", person.id);
        PaginatedList::<'a, HistoricalEmail>::new(self, url)
    }

    // ----------------------------------------------------------------------------------------------------------------------------
    // Datatracker API endpoints returning information about people:
    // * https://datatracker.ietf.org/api/v1/person/person/20209/
    // * https://datatracker.ietf.org/api/v1/person/person/
    // * https://datatracker.ietf.org/api/v1/person/historicalperson/
    // * https://datatracker.ietf.org/api/v1/person/alias/

    pub fn person(&self, person_uri : &PersonUri) -> Result<Person, DatatrackerError> {
        assert!(person_uri.0.starts_with("/api/v1/person/person/"));
        let url = format!("https://datatracker.ietf.org/{}/", person_uri.0);
        self.retrieve::<Person>(&url)
    }

    pub fn person_from_email(&self, email : &str) -> Result<Person, DatatrackerError> {
        let person = self.email(email)?.person;
        self.person(&person)
    }

    pub fn person_aliases<'a>(&'a self, person : &'a Person) -> Result<PaginatedList<PersonAlias>, DatatrackerError> {
        let url = format!("https://datatracker.ietf.org/api/v1/person/alias/?person={}", person.id);
        PaginatedList::<'a, PersonAlias>::new(self, url)
    }

    pub fn person_history<'a>(&'a self, person : &'a Person) -> Result<PaginatedList<HistoricalPerson>, DatatrackerError> {
        let url = format!("https://datatracker.ietf.org/api/v1/person/historicalperson/?id={}", person.id);
        PaginatedList::<'a, HistoricalPerson>::new(self, url)
    }

    pub fn people<'a>(&'a self) -> Result<PaginatedList<'a, Person>, DatatrackerError> {
        let url = format!("https://datatracker.ietf.org/api/v1/person/person/");
        PaginatedList::<'a, Person>::new(self, url)
    }

    pub fn people_with_name<'a>(&'a self, name: &'a str) -> Result<PaginatedList<'a, Person>, DatatrackerError> {
        let url = format!("https://datatracker.ietf.org/api/v1/person/person/?name={}", name);
        PaginatedList::<'a, Person>::new(self, url)
    }

    pub fn people_with_name_containing<'a>(&'a self, name_contains: &'a str) 
        -> Result<PaginatedList<'a, Person>, DatatrackerError> 
    {
        let url = format!("https://datatracker.ietf.org/api/v1/person/person/?name__contains={}", name_contains);
        PaginatedList::<'a, Person>::new(self, url)
    }

    pub fn people_between<'a>(&'a self, start: DateTime<Utc>, before: DateTime<Utc>) 
        -> Result<PaginatedList<'a, Person>, DatatrackerError> 
    {
        let s =  start.format("%Y-%m-%dT%H:%M:%S");
        let b = before.format("%Y-%m-%dT%H:%M:%S");
        let url = format!("https://datatracker.ietf.org/api/v1/person/person/?time__gte={}&time__lt={}", &s, &b);
        PaginatedList::<'a, Person>::new(self, url)
    }

    // ----------------------------------------------------------------------------------------------------------------------------
    // Datatracker API endpoints returning information about documents:
    //   https://datatracker.ietf.org/api/v1/doc/document/                        - list of documents
    //   https://datatracker.ietf.org/api/v1/doc/document/draft-ietf-avt-rtp-new/ - info about document
    //   https://datatracker.ietf.org/api/v1/doc/docalias/?name=/                 - draft that became the given RFC
    //   https://datatracker.ietf.org/api/v1/doc/state/                           - Types of state a document can be in
    //   https://datatracker.ietf.org/api/v1/doc/statetype/                       - Possible types of state for a document
    //   https://datatracker.ietf.org/api/v1/doc/docevent/                        - list of document events
    //   https://datatracker.ietf.org/api/v1/doc/docevent/?doc=...                - events for a document
    //   https://datatracker.ietf.org/api/v1/doc/docevent/?by=...                 - events by a person (as /api/v1/person/person)
    //   https://datatracker.ietf.org/api/v1/doc/docevent/?time=...               - events by time
    //   https://datatracker.ietf.org/api/v1/doc/documentauthor/?document=...     - authors of a document
    //   https://datatracker.ietf.org/api/v1/doc/documentauthor/?person=...       - documents by person (as /api/v1/person/person)
    //   https://datatracker.ietf.org/api/v1/doc/documentauthor/?email=...        - documents by person with particular email
    //   https://datatracker.ietf.org/api/v1/doc/dochistory/
    //   https://datatracker.ietf.org/api/v1/doc/dochistoryauthor/
    //   https://datatracker.ietf.org/api/v1/doc/docreminder/
    //   https://datatracker.ietf.org/api/v1/doc/documenturl/
    //   https://datatracker.ietf.org/api/v1/doc/statedocevent/                   - subset of /api/v1/doc/docevent/; same parameters
    //   https://datatracker.ietf.org/api/v1/doc/ballotdocevent/                  -               "                "
    //   https://datatracker.ietf.org/api/v1/doc/newrevisiondocevent/             -               "                "
    //   https://datatracker.ietf.org/api/v1/doc/submissiondocevent/              -               "                "
    //   https://datatracker.ietf.org/api/v1/doc/writeupdocevent/                 -               "                "
    //   https://datatracker.ietf.org/api/v1/doc/consensusdocevent/               -               "                "
    //   https://datatracker.ietf.org/api/v1/doc/ballotpositiondocevent/          -               "                "
    //   https://datatracker.ietf.org/api/v1/doc/reviewrequestdocevent/           -               "                "
    //   https://datatracker.ietf.org/api/v1/doc/lastcalldocevent/                -               "                "
    //   https://datatracker.ietf.org/api/v1/doc/telechatdocevent/                -               "                "
    //   https://datatracker.ietf.org/api/v1/doc/relateddocument/?source=...      - documents that source draft relates to (references, replaces, etc)
    //   https://datatracker.ietf.org/api/v1/doc/relateddocument/?target=...      - documents that relate to target draft
    //   https://datatracker.ietf.org/api/v1/doc/ballottype/                      - Types of ballot that can be issued on a document
    //   https://datatracker.ietf.org/api/v1/doc/relateddochistory/
    //   https://datatracker.ietf.org/api/v1/doc/initialreviewdocevent/
    //   https://datatracker.ietf.org/api/v1/doc/deletedevent/
    //   https://datatracker.ietf.org/api/v1/doc/addedmessageevent/
    //   https://datatracker.ietf.org/api/v1/doc/editedauthorsdocevent/



    // ----------------------------------------------------------------------------------------------------------------------------
    // Datatracker API endpoints returning information about names:
    //   https://datatracker.ietf.org/api/v1/name/doctypename/
    //   https://datatracker.ietf.org/api/v1/name/streamname/
    //   https://datatracker.ietf.org/api/v1/name/dbtemplatetypename/
    //   https://datatracker.ietf.org/api/v1/name/docrelationshipname/
    //   https://datatracker.ietf.org/api/v1/name/doctagname/
    //   https://datatracker.ietf.org/api/v1/name/docurltagname/
    //   https://datatracker.ietf.org/api/v1/name/groupstatename/
    //   https://datatracker.ietf.org/api/v1/name/formallanguagename/
    //   https://datatracker.ietf.org/api/v1/name/timeslottypename/
    //   https://datatracker.ietf.org/api/v1/name/liaisonstatementeventtypename/
    //   https://datatracker.ietf.org/api/v1/name/stdlevelname/
    //   https://datatracker.ietf.org/api/v1/name/ballotpositionname/
    //   https://datatracker.ietf.org/api/v1/name/reviewrequeststatename/
    //   https://datatracker.ietf.org/api/v1/name/groupmilestonestatename/
    //   https://datatracker.ietf.org/api/v1/name/iprlicensetypename/
    //   https://datatracker.ietf.org/api/v1/name/feedbacktypename/
    //   https://datatracker.ietf.org/api/v1/name/reviewtypename/
    //   https://datatracker.ietf.org/api/v1/name/iprdisclosurestatename/
    //   https://datatracker.ietf.org/api/v1/name/reviewresultname/
    //   https://datatracker.ietf.org/api/v1/name/liaisonstatementstate/
    //   https://datatracker.ietf.org/api/v1/name/roomresourcename/
    //   https://datatracker.ietf.org/api/v1/name/liaisonstatementtagname/
    //   https://datatracker.ietf.org/api/v1/name/topicaudiencename/
    //   https://datatracker.ietf.org/api/v1/name/continentname/
    //   https://datatracker.ietf.org/api/v1/name/nomineepositionstatename/
    //   https://datatracker.ietf.org/api/v1/name/importantdatename/
    //   https://datatracker.ietf.org/api/v1/name/liaisonstatementpurposename/
    //   https://datatracker.ietf.org/api/v1/name/constraintname/
    //   https://datatracker.ietf.org/api/v1/name/sessionstatusname/
    //   https://datatracker.ietf.org/api/v1/name/ipreventtypename/
    //   https://datatracker.ietf.org/api/v1/name/agendatypename/
    //   https://datatracker.ietf.org/api/v1/name/docremindertypename/
    //   https://datatracker.ietf.org/api/v1/name/intendedstdlevelname/
    //   https://datatracker.ietf.org/api/v1/name/countryname/
    //   https://datatracker.ietf.org/api/v1/name/grouptypename/
    //   https://datatracker.ietf.org/api/v1/name/draftsubmissionstatename/
    //   https://datatracker.ietf.org/api/v1/name/rolename/



    // ----------------------------------------------------------------------------------------------------------------------------
    // Datatracker API endpoints returning information about working groups:
    //   https://datatracker.ietf.org/api/v1/group/group/                               - list of groups
    //   https://datatracker.ietf.org/api/v1/group/group/2161/                          - info about group 2161
    //   https://datatracker.ietf.org/api/v1/group/grouphistory/?group=2161             - history
    //   https://datatracker.ietf.org/api/v1/group/groupurl/?group=2161                 - URLs
    //   https://datatracker.ietf.org/api/v1/group/groupevent/?group=2161               - events
    //   https://datatracker.ietf.org/api/v1/group/groupmilestone/?group=2161           - Current milestones
    //   https://datatracker.ietf.org/api/v1/group/groupmilestonehistory/?group=2161    - Previous milestones
    //   https://datatracker.ietf.org/api/v1/group/milestonegroupevent/?group=2161      - changed milestones
    //   https://datatracker.ietf.org/api/v1/group/role/?group=2161                     - The current WG chairs and ADs of a group
    //   https://datatracker.ietf.org/api/v1/group/role/?person=20209                   - Groups a person is currently involved with
    //   https://datatracker.ietf.org/api/v1/group/role/?email=csp@csperkins.org        - Groups a person is currently involved with
    //   https://datatracker.ietf.org/api/v1/group/rolehistory/?group=2161              - The previous WG chairs and ADs of a group
    //   https://datatracker.ietf.org/api/v1/group/rolehistory/?person=20209            - Groups person was previously involved with
    //   https://datatracker.ietf.org/api/v1/group/rolehistory/?email=csp@csperkins.org - Groups person was previously involved with
    //   https://datatracker.ietf.org/api/v1/group/changestategroupevent/?group=2161    - Group state changes
    //   https://datatracker.ietf.org/api/v1/group/groupstatetransitions                - ???



    // ----------------------------------------------------------------------------------------------------------------------------
    // Datatracker API endpoints returning information about meetings:
    //   https://datatracker.ietf.org/api/v1/meeting/meeting/                        - list of meetings
    //   https://datatracker.ietf.org/api/v1/meeting/meeting/747/                    - information about meeting number 747
    //   https://datatracker.ietf.org/api/v1/meeting/session/                        - list of all sessions in meetings
    //   https://datatracker.ietf.org/api/v1/meeting/session/25886/                  - a session in a meeting
    //   https://datatracker.ietf.org/api/v1/meeting/session/?meeting=747            - sessions in meeting number 747
    //   https://datatracker.ietf.org/api/v1/meeting/session/?meeting=747&group=2161 - sessions in meeting number 747 for group 2161
    //   https://datatracker.ietf.org/api/v1/meeting/schedtimesessassignment/59003/  - a schededuled session within a meeting
    //   https://datatracker.ietf.org/api/v1/meeting/timeslot/9480/                  - a time slot within a meeting (time, duration, location)
    //   https://datatracker.ietf.org/api/v1/meeting/schedule/791/                   - a draft of the meeting agenda
    //   https://datatracker.ietf.org/api/v1/meeting/room/537/                       - a room at a meeting
    //   https://datatracker.ietf.org/api/v1/meeting/floorplan/14/                   - floor plan for a meeting venue
    //   https://datatracker.ietf.org/api/v1/name/meetingtypename/



}
// =================================================================================================================================
// Test suite:

#[cfg(test)]
mod ietfdata_tests {
    use super::*;

    #[test]
    fn test_email() -> Result<(), DatatrackerError> {
        let dt = Datatracker::new();
        let e  = dt.email("csp@csperkins.org")?;

        assert_eq!(e.resource_uri, EmailUri("/api/v1/person/email/csp@csperkins.org/".to_string()));
        assert_eq!(e.address,      "csp@csperkins.org");
        assert_eq!(e.person,       PersonUri("/api/v1/person/person/20209/".to_string()));
        assert_eq!(e.time,         Utc.ymd(1970, 1, 1).and_hms(23, 59, 59));
        assert_eq!(e.origin,       "author: draft-ietf-mmusic-rfc4566bis");
        assert_eq!(e.primary,      true);
        assert_eq!(e.active,       true);

        // Lookup a non-existing address; this should fail
        assert!(dt.email("nobody@example.com").is_err());

        Ok(())
    }

    #[test]
    fn test_email_history_for_address() -> Result<(), DatatrackerError> {
        let dt = Datatracker::new();
        let h  = dt.email_history_for_address("csp@isi.edu")?.collect::<Result<Vec<_>, _>>()?;

        assert_eq!(h.len(), 1);
        assert_eq!(h[0].address, "csp@isi.edu");
        assert_eq!(h[0].person,  PersonUri("/api/v1/person/person/20209/".to_string()));

        Ok(())
    }

/*
    #[test]
    fn test_email_history_for_person() -> Result<(), DatatrackerError> {
        let dt = Datatracker::new();
        let p  = dt.person_from_email("csp@csperkins.org")?;
        for h in dt.email_history_for_person(&p) {
            println!("{:?}", h);
        }
        Ok(())
    }
*/

    #[test]
    fn test_person() -> Result<(), DatatrackerError> {
        let dt = Datatracker::new();
        let p  = dt.person(&PersonUri("/api/v1/person/person/20209/".to_string()))?;

        assert_eq!(p.id,              20209);
        assert_eq!(p.resource_uri,    PersonUri("/api/v1/person/person/20209/".to_string()));
        assert_eq!(p.name,            "Colin Perkins");
        assert_eq!(p.name_from_draft, Some("Colin Perkins".to_string()));
        assert_eq!(p.biography,       "Colin Perkins is a Senior Lecturer (Associate Professor) in the School of Computing Science at the University of Glasgow. His research interests are on transport protocols for real-time and interactive multimedia, and on network protocol design, implementation, and specification. He’s been a participant in the IETF and IRTF since 1996, working primarily in the transport area where he co-chairs the RMCAT working group and is a past chair of the AVT and MMUSIC working groups, and in related IRTF research groups. He proposed and co-chaired the first Applied Networking Research Workshop (ANRW), and has been a long-term participant in the Applied Networking Research Prize (ANRP) awarding committee. He received his BEng in Electronic Engineering in 1992, and my PhD in 1996, both from the Department of Electronics at the University of York.");
        assert_eq!(p.ascii,           "Colin Perkins");
        assert_eq!(p.ascii_short,     None);
        assert_eq!(p.time,            Utc.ymd(2012,2,26).and_hms(0,3,54));
        assert_eq!(p.photo,           Some("https://www.ietf.org/lib/dt/media/photo/Colin-Perkins-sm.jpg".to_string()));
        assert_eq!(p.photo_thumb,     Some("https://www.ietf.org/lib/dt/media/photo/Colin-Perkins-sm_PMIAhXi.jpg".to_string()));
        assert_eq!(p.user,            Some("".to_string()));
        assert_eq!(p.consent,         Some(true));
        Ok(())
    }

    #[test]
    fn test_person_from_email() -> Result<(), DatatrackerError> {
        let dt = Datatracker::new();
        let p  = dt.person_from_email("csp@csperkins.org")?;

        assert_eq!(p.id,   20209);
        assert_eq!(p.name, "Colin Perkins");

        Ok(())
    }

/*
    #[test]
    fn test_people() {
        let dt = Datatracker::new();
        let people = dt.people();
        for person in people.into_iter() {
            println!("{:?}", person);
        }
    }
*/

    #[test]
    fn test_people_with_name() -> Result<(), DatatrackerError> {
        let dt = Datatracker::new();
        let people = dt.people_with_name("Colin Perkins")?.collect::<Result<Vec<_>, _>>()?;

        assert_eq!(people[0].id,   20209);
        assert_eq!(people[0].name, "Colin Perkins");

        Ok(())
    }

    #[test]
    fn test_people_with_name_containing() -> Result<(), DatatrackerError> {
        let dt = Datatracker::new();
        let people = dt.people_with_name_containing("Perkins")?.collect::<Result<Vec<_>, _>>()?;

        // As of 2019-08-17, there are six people named Perkins in the datatracker.
        assert_eq!(people.len(), 6);

        Ok(())
    }

    #[test]
    fn test_people_between() -> Result<(), DatatrackerError> {
        let start = Utc.ymd(2019, 7, 1).and_hms( 0,  0,  0);
        let until = Utc.ymd(2019, 7, 7).and_hms(23, 59, 59);

        let dt = Datatracker::new();
        let people = dt.people_between(start, until)?.collect::<Result<Vec<_>, _>>()?;

        // There are 26 people in the tracker with dates in the first week of July 2019
        assert_eq!(people.len(), 26);

        Ok(())
    }

    #[test]
    fn test_person_history() -> Result<(), DatatrackerError> {
        let dt = Datatracker::new();
        let p  = dt.person_from_email("csp@csperkins.org")?;
        let h  = dt.person_history(&p)?.collect::<Result<Vec<_>, _>>()?;

        // As of 2019-08-18, there are two history items for csp@csperkins.org
        assert_eq!(h.len(), 2);

        Ok(())
    }

    #[test]
    fn test_person_aliases() -> Result<(), DatatrackerError> {
        let dt = Datatracker::new();
        let p  = dt.person_from_email("csp@csperkins.org")?;
        let h  = dt.person_aliases(&p)?.collect::<Result<Vec<_>, _>>()?;

        // As of 2019-08-18, there are two aliases for csp@csperkins.org
        assert_eq!(h.len(), 2);
        assert_eq!(h[0].name, "Dr. Colin Perkins");
        assert_eq!(h[1].name, "Colin Perkins");

        Ok(())
    }
}

// =================================================================================================================================