Introducing UncompleteZoneMeta to solve inconsistent API on zone_history

Closes: https://github.com/happyDomain/python-sdk/issues/1
This commit is contained in:
nemunaire 2023-05-02 20:36:53 +02:00
parent 7325b3956b
commit a62e5f1a59
3 changed files with 55 additions and 4 deletions

View File

@ -51,7 +51,7 @@ class HappyDomain:
if val is not None: if val is not None:
for au in val: for au in val:
ret.append(Domain(self, **au)) ret.append(Domain(self, zone_history_are_ids=True, **au))
return ret return ret

View File

@ -2,11 +2,11 @@ import json
from urllib.parse import quote from urllib.parse import quote
from .error import HappyError from .error import HappyError
from .zone import ZoneMeta, Zone from .zone import UncompleteZoneMeta, ZoneMeta, Zone
class Domain: class Domain:
def __init__(self, _session, id, id_owner, id_provider, domain, zone_history, group=""): def __init__(self, _session, id, id_owner, id_provider, domain, zone_history, zone_history_are_ids=False, group=""):
self._session = _session self._session = _session
self.id = id self.id = id
@ -14,7 +14,10 @@ class Domain:
self.id_provider = id_provider self.id_provider = id_provider
self.domain = domain self.domain = domain
self.group = group self.group = group
self.zone_history = zone_history if zone_history is not None else [] if zone_history_are_ids:
self.zone_history = [UncompleteZoneMeta(self, zid) for zid in zone_history]
else:
self.zone_history = zone_history if zone_history is not None else []
def _dumps(self): def _dumps(self):
return json.dumps({ return json.dumps({

View File

@ -31,6 +31,54 @@ class ZoneMeta:
}) })
class UncompleteZoneMeta(ZoneMeta):
def __init__(self, _domain, id):
self._complete = None
self._domain = _domain
self.id = id
def resolve(self):
if self._complete is None:
self._complete = self._domain.get_zone(self.id)
@property
def id_author(self):
self.resolve()
return self._complete.id_author
@property
def default_ttl(self):
self.resolve()
return self._complete.default_ttl
@property
def last_modified(self):
self.resolve()
return self._complete.last_modified
@property
def last_modified(self):
self.resolve()
return self._complete.last_modified
@property
def commit_message(self):
self.resolve()
return self._complete.commit_message
@property
def commit_date(self):
self.resolve()
return self._complete.commit_date
@property
def published(self):
self.resolve()
return self._complete.published
class Zone(ZoneMeta): class Zone(ZoneMeta):
def __init__(self, _session, _domainid, **kwargs): def __init__(self, _session, _domainid, **kwargs):