//* comment *// // Copyright (c) 2015 Walter Bender, Sam Parkinson // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 3 of the License, or // (at your option) any later version. // // You should have received a copy of the GNU General Public License // along with this library; if not, write to the Free Software // Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA // Plugins are a dictionary of json-encoded components: a flow-block // dictionary, an arg-block dictionary, a block dictionary, and a // palette dictionary. The flow-block dictionary is a set of commands // that are evaluated when a flow block is run; the arg-block // dictionary is a set of commands that are evaluated when an arg // block is run; the block dictionary defines the new blocks in the // plugin; and the palette dictionary defines icons (svg) associated // with the palettes populated by the blocks found in the plugin. // The Mashape plugin provides blocks that use the mashape.com APIs. // Included here are blocks to translate strings and to poll // international weather forecasts. //* globals *// var weatherMashapeKey = '3Rfxc7fwp2mshJxgtDxKSueYna8Ap1qZfAcjsn2hjpuWPuBCrI'; //* arg:weatherincity *// var block = logo.blocks.blockList[blk]; var apiURL = 'https://george-vustrey-weather.p.mashape.com/api.php?location='; var conns = block.connections; var city = logo.parseArg(logo, turtle, conns[1]); var daysAhead = parseInt(logo.parseArg(logo, turtle, conns[2])); if (daysAhead < -1 || daysAhead > 5) { logo.errorMsg('Days ahead must be in the range of -1 to 5.', blk); daysAhead = 0; } if (block.cacheCity === city && block.cache !== undefined) { var response = block.cache; } else { var request = new XMLHttpRequest(); request.open('GET', apiURL + city, false); request.setRequestHeader('X-Mashape-Authorization', weatherMashapeKey); request.send(null); var response = request.responseText; block.cacheCity = city; block.cache = response; } var forecast = JSON.parse(response); block.value = forecast[daysAhead + 1]['condition']; //* arg:weatherincityhigh *// var block = logo.blocks.blockList[blk]; var apiURL = 'https://george-vustrey-weather.p.mashape.com/api.php?location='; var conns = block.connections; var city = logo.parseArg(logo, turtle, conns[1]); var daysAhead = parseInt(logo.parseArg(logo, turtle, conns[2])); if (daysAhead < -1 || daysAhead > 5) { logo.errorMsg(_('Days ahead must be in the range of -1 to 5.'), blk); daysAhead = 0; } if (block.cacheCity === city && block.cache !== undefined) { var response = block.cache; } else { var request = new XMLHttpRequest(); request.open('GET', apiURL + city, false); request.setRequestHeader('X-Mashape-Authorization', weatherMashapeKey); request.send(null); var response = request.responseText; block.cacheCity = city; block.cache = response; } var forecast = JSON.parse(response); block.value = parseInt(forecast[daysAhead + 1]['high_celsius']); //* arg:weatherincitylow *// var block = logo.blocks.blockList[blk]; var apiURL = 'https://george-vustrey-weather.p.mashape.com/api.php?location='; var conns = block.connections; var city = logo.parseArg(logo, turtle, conns[1]); var daysAhead = parseInt(logo.parseArg(logo, turtle, conns[2])); if (daysAhead < -1 || daysAhead > 5) { logo.errorMsg(_('Days ahead must be in the range of -1 to 5.'), blk); daysAhead = 0; } if (block.cacheCity === city && block.cache !== undefined) { var response = block.cache; } else { var request = new XMLHttpRequest(); request.open('GET', apiURL + city, false); request.setRequestHeader('X-Mashape-Authorization', weatherMashapeKey); request.send(null); var response = request.responseText; block.cacheCity = city; block.cache = response; } var forecast = JSON.parse(response); block.value = parseInt(forecast[daysAhead + 1]['low_celsius']); //* block:weatherincity *// var weatherBlock = new ProtoBlock('weatherincity'); weatherBlock.palette = palettes.dict['external']; blocks.protoBlockDict['weatherincity'] = weatherBlock; weatherBlock.staticLabels.push(_('forecast')); weatherBlock.staticLabels.push(_('city')); weatherBlock.staticLabels.push(_('day')); weatherBlock.adjustWidthToLabel(); weatherBlock.twoArgMathBlock(); weatherBlock.dockTypes[0] = 'textout'; weatherBlock.dockTypes[1] = 'anyin'; weatherBlock.defaults.push('Canberra'); weatherBlock.defaults.push(1); //* block:weatherincityhigh *// var weatherHighBlock = new ProtoBlock('weatherincityhigh'); weatherHighBlock.palette = palettes.dict['external']; blocks.protoBlockDict['weatherincityhigh'] = weatherHighBlock; weatherHighBlock.staticLabels.push(_('high')); weatherHighBlock.staticLabels.push(_('city')); weatherHighBlock.staticLabels.push(_('day')); weatherHighBlock.adjustWidthToLabel(); weatherHighBlock.twoArgMathBlock(); weatherHighBlock.dockTypes[1] = 'anyin'; weatherHighBlock.defaults.push('Canberra'); weatherHighBlock.defaults.push(1); //* block:weatherincitylow *// var weatherLowBlock = new ProtoBlock('weatherincitylow'); weatherLowBlock.palette = palettes.dict['external']; blocks.protoBlockDict['weatherincitylow'] = weatherLowBlock; weatherLowBlock.staticLabels.push(_('low')); weatherLowBlock.staticLabels.push(_('city')); weatherLowBlock.staticLabels.push(_('day')); weatherLowBlock.adjustWidthToLabel(); weatherLowBlock.twoArgMathBlock(); weatherLowBlock.dockTypes[1] = 'anyin'; weatherLowBlock.defaults.push('Canberra'); weatherLowBlock.defaults.push(1); //* palette-icon:external *// //* palette-fill:external *// #59f //* palette-stroke:external *// #3771c8 //* palette-highlight:external *// #9DC4FF //* palette-stroke-highlight:external *// #000000