turtlestitch/libraries/httpBlocks.xml

1 wiersz
3.5 KiB
XML

<blocks app="Snap! 5.0, http://snap.berkeley.edu" version="1"><block-definition s="%&apos;method&apos; url: %&apos;url&apos; send: %&apos;payload&apos; headers: %&apos;headers&apos;" type="reporter" category="sensing"><header></header><code></code><translations>pt:a resposta a _ de _ enviando _ e cabeçalhos _&#xD;</translations><inputs><input type="%s" readonly="true">GET<options>GET&#xD;POST&#xD;PUT&#xD;DELETE</options></input><input type="%s">https://snap.berkeley.edu</input><input type="%s"></input><input type="%mult%l" readonly="true"></input></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>method</l><l>url</l><l>data</l><l>headers</l><l>proc</l></list><l>var response, i, header;&#xD;if (!proc.httpRequest) {&#xD; proc.httpRequest = new XMLHttpRequest();&#xD; proc.httpRequest.open(method, url, true);&#xD; proc.assertType(headers, &apos;list&apos;);&#xD; for (i = 1; i &lt;= headers.length(); i += 1) {&#xD; header = headers.at(i);&#xD; proc.assertType(header, &apos;list&apos;);&#xD; proc.httpRequest.setRequestHeader(&#xD; header.at(1),&#xD; header.at(2)&#xD; );&#xD; }&#xD; proc.httpRequest.send(data || null);&#xD;} else if (proc.httpRequest.readyState === 4) {&#xD; response = proc.httpRequest.responseText;&#xD; proc.httpRequest = null;&#xD; return response;&#xD;}&#xD;proc.pushContext(&apos;doYield&apos;);&#xD;proc.pushContext();</l></block><list><block var="method"/><block var="url"/><block var="payload"/><block var="headers"/></list></block></block></script></block-definition><block-definition s="key: %&apos;key&apos; value: %&apos;value&apos;" type="reporter" category="operators"><header></header><code></code><translations>pt:um par (chave: _ , valor: _ )&#xD;</translations><inputs><input type="%s"></input><input type="%s"></input></inputs><script><block s="doReport"><block s="reportNewList"><list><block var="key"/><block var="value"/></list></block></block></script></block-definition><block-definition s="current location" type="reporter" category="sensing"><comment w="200" collapsed="false">Reports a three-item list containing the latitude and longitude of the user, and the precision of the measurements. Works only if the user allows snap.berkeley.edu access to location data. Some browsers also require an HTTPS connection to Snap!.</comment><header></header><code></code><translations>pt:a localização actual do dispositivo&#xD;</translations><inputs></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>proc</l></list><l>if (!proc.geostarted) {&#xD; var geo = navigator.geolocation;&#xD; var cords = [];&#xD; var options = {&#xD; enableHighAccuracy: false,&#xD; };&#xD;&#xD; function success(pos) {&#xD; console.log(pos);&#xD; proc.geocords = [pos.coords.latitude,&#xD; pos.coords.longitude,&#xD; pos.coords.accuracy];&#xD; }&#xD;&#xD; function error(err) {&#xD; alert("ERROR " + err.code + ": " + err.message);&#xD; }&#xD; proc.geostarted = true;&#xD; proc.geocords = null;&#xD; console.log("starting geolocation")&#xD; geo.getCurrentPosition(success, error, options);&#xD;} else if (proc.geocords) {&#xD; var cords = proc.geocords;&#xD; proc.geostarted = null;&#xD; proc.geocords = null;&#xD; console.log("returning");&#xD; return new List(cords);&#xD;} else {&#xD; console.log("yielding");&#xD; proc.pushContext(&apos;doYield&apos;);&#xD; proc.pushContext();&#xD;}</l></block><list></list></block></block></script></block-definition></blocks>