Created
April 25, 2018 15:55
-
-
Save adrianmg/39d28aff8a4023bbbd33e92f6b6f399f to your computer and use it in GitHub Desktop.
Figma API basic request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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