melanie / fetch-for-osascript.js

Last active 3 months ago

Like 0

melanie revised this gist 1 year ago · 3da8c80

No changes

melanie revised this gist 2 years ago · 00d453e

1 file changed, 16 insertions

fetch-for-osascript.js (file created)
@@ -0,0 +1,16 @@
1 + /*
2 + Try it from the command line on Mac:
3 + `osascript -l JavaScript fetch-for-osascript.js`
4 + */
5 + function fetch(url) {
6 + const queryURL = $.NSURL.URLWithString(url);
7 + const requestData = $.NSData.dataWithContentsOfURL(queryURL);
8 + const requestString = $.NSString.alloc.initWithDataEncoding(
9 + requestData,
10 + $.NSUTF8StringEncoding,
11 + ).js;
12 + return JSON.parse(requestString);
13 + }
14 +
15 + const json = fetch("https://melaniekat.com/gifs/api")
16 + console.log(JSON.stringify(json))