UNPKG

@aleph/gatsby-source-greenhouse-job-board

Version:

Gatsby source plugin for pulling offices, departments, and jobs into Gatsby from the Greenhouse Job Board API. It creates links between offices, departments, and jobs so they can be queried in Gatsby using GraphQL.

64 lines (63 loc) 2.32 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); const axios = require('axios'); const baseUrl = `https://boards-api.greenhouse.io/v1/boards`; function fetchJobs(_x) { return _fetchJobs.apply(this, arguments); } function _fetchJobs() { _fetchJobs = (0, _asyncToGenerator2.default)(function* (boardToken) { const url = `${baseUrl}/${boardToken}/jobs/`; const jobs = yield getJobs(url); return jobs; }); return _fetchJobs.apply(this, arguments); } function fetchOffices(_x2) { return _fetchOffices.apply(this, arguments); } function _fetchOffices() { _fetchOffices = (0, _asyncToGenerator2.default)(function* (boardToken) { const url = `${baseUrl}/${boardToken}/offices/`; const offices = yield getOffices(url); return offices; }); return _fetchOffices.apply(this, arguments); } function fetchDepartments(_x3) { return _fetchDepartments.apply(this, arguments); } function _fetchDepartments() { _fetchDepartments = (0, _asyncToGenerator2.default)(function* (boardToken) { const url = `${baseUrl}/${boardToken}/departments/`; const departments = yield getDepartments(url); return departments; }); return _fetchDepartments.apply(this, arguments); } const getJobs = url => axios.get(url).then(response => response.data.jobs).then(jobs => { return Promise.all(jobs.map( /*#__PURE__*/function () { var _ref = (0, _asyncToGenerator2.default)(function* (job) { const node = yield getJob(`${url}${job.id}?questions=true`); return node; }); return function (_x4) { return _ref.apply(this, arguments); }; }())); }).catch(error => console.log(error)); const getJob = url => axios.get(url).then(response => response.data).then(data => { return data; }).catch(error => console.log(error)); const getOffices = url => axios.get(url).then(response => response.data.offices).then(offices => { return offices; }).catch(error => console.log(error)); const getDepartments = url => axios.get(url).then(response => response.data.departments).then(departments => { return departments; }).catch(error => console.log(error)); module.exports = { fetchJobs, fetchOffices, fetchDepartments };