UNPKG

garyapi

Version:

A simple Node.js client for the Gary the Cat API 🐾

69 lines (60 loc) 1.53 kB
const fetch = require("node-fetch"); const BASE_URL = "https://api.garythe.cat"; /** * A simple Node.js client for the Gary API 🐾 */ class GaryAPI { /** * Fetch a random Gary image URL (JSON). * @returns {Promise<string>} */ async getGary() { const res = await fetch(`${BASE_URL}/gary`); const data = await res.json(); return data.url; } /** * Fetch a random Goober image URL (JSON). * @returns {Promise<string>} */ async getGoober() { const res = await fetch(`${BASE_URL}/goober`); const data = await res.json(); return data.url; } /** * Fetch a random quote. * @returns {Promise<string>} */ async getQuote() { const res = await fetch(`${BASE_URL}/quote`); const data = await res.json(); return data.quote; } /** * Fetch a random joke. * @returns {Promise<string>} */ async getJoke() { const res = await fetch(`${BASE_URL}/joke`); const data = await res.json(); return data.joke; } /** * Fetch the image buffer of a random Gary image. * @returns {Promise<Buffer>} */ async getGaryImageBuffer() { const res = await fetch(`${BASE_URL}/gary/image`); return res.buffer(); } /** * Fetch the image buffer of a random Goober image. * @returns {Promise<Buffer>} */ async getGooberImageBuffer() { const res = await fetch(`${BASE_URL}/goober/image`); return res.buffer(); } } module.exports = GaryAPI;