This repository was archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Code Improvement: #821
Merged
Merged
Code Improvement: #821
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,10 +127,7 @@ module.exports = function(bot, config) { | |
| * @param {function} cb A NodeJS-style callback | ||
| */ | ||
| slack_api.callAPI = function(command, data, cb, multipart) { | ||
| if (!data.token) { | ||
| data.token = config.token; | ||
| } | ||
|
|
||
| data.token = data.token || config.token; | ||
| bot.debug(command, data); | ||
| postForm(slack_api.api_url + command, data, cb, multipart); | ||
| }; | ||
|
|
@@ -143,16 +140,9 @@ module.exports = function(bot, config) { | |
| * @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 (!data.client_secret) { | ||
| data.client_secret = bot.config.clientSecret; | ||
| } | ||
| if (!data.redirect_uri) { | ||
| data.redirect_uri = bot.config.redirectUri; | ||
| } | ||
|
|
||
| data.client_id = data.client_id || bot.config.clientId; | ||
| data.client_secret = data.client_secret || bot.config.clientSecret; | ||
| 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, data, cb); | ||
| }; | ||
|
|
@@ -170,9 +160,7 @@ module.exports = function(bot, config) { | |
| var currentGroup = slack_api; | ||
|
|
||
| groups.forEach(function(nextGroupName) { | ||
| if (!currentGroup[nextGroupName]) { | ||
| currentGroup[nextGroupName] = {}; | ||
| } | ||
| currentGroup[nextGroupName] = currentGroup[nextGroupName] || {}; | ||
| currentGroup = currentGroup[nextGroupName]; | ||
| }); | ||
|
|
||
|
|
@@ -195,11 +183,7 @@ module.exports = function(bot, config) { | |
|
|
||
| // specify that files get uploaded using multipart | ||
| slack_api.files.upload = function(options, cb) { | ||
| if (options.file) { | ||
| slack_api.callAPI('files.upload', options, cb, true); | ||
| } else { | ||
| slack_api.callAPI('files.upload', options, cb, false); | ||
| } | ||
| slack_api.callAPI('files.upload', options, cb, !!options.file); | ||
| }; | ||
|
|
||
| function sanitizeOptions(options) { | ||
|
|
@@ -251,10 +235,7 @@ module.exports = function(bot, config) { | |
| return cb(parseError); | ||
| } | ||
|
|
||
| if (json.ok) { | ||
| return cb(null, json); | ||
| } | ||
| return cb(json.error, json); | ||
| return cb((json.ok ? null : json.error), json); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| } | ||
| return cb(error || new Error('Invalid response')); | ||
| }); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍