Introducing UncompleteZoneMeta to solve inconsistent API on zone_history
Closes: https://github.com/happyDomain/python-sdk/issues/1
This commit is contained in:
parent
7325b3956b
commit
a62e5f1a59
@ -51,7 +51,7 @@ class HappyDomain:
|
||||
|
||||
if val is not None:
|
||||
for au in val:
|
||||
ret.append(Domain(self, **au))
|
||||
ret.append(Domain(self, zone_history_are_ids=True, **au))
|
||||
|
||||
return ret
|
||||
|
||||
|
@ -2,11 +2,11 @@ import json
|
||||
from urllib.parse import quote
|
||||
|
||||
from .error import HappyError
|
||||
from .zone import ZoneMeta, Zone
|
||||
from .zone import UncompleteZoneMeta, ZoneMeta, Zone
|
||||
|
||||
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.id = id
|
||||
@ -14,7 +14,10 @@ class Domain:
|
||||
self.id_provider = id_provider
|
||||
self.domain = domain
|
||||
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):
|
||||
return json.dumps({
|
||||
|
@ -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):
|
||||
|
||||
def __init__(self, _session, _domainid, **kwargs):
|
||||
|
Loading…
x
Reference in New Issue
Block a user