David Blume's GitList
Repositories
dxb_channel.git
Code
Commits
Branches
Tags
Search
Tree:
2daf511
Branches
Tags
main
dxb_channel.git
components
testtask.brs
Fix off-by-one loop error
dblume
commited
2daf511
at 2023-03-10 20:26:59
testtask.brs
Blame
History
Raw
sub init() m.top.functionName = "executeTest" m.top.ObserveField("pucidHash", "onUpdatePucidHash") end sub function GetRequest() as object r = CreateObject("roUrlTransfer") r.InitClientCertificates() r.SetCertificatesFile("pkg:/certificates/rokuca.pem") ' r.SetCertificatesFile("common:/certs/ca-bundle.crt") r.SetUrl("https://api.roku.com/registrysvc/api/" + CreateObject("roAppInfo").GetDevID()) r.AddHeader("accept", "application/json") r.AddHeader("content-type", "application/*") r.AddHeader("x-roku-registry-aes-key-version", "v1") r.AddHeader("x-roku-reserved-regsvc-token", "") ' Note if called from init(), then m.top.pucidHash won't have been set yet. r.AddHeader("x-roku-registry-aes-encryption-key", m.top.pucidHash) print "GetRequest() x-roku-registry-aes-encryption-key:" + m.top.pucidHash print " URL:" + r.GetUrl() return r end function function onUpdatePucidHash() as void ' Maybe do something with m.top.pucidHash end function sub printAA(aa) for each key in aa.Keys() val = aa[key] if type(val) = "roByteArray" m.top.updateText = " " + key + " = a byte array" elseif type(val) = "roArray" for i=0 to val.Count() - 1 m.top.updateText = " " + key + "[" + i.toStr() + "] = " + val[i] end for else m.top.updateText = " " + key + " = " + val.ToStr() endif end for end sub function executeTest() as void ' This task gets run one at the start, and then ' again every time the OK button is pressed. deviceInfo = CreateObject("roDeviceInfo") aaConnectionInfo = deviceInfo.GetDisplayProperties() m.top.updateText = "roDeviceInfo.GetDisplayProperties" printAA(aaConnectionInfo) aaConnectionInfo = deviceInfo.GetConnectionInfo() m.top.updateText = "roDeviceInfo.GetConnectionInfo" printAA(aaConnectionInfo) request = GetRequest() port = CreateObject("roMessagePort") request.SetMessagePort(port) requestBody = { "token": "auth" } res = request.AsyncPostFromString(FormatJson(requestBody)) if res = true msg = wait(0, port) if type(msg) = "roUrlEvent" if msg.GetInt() = 1 print "PSI Request roUrlEvent = " + msg.GetResponseCode().ToStr() end if ' else if msg = invalid ' request.AsyncCancel() end if else m.top.updateText = "AsyncPostFromString failed" end if end function