diff --git a/.gitignore b/.gitignore index 260f801..2d0acaf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules lib/*.cache .DS_Store +.idea/ diff --git a/README.md b/README.md index fa3c893..ae414dc 100644 --- a/README.md +++ b/README.md @@ -77,11 +77,12 @@ The callback receives an object as the 2nd argument and contains the number of a Clears cached rules. ### The following methods uses Gnip API directly and ignores the local cache. Avoid usage if you are working with too many rules! -- `live.update(rules: Array, callback)` -- `live.add(rules: Array, callback)` -- `live.remove(rules: Array, callback)` +- `live.update(rules: Array<(string|{value:string, tag:string})>, callback)` +- `live.add(rules: Array<(string|{value:string, tag:string})>, callback)` +- `live.remove(rules: Array<(string|{value:string, tag:string})>, callback)` +- `live.removeByIds(ids: Array, cb)` - `live.getAll(callback)` -- `live.getByIds(ids: Array, callback)` +- `live.getByIds(ids: Array, callback)` - `live.removeAll(callback)` # Gnip.Search diff --git a/lib/index.js b/lib/index.js index 3c53026..624cbfa 100644 --- a/lib/index.js +++ b/lib/index.js @@ -123,7 +123,7 @@ GnipStream.prototype.start = function () { self.end(); }); if (res.statusCode < 200 || res.statusCode > 299) { - self.emit('error', new Error('Response error. HTTP status code: ' + res.statusCode)); + self.emit('error', new Error('Response error. HTTP status code: ' + res.statusCode + 'body: '+ JSON.stringify(res && res.body))); self.end(); } else { diff --git a/lib/rules.js b/lib/rules.js index cdcea2e..968255a 100644 --- a/lib/rules.js +++ b/lib/rules.js @@ -26,7 +26,7 @@ function formatFailedRules (body) { /** * Add rules - * @param rules Array of rules as strings or objects in the form {value: String, tag: String} + * @param {Array<(string|{value:string, tag:string})>} rules Array of rules as strings or objects in the form {value: String, tag: String} * @param cb Function callback */ LiveRules.prototype.add = function (rules, cb) { @@ -54,7 +54,7 @@ LiveRules.prototype.add = function (rules, cb) { /** * Delete rules - * @param rules Array of rules as strings or objects in the form {value: String, tag: String} + * @param {Array<(string|{value:string, tag:string})>}rules Array of rules as strings or objects in the form {value: String, tag: String} * @param cb Function callback */ LiveRules.prototype.remove = function (rules, cb) { @@ -77,10 +77,29 @@ LiveRules.prototype.remove = function (rules, cb) { } }); }; +/** + * delete rules by ids + * @param {Array} rules_ids + * @param cb + */ +LiveRules.prototype.removeByIds = function (rules_ids, cb) { + var json = { + rule_ids: rules_ids + }; + request.post({ + url: this._api + '?_method=delete', + json: json, + headers: { 'Authorization': this._auth } + }, function (err, response, body) { + if (err) cb(err); + else if (response.statusCode >= 200 && response.statusCode < 300) cb(null, body); + else cb(new Error('Unable to delete rules. Request failed with status code: ' + response.statusCode + 'body: '+ JSON.stringify(body))); + }); +}; /** * Replace existing tracking rules -* @param rules Array of rules as strings or objects in the form {value: String, tag: String} +* @param {Array<(string|{value:string, tag:string})>} rules Array of rules as strings or objects in the form {value: String, tag: String} * @param cb Function callback */ LiveRules.prototype.update = function (rules, cb) { @@ -118,7 +137,7 @@ LiveRules.prototype.getAll = function (cb) { /** * Get rules matching GNIP IDs -* @param ids List of strings +* @param {Array} ids List of strings * @param cb Function callback */ LiveRules.prototype.getByIds = function (ids, cb) { diff --git a/package-lock.json b/package-lock.json index 2bef6b5..e246e75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "gnip", - "version": "2.2.3", + "version": "2.2.4", "lockfileVersion": 1, "requires": true, "dependencies": {