Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gatsby-source-hire-with-google

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-source-hire-with-google - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

helpers.js

44

gatsby-node.js

@@ -6,9 +6,7 @@ "use strict";

});
exports.getJobs = getJobs;
exports.sourceNodes = sourceNodes;
exports.generateBaseUrl = void 0;
var _crypto = _interopRequireDefault(require("crypto"));
var _axios = _interopRequireDefault(require("axios"));
var _helpers = require("./helpers");

@@ -23,39 +21,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const generateBaseUrl = companyName => `https://hire.withgoogle.com/v2/api/t/${companyName}/public/jobs`;
exports.generateBaseUrl = generateBaseUrl;
function getJobs(_x) {
return _getJobs.apply(this, arguments);
}
function _getJobs() {
_getJobs = _asyncToGenerator(function* (companyName) {
if (!companyName) throw new Error('You need to define companyName in gatsby-config.js.');
try {
const URL = generateBaseUrl(companyName);
const _ref = yield _axios.default.get(URL, {
maxRedirects: 0,
validateStatus: status => status >= 200 && status < 300 || status === 404
}),
data = _ref.data,
status = _ref.status;
if (status === 404) {
return [];
} else return data.map(j => {
return _objectSpread({
id: j.identifier.value
}, j);
});
} catch (e) {
throw new Error(`Couldn't fetch jobs for ${companyName}. You sure ${generateBaseUrl(companyName)} exists?`);
}
});
return _getJobs.apply(this, arguments);
}
function sourceNodes(_x2, _x3) {
function sourceNodes(_x, _x2) {
return _sourceNodes.apply(this, arguments);

@@ -71,3 +33,3 @@ }

const createNode = boundActionCreators.createNode;
const jobs = yield getJobs(companyName);
const jobs = yield (0, _helpers.fetchJobs)(companyName);
jobs.forEach(job => {

@@ -74,0 +36,0 @@ const jsonString = JSON.stringify(job);

{
"name": "gatsby-source-hire-with-google",
"version": "1.2.0",
"version": "1.3.0",
"description": "Gatsby source plugin for loading job openings from hire.withgoogle.com",

@@ -5,0 +5,0 @@ "main": "gatsby-node.js",

import crypto from 'crypto'
import axios from 'axios'
import { generateBaseUrl, fetchJobs } from './helpers'
export const generateBaseUrl = (companyName) => `https://hire.withgoogle.com/v2/api/t/${companyName}/public/jobs`
export async function getJobs(companyName) {
if (!companyName) throw new Error('You need to define companyName in gatsby-config.js.')
try {
const URL = generateBaseUrl(companyName)
const { data, status } = await axios.get(URL, {
maxRedirects: 0,
validateStatus: status => status >= 200 && status < 300 || status === 404
})
if (status === 404) {
return []
}
else return data.map(j => {
return {
id: j.identifier.value, // Gatsby requires each node to contain an id, so that is why add it here.
...j
}
})
} catch (e) {
throw new Error(`Couldn't fetch jobs for ${companyName}. You sure ${generateBaseUrl(companyName)} exists?`)
}
}
export async function sourceNodes ({ boundActionCreators }, { companyName }) {
const { createNode } = boundActionCreators
const jobs = await getJobs(companyName)
const jobs = await fetchJobs(companyName)

@@ -35,0 +8,0 @@ jobs.forEach(job => {

import test from 'ava';
import { generateBaseUrl, getJobs, sourceNodes } from '../../gatsby-node'
import { sourceNodes } from '../../gatsby-node'
import { generateBaseUrl, fetchJobs } from '../../helpers'

@@ -17,4 +18,4 @@ const TEST_COMPANY = 'dromae'

test(`getJobs(${TEST_COMPANY}) should return .. jobs :)`, async t => {
const jobs = await getJobs(TEST_COMPANY)
test(`fetchJobs(${TEST_COMPANY}) should return .. jobs :)`, async t => {
const jobs = await fetchJobs(TEST_COMPANY)

@@ -24,4 +25,4 @@ t.snapshot(jobs);

test('getJobs() should return an error', async t => {
const error = await t.throws(getJobs())
test('fetchJobs() should return an error', async t => {
const error = await t.throws(fetchJobs())

@@ -31,4 +32,4 @@ t.is(error.message, 'You need to define companyName in gatsby-config.js.');

test(`getJobs(${TEST_COMPANY_THAT_DOESNT_EXIST}) should return an error`, async t => {
const error = await t.throws(getJobs(TEST_COMPANY_THAT_DOESNT_EXIST))
test(`fetchJobs(${TEST_COMPANY_THAT_DOESNT_EXIST}) should return an error`, async t => {
const error = await t.throws(fetchJobs(TEST_COMPANY_THAT_DOESNT_EXIST))

@@ -35,0 +36,0 @@ t.is(error.message, `Couldn't fetch jobs for ${TEST_COMPANY_THAT_DOESNT_EXIST}. You sure ${generateBaseUrl(TEST_COMPANY_THAT_DOESNT_EXIST)} exists?`);

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc