diff --git a/APIManager.js b/APIManager.js index 493c6d60..fb52ad2e 100644 --- a/APIManager.js +++ b/APIManager.js @@ -1,7 +1,39 @@ -//This is the class that will manage all your APIs - -class APIManager { +class APIManager +{ constructor() { this.data = {} + this.currentUser = {} + + } + + fetchData() + { + const numberUsers = 7 + + const randomUserApi = `https://randomuser.me/api/?results=${numberUsers}` + const kanyeApi = 'https://api.kanye.rest/' + const pokemonApi = `https://pokeapi.co/api/v2/pokemon/${Math.floor(Math.random() * 950)}` + const meatApi = 'https://baconipsum.com/api/?type=meat' + + return Promise.all([ + + $.get(randomUserApi), + $.get(kanyeApi), + $.get(pokemonApi), + $.get(meatApi) + ]).then(data => + { + const users = data[0] + this.data = { + meanUser: users.results[0], + kanyeQuote: data[1].quote, + pokemon: data[2], + meat: data[3][0], + friends: users.results.slice(1) + } + + }) } + } + diff --git a/Renderer.js b/Renderer.js index 6c2cb903..bc230966 100644 --- a/Renderer.js +++ b/Renderer.js @@ -1,4 +1,33 @@ - class Renderer { + + renderContent(classHTML, ID, data) { + const source = $(`#${ID}`).html() + const template = Handlebars.compile(source) + const newHTML = template(data) + $(`.${classHTML}`).html(newHTML) + } + + renderMainUser(userobject) { + this.renderContent('user-container', 'meanUser-template', userobject) + } + + renderQuote(quote) { + this.renderContent('quote-container', 'quote-template', { quote }) + } + + renderPokemon(pokemon) { + this.renderContent('pokemon-container', 'pokemon-template', { pokemon }) + } + + renderMeat(meat) { + this.renderContent('meat-container', 'meat-template', { meat }) + } + + renderFriends(friends) { + this.renderContent('friends-container', 'friends-template', { friends }) + } -} \ No newline at end of file + rendersaveFriends(items) { + this.renderContent('saveFriends-container', 'saveFriends-template', { items }) + } +} diff --git a/index.html b/index.html index c27bda4e..7243cdba 100644 --- a/index.html +++ b/index.html @@ -4,31 +4,77 @@