Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplifies slack web api instantiation #319

Merged
merged 6 commits into from
Aug 13, 2016

Conversation

colestrode
Copy link
Contributor

This change simplifies the creation of the Slack web api interface and reduces the amount of copy paste code.

I also simplified the callbacks in the callAPI and callAPIWithoutToken methods.


// generate all API methods
slackApiMethods.forEach(function(slackMethod) {
// most slack api methods are only two parts, of the form group.method, e.g. auth.test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All comments should be written using JSDoc. Can you update all of these comments, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, is there a jsdoc convention for inline docs like this? Most of what I know is for method signatures or class definitions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got all the JSDoc ironed out 😄

* @param options
* @param cb
*/
function postForm(url, options, cb) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also pulled out this request.post and any other duplicate code, this reduces callAPI and callAPIWithoutToken to constructing options objects, all other request logic is handled here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a function and removing the code duplicate parts is a good choice!

try {
json = JSON.parse(body);
} catch (parseError) {
return cb(parseError);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've indicated that callback is optional. But you didn't check if cb is defined or not. Is it truely optional?

Copy link
Contributor Author

@colestrode colestrode Jul 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first line checks for a callback and if it's not defined sets it to the noop function. That simplifies the checks later since cb will always be defined.

The checks on cb were there before I refactored so it seems the previous behavior was to allow optional callbacks. I'm keeping with that for backwards compatibility.

@benbrown benbrown merged commit 3837975 into howdyai:master Aug 13, 2016
@benbrown
Copy link
Contributor

@colestrode sorry it took so long to merge this!
thanks for cleaning everything up so nicely.

@colestrode
Copy link
Contributor Author

No problem @benbrown glad to help 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants