@trivia-api/fetch
Version:
Functions to fetch data from The Trivia API.
34 lines (33 loc) • 1.72 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.submitQuestion = void 0;
const constants_1 = require("./constants");
const axios_1 = __importDefault(require("axios"));
/**
* Submits a question to the trivia api
* @param key - API Key
* @param question - Question to submit
* @param host - Optional host to send request to
* @returns the ID of the newly created question
*/
const submitQuestion = (key, question, host = constants_1.TRIVIA_API_BASE_URL) => __awaiter(void 0, void 0, void 0, function* () {
const _headers = Object.assign({}, constants_1.headers);
if (key) {
_headers["x-api-key"] = key;
}
const res = yield axios_1.default.post(`${host}/question`, Object.assign({ regions: [], type: "Multiple Choice", tags: [] }, question), { headers: _headers });
return res.data;
});
exports.submitQuestion = submitQuestion;