Skip to content

Commit 22d987d

Browse files
committed
nioleads init
1 parent bde7b75 commit 22d987d

File tree

6 files changed

+310
-6
lines changed

6 files changed

+310
-6
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import nioleads from "../../nioleads.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "nioleads-find-email",
6+
name: "Find Email",
7+
description: "Finds a business email address using a full name and a website domain.",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
nioleads,
12+
fullName: {
13+
propDefinition: [
14+
nioleads,
15+
"fullName",
16+
],
17+
},
18+
websiteDomain: {
19+
propDefinition: [
20+
nioleads,
21+
"websiteDomain",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.nioleads.findEmail(this.fullName, this.websiteDomain);
27+
$.export("$summary", `Found email: ${response.email}`);
28+
return response;
29+
},
30+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import nioleads from "../../nioleads.app.mjs";
2+
3+
export default {
4+
key: "nioleads-verify-email",
5+
name: "Verify Email",
6+
description: "Checks the deliverability of a specified email address. [See the documentation](https://apidoc.nioleads.com)",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
nioleads,
11+
email: {
12+
propDefinition: [
13+
nioleads,
14+
"email",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.nioleads.verifyEmail(this.email);
20+
$.export("$summary", `Verified email ${this.email}`);
21+
return response;
22+
},
23+
};
Lines changed: 99 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,105 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "nioleads",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
email: {
8+
type: "string",
9+
label: "Email",
10+
description: "The email address of the contact",
11+
},
12+
firstName: {
13+
type: "string",
14+
label: "First Name",
15+
description: "The first name of the contact",
16+
optional: true,
17+
},
18+
lastName: {
19+
type: "string",
20+
label: "Last Name",
21+
description: "The last name of the contact",
22+
optional: true,
23+
},
24+
fullName: {
25+
type: "string",
26+
label: "Full Name",
27+
description: "The full name of the person",
28+
},
29+
websiteDomain: {
30+
type: "string",
31+
label: "Website Domain",
32+
description: "The domain of the website",
33+
},
34+
},
535
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
36+
_baseUrl() {
37+
return "https://api.nioleads.com/v1/openapi";
38+
},
39+
async _makeRequest(opts = {}) {
40+
const {
41+
$ = this,
42+
method = "GET",
43+
path,
44+
data,
45+
headers,
46+
...otherOpts
47+
} = opts;
48+
return axios($, {
49+
...otherOpts,
50+
method,
51+
url: this._baseUrl() + path,
52+
data,
53+
headers: {
54+
...headers,
55+
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
56+
"Content-Type": "application/json",
57+
"Accept": "application/json",
58+
},
59+
});
60+
},
61+
async verifyEmail(email) {
62+
return this._makeRequest({
63+
method: "POST",
64+
path: "/verify_email",
65+
data: {
66+
email,
67+
},
68+
});
69+
},
70+
async findEmail(fullName, websiteDomain) {
71+
return this._makeRequest({
72+
method: "POST",
73+
path: "/find_email",
74+
data: {
75+
name: fullName,
76+
domain: websiteDomain,
77+
},
78+
});
79+
},
80+
async emitNewContactData(email, firstName, lastName) {
81+
return this.$emit(
82+
{
83+
email,
84+
firstName,
85+
lastName,
86+
},
87+
{
88+
summary: `New contact data found for ${email}`,
89+
},
90+
);
91+
},
92+
async emitNewWatchedContact(email, firstName, lastName) {
93+
return this.$emit(
94+
{
95+
email,
96+
firstName,
97+
lastName,
98+
},
99+
{
100+
summary: `New contact is watched for ${email}`,
101+
},
102+
);
9103
},
10104
},
11-
};
105+
};

components/nioleads/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import nioleads from "../../nioleads.app.mjs";
2+
3+
export default {
4+
type: "source",
5+
key: "nioleads-new-contact-watch",
6+
name: "New Contact Watch",
7+
description: "Emit new event when a new contact is watched.",
8+
version: "0.0.1",
9+
dedupe: "unique",
10+
props: {
11+
nioleads,
12+
db: "$.service.db",
13+
timer: {
14+
type: "$.interface.timer",
15+
default: {
16+
intervalSeconds: 60 * 15, // 15 minutes
17+
},
18+
},
19+
email: {
20+
propDefinition: [
21+
nioleads,
22+
"email",
23+
],
24+
},
25+
firstName: {
26+
propDefinition: [
27+
nioleads,
28+
"firstName",
29+
],
30+
optional: true,
31+
},
32+
lastName: {
33+
propDefinition: [
34+
nioleads,
35+
"lastName",
36+
],
37+
optional: true,
38+
},
39+
},
40+
hooks: {
41+
async deploy() {
42+
const email = this.email;
43+
const firstName = this.firstName;
44+
const lastName = this.lastName;
45+
await this.nioleads.emitNewWatchedContact(email, firstName, lastName);
46+
},
47+
},
48+
async run() {
49+
const lastRunTime = this.db.get("lastRunTime") || this.timer.timestamp;
50+
const currentTime = +new Date();
51+
const email = await this.nioleads.verifyEmail(this.email);
52+
if (email && email.verified) {
53+
const contactData = {
54+
email: this.email,
55+
firstName: this.firstName,
56+
lastName: this.lastName,
57+
};
58+
this.$emit(contactData, {
59+
id: this.email,
60+
summary: `New contact is watched for ${this.email}`,
61+
ts: currentTime,
62+
});
63+
}
64+
this.db.set("lastRunTime", currentTime);
65+
},
66+
};
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import nioleads from "../../nioleads.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "nioleads-new-contact",
6+
name: "New Contact",
7+
description: "Emits a new event when a new contact data is found.",
8+
version: "0.0.{{ts}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
nioleads,
13+
db: "$.service.db",
14+
timer: {
15+
type: "$.interface.timer",
16+
default: {
17+
intervalSeconds: 60 * 15, // 15 minutes
18+
},
19+
},
20+
email: {
21+
propDefinition: [
22+
nioleads,
23+
"email",
24+
],
25+
},
26+
firstName: {
27+
propDefinition: [
28+
nioleads,
29+
"firstName",
30+
],
31+
optional: true,
32+
},
33+
lastName: {
34+
propDefinition: [
35+
nioleads,
36+
"lastName",
37+
],
38+
optional: true,
39+
},
40+
},
41+
methods: {
42+
_getPreviousEmail() {
43+
return this.db.get("previousEmail") || null;
44+
},
45+
_setPreviousEmail(email) {
46+
this.db.set("previousEmail", email);
47+
},
48+
},
49+
hooks: {
50+
async deploy() {
51+
// Emit the current email as an event on deploy
52+
const email = this._getPreviousEmail();
53+
if (email) {
54+
const {
55+
firstName, lastName,
56+
} = await this.nioleads.verifyEmail(email);
57+
this.$emit(
58+
{
59+
email,
60+
firstName,
61+
lastName,
62+
},
63+
{
64+
summary: `Found contact data for ${email}`,
65+
},
66+
);
67+
}
68+
},
69+
},
70+
async run() {
71+
const email = this.email;
72+
const previousEmail = this._getPreviousEmail();
73+
74+
if (email !== previousEmail) {
75+
const {
76+
firstName, lastName,
77+
} = await this.nioleads.verifyEmail(email);
78+
this.$emit(
79+
{
80+
email,
81+
firstName,
82+
lastName,
83+
},
84+
{
85+
summary: `New contact data found for ${email}`,
86+
},
87+
);
88+
this._setPreviousEmail(email);
89+
}
90+
},
91+
};

0 commit comments

Comments
 (0)