as_figma_document {figma}R Documentation

Convert a httr response object to a Figma Document object

Description

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;

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.

Value

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

Examples

## Not run: 
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)

## End(Not run)

[Package figma version 0.2.0 Index]