File size: 1,574 Bytes
a746d34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
 * Generates a sequence diagram using PlantUML.
 */
function generateSequenceDiagram() {
  var plantUmlCode = "@startuml\n" +
                     "participant Line as L\n" +
                     "participant Google Apps Script as G\n" +
                     "L->>G: Get image data\n" +
                     "G->>L: Return image data\n" +
                     "G->>Drive: Save image to Drive\n" +
                     "@enduml";
  
  var plantUmlService = getPlantUmlService();
  var diagram = plantUmlService.generateDiagram(plantUmlCode);
  var blob = Utilities.newBlob(diagram, "image/png");
  DriveApp.getFolderById("YOUR_GOOGLE_DRIVE_FOLDER_ID").createFile(blob).setName("sequence_diagram.png");
}

/**
 * Returns a PlantUML service instance.
 * @return {PlantUmlService} PlantUML service instance.
 */
function getPlantUmlService() {
  var service = OAuth2.createService("plantuml")
    .setAuthorizationBaseUrl("https://plantuml.com/")
    .setTokenUrl("https://plantuml.com/api/token")
    .setClientId("YOUR_PLANTUML_API_KEY")
    .setClientSecret("YOUR_PLANTUML_API_SECRET")
    .setCallbackFunction("authCallback")
    .setPropertyStore(PropertiesService.getUserProperties());
  return service;
}

/**
 * OAuth2 callback function.
 * @param {Object} request OAuth2 request object.
 */
function authCallback(request) {
  var service = getPlantUmlService();
  var authorized = service.handleCallback(request);
  if (authorized) {
    return HtmlService.createHtmlOutput("Authorized!");
  } else {
    return HtmlService.createHtmlOutput("Access denied.");
  }
}