//* comment *//
Copyright (C) 2015 Walter Bender
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
//* globals *//
var bitcoinMashapeKey = 'PCwj8N1ftxmsh4WCJmQoJqiNhRCbp1DTsnTjsnkmyDCNwB94sm';
//* block:bitcoinrate *//
var bitcoinRate = new ProtoBlock('bitcoinrate');
bitcoinRate.palette = palettes.dict['external'];
blocks.protoBlockDict['bitcoinrate'] = bitcoinRate;
bitcoinRate.staticLabels.push(_('bitcoin'), _('from'), _('value'));
bitcoinRate.adjustWidthToLabel();
bitcoinRate.twoArgMathBlock();
bitcoinRate.dockTypes[1] = 'anyin';
bitcoinRate.dockTypes[2] = 'numberin';
bitcoinRate.defaults.push('USD', 100);
//* arg:bitcoinrate *//
var block = logo.blocks.blockList[blk];
var conns = block.connections;
var from = logo.parseArg(logo, turtle, conns[1]);
var amount = logo.parseArg(logo, turtle, conns[2]);
var apiURL = 'https://community-bitcointy.p.mashape.com/convert/' + amount + '/' + from;
if (block.cacheFor === apiURL && block.cache !== undefined) {
var response = block.cache;
} else {
try {
var request = new XMLHttpRequest();
request.open('GET', apiURL, false);
request.setRequestHeader('X-Mashape-Authorization', bitcoinMashapeKey);
request.send(null);
var response = request.responseText;
block.cacheFor = apiURL;
block.cache = response;
} catch (e) {
logo.errorMsg('Could not connect to Currency API', blk);
}
}
console.log(response);
obj = JSON.parse(response);
block.value = obj['value'] / 100;
//* palette-icon:external *//
//* palette-fill:external *// #59f
//* palette-stroke:external *// #3771c8
//* palette-highlight:external *// #9DC4FF
//* palette-stroke-highlight:external *// #000000