Skip to content

Instantly share code, notes, and snippets.

@RChloe
Created March 22, 2017 21:10
Show Gist options
  • Save RChloe/bde1b3d7c059c87413809917cbf58e15 to your computer and use it in GitHub Desktop.
Save RChloe/bde1b3d7c059c87413809917cbf58e15 to your computer and use it in GitHub Desktop.
var alreadyStreamed = "Already Streamed";
function stream() {
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
var startRow = sheets[0].getLastRow();
var numRows = 1;
var dataRange = sheets[1].getRange(startRow, 1, numRows, 4);
var streamedRange = sheets[1].getRange("D"+startRow);
var dataValues = dataRange.getValues();
for (var i = 0; i < dataValues.length; ++i) {
var row = dataValues[i];
var timeOrdered = row[0];
var price = row[1];
var deliveryTime = row[2];
};
var url = "https://groker.initialstate.com/api/events?";
var data = [{
"key": "Time Ordered",
"value": timeOrdered},{
"key": "Price",
"value": price},{
"key": "Time to Delivery",
"value": deliveryTime,
}];
var options = {
"method": "post",
"headers": {
"Content-Type":"application/json",
"X-IS-AccessKey":"YOUR_ACCESS_KEY_HERE",
"X-IS-BucketKey":"pietops",
"Accept-Version":"~0",
},
"payload": JSON.stringify(data),
};
if (streamedRange.isBlank()){
var response = UrlFetchApp.fetch(url, options);
response;
sheets[1].getRange(startRow, 4).setValue(alreadyStreamed);
SpreadsheetApp.flush();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment