Skip to content

Commit 3d6759a

Browse files
authored
New Components - firefish (#13948)
* new components * pnpm-lock.yaml
1 parent d5a3176 commit 3d6759a

File tree

9 files changed

+321
-59
lines changed

9 files changed

+321
-59
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import firefish from "../../firefish.app.mjs";
2+
3+
export default {
4+
key: "firefish-unsubscribe-email",
5+
name: "Unsubscribe Email",
6+
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)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
firefish,
11+
email: {
12+
type: "string",
13+
label: "Email",
14+
description: "The email address of the subscriber you want to remove",
15+
},
16+
},
17+
async run({ $ }) {
18+
const contacts = await this.firefish.searchContacts({
19+
$,
20+
params: {
21+
"email-address": this.email,
22+
},
23+
});
24+
for (const contact of contacts) {
25+
contact.EmailMarketing = false;
26+
await this.firefish.updateContact({
27+
$,
28+
contactId: contact.Ref,
29+
data: contact,
30+
});
31+
}
32+
33+
const candidates = await this.firefish.searchCandidates({
34+
$,
35+
params: {
36+
"email-address": this.email,
37+
},
38+
});
39+
for (const candidate of candidates) {
40+
candidate.EmailMarketing = false;
41+
await this.firefish.updateCandidate({
42+
$,
43+
candidateId: candidate.Ref,
44+
data: candidate,
45+
});
46+
}
47+
48+
$.export("$summary", `Successfully removed ${this.email} from email marketing`);
49+
return {
50+
contacts,
51+
candidates,
52+
};
53+
},
54+
};
Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,56 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "firefish",
46
propDefinitions: {},
57
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
8+
_baseUrl() {
9+
return "https://api.firefishsoftware.com/api/v1.0";
10+
},
11+
_makeRequest(opts = {}) {
12+
const {
13+
$ = this,
14+
path,
15+
...otherOpts
16+
} = opts;
17+
return axios($, {
18+
...otherOpts,
19+
url: `${this._baseUrl()}${path}`,
20+
headers: {
21+
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
22+
},
23+
});
24+
},
25+
searchContacts(opts = {}) {
26+
return this._makeRequest({
27+
path: "/contacts/search",
28+
...opts,
29+
});
30+
},
31+
searchCandidates(opts = {}) {
32+
return this._makeRequest({
33+
path: "/candidates/search",
34+
...opts,
35+
});
36+
},
37+
updateContact({
38+
contactId, ...opts
39+
}) {
40+
return this._makeRequest({
41+
method: "PUT",
42+
path: `/contacts/${contactId}`,
43+
...opts,
44+
});
45+
},
46+
updateCandidate({
47+
candidateId, ...opts
48+
}) {
49+
return this._makeRequest({
50+
method: "PUT",
51+
path: `/candidates/${candidateId}`,
52+
...opts,
53+
});
954
},
1055
},
11-
};
56+
};

components/firefish/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/firefish",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Firefish Components",
55
"main": "firefish.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.1"
1417
}
15-
}
18+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import firefish from "../../firefish.app.mjs";
2+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3+
4+
export default {
5+
props: {
6+
firefish,
7+
db: "$.service.db",
8+
timer: {
9+
type: "$.interface.timer",
10+
default: {
11+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
12+
},
13+
},
14+
},
15+
hooks: {
16+
async deploy() {
17+
await this.processEvent(25);
18+
},
19+
},
20+
methods: {
21+
_getLastCreated() {
22+
return this.db.get("lastCreated");
23+
},
24+
_setLastCreated(lastCreated) {
25+
this.db.set("lastCreated", lastCreated);
26+
},
27+
async processEvent(limit) {
28+
const lastCreated = this._getLastCreated();
29+
const resourceFn = this.getResourceFn();
30+
const results = await resourceFn({
31+
params: {
32+
"from-date": lastCreated && lastCreated.slice(0, 10),
33+
},
34+
});
35+
if (!results?.length) {
36+
return;
37+
}
38+
this._setLastCreated(results[0].Created);
39+
if (limit && results.length > limit) {
40+
results.length = limit;
41+
}
42+
results.reverse().forEach((result) => {
43+
const meta = this.generateMeta(result);
44+
this.$emit(result, meta);
45+
});
46+
},
47+
getResourceFn() {
48+
throw new Error("getResourceFn is not implemented");
49+
},
50+
generateMeta() {
51+
throw new Error("generateMeta is not implemented");
52+
},
53+
},
54+
async run() {
55+
await this.processEvent();
56+
},
57+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "firefish-new-candidate-created",
7+
name: "New Candidate Created",
8+
description: "Emit new event when a new candidate is created. [See the documentation](https://developer.firefishsoftware.com/#0dc51713-8397-4aaa-a85e-a66eb8f94d9d)",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getResourceFn() {
15+
return this.firefish.searchCandidates;
16+
},
17+
generateMeta(candidate) {
18+
return {
19+
id: candidate.Ref,
20+
summary: `New Candidate ID: ${candidate.Ref}`,
21+
ts: Date.parse(candidate.Created),
22+
};
23+
},
24+
},
25+
sampleEmit,
26+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export default {
2+
"Ref": 48889,
3+
"FirstName": "Gerardo",
4+
"Surname": "Smitho",
5+
"DateOfBirth": null,
6+
"JobTitle": null,
7+
"EmailAddress": "[email protected]",
8+
"Address": {
9+
"Address1": null,
10+
"Address2": null,
11+
"Address3": null,
12+
"Town": null,
13+
"County": null,
14+
"Country": null,
15+
"PostCode": null
16+
},
17+
"MobileNumber": "07595878736",
18+
"HomeNumber": null,
19+
"WorkNumber": null,
20+
"IsArchived": false,
21+
"CreatedBy": "Superuser Role",
22+
"Created": "2024-02-09T09:39:01.383Z",
23+
"UpdatedBy": "Gerardo Smitho",
24+
"Updated": "2024-02-09T09:43:13.773Z",
25+
"LastActionRef": 80198,
26+
"LastActionName": "Advert Application",
27+
"LastActionDate": "2024-02-09T09:51:56.007Z"
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "firefish-new-contact-created",
7+
name: "New Contact Created",
8+
description: "Emit new event when a new contact is created. [See the documentation](https://developer.firefishsoftware.com/#fcb38fee-8ad7-4aec-b1bd-ba7871e8258c)",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getResourceFn() {
15+
return this.firefish.searchContacts;
16+
},
17+
generateMeta(contact) {
18+
return {
19+
id: contact.Ref,
20+
summary: `New Contact ID: ${contact.Ref}`,
21+
ts: Date.parse(contact.Created),
22+
};
23+
},
24+
},
25+
sampleEmit,
26+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default {
2+
"Ref": 48749,
3+
"FirstName": "Kade",
4+
"Surname": "Tran",
5+
"Title": null,
6+
"CompanyRef": null,
7+
"CompanyName": null,
8+
"JobTitle": "EMS Helicopter Pilot",
9+
"EmailAddress": "[email protected]",
10+
"MobileNumber": null,
11+
"WorkNumber": null,
12+
"IsArchived": false,
13+
"CreatedBy": "System Administrator",
14+
"Created": "2020-03-24T08:53:00.830Z",
15+
"UpdatedBy": "System Administrator",
16+
"Updated": "2020-03-24T08:53:00.830Z",
17+
"LastActionRef": 78075,
18+
"LastActionName": "Create Contact - Manual",
19+
"LastActionDate": "2020-03-24T08:53:00.847Z"
20+
}

0 commit comments

Comments
 (0)