First SDK version
This commit is contained in:
parent
952e9d06b0
commit
7aaf0e2a96
9 changed files with 532 additions and 2 deletions
66
happydomain/service.py
Normal file
66
happydomain/service.py
Normal file
|
@ -0,0 +1,66 @@
|
|||
import json
|
||||
from urllib.parse import quote
|
||||
|
||||
from .error import HappyError
|
||||
|
||||
class ServiceMeta:
|
||||
|
||||
def __init__(self, _session, _svctype, _domain, _ttl, _id=None, _ownerid=None, _comment="", _mycomment="", _aliases=[], _tmp_hint_nb=0):
|
||||
self._svctype = _svctype
|
||||
self._domain = _domain
|
||||
self._ttl = _ttl
|
||||
self._id = _id
|
||||
self._ownerid = _ownerid
|
||||
self._comment = _comment
|
||||
self._mycomment = _mycomment
|
||||
self._aliases = _aliases
|
||||
self._tmp_hint_nb = _tmp_hint_nb
|
||||
|
||||
def _dumps(self):
|
||||
return json.dumps({
|
||||
"_svctype": self._svctype,
|
||||
"_domain": self._domain,
|
||||
"_ttl": self._ttl,
|
||||
"_id": self._id,
|
||||
"_ownerid": self._ownerid,
|
||||
"_comment": self._comment,
|
||||
"_mycomment": self._mycomment,
|
||||
"_aliases": self._aliases,
|
||||
"_tmp_hint_nb": self._tmp_hint_nb,
|
||||
})
|
||||
|
||||
|
||||
class HService(ServiceMeta):
|
||||
|
||||
def __init__(self, _session, _domainid, _zoneid, Service, **kwargs):
|
||||
super(HService, self).__init__(_session, **kwargs)
|
||||
self._domainid = _domainid
|
||||
self._zoneid = _zoneid
|
||||
self.service = Service
|
||||
|
||||
def _dumps(self):
|
||||
return json.dumps(self._flat())
|
||||
|
||||
def _flat(self):
|
||||
return {
|
||||
"_svctype": self._svctype,
|
||||
"_domain": self._domain,
|
||||
"_ttl": self._ttl,
|
||||
"_id": self._id,
|
||||
"_ownerid": self._ownerid,
|
||||
"_comment": self._comment,
|
||||
"_mycomment": self._mycomment,
|
||||
"_aliases": self._aliases,
|
||||
"_tmp_hint_nb": self._tmp_hint_nb,
|
||||
"Service": self.service,
|
||||
}
|
||||
|
||||
def delete(self):
|
||||
r = self._session.session.delete(
|
||||
self.baseurl + "/api/domains/" + quote(self._domainid) + "/zone/" + quote(self._zoneid) + "/" + quote(self._domain) + "/services/" + quote(self._id),
|
||||
)
|
||||
|
||||
if r.status_code > 300:
|
||||
raise HappyError(r.status_code, **r.json())
|
||||
|
||||
return r.json()
|
Loading…
Add table
Add a link
Reference in a new issue