About me...
● Job:MiCloud RD Leader (http://micloud.tw)
● Skills:○ Service Architecture○ Node.js○ Google Service
● Open Sources:○ opennodes.arecord.us○ peihsinsu.blogspot.tw○ blog.micloud.tw○ slideshare.net/peihsinsu
Cloud Changes the Developer
Few years ago● system and os● network setup● install what I need● mail sdk● sms bridge● backup and archive● socket protocol● building versioning
system for develop● ...
Now● cloud machine● vpc and permission● software preload● email service● sms service● object storage● restful protocal● git deploy & github
in the world● ...
Apps Script Serves
By Type● Standalone Scripts● Container-Bound ScriptsBy Function● Spreadsheet Custom Functions● Web Apps● Google Sites Gadgets● Container Extensions
API Supports
● Google Apps Services
● Calendar● Contacts● DocsList● Document● Domain● Drive
● Finance● Forms● Gmail● Groups● Language● Maps● Sites● Spreadsheet
● Idea○ Using google sheet for data persistance○ Using apps script UrlFetch to retrieve monitor target
resource● Some Reference
○ http://gappsnews.blogspot.tw/2013/01/google-apps-script-http-monitor.html
○ http://gappsnews.blogspot.tw/2013/03/re-google-google-apps-scriptgoogle-form.html
First Apps Script - Service Monitor using Google Drive
You will know...
● SpreadsheetApp.openById(...)○ getSheetByName(...)○ insertSheet(...)○ appendRow(...)
● UrlFetchApp.fetch(...)
2nd Apps Script - Google Form send notification● Idea:
○ Send mail notify when form sent○ Call remote rest when form sent
● Some References:○ http://gappsnews.blogspot.tw/2013/03/fwd-google-
apps-script-event-object.html○ http://gappsnews.blogspot.tw/2013/02/google-apps-
scriptgoogle-form.html
You will know...
● SpreadsheetApp.getActiveSheet()● GmailApp.sendEmail(...)● JSON
○ Object.keys(jsonObject)○ JSON.stringify(jsonObject)○ JSON.parse(string)
function notify(){ var sheet = SpreadsheetApp.getActiveSheet(); var rows = sheet.getDataRange(); var values = rows.getValues(); var content = getLastRowTable(values); var htmlBody = "Hi Admin: <br/><br/>”+ ”有人填表拉,檢查一下吧! <br/><br/>" + content + “<br/><br/>Send by Google Apps”; GmailApp.sendEmail( "[email protected]", "Form Submit Confirm Notice", htmlBody, {from: [email protected], htmlBody:htmlBody} ); }
Piece of Codefunction getLastRowTable(arr){ return jsonObjToTableWithTitle(arr[0], arr[arr.length-1]);}function jsonObjToTableWithTitle(title, row){ var TRs = ''; var keys = Object.keys(row); for(var j = 0 ; j < keys.length ; j++) { var TR = '<tr>'; var rowvalue = row[keys[j]]; TR += ('<td>' + title[keys[j]] + '</td><td>' + rowvalue + '</td>' ); TR+= '</tr>'; TRs += TR; } var table = '<table border="1px">' + TRs +'</table>'; return table;}
3rd Apps Script - Build a RESTful Service● Idea
○ The advance interactive to all clients● Restrictions
○ base url is fixed, only query and form as patameter can be the input
○ get, post method only (2013.7.21)○ need solve the HTTP CODE: 302 problem
● Some Reference○ http://gappsnews.blogspot.tw/2013/07/apps-script-
with-restful.html○ http://gappsnews.blogspot.tw/2013/07/fwd-apps-
script.html○ http://gappsnews.blogspot.tw/2013/07/apps-script-
rest-dopost-request.html
Testing in curl
URL Pattern:https://script.google.com/macros/s/:id/exec
Script ID
Thinking in different...
● Drive application integrate related, scheduling, data present and interactive...
● Static page service (Github Page, Cloud CMS) interactive...
● Mobile devices' remote thin app server, to be a RDB, NDB, BigQuery... middleware
● The chrome extension server side...
Other Features - Connect to Google Services
● Google Apps○ Document extension○ Simple form services
● Google Cloud Platform○ BigQuery integrate○ ScriptDB
● External Services○ Connect with JDBC
● Apps Script Example: https://developers.google.com/apps-script/case-studies
● Sunset Scripts: https://developers.google.com/apps-script/sunset
Reference
Q&ASlideshare: http://www.slideshare.net/peihsinsu/google-apps-script-24469585