he‎ > ‎security‎ > ‎

Testing App Scripts

Apps Script-Gadget


Example App Script Test

function doGet(e) {

  var app = UiApp.createApplication();

//  var wsdl = SoapService.wsdl("http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl");  
//  var ndfdXML = wsdl.getService("ndfdXML"); 
//  ndfdXML.setEndpointOverride("http://www.example.com"); 
//  Browser.msgBox(ndfdXML.getEndpointOverride());

//   try {
//     var prexixText = "Ma"; 
//     var wsdl = SoapService.wsdl(
//       "http://www.riskexperts.at/AutoComplete.asmx?wsdl");
//    var riskexpertsService = wsdl.AutoComplete();
//    var param = Xml.element("GetCompletionList", [
//      Xml.attribute("xmlns", "http://tempuri.org"),
//      Xml.element("prefixText", [
//        prexixText
//      ]),
//      Xml.element("count", [
//        10
//      ])
//    ]);
//    
//    var result = riskexpertsService.GetCompletionList(param);
//    var resultText = result.Envelope.Body.GetCompletionListResponse
//      .GetCompletionListResult.ArrayOfString.Text;
//
//    Browser.msgBox(resultText);
//  } catch (e1) {
//    Browser.msgBox(e1)
//  }
  
  var label1 = app.createLabel("Welcome, this is a test AppScript: ");
  label1.setStyleAttribute("fontSize","16px");
  app.add(label1);  


  var logmsg = "";
  var emailmsg = "";
  var useridmsg = "(anonymous user)";
  var timezonemsg = "";
  var msgtext = "Hello visitor, app script runs under hidden userid!";    
  var results = "";
  
//  try {
// 
//    if (Session.getActiveUser().getEmail() != null && Session.getActiveUser().getEmail() != "" && Session.getActiveUser().getUserLoginId() != null) {
//      
//      emailmsg = Session.getActiveUser().getEmail();
//      useridmsg = Session.getActiveUser().getUserLoginId();
//      if (Session.getTimeZone() != null && Session.getTimeZone() != "") {
//        timezonemsg = " timezone: " + Session.getTimeZone();
//      }
//      msgtext = "Hello Google registered user " + emailmsg + " userid=" + useridmsg + " " + timezonemsg;
//
//    } else if (Session.getEffectiveUser().getEmail() != null && Session.getEffectiveUser().getEmail() != "") {
//      
//      emailmsg = Session.getEffectiveUser().getEmail();     
//      useridmsg = Session.getEffectiveUser().getUserLoginId();
//      msgtext = "Hello visitor, scripts runs under userid=" + useridmsg + " / " + emailmsg;
//
//    } else {
//      msgtext = "Hello visitor, scripts runs under hidden userid!";
//    }
//  }
//  catch (ex) { 
//    msgtext = "exception was thrown: " + ex.message;
//  }
  
  var msgLabel = app.createLabel(msgtext);
  app.add(msgLabel);

  
  var url2fetch = "http://staatsschulden.at/widget.php?layout=3";
  app.add(app.createLabel(url2fetch));
  
  try {  
    var response = UrlFetchApp.fetch(url2fetch);
    // var fetchLabel = app.createLabel(response.getAs("html").getDataAsString());
    // fetchLabel = app.createLabel(response.getBlob().getDataAsString());
    var contentX = ContentService.createTextOutput(response.getContentText().getContent());
    var fetchLabel = app.createLabel(contentX);        
    app.add(fetchLabel);

  }
  catch (ex0) { 
    app.add(app.createLabel("LogLevel= " + logmsg + "exception: " + ex0.message));
  } 

  app.add(app.createLabel("Finished"));

  return app;
}
Comments