DaveH Where would I find the description of a 'conf' object for example
Here is a hacked-together example of some python code. It won't work as is, but it should give lots of hints.
Have a look at how the newChannel
object is created and then in __createOBJ
how newObject
is created and then added to the URL.
newChannel = {}
newChannel['class'] = "channel"
newChannel['conf'] = {}
newChannel['conf']['enabled'] = True
newChannel['conf']['autoname'] = True
newChannel['conf']['name'] = service['svcname']
newChannel['conf']['number'] = service['lcn']
newChannel['conf']['services'] = []
newChannel['conf']['services'].append(service['uuid'])
newChannel['conf']['tags'] = []
if len(tagUUID) != 0:
newChannel['conf']['tags'].append(tagUUID)
ret = self.__createOBJ("channel/create", newChannel)
#Create a TVH Object
def __createOBJ(self, url, payload):
tvhResponse = ""
newObject = "class=" + payload['class'] + "&conf=" + json.dumps(payload['conf'], separators=(',', ':'))
newObject = newObject.replace(" ", "%20")
json_url = "http://" + self.__hostName + ":" + str(self.__httpPort) + "/api/" + url + "?" + newObject
req = request.Request(json_url, method="GET")
req.add_header('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
r = request.urlopen(req)
tvhResponse = r.read()
jRet = json.loads(tvhResponse)
uu = ""
if 'uuid' in jRet:
uu = jRet['uuid']
else:
uu = str(tvhResponse)
extra = ""
if 'name' in payload['conf']:
extra = " name = '" + payload['conf']['name'] + "'"
if 'networkname' in payload['conf']:
extra = " networkname = '" + payload['conf']['networkname'] + "'"
if 'display_label' in payload['conf']:
extra = " display_label = '" + payload['conf']['display_label'] + "'"
self.__logger("Created object, class '" + payload['class'] + "' uuid = '" + uu + "'" + extra)
return tvhResponse