Class FigmaClient
java.lang.Object
com.codename1.art.FigmaClient
Fetches a file from Figma's REST API and reads it into an ArtDocument.
The token is a personal access token (or OAuth token) the user supplies. It is kept only
in this object, sent only to api.figma.com in the X-Figma-Token header, and never
stored or logged. Requests block until they finish, so call from a background thread or
through invokeAndBlock.
String token = "PERSONAL_ACCESS_TOKEN"; // typed by the user, never stored
Display.getInstance().startThread(() -> {
try {
ArtDocument doc = new FigmaClient(token).fetch("FILE_KEY_FROM_THE_URL");
Log.p("Layers: " + doc.getRoot().getChildren().size());
} catch (IOException err) {
Log.e(err);
}
}, "figma").start();
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe API this client talks to.static final intThe most image fills downloaded for one file. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionFetches a file with its geometry and image fills and reads it.byte[]The raw JSON of any API path, such asfiles/KEY/nodes?ids=1:2&geometry=paths.setOAuth(boolean oauth) Sends the token as an OAuth bearer token instead of a personal access token.
-
Field Details
-
API
-
MAX_IMAGES
public static final int MAX_IMAGESThe most image fills downloaded for one file.- See Also:
-
-
Constructor Details
-
FigmaClient
Creates a client.
Parameters
token: a personal access token
-
-
Method Details
-
setOAuth
Sends the token as an OAuth bearer token instead of a personal access token.
Parameters
oauth: true for an OAuth token
-
fetch
Fetches a file with its geometry and image fills and reads it.
Parameters
fileKey: the key in the file's URL,figma.com/design/KEY/...
- Throws:
IOException
-
get
The raw JSON of any API path, such as
files/KEY/nodes?ids=1:2&geometry=paths.Parameters
path: the path after/v1/
- Throws:
IOException
-