Last active
February 3, 2017 14:26
-
-
Save max3uc3/19954899fed48e97265863068ace462d 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 | |
} | |
module.exports = helper |
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