mirror of
https://github.com/Expand-sys/PharmaBot
synced 2026-03-22 12:27:08 +11:00
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
var http = require("https");
|
|
|
|
|
|
|
|
async function define(term) {
|
|
return new Promise((resolve, reject) => {
|
|
const path = '/define?term='+term;
|
|
const options = {
|
|
"method": "GET",
|
|
"hostname": "mashape-community-urban-dictionary.p.rapidapi.com",
|
|
"port": null,
|
|
"path": path,
|
|
"headers": {
|
|
"x-rapidapi-key": "1276b32e63msh739dcbdeaf39a12p175d69jsn31c93e5fcdbc",
|
|
"x-rapidapi-host": "mashape-community-urban-dictionary.p.rapidapi.com",
|
|
"useQueryString": true
|
|
}
|
|
};
|
|
|
|
const req = http.request(options, (res) => {
|
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
return reject(new Error('statusCode=' + res.statusCode));
|
|
}
|
|
var body = [];
|
|
res.on('data', function(chunk) {
|
|
body.push(chunk);
|
|
});
|
|
res.on('end', function() {
|
|
try {
|
|
body = JSON.parse(Buffer.concat(body).toString());
|
|
} catch(e) {
|
|
reject(e);
|
|
}
|
|
resolve(body);
|
|
});
|
|
});
|
|
req.on('error', (e) => {
|
|
reject(e.message);
|
|
});
|
|
// send the request
|
|
req.end();
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
define,
|
|
};
|