-
-
Save ThatCheck/7e1055aa0c8afbd61fa887188d4818ff to your computer and use it in GitHub Desktop.
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
| const text = require('./text.js') | |
| const image = require('./image.js') | |
| const helper = { | |
| text: text, | |
| image: image | |
| } | |
| export default helper; | |
| export {text, image}; |
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
| const image = { | |
| toImage: image => { | |
| return { | |
| type: 'image', | |
| content: image | |
| } | |
| } | |
| } | |
| module.exports = image |
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
| /* EXEMPLES D UTILISATION DU HELPER */ | |
| const request = require('superagent') | |
| import {text} from '../helper/helper.js' | |
| import {image} from '../helper/helper.js' | |
| const getInfoPokemon = (entity) => { | |
| if (!entity) { return Promise.reject('Vous n\'avez donné aucun Pokémon')} | |
| return new Promise( | |
| function(resolve, reject) { | |
| request.get('https://pokeapi.co/api/v2/pokemon/' + entity.raw.toLowerCase()) | |
| .end((err, res) => { | |
| if (err) { | |
| console.log(new Error().stack) | |
| return reject("Le pokemon que vous avez demandé n'a pas été trouvé dans la base de données.") | |
| } | |
| const infosP = infoPokemonLayout(res.body) | |
| resolve(infoPokemonLayout(res.body)) | |
| }) | |
| }) | |
| } | |
| const infoPokemonLayout = (json) => { | |
| const answer = [helper.text.toText(`:mag_right: ${json.name} infos`)] | |
| const toAdd = json.types.map(elem => elem.type.name).join(' / ') | |
| answer.push(helper.text.toText(`Type(s): ${toAdd}`)) | |
| if (json.sprites.front_default) { | |
| answer.push(helper.image.toImage(json.sprites.front_default)) | |
| } | |
| return answer | |
| } | |
| module.exports = getInfoPokemon |
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
| const text = { | |
| toText: message => { | |
| return { | |
| type: 'text', | |
| content: message | |
| } | |
| } | |
| } | |
| module.exports = text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment