Skip to content

Commit 10b7a45

Browse files
committed
Added doc with jsdoc
1 parent 5e6c461 commit 10b7a45

File tree

6 files changed

+526
-15
lines changed

6 files changed

+526
-15
lines changed

API.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
## Classes
2+
3+
<dl>
4+
<dt><a href="#Rest">Rest</a></dt>
5+
<dd><p>Class to communicate with CARTO Rest API</p>
6+
</dd>
7+
<dt><a href="#Turbocarto">Turbocarto</a></dt>
8+
<dd><p>Class to manipulate TurboCarto strings.</p>
9+
</dd>
10+
</dl>
11+
12+
<a name="Rest"></a>
13+
14+
## Rest
15+
Class to communicate with CARTO Rest API
16+
17+
**Kind**: global class
18+
19+
* [Rest](#Rest)
20+
* [new Rest(args)](#new_Rest_new)
21+
* [.get(args)](#Rest+get) ⇒ <code>Promise</code>
22+
* [.post(args)](#Rest+post) ⇒ <code>Promise</code>
23+
* [.delete(args)](#Rest+delete) ⇒ <code>Promise</code>
24+
* ~~[.del(args)](#Rest+del) ⇒ <code>Promise</code>~~
25+
26+
<a name="new_Rest_new"></a>
27+
28+
### new Rest(args)
29+
Create a Rest instance
30+
31+
32+
| Param | Type | Description |
33+
| --- | --- | --- |
34+
| args | <code>Object</code> | An object to configure the client with a "user" and "api_key" properties. |
35+
36+
<a name="Rest+get"></a>
37+
38+
### rest.get(args) ⇒ <code>Promise</code>
39+
Perform a GET request over CARTO API.
40+
41+
**Kind**: instance method of [<code>Rest</code>](#Rest)
42+
43+
| Param | Type | Description |
44+
| --- | --- | --- |
45+
| args | <code>Object</code> | Spread parameters to `axios` method |
46+
47+
<a name="Rest+post"></a>
48+
49+
### rest.post(args) ⇒ <code>Promise</code>
50+
Perform a POST request over CARTO API.
51+
52+
**Kind**: instance method of [<code>Rest</code>](#Rest)
53+
54+
| Param | Type | Description |
55+
| --- | --- | --- |
56+
| args | <code>Object</code> | Spread parameters to `axios` method |
57+
58+
<a name="Rest+delete"></a>
59+
60+
### rest.delete(args) ⇒ <code>Promise</code>
61+
Perform a DELETE request over CARTO API.
62+
63+
**Kind**: instance method of [<code>Rest</code>](#Rest)
64+
65+
| Param | Type | Description |
66+
| --- | --- | --- |
67+
| args | <code>Object</code> | Spread parameters to `axios` method |
68+
69+
<a name="Rest+del"></a>
70+
71+
### ~~rest.del(args) ⇒ <code>Promise</code>~~
72+
***Deprecated***
73+
74+
Perform a DELETE request over CARTO API.
75+
76+
**Kind**: instance method of [<code>Rest</code>](#Rest)
77+
78+
| Param | Type | Description |
79+
| --- | --- | --- |
80+
| args | <code>Object</code> | Spread parameters to `axios` method |
81+
82+
<a name="Turbocarto"></a>
83+
84+
## Turbocarto
85+
Class to manipulate TurboCarto strings.
86+
87+
**Kind**: global class
88+
89+
* [Turbocarto](#Turbocarto)
90+
* [new Turbocarto(rest)](#new_Turbocarto_new)
91+
* [.turbocartoToCartocss(turbocarto, sql)](#Turbocarto+turbocartoToCartocss) ⇒ <code>Promise</code>
92+
93+
<a name="new_Turbocarto_new"></a>
94+
95+
### new Turbocarto(rest)
96+
Create a Turbocarto instance
97+
98+
99+
| Param | Type | Description |
100+
| --- | --- | --- |
101+
| rest | [<code>Rest</code>](#Rest) | An instance of Rest |
102+
103+
<a name="Turbocarto+turbocartoToCartocss"></a>
104+
105+
### turbocarto.turbocartoToCartocss(turbocarto, sql) ⇒ <code>Promise</code>
106+
Populate the TurboCarto strings with data from an SQL query in order to generate CartoCSS.
107+
108+
**Kind**: instance method of [<code>Turbocarto</code>](#Turbocarto)
109+
110+
| Param | Type | Description |
111+
| --- | --- | --- |
112+
| turbocarto | <code>string</code> | TurboCarto string. |
113+
| sql | <code>string</code> | SQL query to read data. |
114+

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]
22

3-
> A wrapper for CartoDB APIs using SQL and REST.
3+
> A wrapper for CARTO APIs using SQL and REST.
44
55

66
## Install
@@ -9,13 +9,10 @@
99
$ npm install --save cartodb-layers
1010
```
1111

12-
13-
1412
## License
1513

1614
MIT © [Journalism++](http://jplusplus.org)
1715

18-
1916
[npm-image]: https://badge.fury.io/js/cartodb-layers.svg
2017
[npm-url]: https://npmjs.org/package/cartodb-layers
2118
[travis-image]: https://travis-ci.org/jplusplus/cartodb-layers.svg?branch=master

lib/rest.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ const axios = require('axios'),
88
jsonQuery = require('json-query'),
99
Memoizable = require('./memoizable');
1010

11+
/** Class to communicate with CARTO Rest API */
1112
class Rest extends Memoizable {
13+
/**
14+
* Create a Rest instance
15+
* @param {Object} args - An object to configure the client with a "user" and "api_key" properties.
16+
*/
1217
constructor ({ user = "cartodb", api_key }) {
1318
super()
1419
this.api_key = api_key;
@@ -28,16 +33,36 @@ class Rest extends Memoizable {
2833
}
2934
});
3035
}
36+
/**
37+
* Perform a GET request over CARTO API.
38+
* @param {Object} args - Spread parameters to `axios` method
39+
* @return {Promise}
40+
*/
3141
get () {
3242
return this.axios.get(...arguments).then(r => r.data)
3343
}
44+
/**
45+
* Perform a POST request over CARTO API.
46+
* @param {Object} args - Spread parameters to `axios` method
47+
* @return {Promise}
48+
*/
3449
post () {
3550
return this.axios.post(...arguments).then(r => r.data)
3651
}
52+
/**
53+
* Perform a DELETE request over CARTO API.
54+
* @param {Object} args - Spread parameters to `axios` method
55+
* @return {Promise}
56+
*/
3757
delete () {
3858
return this.axios.delete(...arguments)
3959
}
40-
// Backward compatibility
60+
/**
61+
* Perform a DELETE request over CARTO API.
62+
* @param {Object} args - Spread parameters to `axios` method
63+
* @return {Promise}
64+
* @deprecated
65+
*/
4166
del () {
4267
return this.delete(...arguments)
4368
}

lib/turbocarto.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@ const Q = require('q');
33
const SqlApiDatasource = require('./sqlApiDatasource.js')
44
const Memoizable = require('./memoizable.js');
55

6+
/** Class to manipulate TurboCarto strings. */
67
class Turbocarto extends Memoizable {
8+
/**
9+
* Create a Turbocarto instance
10+
* @param {Rest} rest - An instance of Rest
11+
*/
712
constructor (rest) {
813
super();
914
this.rest = rest;
1015
}
16+
/**
17+
* Populate the TurboCarto strings with data from an SQL query in order to generate CartoCSS.
18+
* @param {string} turbocarto - TurboCarto string.
19+
* @param {string} sql - SQL query to read data.
20+
* @return {Promise}
21+
*/
1122
turbocartoToCartocss(turbocarto, sql) {
1223
const q = Q.defer();
1324
preprocessor(turbocarto, new SqlApiDatasource(sql, this.rest), (err, cartocss) => {

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"dependencies": {
2828
"axios": "^0.19.0",
2929
"cartodb": "^0.5.1",
30+
"jsdoc-to-markdown": "^5.0.3",
3031
"json-query": "^2.2.2",
3132
"lodash": "^4.17.15",
3233
"q": "^1.5.1",
@@ -46,6 +47,7 @@
4647
},
4748
"scripts": {
4849
"test": "npx jest",
49-
"lint": "npx grunt jshint"
50+
"lint": "npx grunt jshint",
51+
"doc": "npx jsdoc2md lib/*.js > API.md"
5052
}
5153
}

0 commit comments

Comments
 (0)