UNPKG

dce-icommons

Version:

The Harvard DCE wrapper for the iCommons API.

50 lines (43 loc) 1.15 kB
// Import path import path from 'path'; // Import other helpers import sendRequest from './helpers/sendRequest'; /* -------------------------- Function -------------------------- */ /** * Send an API request to Zoom * @author Gabe Abrams * @param opts object containing all arguments * @param opts.path the url path to hit * @param opts.token the iCommons token to use * @param [opts.method=GET] the https method to use * @param [opts.params] the request params to include */ const visitICommonsEndpoint = async ( opts: { path: string, token: string, method?: ('GET' | 'POST' | 'PUT' | 'DELETE'), params?: { [k in string]: any }, }, ) => { const { method, params, token, } = opts; // Require token if (!token) { throw new Error('No iCommons token was provided.'); } /* ---------------------- Send the Request ---------------------- */ return sendRequest({ params, method, headers: { Authorization: `Token ${token}`, }, host: 'icommons-rest-api.tlt.harvard.edu', path: path.join('/api/course/v2', opts.path), }); }; export default visitICommonsEndpoint;