Skip to content

Instantly share code, notes, and snippets.

@adrianmg
Created April 25, 2018 15:55
Show Gist options
  • Save adrianmg/39d28aff8a4023bbbd33e92f6b6f399f to your computer and use it in GitHub Desktop.
Save adrianmg/39d28aff8a4023bbbd33e92f6b6f399f to your computer and use it in GitHub Desktop.
Figma API basic request
var request = require("request");
let lastUpdate;
const time = 1000;
const source = "xxx";
const options = {
url: `https://api.figma.com/v1/files/${source}`,
headers: {
"Content-Type": "application/json",
"x-figma-token": "xxx"
}
};
function callback(error, response, body) {
try {
body = JSON.parse(body);
if (body.lastModified != lastUpdate) {
lastUpdate = body.lastModified;
console.log("Document updated: ", lastUpdate);
return lastUpdate;
}
} catch (error) {
console.log("Error: ", error);
}
setTimeout(requestUpdate, time);
}
function requestUpdate() {
request.get(options, callback);
}
// Initiates
exports.startPoll = function() {
setTimeout(requestUpdate, time);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment