/*global JSONP */ if (window.Transistor === undefined) { window.Transistor = {}; } (function (transistor) { var Control = (function () { return function (broadcaster, station_uid, token) { var jsonp, set, insert, update, remove, command_url, send; jsonp = JSONP(); set = function (channel, collection, cb) { send(command_url('set', channel), {collection: collection}, cb); }; insert = function (channel, entry, cb) { send(command_url('insert', channel), {entry: entry}, cb); }; update = function (channel, id, entry, cb) { send(command_url('update', channel), {id: id, entry: entry}, cb); }; remove = function (channel, id, cb) { send(command_url('remove', channel), {id: id}, cb); }; command_url = function (cmd, channel) { var base = broadcaster + '/command/' + cmd + '/' + station_uid + '/' + token; if (channel === undefined) { return base; } else { return base + '/' + channel; } }; send = function (command_url, data, cb) { if (cb === undefined) { cb = function (result) {}; } if (data === undefined) { jsonp.get(command_url, {}, cb); } else { jsonp.get(command_url, {data: JSON.stringify(data)}, cb); } }; return { set: set, insert: insert, update: update, remove: remove }; }; }()); transistor.Control = Control; }(window.Transistor));