diff --git a/GitHubCard/index.js b/GitHubCard/index.js index 9423d23af..de7c65d2b 100644 --- a/GitHubCard/index.js +++ b/GitHubCard/index.js @@ -1,8 +1,27 @@ +import axios from "axios"; /* STEP 1: using axios, send a GET request to the following URL (replacing the placeholder with your Github name): https://api.github.com/users/ */ +const followersArray = ['tetondan', + 'dustinmyers', + 'justsml', + 'luishrd', + 'bigknell']; + +for (let i = 0; i < followersArray.length; i++){ + getGitCard(followersArray[i]); +} + + +function getGitCard(username){ + axios.get(`https://api.github.com/users/${username}`) +.then(resp => { + document.querySelector('.cards').appendChild(gitHubCard(resp)); +}) +.catch( err => console.error(err)); +} /* STEP 2: Inspect and study the data coming back, this is YOUR @@ -12,6 +31,7 @@ Skip to STEP 3 (line 34). */ + /* STEP 4: Pass the data received from Github into your function, and append the returned markup to the DOM as a child of .cards @@ -28,7 +48,55 @@ user, and adding that card to the DOM. */ -const followersArray = []; + + +function gitHubCard(gitInfo) { + const card = document.createElement('div'); + const img = document.createElement('img'); + const cardInfo = document.createElement('div'); + const name = document.createElement('h3'); + const username = document.createElement('p'); + const location = document.createElement('p'); + const profile = document.createElement('p'); + const profileLink = document.createElement('a'); + const followers = document.createElement('p'); + const following = document.createElement('p'); + const bio = document.createElement('p'); + + img.src = gitInfo.avatar_url; + name.textContent = gitInfo.name; + username.textContent = gitInfo.login; + location.textContent = gitInfo.location; + profile.textContent = "Profile"; + profileLink.textContent = "Link to Profile"; + profileLink.href = gitInfo.html_url; + followers.textContent = `Follower: ${gitInfo.followers}`; + following.textContent = `Following: ${gitInfo.following}`; + bio.textContent = gitInfo.bio; + + + card.appendChild(img); + card.appendChild(cardInfo); + cardInfo.appendChild(name); + cardInfo.appendChild(username); + cardInfo.appendChild(location); + cardInfo.appendChild(profile); + profile.appendChild(profileLink); + cardInfo.appendChild(followers); + cardInfo.appendChild(following); + cardInfo.appendChild(bio); + + card.classList.add('card'); + cardInfo.classList.add('card-info'); + name.classList.add('name'); + username.classList.add('username'); + + + + + return card; +} + /* STEP 3: Create a function that accepts a single object as its only argument. @@ -58,3 +126,5 @@ const followersArray = []; luishrd bigknell */ + + diff --git a/package-lock.json b/package-lock.json index 09ae31ca5..9aedbc81d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "github-usercard", "version": "1.0.0", "license": "ISC", + "dependencies": { + "axios": "^0.26.1" + }, "devDependencies": { "eslint": "^8.10.0", "parcel-bundler": "^1.12.4" @@ -2373,6 +2376,14 @@ "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==", "dev": true }, + "node_modules/axios": { + "version": "0.26.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz", + "integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==", + "dependencies": { + "follow-redirects": "^1.14.8" + } + }, "node_modules/babel-plugin-dynamic-import-node": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz", @@ -4886,6 +4897,25 @@ "integrity": "sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==", "dev": true }, + "node_modules/follow-redirects": { + "version": "1.14.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz", + "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", @@ -12618,6 +12648,14 @@ "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==", "dev": true }, + "axios": { + "version": "0.26.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz", + "integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==", + "requires": { + "follow-redirects": "^1.14.8" + } + }, "babel-plugin-dynamic-import-node": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz", @@ -14692,6 +14730,11 @@ "integrity": "sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==", "dev": true }, + "follow-redirects": { + "version": "1.14.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz", + "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==" + }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", diff --git a/package.json b/package.json index d85e259b0..019a9d954 100644 --- a/package.json +++ b/package.json @@ -19,5 +19,7 @@ "eslint": "^8.10.0", "parcel-bundler": "^1.12.4" }, - "dependencies": {} + "dependencies": { + "axios": "^0.26.1" + } }