Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit de16c41

Browse files
committed
docs: add JSDoc to main interface and resources
Begin to document the project with JSDoc code blocks.
1 parent c3e1c83 commit de16c41

10 files changed

Lines changed: 395 additions & 64 deletions

File tree

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,13 @@ jobs:
3737
skip_cleanup: true
3838
on:
3939
tags: true
40+
- stage: release
41+
node_js: 8
42+
script:
43+
- npm install -g documentation@^5.3.5
44+
- documentation build index.js --format html --output documentation
45+
deploy:
46+
provider: pages
47+
skip_cleanup: true
48+
github_token: $GITHUB_TOKEN
49+
local_dir: documentation

README.md

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,6 @@ async function getZoneStatus(id) {
5151
}
5252
```
5353

54-
### Available resources and methods
55-
56-
* dnsRecords
57-
* `browse(zoneId)`
58-
* `read(zoneId, dnsRecordId)`
59-
* `edit(zoneId, dnsRecordId, params)`
60-
* `add(zoneId, params)`
61-
* `del(zoneId, dnsRecordId)`
62-
* ips
63-
* `browse()`
64-
* zones
65-
* `browse()`
66-
* `read(zoneId)`
67-
* `edit(zoneId, params)`
68-
* `add(params)`
69-
* `del(zoneId)`
70-
* `activationCheck(zoneId)`
71-
* `purgeCache(zoneId, params)`
72-
* user
73-
* `read()`
74-
* `edit(params)`
54+
### Documentation
55+
56+
* [Generated JSDoc](https://cloudflare.github.io/node-cloudflare)

index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ var resources = {
1313
user: require('./lib/resources/User')
1414
};
1515

16+
/**
17+
* Constructs and returns a new Cloudflare API client with the specified authentication.
18+
*
19+
* @class Cloudflare
20+
* @param {Object} auth - The API authentication for an account
21+
* @param {string} auth.email - The account email address
22+
* @param {string} auth.key - The account API token key
23+
*
24+
* @property {DNSRecords} dnsRecords - DNS Records instance
25+
* @property {IPs} ips - IPs instance
26+
* @property {Zones} zones - Zones instance
27+
* @property {ZoneSettings} zoneSettings - Zone Settings instance
28+
* @property {ZoneCustomHostNames} zoneCustomHostNames - Zone Custom Host Names instance
29+
* @property {User} user - User instance
30+
*/
1631
var Cloudflare = auto(prototypal({
1732
constructor: function (auth) {
1833
var client = new Client({

lib/Resource.js

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,43 @@ var BASIC_METHODS = {
2323
})
2424
};
2525

26-
module.exports = prototypal({
27-
constructor: function (client) {
28-
Object.defineProperty(this, '_client', {
29-
value: client,
30-
writable: false,
31-
enumerable: false,
32-
configurable: false
33-
});
26+
/**
27+
* Resource generates basic methods defined on subclasses. It is not intended to
28+
* be constructed directly.
29+
*
30+
* @class Resource
31+
* @private
32+
*/
33+
module.exports = prototypal(
34+
/** @lends Resource.prototype */
35+
{
36+
constructor: function (client) {
37+
Object.defineProperty(this, '_client', {
38+
value: client,
39+
writable: false,
40+
enumerable: false,
41+
configurable: false
42+
});
3443

35-
if (Array.isArray(this.includeBasic)) {
36-
this.includeBasic.forEach(function (m) {
37-
Object.defineProperty(this, m, {
38-
value: BASIC_METHODS[m],
39-
writable: true,
40-
enumberable: false,
41-
configurable: true
42-
});
43-
}, this);
44-
}
45-
},
46-
createFullPath: function (methodPath) {
47-
return (methodPath && [this.path, methodPath].join('/')) || this.path;
48-
},
49-
path: '',
50-
hasBrokenPatch: false
51-
});
44+
if (Array.isArray(this.includeBasic)) {
45+
this.includeBasic.forEach(function (m) {
46+
Object.defineProperty(this, m, {
47+
value: BASIC_METHODS[m],
48+
writable: true,
49+
enumberable: false,
50+
configurable: true
51+
});
52+
}, this);
53+
}
54+
},
55+
/**
56+
* @param {string} methodPath - The path from the {@link method} that should be
57+
* joined with the resource's path.
58+
*/
59+
createFullPath: function (methodPath) {
60+
return (methodPath && [this.path, methodPath].join('/')) || this.path;
61+
},
62+
path: '',
63+
hasBrokenPatch: false
64+
}
65+
);

lib/resources/DNSRecords.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ var auto = require('autocreate');
55
var Resource = require('../Resource');
66
var method = require('../method');
77

8+
/**
9+
* DNSRecords represents the /zones/:zoneID/dns_records API endpoint.
10+
*
11+
* @class DNSRecords
12+
* @hideconstructor
13+
* @extends Resource
14+
*/
815
module.exports = auto(prototypal({
916
extends: Resource,
1017
path: 'zones/:zoneId/dns_records',
@@ -16,8 +23,64 @@ module.exports = auto(prototypal({
1623
'del'
1724
],
1825

26+
/**
27+
* edit allows for modification of the specified DNS Record
28+
*
29+
* @function edit
30+
* @memberof DNSRecords
31+
* @instance
32+
* @async
33+
* @param {string} zone_id - The zone ID
34+
* @param {string} id - The DNS record ID being modified
35+
* @param {Object} record - The modified dns record object
36+
* @returns {Promise<Object>} The DNS record object.
37+
*/
1938
edit: method({
2039
method: 'PUT',
2140
path: '/:id'
2241
})
42+
43+
/**
44+
* browse allows for listing all DNS Records for a zone
45+
*
46+
* @function browse
47+
* @memberof DNSRecords
48+
* @instance
49+
* @async
50+
* @param {string} zone_id - The zone ID
51+
* @returns {Promise<Object>} The DNS browser response object.
52+
*/
53+
/**
54+
* read allows for retrieving the specified DNS Record
55+
*
56+
* @function read
57+
* @memberof DNSRecords
58+
* @instance
59+
* @async
60+
* @param {string} zone_id - The zone ID
61+
* @param {string} id - The DNS record ID
62+
* @returns {Promise<Object>} The DNS record object.
63+
*/
64+
/**
65+
* add allows for creating a new DNS record for a zone.
66+
*
67+
* @function add
68+
* @memberof DNSRecords
69+
* @instance
70+
* @async
71+
* @param {string} zone_id - The zone ID
72+
* @param {Object} record - The new DNS record object
73+
* @returns {Promise<Object>} The created DNS record object.
74+
*/
75+
/**
76+
* del allows for deleting the specified DNS Record
77+
*
78+
* @function del
79+
* @memberof DNSRecords
80+
* @instance
81+
* @async
82+
* @param {string} zone_id - The zone ID
83+
* @param {string} id - The DNS record ID to delete
84+
* @returns {Promise<Object>} The deleted DNS record object.
85+
*/
2386
}));

lib/resources/IPs.js

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,33 @@ var auto = require('autocreate');
44

55
var Resource = require('../Resource');
66

7-
module.exports = auto(prototypal({
8-
extends: Resource,
9-
path: 'ips',
10-
11-
includeBasic: [
12-
'browse'
13-
]
14-
}));
7+
/**
8+
* IPs represents the /ips API endpoint.
9+
*
10+
* @class IPs
11+
* @hideconstructor
12+
* @extends Resource
13+
*/
14+
module.exports = auto(prototypal(
15+
{
16+
extends: Resource,
17+
path: 'ips',
18+
19+
includeBasic: [
20+
'browse'
21+
]
22+
23+
/**
24+
* browse returns a Promise of the current Cloudflare IPv4 and IPv6 addresses.
25+
*
26+
* @function browse
27+
* @memberof IPs
28+
* @instance
29+
* @async
30+
* @returns {Promise<Object>} The IPv4 and IPv6 addresses
31+
* @example
32+
* // logs the fetched IP addresses
33+
* cf.ips.browse(console.log)
34+
*/
35+
}
36+
));

lib/resources/User.js

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,43 @@ var auto = require('autocreate');
55
var Resource = require('../Resource');
66
var method = require('../method');
77

8-
module.exports = auto(prototypal({
9-
extends: Resource,
10-
path: 'user',
8+
/**
9+
* User represents the /user API endpoint.
10+
*
11+
* @class User
12+
* @hideconstructor
13+
* @extends Resource
14+
*/
15+
module.exports = auto(prototypal(
16+
{
17+
extends: Resource,
18+
path: 'user',
1119

12-
read: method({
13-
method: 'GET'
14-
}),
20+
/**
21+
* read returns the current user object
22+
*
23+
* @function read
24+
* @memberof User
25+
* @instance
26+
* @async
27+
* @returns {Promise<Object>} The user object
28+
*/
29+
read: method({
30+
method: 'GET'
31+
}),
1532

16-
edit: method({
17-
method: 'PATCH'
18-
})
19-
}));
33+
/**
34+
* edit allows for modification of the current user
35+
*
36+
* @function edit
37+
* @memberof User
38+
* @instance
39+
* @async
40+
* @param {Object} user - The modified user object
41+
* @returns {Promise<Object>} The user object
42+
*/
43+
edit: method({
44+
method: 'PATCH'
45+
})
46+
}
47+
));

lib/resources/ZoneCustomHostNames.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ var auto = require('autocreate');
44

55
var Resource = require('../Resource');
66

7+
/**
8+
* ZoneCustomHostNames represents the /zones/:zoneID/custom_hostnames API endpoint.
9+
*
10+
* @class ZoneCustomHostNames
11+
* @hideconstructor
12+
* @extends Resource
13+
*/
714
module.exports = auto(prototypal({
815
extends: Resource,
916
path: 'zones/:zoneId/custom_hostnames',
@@ -15,4 +22,60 @@ module.exports = auto(prototypal({
1522
'add',
1623
'del'
1724
]
25+
26+
/**
27+
* browse allows for listing all of a zone's custom hostanames
28+
*
29+
* @function browse
30+
* @memberof ZoneCustomHostNames
31+
* @instance
32+
* @async
33+
* @param {string} zone_id - The zone ID
34+
* @returns {Promise<Object>} The custom hostname browse response object.
35+
*/
36+
/**
37+
* read allows for retrieving a specific custom hostname
38+
*
39+
* @function read
40+
* @memberof ZoneCustomHostNames
41+
* @instance
42+
* @async
43+
* @param {string} zone_id - The zone ID
44+
* @param {string} id - The custom hostname ID
45+
* @returns {Promise<Object>} The custom hostname response object.
46+
*/
47+
/**
48+
* edit allows for modifying a specific zone
49+
*
50+
* @function edit
51+
* @memberof ZoneCustomHostNames
52+
* @instance
53+
* @async
54+
* @param {string} zone_id - The zone ID
55+
* @param {string} id - The custom hostname ID
56+
* @param {Object} config - The modified custom hostname object
57+
* @returns {Promise<Object>} The custom hostname response object.
58+
*/
59+
/**
60+
* add allows for creating a new zone
61+
*
62+
* @function add
63+
* @memberof ZoneCustomHostNames
64+
* @instance
65+
* @async
66+
* @param {string} zone_id - The zone ID
67+
* @param {Object} config - The new custom hostname object
68+
* @returns {Promise<Object>} The custom hostname response object.
69+
*/
70+
/**
71+
* del allows for removing a new zone
72+
*
73+
* @function del
74+
* @memberof ZoneCustomHostNames
75+
* @instance
76+
* @async
77+
* @param {string} zone_id - The zone ID
78+
* @param {string} id - The custom hostname ID to delete
79+
* @returns {Promise<Object>} The custom hostname response object.
80+
*/
1881
}));

0 commit comments

Comments
 (0)