From d18b427b72802c04a4fa293f678027465a8ee5bc Mon Sep 17 00:00:00 2001 From: Tek <140775902+Tekinical@users.noreply.github.com> Date: Mon, 4 Sep 2023 01:21:41 -0500 Subject: [PATCH] Update turboapi.js --- extensions/turboapi.js | 91 ++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/extensions/turboapi.js b/extensions/turboapi.js index 757aa7b0d7..cb0a75d039 100644 --- a/extensions/turboapi.js +++ b/extensions/turboapi.js @@ -5,73 +5,78 @@ (function (Scratch) { "use strict"; - + let APIResponse = null; let JsonThing = null; - + class TurboAPI { getInfo() { return { - id: 'TurboAPI', - name: 'TurboAPI', - menuIconURI: 'https://files.catbox.moe/4eb196.png', - color1: '#FF4C4C', + id: "TurboAPI", + name: "TurboAPI", + menuIconURI: "https://files.catbox.moe/4eb196.png", + color1: "#FF4C4C", blocks: [ { - opcode: 'sendResponse', + opcode: "sendResponse", blockType: Scratch.BlockType.COMMAND, - text: 'GET Request from [endpoint]', + text: "GET Request from [endpoint]", arguments: { endpoint: { type: Scratch.ArgumentType.STRING, - defaultValue: 'Website Endpoint' - } - } + defaultValue: "Website Endpoint", + }, + }, }, { - opcode: 'sendPost', + opcode: "sendPost", blockType: Scratch.BlockType.COMMAND, - text: 'Send a Post Request to [endpoint] with [arg]', + text: "Send a Post Request to [endpoint] with [arg]", arguments: { endpoint: { type: Scratch.ArgumentType.STRING, - defaultValue: 'Website Endpoint' + defaultValue: "Website Endpoint", }, arg: { type: Scratch.ArgumentType.STRING, - defaultValue: 'Arguments' - } - } + defaultValue: "Arguments", + }, + }, }, { - opcode: 'responseAPI', + opcode: "responseAPI", blockType: Scratch.BlockType.REPORTER, - text: 'API Response', - blockIconURI: 'https://freeiconshop.com/wp-content/uploads/edd/download-flat.png' - } - ] - } - } - - sendResponse(args) { - APIResponse = Scratch.fetch(args.endpoint).then((r) => r.text()).catch(() => ""); - } - - sendPost(args) { - APIResponse = Scratch.fetch(args.endpoint, { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' + text: "API Response", + blockIconURI: + "https://freeiconshop.com/wp-content/uploads/edd/download-flat.png", }, - body: args.arg - }).then((r) => r.text()).catch(() => ""); - } - - responseAPI() { - return APIResponse; - } + ], + }; + } + + sendResponse(args) { + APIResponse = Scratch.fetch(args.endpoint) + .then((r) => r.text()) + .catch(() => ""); + } + + sendPost(args) { + APIResponse = Scratch.fetch(args.endpoint, { + method: "POST", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + }, + body: args.arg, + }) + .then((r) => r.text()) + .catch(() => ""); + } + + responseAPI() { + return APIResponse; + } } - + Scratch.extensions.register(new TurboAPI()); })(Scratch);