@slack/client
Advanced tools
Comparing version 2.3.0 to 3.0.0
@@ -0,1 +1,22 @@ | ||
### v3.0.0 (2016-04-24) | ||
* Adds a number of new web client API facets: | ||
- [`dnd`](/lib/clients/web/facets/dnd.js) | ||
- [`files.comments`](/lib/clients/web/facets/files.comments.js) | ||
- [`mpim`](/lib/clients/web/facets/mpim.js) | ||
- [`usergroups`](/lib/clients/web/facets/usergroups.js) | ||
- [`usergroups.users`](/lib/clients/web/facets/usergroups.users.js) | ||
* **BREAKING** Changes the function signatures for some facet methods: | ||
- [`channels.list`](/lib/clients/web/facets/channels.js): `exclude_archived` moves to an `opts` object, instead of being a separate argument | ||
- [`groups.list`](/lib/clients/web/facets/groups.js): `exclude_archived` moves to an `opts` object, instead of being a separate argument | ||
- [`chat.delete`](/lib/clients/web/facets/chat.js): The `ts` and `channel` arguments are re-ordered to be alphabetical | ||
- [`stars.list`](/lib/clients/web/facets/stars.js): `user` moves to an `opts` object, instead of being a separate argument | ||
- [`users.list`](/lib/clients/web/facets/users.js): `presence` moves to an `opts` object, instead of being a separate argument | ||
* **BREAKING** Updates the function signature for [`BaseAPIClient.prototype.makeAPICall`](/lib/clients/client.js) to take required API args and optional API args as separate params, from `makeAPICall(endpoint, optData, optCb)` to `makeAPICall(endpoint, apiArgs, apiOptArgs, optCb)` | ||
* New methods are added to various facets: | ||
- [`files.revokePublicURL`](/lib/clients/web/facets/files.js) | ||
- [`files.sharedPublicURL`](/lib/clients/web/facets/files.js) | ||
- [`team.integrationLogs`](/lib/clients/web/facets/team.js) | ||
- [`team.integrationLogs`](/lib/clients/web/facets/team.js) | ||
### v2.3.0 (2016-02-28) | ||
@@ -2,0 +23,0 @@ |
@@ -137,14 +137,13 @@ /** | ||
* @param {String} endpoint The API endpoint to send to. | ||
* @param {Object=} optData The data send to the Slack API. | ||
* @param {Object=} apiArgs | ||
* @param {Object=} apiOptArgs | ||
* @param {function=} optCb The callback to run on completion. | ||
* @private | ||
*/ | ||
BaseAPIClient.prototype.makeAPICall = function makeAPICall(endpoint, optData, optCb) { | ||
BaseAPIClient.prototype._makeAPICall = function _makeAPICall(endpoint, apiArgs, apiOptArgs, optCb) { | ||
var promise; | ||
var args; | ||
var _this = this; | ||
var apiCallArgs = helpers.getAPICallArgs(this._token, optData, optCb); | ||
args = { | ||
var args = { | ||
url: urlJoin(this.slackAPIUrl, endpoint), | ||
data: apiCallArgs.data, | ||
data: helpers.getApiCallData(this._token, apiArgs, apiOptArgs), | ||
headers: { | ||
@@ -155,3 +154,3 @@ 'User-Agent': this.userAgent | ||
if (!apiCallArgs.cb) { | ||
if (!optCb) { | ||
promise = new Promise(function makeAPICallPromiseResolver(resolve, reject) { | ||
@@ -176,3 +175,3 @@ _this.requestQueue.push({ | ||
args: args, | ||
cb: apiCallArgs.cb | ||
cb: optCb | ||
}); | ||
@@ -179,0 +178,0 @@ } |
@@ -5,5 +5,7 @@ /** | ||
var assign = require('lodash').assign; | ||
var isFunction = require('lodash').isFunction; | ||
// For some reason eslint sees the target[key] assigns as an issue | ||
/* eslint no-param-reassign: 0 */ | ||
var isUndefined = require('lodash').isUndefined; | ||
var isPlainObject = require('lodash').isPlainObject; | ||
var isString = require('lodash').isString; | ||
@@ -13,12 +15,8 @@ var forEach = require('lodash').forEach; | ||
/** | ||
* | ||
* @param {object} data | ||
* @returns {object} | ||
*/ | ||
var getData = function getData(data, token) { | ||
var newData = {}; | ||
assign(data, data ? data.opts || {} : {}); | ||
var assignApiArgs = function assignApiArgs(target, source) { | ||
if (!isPlainObject(source)) { | ||
return; | ||
} | ||
forEach(data || {}, function getValidData(val, key) { | ||
forEach(source, function getValidData(val, key) { | ||
if (!isUndefined(val) && val !== null && key !== 'opts') { | ||
@@ -29,12 +27,26 @@ // For the web API, this should always be a JSON-encoded array, see: | ||
if (isString(val)) { | ||
newData[key] = val; | ||
target[key] = val; | ||
} else { | ||
newData[key] = JSON.stringify(val); | ||
target[key] = JSON.stringify(val); | ||
} | ||
} else if (key !== 'opts') { | ||
newData[key] = val; | ||
target[key] = val; | ||
} | ||
} | ||
}); | ||
}; | ||
/** | ||
* | ||
* @param token | ||
* @param requiredArgs | ||
* @param optArgs | ||
* @returns {{}} | ||
*/ | ||
var getApiCallData = function getApiCallData(token, requiredArgs, optArgs) { | ||
var newData = {}; | ||
assignApiArgs(newData, optArgs); | ||
assignApiArgs(newData, requiredArgs); | ||
// There are a couple of API calls that don't require tokens, so check before passing it through | ||
@@ -49,28 +61,2 @@ if (token) { | ||
var getAPICallArgs = function getAPICallArgs(token, optData, optCb) { | ||
var data; | ||
var cb; | ||
if (arguments.length === 1) { | ||
data = getData({}, token); | ||
} else if (arguments.length === 2) { | ||
if (isFunction(arguments[1])) { | ||
cb = arguments[1]; | ||
data = getData({}, token); | ||
} else { | ||
data = getData(optData, token); | ||
} | ||
} else if (arguments.length === 3) { | ||
cb = optCb; | ||
data = getData(optData, token); | ||
} | ||
return { | ||
cb: cb, | ||
data: data | ||
}; | ||
}; | ||
module.exports.getData = getData; | ||
module.exports.getAPICallArgs = getAPICallArgs; | ||
module.exports.getApiCallData = getApiCallData; |
@@ -200,3 +200,3 @@ /** | ||
*/ | ||
this._rtm = new RtmFacet(bind(this.makeAPICall, this)); | ||
this._rtm = new RtmFacet(bind(this._makeAPICall, this)); | ||
}; | ||
@@ -203,0 +203,0 @@ |
@@ -37,3 +37,3 @@ /** | ||
makeAPICall = bind(this.makeAPICall, this); | ||
makeAPICall = bind(this._makeAPICall, this); | ||
forEach(facets, function registerWebClientFacet(Facet) { | ||
@@ -40,0 +40,0 @@ newFacet = new Facet(makeAPICall); |
@@ -21,12 +21,8 @@ /** | ||
* @param {Object=} opts | ||
* @param {?} opts.error Error response to return | ||
* @param {?} opts.foo example property to return | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.error - Error response to return | ||
* @param {?} opts.foo - example property to return | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ApiFacet.prototype.test = function test(opts, optCb) { | ||
var args = { | ||
opts: opts | ||
}; | ||
return this.makeAPICall('api.test', args, optCb); | ||
return this.makeAPICall('api.test', null, opts, optCb); | ||
}; | ||
@@ -33,0 +29,0 @@ |
@@ -20,8 +20,6 @@ /** | ||
* | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
AuthFacet.prototype.test = function test(optCb) { | ||
var args = {}; | ||
return this.makeAPICall('auth.test', args, optCb); | ||
return this.makeAPICall('auth.test', null, null, optCb); | ||
}; | ||
@@ -28,0 +26,0 @@ |
@@ -22,5 +22,3 @@ /** | ||
var getArgsForFnsWithOptArgs = require('./helpers').getArgsForFnsWithOptArgs; | ||
function ChannelsFacet(makeAPICall) { | ||
@@ -36,13 +34,14 @@ this.name = 'channels'; | ||
* | ||
* @param {?} channel Channel to archive | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Channel to archive | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ChannelsFacet.prototype.archive = function archive(channel, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel | ||
}; | ||
return this.makeAPICall('channels.archive', args, optCb); | ||
return this.makeAPICall('channels.archive', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
@@ -52,13 +51,14 @@ * Creates a channel. | ||
* | ||
* @param {?} name Name of channel to create | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} name - Name of channel to create | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ChannelsFacet.prototype.create = function create(name, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
name: name | ||
}; | ||
return this.makeAPICall('channels.create', args, optCb); | ||
return this.makeAPICall('channels.create', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
@@ -68,19 +68,20 @@ * Fetches history of messages and events from a channel. | ||
* | ||
* @param {?} channel Channel to fetch history for. | ||
* @param {?} channel - Channel to fetch history for. | ||
* @param {Object=} opts | ||
* @param {?} opts.latest End of time range of messages to include in results. | ||
* @param {?} opts.oldest Start of time range of messages to include in results. | ||
* @param {?} opts.inclusive Include messages with latest or oldest timestamp in results. | ||
* @param {?} opts.count Number of messages to return, between 1 and 1000. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.latest - End of time range of messages to include in results. | ||
* @param {?} opts.oldest - Start of time range of messages to include in results. | ||
* @param {?} opts.inclusive - Include messages with latest or oldest timestamp in results. | ||
* @param {?} opts.count - Number of messages to return, between 1 and 1000. | ||
* @param {?} opts.unreads - Include `unread_count_display` in the output? | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ChannelsFacet.prototype.history = function history(channel, opts, optCb) { | ||
var args = { | ||
channel: channel, | ||
opts: opts | ||
var requiredArgs = { | ||
channel: channel | ||
}; | ||
return this.makeAPICall('channels.history', args, optCb); | ||
return this.makeAPICall('channels.history', requiredArgs, opts, optCb); | ||
}; | ||
/** | ||
@@ -90,13 +91,14 @@ * Gets information about a channel. | ||
* | ||
* @param {?} channel Channel to get info on | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Channel to get info on | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ChannelsFacet.prototype.info = function info(channel, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel | ||
}; | ||
return this.makeAPICall('channels.info', args, optCb); | ||
return this.makeAPICall('channels.info', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
@@ -106,8 +108,8 @@ * Invites a user to a channel. | ||
* | ||
* @param {?} channel Channel to invite user to. | ||
* @param {?} user User to invite to channel. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Channel to invite user to. | ||
* @param {?} user - User to invite to channel. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ChannelsFacet.prototype.invite = function invite(channel, user, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel, | ||
@@ -117,5 +119,6 @@ user: user | ||
return this.makeAPICall('channels.invite', args, optCb); | ||
return this.makeAPICall('channels.invite', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
@@ -125,13 +128,14 @@ * Joins a channel, creating it if needed. | ||
* | ||
* @param {?} name Name of channel to join | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} name - Name of channel to join | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ChannelsFacet.prototype.join = function join(name, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
name: name | ||
}; | ||
return this.makeAPICall('channels.join', args, optCb); | ||
return this.makeAPICall('channels.join', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
@@ -141,8 +145,8 @@ * Removes a user from a channel. | ||
* | ||
* @param {?} channel Channel to remove user from. | ||
* @param {?} user User to remove from channel. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Channel to remove user from. | ||
* @param {?} user - User to remove from channel. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ChannelsFacet.prototype.kick = function kick(channel, user, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel, | ||
@@ -152,5 +156,6 @@ user: user | ||
return this.makeAPICall('channels.kick', args, optCb); | ||
return this.makeAPICall('channels.kick', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
@@ -160,13 +165,14 @@ * Leaves a channel. | ||
* | ||
* @param {?} channel Channel to leave | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Channel to leave | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ChannelsFacet.prototype.leave = function leave(channel, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel | ||
}; | ||
return this.makeAPICall('channels.leave', args, optCb); | ||
return this.makeAPICall('channels.leave', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
@@ -176,10 +182,11 @@ * Lists all channels in a Slack team. | ||
* | ||
* @param {?} optExcludeArchived Don't return archived channels. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {Object=} opts | ||
* @param {?} opts.exclude_archived - Don't return archived channels. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ChannelsFacet.prototype.list = function list(optExcludeArchived, optCb) { | ||
var fnArgs = getArgsForFnsWithOptArgs(optExcludeArchived, optCb, 'exclude_archived'); | ||
return this.makeAPICall('channels.list', fnArgs.args, fnArgs.cb); | ||
ChannelsFacet.prototype.list = function list(opts, optCb) { | ||
return this.makeAPICall('channels.list', null, opts, optCb); | ||
}; | ||
/** | ||
@@ -189,8 +196,8 @@ * Sets the read cursor in a channel. | ||
* | ||
* @param {?} channel Channel to set reading cursor in. | ||
* @param {?} ts Timestamp of the most recently seen message. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Channel to set reading cursor in. | ||
* @param {?} ts - Timestamp of the most recently seen message. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ChannelsFacet.prototype.mark = function mark(channel, ts, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel, | ||
@@ -200,5 +207,6 @@ ts: ts | ||
return this.makeAPICall('channels.mark', args, optCb); | ||
return this.makeAPICall('channels.mark', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
@@ -208,8 +216,8 @@ * Renames a channel. | ||
* | ||
* @param {?} channel Channel to rename | ||
* @param {?} name New name for channel. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Channel to rename | ||
* @param {?} name - New name for channel. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ChannelsFacet.prototype.rename = function rename(channel, name, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel, | ||
@@ -219,5 +227,6 @@ name: name | ||
return this.makeAPICall('channels.rename', args, optCb); | ||
return this.makeAPICall('channels.rename', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
@@ -227,8 +236,8 @@ * Sets the purpose for a channel. | ||
* | ||
* @param {?} channel Channel to set the purpose of | ||
* @param {?} purpose The new purpose | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Channel to set the purpose of | ||
* @param {?} purpose - The new purpose | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ChannelsFacet.prototype.setPurpose = function setPurpose(channel, purpose, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel, | ||
@@ -238,5 +247,6 @@ purpose: purpose | ||
return this.makeAPICall('channels.setPurpose', args, optCb); | ||
return this.makeAPICall('channels.setPurpose', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
@@ -246,8 +256,8 @@ * Sets the topic for a channel. | ||
* | ||
* @param {?} channel Channel to set the topic of | ||
* @param {?} topic The new topic | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Channel to set the topic of | ||
* @param {?} topic - The new topic | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ChannelsFacet.prototype.setTopic = function setTopic(channel, topic, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel, | ||
@@ -257,5 +267,6 @@ topic: topic | ||
return this.makeAPICall('channels.setTopic', args, optCb); | ||
return this.makeAPICall('channels.setTopic', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
@@ -265,11 +276,11 @@ * Unarchives a channel. | ||
* | ||
* @param {?} channel Channel to unarchive | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Channel to unarchive | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ChannelsFacet.prototype.unarchive = function unarchive(channel, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel | ||
}; | ||
return this.makeAPICall('channels.unarchive', args, optCb); | ||
return this.makeAPICall('channels.unarchive', requiredArgs, null, optCb); | ||
}; | ||
@@ -276,0 +287,0 @@ |
@@ -22,8 +22,8 @@ /** | ||
* | ||
* @param {?} ts Timestamp of the message to be deleted. | ||
* @param {?} channel Channel containing the message to be deleted. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} ts - Timestamp of the message to be deleted. | ||
* @param {?} channel - Channel containing the message to be deleted. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ChatFacet.prototype.delete = function delete_(ts, channel, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
ts: ts, | ||
@@ -33,5 +33,6 @@ channel: channel | ||
return this.makeAPICall('chat.delete', args, optCb); | ||
return this.makeAPICall('chat.delete', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
@@ -41,27 +42,35 @@ * Sends a message to a channel. | ||
* | ||
* @param {?} channel Channel, private group, or IM channel to send message to. | ||
* Can be an encoded ID, or a name. See below for more details. | ||
* @param {?} text Text of the message to send. See below for an explanation of formatting. | ||
* @param {?} channel - Channel, private group, or IM channel to send message to. Can be an | ||
* encoded ID, or a name. See [below](#channels) for more details. | ||
* @param {?} text - Text of the message to send. See below for an explanation of | ||
* [formatting](#formatting). | ||
* @param {Object=} opts | ||
* @param {?} opts.username Name of bot. | ||
* @param {?} opts.as_user Pass true to post the message as the authed user, instead of as a bot | ||
* @param {?} opts.parse Change how messages are treated. See below. | ||
* @param {?} opts.link_names Find and link channel names and usernames. | ||
* @param {?} opts.attachments Structured message attachments. | ||
* @param {?} opts.unfurl_links Pass true to enable unfurling of primarily text-based content. | ||
* @param {?} opts.unfurl_media Pass false to disable unfurling of media content. | ||
* @param {?} opts.icon_url URL to an image to use as the icon for this message | ||
* @param {?} opts.icon_emoji emoji to use as the icon for this message. Overrides `icon_url`. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.parse - Change how messages are treated. Defaults to `none`. See | ||
* [below](#formatting). | ||
* @param {?} opts.link_names - Find and link channel names and usernames. | ||
* @param {?} opts.attachments - Structured message attachments. | ||
* @param {?} opts.unfurl_links - Pass true to enable unfurling of primarily text-based content. | ||
* @param {?} opts.unfurl_media - Pass false to disable unfurling of media content. | ||
* @param {?} opts.username - Set your bot's user name. Must be used in conjunction with `as_user` | ||
* set to false, otherwise ignored. See [authorship](#authorship) below. | ||
* @param {?} opts.as_user - Pass true to post the message as the authed user, instead of as a | ||
* bot. Defaults to false. See [authorship](#authorship) below. | ||
* @param {?} opts.icon_url - URL to an image to use as the icon for this message. Must be used in | ||
* conjunction with `as_user` set to false, otherwise ignored. See [authorship](#authorship) | ||
* below. | ||
* @param {?} opts.icon_emoji - emoji to use as the icon for this message. Overrides `icon_url`. | ||
* Must be used in conjunction with `as_user` set to false, otherwise ignored. See | ||
* [authorship](#authorship) below. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ChatFacet.prototype.postMessage = function postMessage(channel, text, opts, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel, | ||
text: text, | ||
opts: opts | ||
text: text | ||
}; | ||
return this.makeAPICall('chat.postMessage', args, optCb); | ||
return this.makeAPICall('chat.postMessage', requiredArgs, opts, optCb); | ||
}; | ||
/** | ||
@@ -71,20 +80,25 @@ * Updates a message. | ||
* | ||
* @param {?} ts Timestamp of the message to be updated. | ||
* @param {?} channel Channel containing the message to be updated. | ||
* @param {?} text New text for the message, using the [default formatting rules](/docs/formatting). | ||
* @param {?} ts - Timestamp of the message to be updated. | ||
* @param {?} channel - Channel containing the message to be updated. | ||
* @param {?} text - New text for the message, using the [default formatting | ||
* rules](/docs/formatting). | ||
* @param {Object=} opts | ||
* @param {?} opts.attachments Structured message attachments. | ||
* @param {?} opts.parse Change how messages are treated. See below. | ||
* @param {?} opts.link_names Find and link channel names and usernames. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.attachments - Structured message attachments. | ||
* @param {?} opts.parse - Change how messages are treated. Defaults to `client`, unlike | ||
* `chat.postMessage`. See [below](#formatting). | ||
* @param {?} opts.link_names - Find and link channel names and usernames. Defaults to `none`. | ||
* This parameter should be used in conjunction with `parse`. To set `link_names` to `1`, specify | ||
* a `parse` mode of `full`. | ||
* @param {?} opts.as_user - Pass true to update the message as the authed user. [Bot | ||
* users](/bot-users) in this context are considered authed users. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ChatFacet.prototype.update = function update(ts, channel, text, opts, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
ts: ts, | ||
channel: channel, | ||
text: text, | ||
opts: opts | ||
text: text | ||
}; | ||
return this.makeAPICall('chat.update', args, optCb); | ||
return this.makeAPICall('chat.update', requiredArgs, opts, optCb); | ||
}; | ||
@@ -91,0 +105,0 @@ |
@@ -20,8 +20,6 @@ /** | ||
* | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
EmojiFacet.prototype.list = function list(optCb) { | ||
var args = {}; | ||
return this.makeAPICall('emoji.list', args, optCb); | ||
return this.makeAPICall('emoji.list', null, null, optCb); | ||
}; | ||
@@ -28,0 +26,0 @@ |
@@ -8,2 +8,4 @@ /** | ||
* - list: {@link https://api.slack.com/methods/files.list|files.list} | ||
* - revokePublicURL: {@link https://api.slack.com/methods/files.revokePublicURL|files.revokePublicURL} | ||
* - sharedPublicURL: {@link https://api.slack.com/methods/files.sharedPublicURL|files.sharedPublicURL} | ||
* - upload: {@link https://api.slack.com/methods/files.upload|files.upload} | ||
@@ -24,13 +26,14 @@ * | ||
* | ||
* @param {?} file ID of file to delete. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} file - ID of file to delete. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
FilesFacet.prototype.delete = function delete_(file, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
file: file | ||
}; | ||
return this.makeAPICall('files.delete', args, optCb); | ||
return this.makeAPICall('files.delete', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
@@ -40,13 +43,17 @@ * Gets information about a team file. | ||
* | ||
* @param {?} file File to fetch info for | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} file - Specify a file by providing its ID. | ||
* @param {Object=} opts | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
FilesFacet.prototype.info = function info(file, optCb) { | ||
var args = { | ||
FilesFacet.prototype.info = function info(file, opts, optCb) { | ||
var requiredArgs = { | ||
file: file | ||
}; | ||
return this.makeAPICall('files.info', args, optCb); | ||
return this.makeAPICall('files.info', requiredArgs, opts, optCb); | ||
}; | ||
/** | ||
@@ -57,47 +64,82 @@ * Lists & filters team files. | ||
* @param {Object=} opts | ||
* @param {?} opts.user Filter files created by a single user. | ||
* @param {?} opts.ts_from Filter files created after this timestamp (inclusive). | ||
* @param {?} opts.ts_to Filter files created before this timestamp (inclusive). | ||
* @param {?} opts.types Filter files by type: | ||
- `all` - All files | ||
- `posts` - Posts | ||
- `snippets` - Snippets | ||
- `images` - Image files | ||
- `gdocs` - Google docs | ||
- `zips` - Zip files | ||
- `pdfs` - PDF files | ||
* @param {?} opts.user - Filter files created by a single user. | ||
* @param {?} opts.channel - Filter files appearing in a specific channel, indicated by its ID. | ||
* @param {?} opts.ts_from - Filter files created after this timestamp (inclusive). | ||
* @param {?} opts.ts_to - Filter files created before this timestamp (inclusive). | ||
* @param {?} opts.types - Filter files by type: | ||
* | ||
* * `all` - All files | ||
* * `posts` - Posts | ||
* * `snippets` - Snippets | ||
* * `images` - Image files | ||
* * `gdocs` - Google docs | ||
* * `zips` - Zip files | ||
* * `pdfs` - PDF files | ||
* | ||
* You can pass multiple values in the types argument, like `types=posts,snippets`.The default | ||
* value is `all`, which does not filter the list. | ||
* You can pass multiple values in the types argument, like `types=posts,snippets`. | ||
* The default value is `all`, which does not filter the list. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
FilesFacet.prototype.list = function list(opts, optCb) { | ||
return this.makeAPICall('files.list', null, opts, optCb); | ||
}; | ||
/** | ||
* Revokes public/external sharing access for a file | ||
* @see {@link https://api.slack.com/methods/files.revokePublicURL|files.revokePublicURL} | ||
* | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} file - File to revoke | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
FilesFacet.prototype.list = function list(opts, optCb) { | ||
var args = { | ||
opts: opts | ||
FilesFacet.prototype.revokePublicURL = function revokePublicURL(file, optCb) { | ||
var requiredArgs = { | ||
file: file | ||
}; | ||
return this.makeAPICall('files.list', args, optCb); | ||
return this.makeAPICall('files.revokePublicURL', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
* Enables a file for public/external sharing. | ||
* @see {@link https://api.slack.com/methods/files.sharedPublicURL|files.sharedPublicURL} | ||
* | ||
* @param {?} file - File to share | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
FilesFacet.prototype.sharedPublicURL = function sharedPublicURL(file, optCb) { | ||
var requiredArgs = { | ||
file: file | ||
}; | ||
return this.makeAPICall('files.sharedPublicURL', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
* Uploads or creates a file. | ||
* @see {@link https://api.slack.com/methods/files.upload|files.upload} | ||
* | ||
* @param {?} filename - Filename of file. | ||
* @param {Object=} opts | ||
* @param {?} opts.file File contents via `multipart/form-data`. | ||
* @param {?} opts.content File contents via a POST var. | ||
* @param {?} opts.filetype Slack-internal file type identifier. | ||
* @param {?} opts.filename Filename of file. | ||
* @param {?} opts.title Title of file. | ||
* @param {?} opts.initial_comment Initial comment to add to file. | ||
* @param {?} opts.channels Comma separated list of channels to share the file into. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.file - File contents via `multipart/form-data`. If omitting this parameter, you | ||
* must submit `content`. | ||
* @param {?} opts.content - File contents via a POST variable. If omitting this parameter, you | ||
* must provide a `file`. | ||
* @param {?} opts.filetype - A [file type](/types/file#file_types) identifier. | ||
* @param {?} opts.title - Title of file. | ||
* @param {?} opts.initial_comment - Initial comment to add to file. | ||
* @param {?} opts.channels - Comma-separated list of channel names or IDs where the file will be | ||
* shared. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
FilesFacet.prototype.upload = function upload(opts, optCb) { | ||
var args = { | ||
opts: opts | ||
FilesFacet.prototype.upload = function upload(filename, opts, optCb) { | ||
var requiredArgs = { | ||
filename: filename | ||
}; | ||
return this.makeAPICall('files.upload', args, optCb); | ||
return this.makeAPICall('files.upload', requiredArgs, opts, optCb); | ||
}; | ||
@@ -104,0 +146,0 @@ |
@@ -24,5 +24,3 @@ /** | ||
var getArgsForFnsWithOptArgs = require('./helpers').getArgsForFnsWithOptArgs; | ||
function GroupsFacet(makeAPICall) { | ||
@@ -35,107 +33,113 @@ this.name = 'groups'; | ||
/** | ||
* Archives a private group. | ||
* Archives a private channel. | ||
* @see {@link https://api.slack.com/methods/groups.archive|groups.archive} | ||
* | ||
* @param {?} channel Private group to archive | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Private channel to archive | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
GroupsFacet.prototype.archive = function archive(channel, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel | ||
}; | ||
return this.makeAPICall('groups.archive', args, optCb); | ||
return this.makeAPICall('groups.archive', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
* Closes a private group. | ||
* Closes a private channel. | ||
* @see {@link https://api.slack.com/methods/groups.close|groups.close} | ||
* | ||
* @param {?} channel Group to open. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Private channel to close. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
GroupsFacet.prototype.close = function close(channel, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel | ||
}; | ||
return this.makeAPICall('groups.close', args, optCb); | ||
return this.makeAPICall('groups.close', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
* Creates a private group. | ||
* Creates a private channel. | ||
* @see {@link https://api.slack.com/methods/groups.create|groups.create} | ||
* | ||
* @param {?} name Name of group to create | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} name - Name of private channel to create | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
GroupsFacet.prototype.create = function create(name, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
name: name | ||
}; | ||
return this.makeAPICall('groups.create', args, optCb); | ||
return this.makeAPICall('groups.create', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
* Clones and archives a private group. | ||
* Clones and archives a private channel. | ||
* @see {@link https://api.slack.com/methods/groups.createChild|groups.createChild} | ||
* | ||
* @param {?} channel Group to clone and archive. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Private channel to clone and archive. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
GroupsFacet.prototype.createChild = function createChild(channel, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel | ||
}; | ||
return this.makeAPICall('groups.createChild', args, optCb); | ||
return this.makeAPICall('groups.createChild', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
* Fetches history of messages and events from a private group. | ||
* Fetches history of messages and events from a private channel. | ||
* @see {@link https://api.slack.com/methods/groups.history|groups.history} | ||
* | ||
* @param {?} channel Group to fetch history for. | ||
* @param {?} channel - Private channel to fetch history for. | ||
* @param {Object=} opts | ||
* @param {?} opts.latest End of time range of messages to include in results. | ||
* @param {?} opts.oldest Start of time range of messages to include in results. | ||
* @param {?} opts.inclusive Include messages with latest or oldest timestamp in results. | ||
* @param {?} opts.count Number of messages to return, between 1 and 1000. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.latest - End of time range of messages to include in results. | ||
* @param {?} opts.oldest - Start of time range of messages to include in results. | ||
* @param {?} opts.inclusive - Include messages with latest or oldest timestamp in results. | ||
* @param {?} opts.count - Number of messages to return, between 1 and 1000. | ||
* @param {?} opts.unreads - Include `unread_count_display` in the output? | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
GroupsFacet.prototype.history = function history(channel, opts, optCb) { | ||
var args = { | ||
channel: channel, | ||
opts: opts | ||
var requiredArgs = { | ||
channel: channel | ||
}; | ||
return this.makeAPICall('groups.history', args, optCb); | ||
return this.makeAPICall('groups.history', requiredArgs, opts, optCb); | ||
}; | ||
/** | ||
* Gets information about a private group. | ||
* Gets information about a private channel. | ||
* @see {@link https://api.slack.com/methods/groups.info|groups.info} | ||
* | ||
* @param {?} channel Group to get info on | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Private channel to get info on | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
GroupsFacet.prototype.info = function info(channel, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel | ||
}; | ||
return this.makeAPICall('groups.info', args, optCb); | ||
return this.makeAPICall('groups.info', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
* Invites a user to a private group. | ||
* Invites a user to a private channel. | ||
* @see {@link https://api.slack.com/methods/groups.invite|groups.invite} | ||
* | ||
* @param {?} channel Private group to invite user to. | ||
* @param {?} user User to invite. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Private channel to invite user to. | ||
* @param {?} user - User to invite. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
GroupsFacet.prototype.invite = function invite(channel, user, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel, | ||
@@ -145,15 +149,16 @@ user: user | ||
return this.makeAPICall('groups.invite', args, optCb); | ||
return this.makeAPICall('groups.invite', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
* Removes a user from a private group. | ||
* Removes a user from a private channel. | ||
* @see {@link https://api.slack.com/methods/groups.kick|groups.kick} | ||
* | ||
* @param {?} channel Group to remove user from. | ||
* @param {?} user User to remove from group. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Private channel to remove user from. | ||
* @param {?} user - User to remove from private channel. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
GroupsFacet.prototype.kick = function kick(channel, user, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel, | ||
@@ -163,42 +168,45 @@ user: user | ||
return this.makeAPICall('groups.kick', args, optCb); | ||
return this.makeAPICall('groups.kick', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
* Leaves a private group. | ||
* Leaves a private channel. | ||
* @see {@link https://api.slack.com/methods/groups.leave|groups.leave} | ||
* | ||
* @param {?} channel Group to leave | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Private channel to leave | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
GroupsFacet.prototype.leave = function leave(channel, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel | ||
}; | ||
return this.makeAPICall('groups.leave', args, optCb); | ||
return this.makeAPICall('groups.leave', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
* Lists private groups that the calling user has access to. | ||
* Lists private channels that the calling user has access to. | ||
* @see {@link https://api.slack.com/methods/groups.list|groups.list} | ||
* | ||
* @param {?} optExcludeArchived Don't return archived groups. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {Object=} opts | ||
* @param {?} opts.exclude_archived - Don't return archived private channels. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
GroupsFacet.prototype.list = function list(optExcludeArchived, optCb) { | ||
var fnArgs = getArgsForFnsWithOptArgs(optExcludeArchived, optCb, 'exclude_archived'); | ||
return this.makeAPICall('groups.list', fnArgs.args, fnArgs.cb); | ||
GroupsFacet.prototype.list = function list(opts, optCb) { | ||
return this.makeAPICall('groups.list', null, opts, optCb); | ||
}; | ||
/** | ||
* Sets the read cursor in a private group. | ||
* Sets the read cursor in a private channel. | ||
* @see {@link https://api.slack.com/methods/groups.mark|groups.mark} | ||
* | ||
* @param {?} channel Group to set reading cursor in. | ||
* @param {?} ts Timestamp of the most recently seen message. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Private channel to set reading cursor in. | ||
* @param {?} ts - Timestamp of the most recently seen message. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
GroupsFacet.prototype.mark = function mark(channel, ts, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel, | ||
@@ -208,30 +216,32 @@ ts: ts | ||
return this.makeAPICall('groups.mark', args, optCb); | ||
return this.makeAPICall('groups.mark', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
* Opens a private group. | ||
* Opens a private channel. | ||
* @see {@link https://api.slack.com/methods/groups.open|groups.open} | ||
* | ||
* @param {?} channel Group to open. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Private channel to open. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
GroupsFacet.prototype.open = function open(channel, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel | ||
}; | ||
return this.makeAPICall('groups.open', args, optCb); | ||
return this.makeAPICall('groups.open', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
* Renames a private group. | ||
* Renames a private channel. | ||
* @see {@link https://api.slack.com/methods/groups.rename|groups.rename} | ||
* | ||
* @param {?} channel Group to rename | ||
* @param {?} name New name for group. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Private channel to rename | ||
* @param {?} name - New name for private channel. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
GroupsFacet.prototype.rename = function rename(channel, name, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel, | ||
@@ -241,15 +251,16 @@ name: name | ||
return this.makeAPICall('groups.rename', args, optCb); | ||
return this.makeAPICall('groups.rename', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
* Sets the purpose for a private group. | ||
* Sets the purpose for a private channel. | ||
* @see {@link https://api.slack.com/methods/groups.setPurpose|groups.setPurpose} | ||
* | ||
* @param {?} channel Private group to set the purpose of | ||
* @param {?} purpose The new purpose | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Private channel to set the purpose of | ||
* @param {?} purpose - The new purpose | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
GroupsFacet.prototype.setPurpose = function setPurpose(channel, purpose, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel, | ||
@@ -259,15 +270,16 @@ purpose: purpose | ||
return this.makeAPICall('groups.setPurpose', args, optCb); | ||
return this.makeAPICall('groups.setPurpose', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
* Sets the topic for a private group. | ||
* Sets the topic for a private channel. | ||
* @see {@link https://api.slack.com/methods/groups.setTopic|groups.setTopic} | ||
* | ||
* @param {?} channel Private group to set the topic of | ||
* @param {?} topic The new topic | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Private channel to set the topic of | ||
* @param {?} topic - The new topic | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
GroupsFacet.prototype.setTopic = function setTopic(channel, topic, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel, | ||
@@ -277,18 +289,19 @@ topic: topic | ||
return this.makeAPICall('groups.setTopic', args, optCb); | ||
return this.makeAPICall('groups.setTopic', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
* Unarchives a private group. | ||
* Unarchives a private channel. | ||
* @see {@link https://api.slack.com/methods/groups.unarchive|groups.unarchive} | ||
* | ||
* @param {?} channel Group to unarchive | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Private channel to unarchive | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
GroupsFacet.prototype.unarchive = function unarchive(channel, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel | ||
}; | ||
return this.makeAPICall('groups.unarchive', args, optCb); | ||
return this.makeAPICall('groups.unarchive', requiredArgs, null, optCb); | ||
}; | ||
@@ -295,0 +308,0 @@ |
@@ -20,18 +20,17 @@ /** | ||
* | ||
* @param {?} clientId Issued when you created your application. | ||
* @param {?} clientSecret Issued when you created your application. | ||
* @param {?} code The `code` param returned via the OAuth callback. | ||
* @param {?} client_id - Issued when you created your application. | ||
* @param {?} client_secret - Issued when you created your application. | ||
* @param {?} code - The `code` param returned via the OAuth callback. | ||
* @param {Object=} opts | ||
* @param {?} opts.redirect_uri This must match the originally submitted URI (if one was sent). | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.redirect_uri - This must match the originally submitted URI (if one was sent). | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
OauthFacet.prototype.access = function access(clientId, clientSecret, code, opts, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
client_id: clientId, | ||
client_secret: clientSecret, | ||
code: code, | ||
opts: opts | ||
code: code | ||
}; | ||
return this.makeAPICall('oauth.access', args, optCb); | ||
return this.makeAPICall('oauth.access', requiredArgs, opts, optCb); | ||
}; | ||
@@ -38,0 +37,0 @@ |
@@ -22,18 +22,18 @@ /** | ||
* | ||
* @param {?} channel Channel to pin the item in. | ||
* @param {?} channel - Channel to pin the item in. | ||
* @param {Object=} opts | ||
* @param {?} opts.file File to pin. | ||
* @param {?} opts.file_comment File comment to pin. | ||
* @param {?} opts.timestamp Timestamp of the message to pin. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.file - File to pin. | ||
* @param {?} opts.file_comment - File comment to pin. | ||
* @param {?} opts.timestamp - Timestamp of the message to pin. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
PinsFacet.prototype.add = function add(channel, opts, optCb) { | ||
var args = { | ||
channel: channel, | ||
opts: opts | ||
var requiredArgs = { | ||
channel: channel | ||
}; | ||
return this.makeAPICall('pins.add', args, optCb); | ||
return this.makeAPICall('pins.add', requiredArgs, opts, optCb); | ||
}; | ||
/** | ||
@@ -43,13 +43,14 @@ * Lists items pinned to a channel. | ||
* | ||
* @param {?} channel Channel to get pinned items for. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} channel - Channel to get pinned items for. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
PinsFacet.prototype.list = function list(channel, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
channel: channel | ||
}; | ||
return this.makeAPICall('pins.list', args, optCb); | ||
return this.makeAPICall('pins.list', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
@@ -59,16 +60,15 @@ * Un-pins an item from a channel. | ||
* | ||
* @param {?} channel Channel where the item is pinned to. | ||
* @param {?} channel - Channel where the item is pinned to. | ||
* @param {Object=} opts | ||
* @param {?} opts.file File to un-pin. | ||
* @param {?} opts.file_comment File comment to un-pin. | ||
* @param {?} opts.timestamp Timestamp of the message to un-pin. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.file - File to un-pin. | ||
* @param {?} opts.file_comment - File comment to un-pin. | ||
* @param {?} opts.timestamp - Timestamp of the message to un-pin. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
PinsFacet.prototype.remove = function remove(channel, opts, optCb) { | ||
var args = { | ||
channel: channel, | ||
opts: opts | ||
var requiredArgs = { | ||
channel: channel | ||
}; | ||
return this.makeAPICall('pins.remove', args, optCb); | ||
return this.makeAPICall('pins.remove', requiredArgs, opts, optCb); | ||
}; | ||
@@ -75,0 +75,0 @@ |
@@ -20,11 +20,11 @@ /** | ||
* | ||
* @param {?} presence Either `active` or `away` | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} presence - Either `active` or `away` | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
PresenceFacet.prototype.set = function set(presence, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
presence: presence | ||
}; | ||
return this.makeAPICall('presence.set', args, optCb); | ||
return this.makeAPICall('presence.set', requiredArgs, null, optCb); | ||
}; | ||
@@ -31,0 +31,0 @@ |
@@ -23,19 +23,19 @@ /** | ||
* | ||
* @param {?} name Reaction (emoji) name. | ||
* @param {?} name - Reaction (emoji) name. | ||
* @param {Object=} opts | ||
* @param {?} opts.file File to add reaction to. | ||
* @param {?} opts.file_comment File comment to add reaction to. | ||
* @param {?} opts.channel Channel where the message to add reaction to was posted. | ||
* @param {?} opts.timestamp Timestamp of the message to add reaction to. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.file - File to add reaction to. | ||
* @param {?} opts.file_comment - File comment to add reaction to. | ||
* @param {?} opts.channel - Channel where the message to add reaction to was posted. | ||
* @param {?} opts.timestamp - Timestamp of the message to add reaction to. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ReactionsFacet.prototype.add = function add(name, opts, optCb) { | ||
var args = { | ||
name: name, | ||
opts: opts | ||
var requiredArgs = { | ||
name: name | ||
}; | ||
return this.makeAPICall('reactions.add', args, optCb); | ||
return this.makeAPICall('reactions.add', requiredArgs, opts, optCb); | ||
}; | ||
/** | ||
@@ -46,17 +46,14 @@ * Gets reactions for an item. | ||
* @param {Object=} opts | ||
* @param {?} opts.file File to get reactions for. | ||
* @param {?} opts.file_comment File comment to get reactions for. | ||
* @param {?} opts.channel Channel where the message to get reactions for was posted. | ||
* @param {?} opts.timestamp Timestamp of the message to get reactions for. | ||
* @param {?} opts.full If true always return the complete reaction list. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.file - File to get reactions for. | ||
* @param {?} opts.file_comment - File comment to get reactions for. | ||
* @param {?} opts.channel - Channel where the message to get reactions for was posted. | ||
* @param {?} opts.timestamp - Timestamp of the message to get reactions for. | ||
* @param {?} opts.full - If true always return the complete reaction list. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ReactionsFacet.prototype.get = function get(opts, optCb) { | ||
var args = { | ||
opts: opts | ||
}; | ||
return this.makeAPICall('reactions.get', args, optCb); | ||
return this.makeAPICall('reactions.get', null, opts, optCb); | ||
}; | ||
/** | ||
@@ -67,14 +64,13 @@ * Lists reactions made by a user. | ||
* @param {Object=} opts | ||
* @param {?} opts.user Show reactions made by this user. Defaults to the authed user. | ||
* @param {?} opts.full If true always return the complete reaction list. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.user - Show reactions made by this user. Defaults to the authed user. | ||
* @param {?} opts.full - If true always return the complete reaction list. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ReactionsFacet.prototype.list = function list(opts, optCb) { | ||
var args = { | ||
opts: opts | ||
}; | ||
return this.makeAPICall('reactions.list', args, optCb); | ||
return this.makeAPICall('reactions.list', null, opts, optCb); | ||
}; | ||
/** | ||
@@ -84,17 +80,16 @@ * Removes a reaction from an item. | ||
* | ||
* @param {?} name Reaction (emoji) name. | ||
* @param {?} name - Reaction (emoji) name. | ||
* @param {Object=} opts | ||
* @param {?} opts.file File to remove reaction from. | ||
* @param {?} opts.file_comment File comment to remove reaction from. | ||
* @param {?} opts.channel Channel where the message to remove reaction from was posted. | ||
* @param {?} opts.timestamp Timestamp of the message to remove reaction from. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.file - File to remove reaction from. | ||
* @param {?} opts.file_comment - File comment to remove reaction from. | ||
* @param {?} opts.channel - Channel where the message to remove reaction from was posted. | ||
* @param {?} opts.timestamp - Timestamp of the message to remove reaction from. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
ReactionsFacet.prototype.remove = function remove(name, opts, optCb) { | ||
var args = { | ||
name: name, | ||
opts: opts | ||
var requiredArgs = { | ||
name: name | ||
}; | ||
return this.makeAPICall('reactions.remove', args, optCb); | ||
return this.makeAPICall('reactions.remove', requiredArgs, opts, optCb); | ||
}; | ||
@@ -101,0 +96,0 @@ |
@@ -21,13 +21,10 @@ /** | ||
* @param {Object=} opts | ||
* @param {?} opts.simple_latest Return timestamp only for latest message object of each channel | ||
* (improves performance). | ||
* @param {?} opts.no_unreads Skip unread counts for each channel (improves performance). | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.simple_latest - Return timestamp only for latest message object of each channel | ||
* (improves performance). | ||
* @param {?} opts.no_unreads - Skip unread counts for each channel (improves performance). | ||
* @param {?} opts.mpim_aware - Returns MPIMs to the client in the API response. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
RtmFacet.prototype.start = function start(opts, optCb) { | ||
var args = { | ||
opts: opts | ||
}; | ||
return this.makeAPICall('rtm.start', args, optCb); | ||
return this.makeAPICall('rtm.start', null, opts, optCb); | ||
}; | ||
@@ -34,0 +31,0 @@ |
@@ -22,18 +22,20 @@ /** | ||
* | ||
* @param {?} query Search query. May contains booleans, etc. | ||
* @param {?} query - Search query. May contains booleans, etc. | ||
* @param {Object=} opts | ||
* @param {?} opts.sort Return matches sorted by either `score` or `timestamp`. | ||
* @param {?} opts.sort_dir Change sort direction to ascending (`asc`) or descending (`desc`). | ||
* @param {?} opts.highlight Pass a value of `1` to enable query highlight markers (see below). | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.sort - Return matches sorted by either `score` or `timestamp`. | ||
* @param {?} opts.sort_dir - Change sort direction to ascending (`asc`) or descending (`desc`). | ||
* @param {?} opts.highlight - Pass a value of `1` to enable query highlight markers (see below). | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
SearchFacet.prototype.all = function all(query, opts, optCb) { | ||
var args = { | ||
query: query, | ||
opts: opts | ||
var requiredArgs = { | ||
query: query | ||
}; | ||
return this.makeAPICall('search.all', args, optCb); | ||
return this.makeAPICall('search.all', requiredArgs, opts, optCb); | ||
}; | ||
/** | ||
@@ -43,18 +45,20 @@ * Searches for files matching a query. | ||
* | ||
* @param {?} query Search query. May contain booleans, etc. | ||
* @param {?} query - Search query. May contain booleans, etc. | ||
* @param {Object=} opts | ||
* @param {?} opts.sort Return matches sorted by either `score` or `timestamp`. | ||
* @param {?} opts.sort_dir Change sort direction to ascending (`asc`) or descending (`desc`). | ||
* @param {?} opts.highlight Pass a value of `1` to enable query highlight markers (see below). | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.sort - Return matches sorted by either `score` or `timestamp`. | ||
* @param {?} opts.sort_dir - Change sort direction to ascending (`asc`) or descending (`desc`). | ||
* @param {?} opts.highlight - Pass a value of `1` to enable query highlight markers (see below). | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
SearchFacet.prototype.files = function files(query, opts, optCb) { | ||
var args = { | ||
query: query, | ||
opts: opts | ||
var requiredArgs = { | ||
query: query | ||
}; | ||
return this.makeAPICall('search.files', args, optCb); | ||
return this.makeAPICall('search.files', requiredArgs, opts, optCb); | ||
}; | ||
/** | ||
@@ -64,16 +68,17 @@ * Searches for messages matching a query. | ||
* | ||
* @param {?} query Search query. May contains booleans, etc. | ||
* @param {?} query - Search query. May contains booleans, etc. | ||
* @param {Object=} opts | ||
* @param {?} opts.sort Return matches sorted by either `score` or `timestamp`. | ||
* @param {?} opts.sort_dir Change sort direction to ascending (`asc`) or descending (`desc`). | ||
* @param {?} opts.highlight Pass a value of `1` to enable query highlight markers (see below). | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.sort - Return matches sorted by either `score` or `timestamp`. | ||
* @param {?} opts.sort_dir - Change sort direction to ascending (`asc`) or descending (`desc`). | ||
* @param {?} opts.highlight - Pass a value of `1` to enable query highlight markers (see below). | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
SearchFacet.prototype.messages = function messages(query, opts, optCb) { | ||
var args = { | ||
query: query, | ||
opts: opts | ||
var requiredArgs = { | ||
query: query | ||
}; | ||
return this.makeAPICall('search.messages', args, optCb); | ||
return this.makeAPICall('search.messages', requiredArgs, opts, optCb); | ||
}; | ||
@@ -80,0 +85,0 @@ |
@@ -11,5 +11,3 @@ /** | ||
var getArgsForFnsWithOptArgs = require('./helpers').getArgsForFnsWithOptArgs; | ||
function StarsFacet(makeAPICall) { | ||
@@ -26,17 +24,14 @@ this.name = 'stars'; | ||
* @param {Object=} opts | ||
* @param {?} opts.file File to add star to. | ||
* @param {?} opts.file_comment File comment to add star to. | ||
* @param {?} opts.channel Channel to add star to, or channel where the message to add star to was | ||
* posted (used with `timestamp`). | ||
* @param {?} opts.timestamp Timestamp of the message to add star to. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.file - File to add star to. | ||
* @param {?} opts.file_comment - File comment to add star to. | ||
* @param {?} opts.channel - Channel to add star to, or channel where the message to add star to | ||
* was posted (used with `timestamp`). | ||
* @param {?} opts.timestamp - Timestamp of the message to add star to. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
StarsFacet.prototype.add = function add(opts, optCb) { | ||
var args = { | ||
opts: opts | ||
}; | ||
return this.makeAPICall('stars.add', args, optCb); | ||
return this.makeAPICall('stars.add', null, opts, optCb); | ||
}; | ||
/** | ||
@@ -46,10 +41,13 @@ * Lists stars for a user. | ||
* | ||
* @param {?} optUser Show stars by this user. Defaults to the authed user. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {Object=} opts | ||
* @param {?} opts.user - Show stars by this user. Defaults to the authed user. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
StarsFacet.prototype.list = function list(optUser, optCb) { | ||
var fnArgs = getArgsForFnsWithOptArgs(optUser, optCb, 'user'); | ||
return this.makeAPICall('stars.list', fnArgs.args, fnArgs.cb); | ||
StarsFacet.prototype.list = function list(opts, optCb) { | ||
return this.makeAPICall('stars.list', null, opts, optCb); | ||
}; | ||
/** | ||
@@ -60,15 +58,11 @@ * Removes a star from an item. | ||
* @param {Object=} opts | ||
* @param {?} opts.file File to remove star from. | ||
* @param {?} opts.file_comment File comment to remove star from. | ||
* @param {?} opts.channel Channel to remove star from, or channel where the message to remove star | ||
* from was posted (used with `timestamp`). | ||
* @param {?} opts.timestamp Timestamp of the message to remove star from. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} opts.file - File to remove star from. | ||
* @param {?} opts.file_comment - File comment to remove star from. | ||
* @param {?} opts.channel - Channel to remove star from, or channel where the message to remove | ||
* star from was posted (used with `timestamp`). | ||
* @param {?} opts.timestamp - Timestamp of the message to remove star from. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
StarsFacet.prototype.remove = function remove(opts, optCb) { | ||
var args = { | ||
opts: opts | ||
}; | ||
return this.makeAPICall('stars.remove', args, optCb); | ||
return this.makeAPICall('stars.remove', null, opts, optCb); | ||
}; | ||
@@ -75,0 +69,0 @@ |
@@ -7,2 +7,3 @@ /** | ||
* - info: {@link https://api.slack.com/methods/team.info|team.info} | ||
* - integrationLogs: {@link https://api.slack.com/methods/team.integrationLogs|team.integrationLogs} | ||
* | ||
@@ -22,10 +23,12 @@ */ | ||
* | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {Object=} opts | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
TeamFacet.prototype.accessLogs = function accessLogs(optCb) { | ||
var args = {}; | ||
return this.makeAPICall('team.accessLogs', args, optCb); | ||
TeamFacet.prototype.accessLogs = function accessLogs(opts, optCb) { | ||
return this.makeAPICall('team.accessLogs', null, opts, optCb); | ||
}; | ||
/** | ||
@@ -35,8 +38,24 @@ * Gets information about the current team. | ||
* | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
TeamFacet.prototype.info = function info(optCb) { | ||
var args = {}; | ||
return this.makeAPICall('team.info', null, null, optCb); | ||
}; | ||
return this.makeAPICall('team.info', args, optCb); | ||
/** | ||
* Gets the integration logs for the current team. | ||
* @see {@link https://api.slack.com/methods/team.integrationLogs|team.integrationLogs} | ||
* | ||
* @param {Object=} opts | ||
* @param {?} opts.service_id - Filter logs to this service. Defaults to all logs. | ||
* @param {?} opts.app_id - Filter logs to this Slack app. Defaults to all logs. | ||
* @param {?} opts.user - Filter logs generated by this user’s actions. Defaults to all logs. | ||
* @param {?} opts.change_type - Filter logs with this change type. Defaults to all logs. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
TeamFacet.prototype.integrationLogs = function integrationLogs(opts, optCb) { | ||
return this.makeAPICall('team.integrationLogs', null, opts, optCb); | ||
}; | ||
@@ -43,0 +62,0 @@ |
@@ -13,5 +13,3 @@ /** | ||
var getArgsForFnsWithOptArgs = require('./helpers').getArgsForFnsWithOptArgs; | ||
function UsersFacet(makeAPICall) { | ||
@@ -27,13 +25,14 @@ this.name = 'users'; | ||
* | ||
* @param {?} user User to get presence info on. Defaults to the authed user. | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} user - User to get presence info on. Defaults to the authed user. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
UsersFacet.prototype.getPresence = function getPresence(user, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
user: user | ||
}; | ||
return this.makeAPICall('users.getPresence', args, optCb); | ||
return this.makeAPICall('users.getPresence', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
@@ -43,13 +42,14 @@ * Gets information about a user. | ||
* | ||
* @param {?} user User to get info on | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} user - User to get info on | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
UsersFacet.prototype.info = function info(user, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
user: user | ||
}; | ||
return this.makeAPICall('users.info', args, optCb); | ||
return this.makeAPICall('users.info', requiredArgs, null, optCb); | ||
}; | ||
/** | ||
@@ -59,10 +59,11 @@ * Lists all users in a Slack team. | ||
* | ||
* @param {?} optPresence Whether to include presence data in the output | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {Object=} opts | ||
* @param {?} opts.presence - Whether to include presence data in the output | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
UsersFacet.prototype.list = function list(optPresence, optCb) { | ||
var fnArgs = getArgsForFnsWithOptArgs(optPresence, optCb, 'presence'); | ||
return this.makeAPICall('users.list', fnArgs.args, fnArgs.cb); | ||
UsersFacet.prototype.list = function list(opts, optCb) { | ||
return this.makeAPICall('users.list', null, opts, optCb); | ||
}; | ||
/** | ||
@@ -72,10 +73,9 @@ * Marks a user as active. | ||
* | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
UsersFacet.prototype.setActive = function setActive(optCb) { | ||
var args = {}; | ||
return this.makeAPICall('users.setActive', args, optCb); | ||
return this.makeAPICall('users.setActive', null, null, optCb); | ||
}; | ||
/** | ||
@@ -85,11 +85,11 @@ * Manually sets user presence. | ||
* | ||
* @param {?} presence Either `auto` or `away` | ||
* @param {function} optCb Optional callback, if not using promises. | ||
* @param {?} presence - Either `auto` or `away` | ||
* @param {function=} optCb Optional callback, if not using promises. | ||
*/ | ||
UsersFacet.prototype.setPresence = function setPresence(presence, optCb) { | ||
var args = { | ||
var requiredArgs = { | ||
presence: presence | ||
}; | ||
return this.makeAPICall('users.setPresence', args, optCb); | ||
return this.makeAPICall('users.setPresence', requiredArgs, null, optCb); | ||
}; | ||
@@ -96,0 +96,0 @@ |
{ | ||
"name": "@slack/client", | ||
"version": "2.3.0", | ||
"version": "3.0.0", | ||
"description": "A library for creating a Slack client", | ||
@@ -5,0 +5,0 @@ "main": "./index", |
@@ -35,4 +35,8 @@ # Node Library for the Slack APIs | ||
* [Send messages](#send-messages) | ||
* [Data stores] (#data-stores) | ||
* [Send direct messages] (#send-dms) | ||
* [RTM Client Lifecycle](#rtm-client-lifecycle) | ||
* [Migrating from earlier versions](#migrating-from-earlier-versions) | ||
* [Web Client](#web-client) | ||
* [Uploading a file](#uploading-a-file) | ||
* [Migrating from earlier versions](#migrating-from-earlier-versions) | ||
* [Models](#models) | ||
@@ -68,6 +72,5 @@ | ||
rtm.on(CLIENT_EVENTS.RTM.AUTHENTICATED, function (rtmStartData) { | ||
console.log(`Logged in as ${rtmStartData.self.name} of team ${rtmStartData.team.name}, but not yet connected to a channel`); | ||
}); | ||
``` | ||
@@ -107,2 +110,55 @@ | ||
### Data stores | ||
```js | ||
var RtmClient = require('@slack/client').RtmClient; | ||
// The memory data store is a collection of useful functions we can include in our RtmClient | ||
var MemoryDataStore = require('@slack/client').MemoryDataStore; | ||
var CLIENT_EVENTS = require('@slack/client').CLIENT_EVENTS; | ||
var token = process.env.SLACK_API_TOKEN; | ||
var rtm = new RtmClient(token, { | ||
// Sets the level of logging we require | ||
logLevel: 'error', | ||
// Initialise a data store for our client, this will load additional helper functions for the storing and retrieval of data | ||
dataStore: new MemoryDataStore(), | ||
// Boolean indicating whether Slack should automatically reconnect after an error response | ||
autoReconnect: true, | ||
// Boolean indicating whether each message should be marked as read or not after it is processed | ||
autoMark: true | ||
}); | ||
rtm.start(); | ||
// Wait for the client to connect | ||
rtm.on(CLIENT_EVENTS.RTM.RTM_CONNECTION_OPENED, function() { | ||
// Get the user's name | ||
var user = rtm.dataStore.getUserById(rtm.activeUserId); | ||
// Get the team's name | ||
var team = rtm.dataStore.getTeamById(rtm.activeTeamId); | ||
// Log the slack team name and the bot's name | ||
console.log('Connected to ' + team.name + ' as ' + user.name); | ||
}); | ||
``` | ||
### Send Direct Messages | ||
```js | ||
var RTM_EVENTS = require('@slack/client').RTM_EVENTS; | ||
// Responds to a message with a 'hello' DM | ||
rtm.on(RTM_EVENTS.MESSAGE, function(message) { | ||
var user = rtm.dataStore.getUserById(message.user) | ||
var dm = rtm.dataStore.getDMByName(user.name); | ||
rtm.sendMessage('Hello ' + user.name + '!', dm.id); | ||
}); | ||
``` | ||
### RTM Client Lifecycle | ||
@@ -118,2 +174,8 @@ | ||
## Web Client | ||
### Uploading a file | ||
See [examples/upload-a-file.js](/examples/upload-a-file.js) | ||
## Migrating from earlier versions | ||
@@ -120,0 +182,0 @@ |
@@ -7,12 +7,8 @@ var expect = require('chai').expect; | ||
describe('Client Helpers', function () { | ||
describe('#getData()', function () { | ||
it('merges the opts value into the top level data object and then removes opts', function () { | ||
var testData = { | ||
channel: 'slack', | ||
opts: { | ||
count: 125 | ||
} | ||
}; | ||
describe('#getApiCallData()', function () { | ||
it('merges the required and opts values', function () { | ||
var required = { channel: 'slack' }; | ||
var opts = { count: 125 }; | ||
expect(helpers.getData(testData, 'test')).to.be.deep.equal({ | ||
expect(helpers.getApiCallData('test', required, opts)).to.be.deep.equal({ | ||
channel: 'slack', | ||
@@ -24,9 +20,7 @@ count: 125, | ||
it('prunes undefined and null values from the data object', function () { | ||
var testData = { | ||
channel: 'slack', | ||
opt_count: undefined | ||
}; | ||
it('takes required args over optional ones', function () { | ||
var required = { channel: 'slack' }; | ||
var opts = { channel: 'bad' }; | ||
expect(helpers.getData(testData, 'test')).to.be.deep.equal({ | ||
expect(helpers.getApiCallData('test', required, opts)).to.be.deep.equal({ | ||
channel: 'slack', | ||
@@ -37,6 +31,8 @@ token: 'test' | ||
it('handles undefined data object', function () { | ||
var testData = undefined; | ||
it('prunes undefined and null values from the data object', function () { | ||
var required = { channel: 'slack' }; | ||
var opts = { opt_count: undefined }; | ||
expect(helpers.getData(testData, 'test')).to.be.deep.equal({ | ||
expect(helpers.getApiCallData('test', required, opts)).to.be.deep.equal({ | ||
channel: 'slack', | ||
token: 'test' | ||
@@ -46,8 +42,12 @@ }); | ||
it('handles undefined or null data objects', function () { | ||
expect(helpers.getApiCallData('test', undefined, null)).to.be.deep.equal({ | ||
token: 'test' | ||
}); | ||
}); | ||
it('JSON encodes attachments if they are not already encoded', function () { | ||
var testData = { | ||
attachments: [1, 2, 3] | ||
}; | ||
var required = { attachments: [1, 2, 3] }; | ||
expect(helpers.getData(testData, 'test')).to.be.deep.equal({ | ||
expect(helpers.getApiCallData('test', required, null)).to.be.deep.equal({ | ||
attachments: '[1,2,3]', | ||
@@ -59,7 +59,5 @@ token: 'test' | ||
it('leaves attachments alone if they are already encoded', function () { | ||
var testData = { | ||
attachments: '["a","b","c"]' | ||
}; | ||
var required = { attachments: '["a","b","c"]' }; | ||
expect(helpers.getData(testData, 'test')).to.be.deep.equal({ | ||
expect(helpers.getApiCallData('test', required, null)).to.be.deep.equal({ | ||
attachments: '["a","b","c"]', | ||
@@ -70,49 +68,2 @@ token: 'test' | ||
}); | ||
describe('#getAPICallArgs()', function () { | ||
it('returns an args object with the token when called with no data or cb', function () { | ||
var callArgs = helpers.getAPICallArgs('test'); | ||
expect(callArgs.data).to.deep.equal({ | ||
token: 'test' | ||
}); | ||
}); | ||
it('returns an args object with a token and data items when called with a data obj and no cb', | ||
function () { | ||
var callArgs = helpers.getAPICallArgs('test', { test: 1 }); | ||
expect(callArgs.data).to.deep.equal({ | ||
test: 1, | ||
token: 'test' | ||
}); | ||
} | ||
); | ||
it('assigns data from the opts to the returned args obj and removes the opts key', function () { | ||
var callArgs = helpers.getAPICallArgs('test', { test: 1, opts: { cat: 1 } }); | ||
expect(callArgs.data).to.deep.equal({ | ||
test: 1, | ||
token: 'test', | ||
cat: 1 | ||
}); | ||
}); | ||
it('returns the supplied cb and empty object when called with a cb and no object', function () { | ||
var testCb = function testCb() {}; | ||
var callArgs = helpers.getAPICallArgs('test', testCb); | ||
expect(callArgs.data).to.deep.equal({ | ||
token: 'test' | ||
}); | ||
expect(callArgs.cb).to.deep.equal(testCb); | ||
}); | ||
it('returns the supplied object and cb when called with an object and cb', function () { | ||
var testCb = function testCb() {}; | ||
var callArgs = helpers.getAPICallArgs('test', { test: 1 }, testCb); | ||
expect(callArgs.data).to.deep.equal({ | ||
test: 1, | ||
token: 'test' | ||
}); | ||
expect(callArgs.cb).to.deep.equal(testCb); | ||
}); | ||
}); | ||
}); |
@@ -42,3 +42,3 @@ var expect = require('chai').expect; | ||
client.makeAPICall('test', args, function (err, res) { | ||
client._makeAPICall('test', args, null, function (err, res) { | ||
expect(res).to.deep.equal({ test: 10 }); | ||
@@ -52,3 +52,3 @@ done(); | ||
client.makeAPICall('test', { test: 'test' }); | ||
client._makeAPICall('test', { test: 'test' }, null, null); | ||
}); | ||
@@ -73,3 +73,3 @@ | ||
client.makeAPICall('test', {}, function () { | ||
client._makeAPICall('test', {}, null, function () { | ||
expect(client.transport.callCount).to.equal(2); | ||
@@ -76,0 +76,0 @@ done(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
245964
102
6391
225
5