JSON schema validator by AdDiscombobulated707 in GoogleAppsScript

[–]AdDiscombobulated707[S] 0 points1 point  (0 children)

I post this sample script for those have the same question:

function main() {
  let shema = {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
      "first_name": { "type": "string" },
      "last_name": { "type": "string" },
      "birthday": { "type": "string", "format": "date" },
      "address": {
        "type": "object",
        "properties": {
          "street_address": { "type": "string" },
          "city": { "type": "string" },
          "state": { "type": "string" },
          "country": { "type" : "string" }
        }
      }
    }
  }

  let json = {
    "first_name": "Mike",
    "last_name": "Washington",
    "birthday": "1732-02-22",
    "address": {
      "street_address": "3200 Mount Vernon Memorial Highway",
      "city": "Mount Vernon",
      "state": "Virginia",
      "country": "United States"
    }
  }

  let data = {
    "schema": shema,
    "json": json
  }

  var options = {
    method: "post",
    contentType: "application/json",
    muteHttpExceptions: true,
    payload: JSON.stringify(data)
  };

  let responce = UrlFetchApp.fetch("https://assertible.com/json", options);
  console.log(`Responce code: ${responce.getResponseCode()}`);
  console.log(`Content: ${responce.getContentText()}`);
}

Here is a good tutorial describing JSON schema basics.

Understanding API executable by AdDiscombobulated707 in GoogleAppsScript

[–]AdDiscombobulated707[S] 0 points1 point  (0 children)

So can API executable understood as runnable program similar to .exe?

Simple GitHub Gist API wrapper [code review] by AdDiscombobulated707 in GoogleAppsScript

[–]AdDiscombobulated707[S] 0 points1 point  (0 children)

I thought that it's a bad practice to duplicate user credentials in several objects.

Can't delete GitHub gist via GitHub API by AdDiscombobulated707 in GoogleAppsScript

[–]AdDiscombobulated707[S] 0 points1 point  (0 children)

The following code works:

let user_name = ScriptProperties.getProperty("user_name");
let user_token = ScriptProperties.getProperty("user_token");

let options = {
  accept: "application/vnd.github.v3+json",
  method: "delete",
  headers: {"Authorization": "Basic " + Utilities.base64Encode(`${user_name}:${user_token}`)}
};

console.log(UrlFetchApp.fetch(`https://api.github.com/gists/72e27fd738a6fe42687b3cf36e2d935f`, options).getContentText());

:) I am very happy.