Created
October 24, 2017 21:31
-
-
Save bsommardahl/710522a5def0fab9e9e9b4cbb3d7cfbf to your computer and use it in GitHub Desktop.
A simple API wrapper for some functions from Breezy HR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require("request-promise"); | |
const base = "https://breezy.hr/public/api/v2"; | |
let token = false; | |
const breezy = { | |
login: async function(email, password) { | |
const opts = { | |
method: "POST", | |
uri: `${base}/signin`, | |
body: { email, password }, | |
json: true | |
}; | |
try { | |
const response = await request(opts); | |
token = response.access_token; | |
} catch (err) { | |
console.log("Error logging in:"); | |
console.log(err); | |
} | |
}, | |
companies: async function() { | |
const opts = { | |
method: "GET", | |
uri: `${base}/companies`, | |
json: true, | |
headers: { | |
Authorization: token | |
} | |
}; | |
try { | |
const response = await request(opts); | |
return response; | |
} catch (err) { | |
console.log("Error getting companies:"); | |
console.log(err); | |
} | |
}, | |
positions: async function(companyId) { | |
const opts = { | |
method: "GET", | |
uri: `${base}/company/${companyId}/positions`, | |
json: true, | |
headers: { | |
Authorization: token | |
} | |
}; | |
try { | |
const response = await request(opts); | |
return response; | |
} catch (err) { | |
console.log("Error getting positions:"); | |
console.log(err); | |
} | |
}, | |
candidates: async function(companyId, positionId) { | |
const opts = { | |
method: "GET", | |
uri: `${base}/company/${companyId}/position/${positionId}/candidates`, | |
json: true, | |
headers: { | |
Authorization: token | |
} | |
}; | |
try { | |
const response = await request(opts); | |
return response; | |
} catch (err) { | |
console.log("Error getting position meta:"); | |
console.log(err); | |
} | |
}, | |
candidate: async function(companyId, positionId, candidateId, meta) { | |
let url = `${base}/company/${companyId}/position/${positionId}/candidate/${candidateId}`; | |
if (meta) url += "/meta"; | |
const opts = { | |
method: "GET", | |
uri: url, | |
qs: { company_id: companyId, position_id: positionId }, | |
json: true, | |
headers: { | |
Authorization: token | |
} | |
}; | |
try { | |
const response = await request(opts); | |
return response; | |
} catch (err) { | |
console.log(err); | |
} | |
} | |
}; | |
module.exports = breezy; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment