Skip to content

Instantly share code, notes, and snippets.

@JugurthaK
Created March 26, 2018 18:04
Show Gist options
  • Save JugurthaK/7f76684a9f9d0a479675359df79388ec to your computer and use it in GitHub Desktop.
Save JugurthaK/7f76684a9f9d0a479675359df79388ec to your computer and use it in GitHub Desktop.
Prise en main des API, ici pour retrouver un user Git
// gitFinder
// Permet d'afficher le profil d'un user gitHub grâce à l'API
var userElt = document.getElementById('presentation');
var button = document.getElementById('searchbtn');
// Button Click
button.addEventListener('click', function () {
// Formate l'URL selon ce qui a été rentré par l'utilisateur
var gitName = document.getElementById('gitName').value;
var gitUrl = 'https://api.github.com/users/' + gitName;
// Et on récupère les données grâce à l'API de Git
ajaxGet(gitUrl, function (reponse){
var user = JSON.parse(reponse);
var logo = document.createElement('img');
logo.src = user.avatar_url;
var bio = document.createElement('p');
bio.innerHTML = '<i>' + user.bio + '</i>';
var nbFollowers = document.createElement('p');
nbFollowers.textContent = 'Followers : '+ user.followers + ' Following : '+ user.following;
var profilLink = document.createElement('a');
profilLink.innerText = 'Profile link'
profilLink.href = user.html_url;
profilLink.target = '_blank';
// Insertion en HTML
userElt.appendChild(logo);
userElt.appendChild(bio);
userElt.appendChild(nbFollowers);
userElt.appendChild(profilLink);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment