-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassifierManager.js
More file actions
79 lines (66 loc) · 1.99 KB
/
Copy pathClassifierManager.js
File metadata and controls
79 lines (66 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'use strict';
const Base = require('./base');
/**
* @desc Can be accessed through `textrazor.classifier`. More details can be found at https://www.textrazor.com/docs/rest#ClassifierManager
*/
class ClassifierManager extends Base {
constructor(apiKey, opts) {
super(apiKey, opts);
}
/**
* @desc Creates a new classifier
* https://www.textrazor.com/docs/rest#ClassifierManager
*
* @param {String} classifier - classifier id
* @param {Object} [opts] - additional options
* @returns {Promise}
*/
create(classifier, opts) {
return this._makeRequest('put', `/categories/${classifier}`, opts);
}
/**
* Deletes a Classifier
*
* @param {String} classifier - classifier id
* @returns {Promise}
*/
delete(classifier) {
return this._makeRequest('delete', `/categories/${classifier}`);
}
/**
* @desc Lists all categories for a given classifier.
*
* @param {String} classifier - classifier id
* @param {Number} [pageLimit] - number of results to return per page
* @param {Number} [page=0] - page to view when using page limit
* @returns {Promise}
*/
list(classifier, pageLimit, page = 0) {
let qs = '';
if (typeof pageLimit !== `undefined`) {
qs = `?limit=${pageLimit}&offset=${page}`;
}
return this._makeRequest('get', `/categories/${classifier}/_all${qs}`);
}
/**
* @desc Gets details for a given category within a classifier
*
* @param {String} classifier - classifier id
* @param {String} category - category id
* @returns {Promise}
*/
getCategory(classifier, category) {
return this._makeRequest('get', `/categories/${classifier}/${category}`);
}
/**
* Deletes a given category within a classifier
*
* @param {String} classifier - classifier id
* @param {String} category - category id
* @returns {Promise}
*/
deleteCategory(classifier, category) {
return this._makeRequest('delete', `/categories/${classifier}/${category}`);
}
}
module.exports = ClassifierManager;