Skip to content

Latest commit

 

History

History
623 lines (431 loc) · 20 KB

API.md

File metadata and controls

623 lines (431 loc) · 20 KB

Classes

CartodbLayersStream

Main class to expose all the module of this library

Memoizable

Abstract Class to implement memoized methods

Rest

Class to communicate with CARTO Rest API

Turbocarto

Class to manipulate TurboCARTO strings.

CartodbLayers ⇐ Stream

Main class to expose all the module of this library

Kind: global class
Extends: Stream
Properties

Name Type Description
client CartoDB.SQL CartoDB SQL client
rest Rest Rest client
turbocarto Turbocarto TruboCARTO client

new CartodbLayers()

Param Type Default Description
[args.user] String cartodb CARTO username
args.api_key String CARTO api key

Memoizable

Abstract Class to implement memoized methods

Kind: global abstract class
Properties

Name Type Description
methods Object All the methods of the class
memoized Object All the methods of the class, but memoized (no expiration)

new Memoizable()

This abstract class should not call this constructor method or an error will be thrown.

Throws:

  • Error Thrown when the class is called directly.

memoizable.throttled([wait]) ⇒ Object

Returns the methods of the class, wrapped inside a throttled function

Kind: instance method of Memoizable
Returns: Object - All the methods of the class

Param Type Default Description
[wait] Number Throttle duration in millisecond. The null means no limitations.

Rest

Class to communicate with CARTO Rest API

Kind: global class

new Rest(args)

Create a Rest instance

Param Type Default Description
args Object An object to configure the client with a "user" and "api_key" properties.
[args.user] String cartodb CARTO username
args.api_key String CARTO api key

rest.get(args) ⇒ Promise

Perform a GET request over CARTO API.

Kind: instance method of Rest

Param Type Description
args Object Spread parameters to axios method

rest.post(args) ⇒ Promise

Perform a POST request over CARTO API.

Kind: instance method of Rest

Param Type Description
args Object Spread parameters to axios method

rest.delete(args) ⇒ Promise

Perform a DELETE request over CARTO API.

Kind: instance method of Rest

Param Type Description
args Object Spread parameters to axios method

rest.del(args) ⇒ Promise

Deprecated

Perform a DELETE request over CARTO API.

Kind: instance method of Rest

Param Type Description
args Object Spread parameters to axios method

rest.findInfowindow(viz) ⇒ Object

Find an infowindow description object in the given vizualisation

Kind: instance method of Rest

Param Type Description
viz Object Vizualisation description object from CARTO API

rest.buildParams([page], [per_page]) ⇒ Object

Build query parameters to paginate results from CARTO

Kind: instance method of Rest

Param Type Default
[page] Number 1
[per_page] Number 10

rest.buildQuery(page, per_page) ⇒ Object

Deprecated

Build query parameters to paginate results from CARTO

Kind: instance method of Rest

Param Type
page Number
per_page Number

rest.layers() ⇒ Array

Deprecated

Get all "layers" which is basicaly all user's vizualisations

Kind: instance method of Rest

rest.getLayers() ⇒ Array

Get all "layers" which is basicaly all user's vizualisations

Kind: instance method of Rest

rest.tables() ⇒ Array

Get all user's tables

Kind: instance method of Rest

rest.emitterAsPromise(emitter) ⇒ Promise

Cast the given event emmiter to a Promise

Kind: instance method of Rest

Param Type
emitter Object

rest.createNamedMap(template) ⇒ Promise

Create a named map based on the given template object

Kind: instance method of Rest

Param Type
template Object

rest.deleteNamedMap(template_id) ⇒ Promise

Delete a named map

Kind: instance method of Rest

Param Type Description
template_id String Id of the template to delete

rest.deleteNamedMapIfExist(template_id) ⇒ Promise

Delete a named map but return null without throwing an error if the named map doesn't exist

Kind: instance method of Rest

Param Type Description
template_id String Id of the template to delete

rest.instanciate(template_id, params) ⇒ Promise

Deprecated

Create an instance of the given name map with custom params

Kind: instance method of Rest

Param Type Description
template_id String Id of the template
params Object Params of the named map

rest.instantiateNamedMap(template_id, params) ⇒ Promise

Create an instance of the given name map with custom params

Kind: instance method of Rest

Param Type Description
template_id String Id of the template
params Object Params of the named map

rest.viz(id, [resolveNamedMap]) ⇒ Promise

Deprecated

Get a vizualisation using CARTO API v2

Kind: instance method of Rest

Param Type Default Description
id String Id of the vizualisation
[resolveNamedMap] Boolean true Should add the vizualisation's named map

rest.getVizV2(id, [resolveNamedMap]) ⇒ Promise

Get a vizualisation using CARTO API v2

Kind: instance method of Rest

Param Type Default Description
id String Id of the vizualisation
[resolveNamedMap] Boolean true Should add the vizualisation's named map

rest.getVizV1(id) ⇒ Promise

Get a vizualisation using CARTO API v1

Kind: instance method of Rest

Param Type Description
id String Id of the vizualisation

rest.named(name) ⇒ Promise

Get a named map using CARTO API v1

Kind: instance method of Rest
Depracted:

Param Type Description
name String Name of the Named Map

rest.getNamedMap(name) ⇒ Promise

Get a named map using CARTO API v1

Kind: instance method of Rest

Param Type Description
name String Name of the Named Map

rest.getNamedMaps() ⇒ Promise

Get all named maps using CARTO API v1

Kind: instance method of Rest

rest.importedAt() ⇒ String

Get the current date as a locale string in UTC timezone

Kind: instance method of Rest

rest.uniqueNamedMapId(id, [prefix]) ⇒ String

Get a unique named map id based on the date

Kind: instance method of Rest

Param Type Default Description
id String Named Map name (or id)
[prefix] String "dtpl" Prefix to all namedMap ids

rest.projection(id, name, cartocss, sql, interactivity) ⇒ Promise

Instanciate a new Named Map with a custom CartoCSS and SQL projection

Kind: instance method of Rest
Depracted:

Param Type Description
id String Named Map name (or id)
name String Name of the new named map
cartocss String Custom CartoCSS
sql String Custom SQL
interactivity String A commat separated list of fields the user can interact with

rest.vizNewNamedMap(id, name, cartocss, sql, interactivity) ⇒ Promise

Instanciate a new Named Map with a custom CartoCSS and SQL projection

Kind: instance method of Rest

Param Type Description
id String Named Map name (or id)
name String Name of the new named map
cartocss String Custom CartoCSS
sql String Custom SQL
interactivity String A commat separated list of fields the user can interact with

rest.basemapLayer() ⇒ Object

Get the default basemap layer definition

Kind: instance method of Rest

rest.static(id, noBasemap) ⇒ Object

Get the static definition (image) of a given vizualisation

Kind: instance method of Rest

Param Type Description
id String Vizualisation id
noBasemap Boolean Disabled the basemap layer in the static visualization

rest.search(q, [type], page, per_page)

Search a visualization by its name

Kind: instance method of Rest

Param Default Description
q Query string
[type] derived Type of vizualisation to look for
page Page number
per_page Number of visualizations by page

rest.image(specs, [width], [height], [protocol], [format], [useCenter]) ⇒ String

Convert the given static definition into an image URL

Kind: instance method of Rest
Returns: String - Image URL

Param Default Description
specs Static definition
[width] 300 Image width
[height] 170 Image height
[protocol] https URL protocol
[format] png Image format
[useCenter] false The given definition uses center instead of boundaries to pane the map.

rest.data(id) ⇒ Promise

Get data for a given vizualisation using API v2

Kind: instance method of Rest

Param Type Description
id String Id of the vizualisation

rest.vizSqlQuery(id) ⇒ Promise

Get SQL query of a given vizualisation

Kind: instance method of Rest
Returns: Promise - SQL query as string

Param Type Description
id String Id of the vizualisation

rest.vizRelatedTables(id) ⇒ Promise

Get related table of a given vizualisation using API v1

Kind: instance method of Rest
Returns: Promise - A list of related tables

Param Type Description
id String Id of the vizualisation

rest.vizTable(id) ⇒ String

Get the name of table used by a given vizualisation

Kind: instance method of Rest
Returns: String - Table name

Param Type Description
id String Id of the vizualisation

rest.fillParams(sql) ⇒ String

Fills default parameters for a given SQL query template

Kind: instance method of Rest
Returns: String - SQL query

Param Type Description
sql String SQL query template

rest.fields(id) ⇒ Array

Get fields (table rows) for a given vizualization using API v2

Kind: instance method of Rest

Param Type Description
id String Id of the vizualisation

Rest.firstNonNul(tasks) ⇒ Mixed

Evaluate the given list of promises in series, then stops and return the first non null value.

Kind: static method of Rest
Returns: Mixed - First non null value

Param Type Description
tasks Array List of promises

Rest.queryCollection(data, path, force) ⇒ Mixed

Return the value of the given path in the data object

Kind: static method of Rest

Param Type Description
data Object Object to look into
path String Path to use
force Mixed Specify an object to be returned from the query if the query fails.

Rest.sqlQueryToTable(sql) ⇒ String

Get the table from a given SQL query

Kind: static method of Rest
Returns: String - Table name from the query (or null if any)

Param Type Description
sql String SQL query

Turbocarto

Class to manipulate TurboCARTO strings.

Kind: global class

new Turbocarto(rest)

Create a Turbocarto instance

Param Type Description
rest Rest An instance of Rest

turbocarto.turbocartoToCartocss(turbocarto, sql) ⇒ Promise

Populate the TurboCARTO strings with data from an SQL query in order to generate CartoCSS.

Kind: instance method of Turbocarto

Param Type Description
turbocarto string TurboCARTO string.
sql string SQL query to read data.