glasgow-ipl / ietfdata

Python libraries to access the IETF DataTracker and RFC Index
BSD 2-Clause "Simplified" License
18 stars 14 forks source link

Group uri/resource_uri confusion? #53

Closed sbenthall closed 4 years ago

sbenthall commented 4 years ago
dt = DataTracker(cache_dir=Path("cache"))
group = dt.group_from_acronym('mmusic')
drafts = dt.documents(group = group,
                      doctype = dt.document_type('draft'))

This errors with:

Traceback (most recent call last):
  File "affiliations.py", line 36, in <module>
    doctype = dt.document_type('draft')) ###
  File "/home/sb/projects/bigbang-multi/ietfdata/ietfdata/datatracker.py", line 1648, in document_type
    return self._retrieve(doc_type_uri, DocumentType)
  File "/home/sb/projects/bigbang-multi/ietfdata/ietfdata/datatracker.py", line 1367, in _retrieve
    if self._obj_is_cached(resource_uri):
  File "/home/sb/projects/bigbang-multi/ietfdata/ietfdata/datatracker.py", line 1338, in _obj_is_cached
    return self._cache_filepath(resource_uri).exists()
  File "/home/sb/projects/bigbang-multi/ietfdata/ietfdata/datatracker.py", line 1332, in _cache_filepath
    return Path(self.cache_dir, resource_uri.uri[1:-1] + ".json")
AttributeError: 'str' object has no attribute 'uri'
lumisota commented 4 years ago

document_type() takes a DocumentTypeURI - the following should work:

dt = DataTracker(cache_dir=Path("cache"))
group = dt.group_from_acronym('mmusic')
drafts = dt.documents(group = group,
                      doctype = dt.document_type(DocumentTypeURI("/api/v1/name/doctypename/draft")))
csperkins commented 4 years ago

I'm wondering if document_type() and similar methods should be updated to take either a URI or a slug?

dt.document_type(uri=…)

or

dt.document_type(slug="draft")

This would make the implementation of the library a little messy, but might simplify code that uses it somewhat.

sbenthall commented 4 years ago

Ah, thank you, that works @lumisota

@csperkins what about dt.doctype_from_slug

csperkins commented 4 years ago

@sbenthall that's the other option, yeah. If we're going to be consistent with the naming, it would be document_type_from_slug().