Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Components - gem #15763

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 171 additions & 0 deletions components/gem/actions/create-candidate/create-candidate.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import { SOURCED_FROM } from "../../common/constants.mjs";
import gem from "../../gem.app.mjs";

export default {
key: "gem-create-candidate",
name: "Create Candidate",
description: "Creates a new candidate in Gem. [See the documentation](https://api.gem.com/v0/reference#tag/Candidates/paths/~1v0~1candidates/post)",
version: "0.0.1",
type: "action",
props: {
gem,
createdBy: {
propDefinition: [
gem,
"createdBy",
],
},
firstName: {
type: "string",
label: "First Name",
description: "Candidate's first name",
optional: true,
},
lastName: {
type: "string",
label: "Last Name",
description: "Candidate's last name",
optional: true,
},
nickname: {
type: "string",
label: "Nickname",
description: "Candidate's nickname",
optional: true,
},
primaryEmail: {
type: "string",
label: "Primary Email Address",
description: "Candidate's primary email address",
},
additionalEmails: {
type: "string[]",
label: "Email Addresses",
description: "List of candidate's additional email addresses",
optional: true,
},
linkedInHandle: {
type: "string",
label: "LinkedIn Handle",
description: "If `LinkedIn Handle` is provided, candidate creation will be de-duplicated. If a candidate with the provided `LinkedIn Handle already exists, a 400 error will be returned with `errors` containing information on the existing candidate in this shape: `{\"errors\": { \"duplicate_candidate\": { \"id\": \"string\", \"linked_in_handle\": \"string\" }}}`.",
optional: true,
},
title: {
type: "string",
label: "Title",
description: "Candidate's job title",
optional: true,
},
company: {
type: "string",
label: "Company",
description: "Candidate's company name",
optional: true,
},
location: {
type: "string",
label: "Location",
description: "Candidate's location",
optional: true,
},
school: {
type: "string",
label: "School",
description: "Candidate's school",
optional: true,
},
educationalInfo: {
type: "string[]",
label: "Educational Info",
description: "A list of objects containing candidate's educational information. **Format: [{\"school\": \"string\", \"parsed_university\": \"string\", \"parsed_school\": \"string\", \"start_date\": \"string\", \"end_date\": \"string\", \"field_of_study\": \"string\", \"parsed_major_1\": \"string\", \"parsed_major_2\": \"string\", \"degree\": \"string\"}]**. [See the documentation](https://api.gem.com/v0/reference#tag/Candidates/paths/~1v0~1candidates/post) for further details.",
optional: true,
},
workInfo: {
type: "string",
label: "Work Info",
description: "A list of objects containing candidate's work information. **Format: [{\"company\": \"string\", \"title\": \"string\", \"work_start_date\": \"string\", \"work_end_date\": \"string\", \"is_current\": \"string\"}]**. [See the documentation](https://api.gem.com/v0/reference#tag/Candidates/paths/~1v0~1candidates/post) for further details.",
optional: true,
},
Comment on lines +83 to +88
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description says workInfo is a list of objects. Should the type be string[]?

Suggested change
workInfo: {
type: "string",
label: "Work Info",
description: "A list of objects containing candidate's work information. **Format: [{\"company\": \"string\", \"title\": \"string\", \"work_start_date\": \"string\", \"work_end_date\": \"string\", \"is_current\": \"string\"}]**. [See the documentation](https://api.gem.com/v0/reference#tag/Candidates/paths/~1v0~1candidates/post) for further details.",
optional: true,
},
workInfo: {
type: "string[]",
label: "Work Info",
description: "A list of objects containing candidate's work information. **Format: [{\"company\": \"string\", \"title\": \"string\", \"work_start_date\": \"string\", \"work_end_date\": \"string\", \"is_current\": \"string\"}]**. [See the documentation](https://api.gem.com/v0/reference#tag/Candidates/paths/~1v0~1candidates/post) for further details.",
optional: true,
},

profileUrls: {
type: "string[]",
label: "Profile URLs",
description: "If `Profile URLs` is provided with an array of urls, social `profiles` will be generated based on the provided urls and attached to the candidate",
optional: true,
},
phoneNumber: {
type: "string",
label: "Phone Number",
description: "Candidate's phone number",
optional: true,
},
projectIds: {
propDefinition: [
gem,
"projectIds",
],
optional: true,
},
customFields: {
type: "string[]",
label: "Custom Fields",
description: "Array of objects containing new custom field values. Only custom fields specified in the array are updated. **Format: [{\"custom_field_id\": \"string\", \"value\": \"string\"}]**. [See the documentation](https://api.gem.com/v0/reference#tag/Candidates/paths/~1v0~1candidates/post) for further details.",
optional: true,
},
sourcedFrom: {
type: "string",
label: "Sourced From",
description: "Where the candidate was sourced from",
options: SOURCED_FROM,
optional: true,
},
autofill: {
type: "boolean",
label: "Autofill",
description: "Requires `Linked In Handle` to be non-null. Attempts to fill in any missing fields.",
optional: true,
},
},
async run({ $ }) {
const emails = [
{
email_address: this.primaryEmail,
is_primary: true,
},
];
if (this.additionalEmails) emails.push(...this.additionalEmails.map((email) => ({
email_address: email,
is_primary: false,
})));

if (emails.length === 0) {
throw new Error("Primary Email Address is required");
}
const candidate = await this.gem.createCandidate({
$,
data: {
created_by: this.createdBy,
first_name: this.firstName,
last_name: this.lastName,
nickname: this.nickname,
emails,
linked_in_handle: this.linkedInHandle,
title: this.title,
company: this.company,
location: this.location,
school: this.school,
educational_info: this.educationalInfo,
work_info: this.workInfo,
profile_urls: this.profileUrls,
phone_number: this.phoneNumber,
project_ids: this.projectIds,
custom_fields: this.customFields,
Comment on lines +156 to +161
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should create a utils function to parse the JSON in eductionalInfo, workInfo, and customFields.

Suggested change
educational_info: this.educationalInfo,
work_info: this.workInfo,
profile_urls: this.profileUrls,
phone_number: this.phoneNumber,
project_ids: this.projectIds,
custom_fields: this.customFields,
educational_info: utils.parseJson(this.educationalInfo),
work_info: utils.parseJson(this.workInfo),
profile_urls: this.profileUrls,
phone_number: this.phoneNumber,
project_ids: this.projectIds,
custom_fields: utils.parseJson(this.customFields),

sourced_from: this.sourcedFrom,
autofill: this.autofill,
},
});
$.export(
"$summary", `Created candidate ${candidate.first_name} ${candidate.last_name} with ID: ${candidate.id}`,
);
return candidate;
},
};
9 changes: 9 additions & 0 deletions components/gem/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const LIMIT = 100;

export const SOURCED_FROM = [
"SeekOut",
"hireEZ",
"Starcircle",
"Censia",
"Consider",
];
119 changes: 114 additions & 5 deletions components/gem/gem.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,120 @@
import { axios } from "@pipedream/platform";
import { LIMIT } from "./common/constants.mjs";

export default {
type: "app",
app: "gem",
propDefinitions: {},
propDefinitions: {
createdBy: {
type: "string",
label: "Created By",
description: "Who the candidate was created by",
async options({ page }) {
const data = await this.listUsers({
params: {
page: page + 1,
page_size: LIMIT,
},
});

return data.map(({
id: value, email: label,
}) => ({
label,
value,
}));
},
},
projectIds: {
type: "string[]",
label: "Project Ids",
description: "If `Project Ids` is provided with an array of project ids, the candidate will be added into the projects once they are created.",
async options({ page }) {
const data = await this.listProjects({
params: {
page: page + 1,
page_size: LIMIT,
},
});

return data.map(({
id: value, name: label,
}) => ({
label,
value,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.gem.com/v0";
},
_headers() {
return {
"x-api-key": `${this.$auth.api_key}`,
"content-type": "application/json",
};
},
_makeRequest({
$ = this, path, ...opts
}) {
return axios($, {
url: this._baseUrl() + path,
headers: this._headers(),
...opts,
});
},
listCandidates(opts = {}) {
return this._makeRequest({
path: "/candidates",
...opts,
});
},
listProjects(opts = {}) {
return this._makeRequest({
path: "/projects",
...opts,
});
},
listUsers(opts = {}) {
return this._makeRequest({
path: "/users",
...opts,
});
},
createCandidate(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/candidates",
...opts,
});
},
async *paginate({
fn, params = {}, maxResults = null, ...opts
}) {
let hasMore = false;
let count = 0;
let page = 0;

do {
params.page = ++page;
params.page_size = LIMIT;
const data = await fn({
params,
...opts,
});
for (const d of data) {
yield d;

if (maxResults && ++count === maxResults) {
return count;
}
}

hasMore = data.length === LIMIT;

} while (hasMore);
},
},
};
};
7 changes: 5 additions & 2 deletions components/gem/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/gem",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Gem Components",
"main": "gem.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
}
69 changes: 69 additions & 0 deletions components/gem/sources/new-candidate/new-candidate.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import gem from "../../gem.app.mjs";
import sampleEmit from "./test-event.mjs";

export default {
key: "gem-new-candidate",
name: "New Candidate Added",
description: "Emit new event when a candidate is added in Gem. [See the documentation](https://api.gem.com/v0/reference#tag/Candidates/paths/~1v0~1candidates/get)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
gem,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
_getLastDate() {
return this.db.get("lastDate") || 1;
},
_setLastDate(lastDate) {
this.db.set("lastDate", lastDate);
},
async emitEvent(maxResults = false) {
const lastDate = this._getLastDate();

const response = this.gem.paginate({
fn: this.gem.listCandidates,
params: {
created_after: lastDate,
},
});

let responseArray = [];
for await (const item of response) {
responseArray.push(item);
}

if (responseArray.length) {
if (maxResults && (responseArray.length > maxResults)) {
responseArray.length = maxResults;
}
this._setLastDate(responseArray[0].created_at);
}

for (const item of responseArray.reverse()) {
this.$emit(item, {
id: item.id,
summary: `New Candidate with ID: ${item.id}`,
ts: item.created_at,
});
}
},
},
hooks: {
async deploy() {
await this.emitEvent(25);
},
},
async run() {
await this.emitEvent();
},
sampleEmit,
};
Loading
Loading