Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
adds correct jsdoc style docs
Browse files Browse the repository at this point in the history
  • Loading branch information
colestrode committed Jul 20, 2016
1 parent fbdfb0f commit 8d487e3
Showing 1 changed file with 39 additions and 18 deletions.
57 changes: 39 additions & 18 deletions lib/Slack_web_api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
var request = require('request');

/**
* Does nothing. Takes no params, returns nothing. It's a no-op!
*/
function noop() {}

/**
*
* @param {Object} bot The botkit bot object
* @param {Object} config A config containing auth credentials.
* @returns {Object} A callback-based Slack API interface.
*/
module.exports = function(bot, config) {
var slack_api = {
api_url: 'https://slack.com/api/'
Expand Down Expand Up @@ -79,28 +88,40 @@ module.exports = function(bot, config) {
'users.setActive'
];

slack_api.callAPI = function(command, options, cb) {
if (!options.token) {
options.token = config.token;
/**
* Calls Slack using a Token for authentication/authorization
* @param {string} command The Slack API command to call
* @param {Object} data The data to pass to the API call
* @param {function} cb A NodeJS-style callback
*/
slack_api.callAPI = function(command, data, cb) {
if (!data.token) {
data.token = config.token;
}

bot.debug(command, options);
postForm(slack_api.api_url + command, options, cb);
bot.debug(command, data);
postForm(slack_api.api_url + command, data, cb);
};

slack_api.callAPIWithoutToken = function(command, options, cb) {
if (!options.client_id) {
options.client_id = bot.config.clientId;
/**
* Calls Slack using OAuth for authentication/authorization
* @param {string} command The Slack API command to call
* @param {Object} data The data to pass to the API call
* @param {function} cb A NodeJS-style callback
*/
slack_api.callAPIWithoutToken = function(command, data, cb) {
if (!data.client_id) {
data.client_id = bot.config.clientId;
}
if (!options.client_secret) {
options.client_secret = bot.config.clientSecret;
if (!data.client_secret) {
data.client_secret = bot.config.clientSecret;
}
if (!options.redirect_uri) {
options.redirect_uri = bot.config.redirectUri;
if (!data.redirect_uri) {
data.redirect_uri = bot.config.redirectUri;
}

// DON'T log options: that could expose the client secret!
postForm(slack_api.api_url + command, options, cb);
postForm(slack_api.api_url + command, data, cb);
};


Expand Down Expand Up @@ -141,11 +162,11 @@ module.exports = function(bot, config) {

/**
* Makes a POST request as a form to the given url with the options as data
* @param url
* @param options
* @param cb
* @param {string} url The URL to POST to
* @param {Object} formData The data to POST as a form
* @param {function=} cb An optional NodeJS style callback when the POST completes or errors out.
*/
function postForm(url, options, cb) {
function postForm(url, formData, cb) {
cb = cb || noop;

bot.log('** API CALL: ' + url);
Expand All @@ -165,6 +186,6 @@ module.exports = function(bot, config) {
return cb(json.error, json);
}
return cb(error || new Error('Invalid response'));
}).form(options);
}).form(formData);
}
};

0 comments on commit 8d487e3

Please sign in to comment.