Skip to content

Instantly share code, notes, and snippets.

@brucemcpherson
Created April 21, 2019 14:55
Show Gist options
  • Save brucemcpherson/077773b08779a615b17d6ea7b6d45e6a to your computer and use it in GitHub Desktop.
Save brucemcpherson/077773b08779a615b17d6ea7b6d45e6a to your computer and use it in GitHub Desktop.
function doPost(e) {
// some defaults for standalone testing
e = e || {postData:{contents:"<a>a</a>"}};
e.queryString = e.queryString || "convert=xmltojson" ;
var type = e.queryString.toLowerCase().split("=");
// convert xml to json
var results = {status:"bad", error:"no errors"};
try {
if (type.length < 2 || type[0] != "convert") {
results.error = "need convert= on url";
}
else if (type[1] == "xmltojson") {
results.xml = e.postData.contents;
results.json = Xml.parse(results.xml,true);
results.status = "good";
}
else {
results.error = "only xmltojson implemented for now";
}
}
catch(err) {
results.error = err;
}
return ContentService.createTextOutput (JSON.stringify(results))
.setMimeType(ContentService.MimeType.JSON) ;
}
function doGet(e) {
e=e||{};
e.type="get";
return ContentService.createTextOutput (JSON.stringify(e))
.setMimeType(ContentService.MimeType.JSON) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment