Skip to contents

This function receives a httr::response() object, and outputs a figma_document object.

Usage

as_figma_document(response, ...)

Arguments

response

a response object produced by a httr HTTP method (e.g. httr::GET(), httr::POST(), etc.);

...

Further arguments passed by the caller. Currently ignored by the function;

Value

Returns an object of class figma_document, which is a R list with these elements:

  • document: a R list with all of the document metadata of your Figma file;

  • canvas: a R list with all of the canvas and objects data of your Figma file;

  • n_canvas: a integer with the number of canvas/pages in your Figma file;

  • n_objects: a vector of integers with the number of objects in each canvas/page of your Figma file;

Details

A Figma Document is a just a R list with a more organized structure than the raw content of the HTTP request in httr::response(). You can access each part of this list with `$` and `[[` operators. See Value section to understand what is in each element of this list.

as_figma_document() will call different parsers depending on what kind of elements are present in the content of the response object it receives as input. These elements define what kind of data is present in the response object, and how it is structured.

If this input object have a document element in the top-level of the content, is likely that this input object was produced by figma::get_figma_file(). In this case, as_figma_document() will call figma:::parse_figma_file() to parse the contents of the HTTP request.

In the other hand, if this input object have a nodes element in the top-level of the content, is likely that this input object was produced by figma::get_figma_page(). In this case, as_figma_document() will call figma:::parse_figma_page() to parse the contents of the HTTP request.

If none of these key elements ("document" or "nodes") are found in the top-level of the content of the response object, as_figma_document() will issue an error to the user, telling it could not recognize the source of the response object.

Examples

if (FALSE) {
file_key <- "hch8YlkgaUIZ9raDzjPvCz"
token <- "my figma token secret ... "
# Returns a `response` object:
r <- figma::get_figma_file(file_key, token)
result <- figma::as_figma_document(r)
}