Created
August 9, 2017 21:57
-
-
Save slopp/f3f9baee9ded2ed917e28dae40fc5c96 to your computer and use it in GitHub Desktop.
Googlesheets Client Code For Plumber Demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Call plumber API with id to return profile | |
* | |
* @param {number} id The customer id | |
* @param {string} key API Key | |
* @customfunction | |
*/ | |
function getProfileFromPlumber(id, key) { | |
var headers = {'Authorization': 'Key ' + key.toString()}; | |
var options = {'headers' : headers} | |
var request_url = 'http://colorado.rstudio.com:3939/content/614/profile?id=' + id.toString() | |
var r = UrlFetchApp.fetch(request_url, options) | |
var txt = r.getContentText() | |
Logger.log(txt) | |
var j = txt.replace("[","").replace(/[\]]$/,'') | |
Logger.log(j) | |
var p = JSON.parse(j) | |
Logger.log(p) | |
var res = [p.name,p.gender, p.education,p.occupation, p.marital_status] | |
Logger.log(res) | |
return res | |
} | |
/** | |
* Call plumber API with id adn age to return prob income >50 K | |
* | |
* @param {number} id The customer id | |
* @param {number} age | |
* @param {string} key API Key | |
* @customfunction | |
*/ | |
function getProbAtAge(id, age, key) { | |
var headers = {'Authorization': 'Key ' + key.toString()}; | |
var options = {'headers' : headers} | |
var request_url = 'http://colorado.rstudio.com/rsc/content/614/income?id=' + id.toString() + '&age=' + age.toString() | |
var response = UrlFetchApp.fetch(request_url, options) | |
var prediction = response.getContentText() | |
return prediction.replace("[","").replace("]", "") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment