
REST access to blister functions
To take the idea covered in Getting lists as a restquery a little further, why not simple expose all the custom blister functions so they can be queried too. This means that you can use exactly the same […]
To take the idea covered in Getting lists as a restquery a little further, why not simple expose all the custom blister functions so they can be queried too. This means that you can use exactly the same […]
In using scriptDB as a noSQL database, I showed how to do queries on a scriptDB as if it were a REST API. Since these blister lists are just data in a scriptDB, we can […]
Normally I’d want to use the Rest to Excel library to get data into Excel, but sometimes you have to resort to web scraping. My preferred route is to do something in scraperwiki, then use a rest query […]
Treeview traversal and recursion In Rest Results Explorer i showed how to Create a treeview from json using the treeView control. Objects like the treeview are generally dealt with recursively – see Getting started with recursion and Getting to Grips with recursion for […]
What can you learn here? sing cRest Advanced capabilities Building new libraries Accessing the cRest class directly get it now Up till now we’ve been looking at the modules in the Rest to Excel library as the integration […]
In Flight data from Fusion I showed how to get a large amount of data from various Google Fusion tables into a javascript app. Since the Fusion API is just a REST API, you can use the Rest […]
What can you learn here? Using cRest Multiple sources Combining Putting together multiple queries on same sheet get it now So far we’ve been considering Rest queries to be discrete. In this section we are going […]
What can you learn here? Library of Rest Calls One off queries Argument structure Running one off queries using the cRest class get it now Now that we have a generalized mechanism to easily populate […]
What can you learn here? Library of Rest Calls How to add new entries How to query from data Adding more content to the rest library get it now Now that we have a generalized mechanism […]
Promises are an elegant way of providing for the handling of the future completion of an action in JavaScript. You will be familiar with the concept of a callback. This allows your app to get […]
In Rest to Excel library there are plenty of examples of populating sheets from rest queries. Usually you simply name the columns to match the data you want to extract and you are good to go. However, you […]
This is the library you need to include if you want to make a rest API handler for DataHandler, as described in DataHandler REST API. The library reference is McxgTjMRcbw1FnIo94Nml5Ki_d-phDA33 Reference … under way The Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
/** * getPostParams - sorts out parameters for DataHandlerRest in cluding thos passed as postdata * @param {object} e from doPost()/doGet() * return {object} the massaged parameters */ function getPostParams (e) { var postData,params = {}; // data and parameters can co,e via both post or command line // postData should look like {parameters:{},data:{}} // postdata sent via GET should be &data=some json if (e && e.postData) { postData = JSON.parse(e.postData.contents); } if (postData) { params = postData.parameters || {}; if (postData.data) { params.data = JSON.stringify(postData.data); } var ks = postData.keys || postData.handleKeys; if (ks) { params.keys = JSON.stringify(ks); } } // now supercede with command line parameters if (e && e.parameter) { Object.keys(e.parameter).forEach(function(k) { params[k]=e.parameter[k]; }); } params.e = e; return params; } /** * DataHandlerRest - handlesweb app for DataHandler * @param {object} data everything needed to process the request * @param {Array.string} optAllowed array of aoperations im allowed to perform * return {DataHandlerRest} a new DataHandlerRest object */ var DataHandlerRest = function (data,optAllowed,accessToken) { var self = this; var enums = cDataHandler.dhConstants; var params = data; var result = {handleCode:enums.CODE.PUBLISH,handleError:enums.ERROR.PUBLISH}; self.isHappy = function () { return (result && result.handleError === enums.CODE.OK); }; self.publish = function () { var s = JSON.stringify(result); var mime = ContentService.MimeType.JSON; if (params.callback) { s = params.callback + "(" + s + ")"; mime = ContentService.MimeType.JAVASCRIPT; } return ContentService.createTextOutput(s).setMimeType(mime); }; self.getResult = function() { return result ? result : {handleCode:enums.CODE.NO_ACTION, handleError:enums.ERROR.NO_ACTION}; }; // find the type var driverType = params.driver ? enums.DB[params.driver.toUpperCase()] : ''; if (!driverType) { result = {handleCode:enums.CODE.UNKNOWN_DRIVER, handleError:enums.ERROR.UNKNOWN_DRIVER, data:[params]}; return self; }; // open a handler var handler = new cDataHandler.DataHandler ( params.siloid, driverType, params.expiry, params.dbid, params.driverob, undefined, undefined, params.peanut, params.accessToken); if (!handler) { result = {handleCode:enums.CODE.PARAMS_MISSING, handleError:enums.ERROR.PARAMS_MISSING, data:[params]}; return self; } else if (!handler.isHappy()) { result = {handleCode:enums.CODE.HANDLE_GET, handleError:enums.ERROR.HANDLE_GET, data:[params]}; return self; } // now good to try rest processing var rest = new DataRest(handler,params.allowed); if (!rest) { result = {handleCode:enums.CODE.REST_GET, handleError:enums.ERROR.REST_GET, data:[params]}; return self; } // lets go - organize the args into the right order for the called function if (params.action === 'save') { result = rest.generalRoute (params.action,params.dataOb); } else if (params.action === 'update') { result = rest.generalRoute (params.action,params.keyOb,params.dataOb); } else if (params.action === 'get') { result = rest.generalRoute (params.action,params.keyOb,params.nocache,params.keepid); } else { result = rest.generalRoute (params.action,params.query,params.params,params.nocache,params.keepid); } return self; } /** * DataRest - handles rest requests to DATAHANDLER * @param {DataHandler} dataHandler the datahandler to work on * @param {[String]} allowedOperations list of operations that can be done. default ['remove','save','query','count'] * return {DataRest} a new DataHandlerRest object */ var DataRest = function (dataHandler,allowedOperations) { var self = this; var parentHandler = dataHandler; var enums = parentHandler.getEnums(); var pAllowed = allowedOperations || enums.ACTIONS; self.isAllowed = function(access) { return pAllowed.indexOf(access) !== -1 ; } self.generalRoute = function(action) { // hive off all the args but the first var a = Array.prototype.slice.call(arguments); a.shift(); // can we do this? if (!self.isAllowed(action)) { return parentHandler.makeResults (enums.CODE.OPERATION_NOT_ALLOWED,action); } else { var r; try { r = parentHandler[action].apply (null,a); } catch(err) { r = parentHandler.makeResults (enums.CODE.ACTION_FAILED,action+" "+err); } return r; } } return self; } |
What can you learn here? Library of Rest Calls Populate excel tables Add your own A library to populate Excel tables with rest query results get it now I found myself writing similar code to […]
bruce mcpherson is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Based on a work at http://www.mcpher.com. Permissions beyond the scope of this license may be available at code use guidelines