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

Commit

Permalink
Use async/await (#12)
Browse files Browse the repository at this point in the history
* Change some Promises to async/await

* Update eslint and dependencies

* Remove useless comma
  • Loading branch information
rejas authored Oct 9, 2019
1 parent 9aebaf6 commit b755675
Show file tree
Hide file tree
Showing 5 changed files with 309 additions and 298 deletions.
9 changes: 6 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"extends": ["eslint:recommended","plugin:promise/recommended"],
"env": {
"browser": true,
"node": true,
"es6": true
"es6": true,
"node": true
},
"extends": ["eslint:recommended","plugin:promise/recommended"],
"plugins": ["promise"],
"parserOptions": {
"ecmaVersion": 2017
},
"rules": {
"no-console": 0,
"indent": [
Expand Down
42 changes: 21 additions & 21 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,41 +174,41 @@ const itemLink = require('./item'),
};

module.exports = {

createFeed: (options) => {
createFeed: async (options) => {
app.options = options;
app.baseCharUrl = `https://worldofwarcraft.com/en-${options.region}/character/${app.options.realm}/`;

if (options.character) {

return blizzard.getApplicationToken()
await blizzard.getApplicationToken()
.then(response => {
blizzard.defaults.token = response.data.access_token;
return blizzard.wow.character(['feed'], {
origin: options.region,
realm: options.realm,
name: options.character
});
})
.then(response => {
return app.createCharFeed(response.data);
return null;
});

const character = await blizzard.wow.character(['feed'], {
origin: options.region,
realm: options.realm,
name: options.character
});

return app.createCharFeed(character.data);
} else if (options.guild) {
app.options.path = encodeURI('/wow/guild/' + options.realm + '/' + options.guild.replace(' ', '_') + '/');
app.options.host = options.region + '.battle.net';

return blizzard.getApplicationToken()
await blizzard.getApplicationToken()
.then(response => {
blizzard.defaults.token = response.data.access_token;
return blizzard.wow.guild(['news'], {
origin: options.region,
realm: options.realm,
name: options.guild
});
})
.then(response => {
return app.createGuildFeed(response.data);
return null;
});

const guild = await blizzard.wow.guild(['news'], {
origin: options.region,
realm: options.realm,
name: options.guild
});

return app.createGuildFeed(guild.data);
}
}
};
Loading

0 comments on commit b755675

Please sign in to comment.