Skip to content

Commit

Permalink
New Components - firefish (#13948)
Browse files Browse the repository at this point in the history
* new components

* pnpm-lock.yaml
  • Loading branch information
michelle0927 committed Sep 16, 2024
1 parent d5a3176 commit 3d6759a
Show file tree
Hide file tree
Showing 9 changed files with 321 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import firefish from "../../firefish.app.mjs";

export default {
key: "firefish-unsubscribe-email",
name: "Unsubscribe Email",
description: "Removes a particular contact or candidate from all existing firefish email subscriptions. [See the documentatio](https://developer.firefishsoftware.com/#002bb8c0-0b41-4016-b33c-026a46b499b2)",
version: "0.0.1",
type: "action",
props: {
firefish,
email: {
type: "string",
label: "Email",
description: "The email address of the subscriber you want to remove",
},
},
async run({ $ }) {
const contacts = await this.firefish.searchContacts({
$,
params: {
"email-address": this.email,
},
});
for (const contact of contacts) {
contact.EmailMarketing = false;
await this.firefish.updateContact({
$,
contactId: contact.Ref,
data: contact,
});
}

const candidates = await this.firefish.searchCandidates({
$,
params: {
"email-address": this.email,
},
});
for (const candidate of candidates) {
candidate.EmailMarketing = false;
await this.firefish.updateCandidate({
$,
candidateId: candidate.Ref,
data: candidate,
});
}

$.export("$summary", `Successfully removed ${this.email} from email marketing`);
return {
contacts,
candidates,
};
},
};
53 changes: 49 additions & 4 deletions components/firefish/firefish.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,56 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "firefish",
propDefinitions: {},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.firefishsoftware.com/api/v1.0";
},
_makeRequest(opts = {}) {
const {
$ = this,
path,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: `${this._baseUrl()}${path}`,
headers: {
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
},
});
},
searchContacts(opts = {}) {
return this._makeRequest({
path: "/contacts/search",
...opts,
});
},
searchCandidates(opts = {}) {
return this._makeRequest({
path: "/candidates/search",
...opts,
});
},
updateContact({
contactId, ...opts
}) {
return this._makeRequest({
method: "PUT",
path: `/contacts/${contactId}`,
...opts,
});
},
updateCandidate({
candidateId, ...opts
}) {
return this._makeRequest({
method: "PUT",
path: `/candidates/${candidateId}`,
...opts,
});
},
},
};
};
7 changes: 5 additions & 2 deletions components/firefish/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/firefish",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Firefish Components",
"main": "firefish.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.1"
}
}
}
57 changes: 57 additions & 0 deletions components/firefish/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import firefish from "../../firefish.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";

export default {
props: {
firefish,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
hooks: {
async deploy() {
await this.processEvent(25);
},
},
methods: {
_getLastCreated() {
return this.db.get("lastCreated");
},
_setLastCreated(lastCreated) {
this.db.set("lastCreated", lastCreated);
},
async processEvent(limit) {
const lastCreated = this._getLastCreated();
const resourceFn = this.getResourceFn();
const results = await resourceFn({
params: {
"from-date": lastCreated && lastCreated.slice(0, 10),
},
});
if (!results?.length) {
return;
}
this._setLastCreated(results[0].Created);
if (limit && results.length > limit) {
results.length = limit;
}
results.reverse().forEach((result) => {
const meta = this.generateMeta(result);
this.$emit(result, meta);
});
},
getResourceFn() {
throw new Error("getResourceFn is not implemented");
},
generateMeta() {
throw new Error("generateMeta is not implemented");
},
},
async run() {
await this.processEvent();
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "firefish-new-candidate-created",
name: "New Candidate Created",
description: "Emit new event when a new candidate is created. [See the documentation](https://developer.firefishsoftware.com/#0dc51713-8397-4aaa-a85e-a66eb8f94d9d)",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getResourceFn() {
return this.firefish.searchCandidates;
},
generateMeta(candidate) {
return {
id: candidate.Ref,
summary: `New Candidate ID: ${candidate.Ref}`,
ts: Date.parse(candidate.Created),
};
},
},
sampleEmit,
};
28 changes: 28 additions & 0 deletions components/firefish/sources/new-candidate-created/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export default {
"Ref": 48889,
"FirstName": "Gerardo",
"Surname": "Smitho",
"DateOfBirth": null,
"JobTitle": null,
"EmailAddress": "[email protected]",
"Address": {
"Address1": null,
"Address2": null,
"Address3": null,
"Town": null,
"County": null,
"Country": null,
"PostCode": null
},
"MobileNumber": "07595878736",
"HomeNumber": null,
"WorkNumber": null,
"IsArchived": false,
"CreatedBy": "Superuser Role",
"Created": "2024-02-09T09:39:01.383Z",
"UpdatedBy": "Gerardo Smitho",
"Updated": "2024-02-09T09:43:13.773Z",
"LastActionRef": 80198,
"LastActionName": "Advert Application",
"LastActionDate": "2024-02-09T09:51:56.007Z"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "firefish-new-contact-created",
name: "New Contact Created",
description: "Emit new event when a new contact is created. [See the documentation](https://developer.firefishsoftware.com/#fcb38fee-8ad7-4aec-b1bd-ba7871e8258c)",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getResourceFn() {
return this.firefish.searchContacts;
},
generateMeta(contact) {
return {
id: contact.Ref,
summary: `New Contact ID: ${contact.Ref}`,
ts: Date.parse(contact.Created),
};
},
},
sampleEmit,
};
20 changes: 20 additions & 0 deletions components/firefish/sources/new-contact-created/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default {
"Ref": 48749,
"FirstName": "Kade",
"Surname": "Tran",
"Title": null,
"CompanyRef": null,
"CompanyName": null,
"JobTitle": "EMS Helicopter Pilot",
"EmailAddress": "[email protected]",
"MobileNumber": null,
"WorkNumber": null,
"IsArchived": false,
"CreatedBy": "System Administrator",
"Created": "2020-03-24T08:53:00.830Z",
"UpdatedBy": "System Administrator",
"Updated": "2020-03-24T08:53:00.830Z",
"LastActionRef": 78075,
"LastActionName": "Create Contact - Manual",
"LastActionDate": "2020-03-24T08:53:00.847Z"
}
Loading

0 comments on commit 3d6759a

Please sign in to comment.