UNPKG

@sharkfincode/easyapis

Version:

Easily use APIs from Easy APIs.

48 lines (39 loc) 1.27 kB
const request = require('https'); const qs = require('querystring'); const baseURL = 'https://easyapis.soue.ca'; const docURL = `${baseURL}/d`; const apiURL = `${baseURL}/api`; // Cowsay class cowsay { constructor(text = 'Moo', type = 'default', eyes = 'oo', mouth = '__') { this.help = `${docURL}/cowsay`; Object.assign(this, { text, type, eyes, mouth }); } request() { return new Promise((resolve, reject) => { this.uri = qs.stringify({ text: this.text, type: this.type, eyes: this.eyes, mouth: this.mouth }); request.get(`${apiURL}/cowsay?${this.uri}`, res => { let response = ''; res.on('data', d => response+=d); res.on('end', () => { this.statusCode = res.statusCode; this.headers = res.headers; this.body = response; resolve(this); }); res.on('error', reject) }); }); } } module.exports = { cowsay };