From 47f75836597ff13a32660e03d61629ddd173f86c Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Sat, 21 Aug 2021 08:46:56 +0200 Subject: [PATCH] Added comments to apiclient --- src/lib/Apiclient.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/lib/Apiclient.js b/src/lib/Apiclient.js index efe4789..dcb69d2 100644 --- a/src/lib/Apiclient.js +++ b/src/lib/Apiclient.js @@ -11,12 +11,21 @@ axios.interceptors.response.use(response => { }); export default class Apiclient { + + /** + * API-Getter for the linkylinky api stats endpoint + * @returns Current linkylinky stats (url count, total visits) + */ static async getStats() { return ( await axios.get('https://kauft.es/api/stats') ).data; } + /** + * API-Getter for the linkylinky api all urls endpoint (needs auth) + * @returns All urls with shortcode, target, full url and visits in an array of objects + */ static async getUrls() { console.log("APICALL") return ( @@ -26,7 +35,13 @@ export default class Apiclient { ).data; } + /** + * API-Getter for the linkylinky api url details endpoint (needs auth) + * @param {*} shortcode The shortcode of your favourite url + * @returns Url shortcode, target, full url and visit count in an object + */ static async getUrlDetails(shortcode) { + //TODO: Handle 404 return ( await axios.get(`https://kauft.es/api/${shortcode}`, { headers: { Authorization: `Bearer ${UserStore.state.token}` } @@ -34,7 +49,13 @@ export default class Apiclient { ).data; } + /** + * API-Getter for the linkylinky api url vists endpoint (needs auth) + * @param {*} shortcode The shortcode of your favourite url + * @returns Url visit details as an object for each visits (r/n they only contain timestamps) + */ static async getUrlVisits(shortcode) { + //TODO: Handle 404 return ( await axios.get(`https://kauft.es/api/${shortcode}/visits`, { headers: { Authorization: `Bearer ${UserStore.state.token}` } @@ -42,6 +63,11 @@ export default class Apiclient { ).data; } + /** + * API-Delet for the linkylinky api url deletion endpoint (needs auth) + * @param {*} shortcode The shortcode of your most hated url + * @returns Just a 204 (no matter if the url got deleted or didn't exist in the first place) + */ static async deleteUrl(shortcode) { return ( await axios.delete(`https://kauft.es/api/${shortcode}`, { @@ -50,6 +76,12 @@ export default class Apiclient { ).status; } + /** + * Login and receive a JWT for future auth. + * @param {*} username Your username (cleartext) + * @param {*} password Your password (cleartext) + * @returns A user login object containing your jwt + */ static async login(username, password) { return ( await axios.post(`https://kauft.es/api/auth/login`, {}, { @@ -60,6 +92,10 @@ export default class Apiclient { ).data; } + /** + * Log yourself out -> Invalidates your current (and past) JWTs + * @returns Done! + */ static async logout() { return ( await axios.post(`https://kauft.es/api/auth/logout`, {}, {