Skip to content

Commit

Permalink
feat: use node https instead of axios
Browse files Browse the repository at this point in the history
  • Loading branch information
Deadreyo authored and 0-vortex committed Mar 28, 2023
1 parent b1f870c commit 12b86a7
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/fetchers/ProfileCardFetcher.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
import axios from "axios";
import https from "https";
import { TopicContributionEndpoint } from "../utils/types/dtos.types";

export default async function ProfileCardDataFetcher (name: string): Promise<{ langs: string[], repos: string[], img: string }> {
const req = await axios<TopicContributionEndpoint>(`https://beta.gs-api.opensauced.pizza/v1/*/contributions?page=1&limit=1&range=30&contributor=${name}`);
const reqData = await new Promise<TopicContributionEndpoint>((resolve, reject) => {
https
.get(`https://beta.gs-api.opensauced.pizza/v1/*/contributions?page=1&limit=1&range=30&contributor=${name}`, resp => {
let data = "";

// a chunk of data has been recieved.
resp.on("data", chunk => {
data += chunk;
});

// the whole response has been received. Print out the result.
resp.on("end", () => {
resolve(JSON.parse(data));
});
})
.on("error", err => {
console.log(`Error: ${err.message}`);
reject(err);
});
});

console.log(reqData);
const contributor = reqData.data[0];

console.log(req.data);
const contributor = req.data.data[0];

// could be undefined if array is empty
if (!contributor) {
throw new Error(`User '${name}' Not Found`);
Expand Down

0 comments on commit 12b86a7

Please sign in to comment.