<?xml version="1.0" encoding="UTF-8"?>
<component name="GetCode" extends="Task" >
	
	
	<script type="text/brightscript" uri="pkg:/components/generalUtils.brs" />
	<script type="text/brightscript">
		<![CDATA[
			sub init()
			    m.top.functionName = "GetLinkingCode"
			end sub
			
			sub GetLinkingCode()
			    'print "in GetLinkingCode"
			  m.top.result = false
			
			  request = CreateObject("roUrlTransfer")
			  url = m.global.serverURL +"/roku_sg/get_code.php"
			  'print "GetLinkingCode "; url
			  request.SetUrl(url)
			  html = request.GetToString()
              data = html.Trim() 
              json = ParseJSON(data)

			  if json <> invalid then
			      m.top.code = json.code
			      m.top.expires = json.expires
			      print "Code: ";m.top.code
			      m.top.result = true
			  end if
			end sub
		]]>
	</script>
	<interface>
		<field id="code" type="string"/>
		<field id="expires" type="integer"/>
		<field id="result" type="boolean"/>
	</interface>
</component>
