diff --git a/GitHubCard/index.js b/GitHubCard/index.js index 9423d23af..4528a993d 100644 --- a/GitHubCard/index.js +++ b/GitHubCard/index.js @@ -1,55 +1,154 @@ +import axios from 'axios'; +import 'regenerator-runtime/runtime.js'; /* STEP 1: using axios, send a GET request to the following URL (replacing the placeholder with your Github name): - https://api.github.com/users/ + https://api.github.com/users/omaddoc */ /* - STEP 2: Inspect and study the data coming back, this is YOUR - github info! You will need to understand the structure of this - data in order to use it to build your component function +STEP 2: Inspect and study the data coming back, this is YOUR +github info! You will need to understand the structure of this +data in order to use it to build your component function - Skip to STEP 3 (line 34). +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 +STEP 4: Pass the data received from Github into your function, +and append the returned markup to the DOM as a child of .cards */ /* - STEP 5: Now that you have your own card getting added to the DOM, either - follow this link in your browser https://api.github.com/users//followers, - manually find some other users' github handles, or use the list found at the - bottom of the page. Get at least 5 different Github usernames and add them as - Individual strings to the friendsArray below. - - Using that array, iterate over it, requesting data for each user, creating a new card for each - user, and adding that card to the DOM. -*/ +STEP 5: Now that you have your own card getting added to the DOM, either +follow this link in your browser https://api.github.com/users//followers, +manually find some other users' github handles, or use the list found at the +bottom of the page. Get at least 5 different Github usernames and add them as +Individual strings to the friendsArray below. -const followersArray = []; +Using that array, iterate over it, requesting data for each user, creating a new card for each +user, and adding that card to the DOM. +*/ /* - STEP 3: Create a function that accepts a single object as its only argument. - Using DOM methods and properties, create and return the following markup: - -
- -
-

{users name}

-

{users user name}

-

Location: {users location}

-

Profile: - {address to users github page} -

-

Followers: {users followers count}

-

Following: {users following count}

-

Bio: {users bio}

-
-
+STEP 3: Create a function that accepts a single object as its only argument. +Using DOM methods and properties, create and return the following markup: + +
+ +
+

{users name}

+

{users user name}

+

Location: {users location}

+

Profile: +{address to users github page} +

+

Followers: {users followers count}

+

Following: {users following count}

+

Bio: {users bio}

+
+
*/ +const data = axios + .get('https://api.github.com/users/omaddoc') + .then((res) => { + return res.data; + }) + .catch((err) => { + console.log(err); + }); + +const followersArray = [ + 'tetondan', + 'dustinmyers', + 'justsml', + 'luishrd', + 'bigknell', +]; + +function cardCreator(user) { + const card = document.createElement('div'); + const info = document.createElement('div'); + const img = document.createElement('img'); + const username = document.createElement('p'); + const profile = document.createElement('p'); + const name = document.createElement('h3'); + const location = document.createElement('p'); + const followers = document.createElement('p'); + const following = document.createElement('p'); + const bio = document.createElement('p'); + const address = document.createElement('a'); + + img.src = user.avatar_url; + name.textContent = user.name; + username.textContent = user.login; + location.textContent = `Location: ${user.location}`; + followers.textContent = `Followers: ${user.followers}`; + following.textContent = `Following: ${user.following}`; + bio.textContent = `Bio: ${user.bio}`; + + address.href = user.html_url; + address.textContent = user.html_url; + profile.textContent = 'Profile: '; + profile.appendChild(address); + + card.classList.add('card'); + info.classList.add('card-info'); + username.classList.add('username'); + if (user.login === 'omaddoc') { + info.append(name, username, location, profile, followers, following, bio); + card.append(img, info); + } else { + info.append(username, profile); + card.append(img, info); + } + + return card; +} + +async function fetchData() { + try { + const res = await axios.get('https://api.github.com/users/omaddoc'); + const data = res.data; + cards.appendChild(cardCreator(data)); + } catch (err) { + console.log(err); + } +} + +async function fetchFollowers() { + try { + const res = await axios.get( + `https://api.github.com/users/omaddoc/followers` + ); + const data = res.data; + console.log(data); + + const followersCardsPromises = data.map(async (user) => { + return cardCreator(user); + }); + + const followersCards = await Promise.all(followersCardsPromises); + + // Append the followers' cards to the DOM + followersCards.forEach((card) => { + cards.appendChild(card); + }); + } catch (err) { + console.log(err); + } +} + +const cards = document.querySelector('.cards'); + +async function fetchDataAndFollowers() { + await fetchData(); + await fetchFollowers(); +} + +fetchDataAndFollowers(); + /* List of LS Instructors Github username's: tetondan diff --git a/index.html b/index.html index 29eb38fe2..360c9281f 100644 --- a/index.html +++ b/index.html @@ -1,14 +1,17 @@ - - - + + +
- Lambda Logo + Lambda Logo

❤️'s

GitHub Logo
diff --git a/package-lock.json b/package-lock.json index 09ae31ca5..7f0fd0149 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,10 @@ "name": "github-usercard", "version": "1.0.0", "license": "ISC", + "dependencies": { + "axios": "^1.3.6", + "regenerator-runtime": "^0.13.11" + }, "devDependencies": { "eslint": "^8.10.0", "parcel-bundler": "^1.12.4" @@ -2343,8 +2347,7 @@ "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", - "dev": true + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" }, "node_modules/atob": { "version": "2.1.2", @@ -2373,6 +2376,29 @@ "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==", "dev": true }, + "node_modules/axios": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.3.6.tgz", + "integrity": "sha512-PEcdkk7JcdPiMDkvM4K6ZBRYq9keuVJsToxm2zQIM70Qqo2WHTdJZMXcG9X+RmRp2VPNUQC8W1RAGbgt6b1yMg==", + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/axios/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "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", @@ -3238,7 +3264,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, "dependencies": { "delayed-stream": "~1.0.0" }, @@ -3969,7 +3994,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", - "dev": true, "engines": { "node": ">=0.4.0" } @@ -4886,6 +4910,25 @@ "integrity": "sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==", "dev": true }, + "node_modules/follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "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", @@ -6667,7 +6710,6 @@ "version": "1.51.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.51.0.tgz", "integrity": "sha512-5y8A56jg7XVQx2mbv1lu49NR4dokRnhZYTtL+KGfaa27uq4pSTXkwQkFJl4pkRMyNFz/EtYDSkiiEHx3F7UN6g==", - "dev": true, "engines": { "node": ">= 0.6" } @@ -6676,7 +6718,6 @@ "version": "2.1.34", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.34.tgz", "integrity": "sha512-6cP692WwGIs9XXdOO4++N+7qjqv0rqxxVvJ3VHPh/Sc9mVZcQP+ZGhkKiTvWMQRr2tbHkJP/Yn7Y0npb3ZBs4A==", - "dev": true, "dependencies": { "mime-db": "1.51.0" }, @@ -8565,6 +8606,11 @@ "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", "dev": true }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/psl": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", @@ -8859,10 +8905,9 @@ } }, "node_modules/regenerator-runtime": { - "version": "0.13.9", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz", - "integrity": "sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==", - "dev": true + "version": "0.13.11", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", + "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==" }, "node_modules/regenerator-transform": { "version": "0.14.5", @@ -12597,8 +12642,7 @@ "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", - "dev": true + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" }, "atob": { "version": "2.1.2", @@ -12618,6 +12662,28 @@ "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==", "dev": true }, + "axios": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.3.6.tgz", + "integrity": "sha512-PEcdkk7JcdPiMDkvM4K6ZBRYq9keuVJsToxm2zQIM70Qqo2WHTdJZMXcG9X+RmRp2VPNUQC8W1RAGbgt6b1yMg==", + "requires": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + }, + "dependencies": { + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + } + } + }, "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", @@ -13348,7 +13414,6 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dev": true, "requires": { "delayed-stream": "~1.0.0" } @@ -13947,8 +14012,7 @@ "delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", - "dev": true + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, "depd": { "version": "1.1.2", @@ -14692,6 +14756,11 @@ "integrity": "sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==", "dev": true }, + "follow-redirects": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", + "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==" + }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", @@ -16065,14 +16134,12 @@ "mime-db": { "version": "1.51.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.51.0.tgz", - "integrity": "sha512-5y8A56jg7XVQx2mbv1lu49NR4dokRnhZYTtL+KGfaa27uq4pSTXkwQkFJl4pkRMyNFz/EtYDSkiiEHx3F7UN6g==", - "dev": true + "integrity": "sha512-5y8A56jg7XVQx2mbv1lu49NR4dokRnhZYTtL+KGfaa27uq4pSTXkwQkFJl4pkRMyNFz/EtYDSkiiEHx3F7UN6g==" }, "mime-types": { "version": "2.1.34", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.34.tgz", "integrity": "sha512-6cP692WwGIs9XXdOO4++N+7qjqv0rqxxVvJ3VHPh/Sc9mVZcQP+ZGhkKiTvWMQRr2tbHkJP/Yn7Y0npb3ZBs4A==", - "dev": true, "requires": { "mime-db": "1.51.0" } @@ -17613,6 +17680,11 @@ "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", "dev": true }, + "proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "psl": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", @@ -17858,10 +17930,9 @@ } }, "regenerator-runtime": { - "version": "0.13.9", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz", - "integrity": "sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==", - "dev": true + "version": "0.13.11", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", + "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==" }, "regenerator-transform": { "version": "0.14.5", diff --git a/package.json b/package.json index d85e259b0..cf509627c 100644 --- a/package.json +++ b/package.json @@ -19,5 +19,8 @@ "eslint": "^8.10.0", "parcel-bundler": "^1.12.4" }, - "dependencies": {} + "dependencies": { + "axios": "^1.3.6", + "regenerator-runtime": "^0.13.11" + } }