Skip to content

Commit 1c39758

Browse files
authored
[Components] predictleads (#17228)
1 parent dd4d761 commit 1c39758

File tree

16 files changed

+876
-11
lines changed

16 files changed

+876
-11
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import app from "../../predictleads.app.mjs";
2+
3+
export default {
4+
key: "predictleads-get-technologies",
5+
name: "Get Technologies",
6+
description: "Retrieve a list of technologies that PredictLeads tracks. [See the documentation](https://docs.predictleads.com/v3/api_endpoints/technologies_dataset/retrieve_all_tracked_technologies)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
},
12+
async run({ $ }) {
13+
const response = await this.app.retrieveTechnologies({
14+
$,
15+
params: {
16+
limit: 1000,
17+
},
18+
});
19+
$.export("$summary", "Successfully retrieved the first page of technologies.");
20+
return response;
21+
},
22+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import app from "../../predictleads.app.mjs";
2+
3+
export default {
4+
key: "predictleads-lookup-company",
5+
name: "Lookup Company By Domain",
6+
description: "Lookup a company by their domain. [See the documentation](https://docs.predictleads.com/v3/api_endpoints/companies_dataset/retrieve_company)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
domain: {
12+
propDefinition: [
13+
app,
14+
"domain",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const {
20+
app,
21+
domain,
22+
} = this;
23+
24+
const response = await app.retrieveCompany({
25+
$,
26+
domain,
27+
});
28+
29+
if (response.data.length > 0) {
30+
$.export("$summary", `Successfully found company for domain \`${domain}\`.`);
31+
} else {
32+
$.export("$summary", `No company found for domain \`${domain}\`.`);
33+
}
34+
return response;
35+
},
36+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import app from "../../predictleads.app.mjs";
2+
3+
export default {
4+
key: "predictleads-retrieve-companies-by-technology",
5+
name: "Retrieve Companies By Technology",
6+
description: "Retrieve companies that use a specific technology. [See the documentation](https://docs.predictleads.com/v3/api_endpoints/technologies_dataset/retrieve_a_single_technology_by_id)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
technologyId: {
12+
propDefinition: [
13+
app,
14+
"technologyId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const {
20+
app,
21+
technologyId,
22+
} = this;
23+
const response = await app.retrieveCompaniesByTechnology({
24+
$,
25+
technologyId,
26+
});
27+
$.export("$summary", "Successfully retrieved the first page of companies.");
28+
return response;
29+
},
30+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import app from "../../predictleads.app.mjs";
2+
3+
export default {
4+
key: "predictleads-retrieve-news-events-by-domain",
5+
name: "Retrieve News Events By Domain",
6+
description: "Retrieve news events for a company by domain. [See the documentation](https://docs.predictleads.com/v3/api_endpoints/news_events_dataset/retrieve_company_s_news_events)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
domain: {
12+
description: "The domain of the company to retrieve news events for (e.g., `google.com`).",
13+
propDefinition: [
14+
app,
15+
"domain",
16+
],
17+
},
18+
},
19+
async run({ $ }) {
20+
const {
21+
app,
22+
domain,
23+
} = this;
24+
const response = await app.retrieveNewsEvents({
25+
$,
26+
domain,
27+
});
28+
$.export("$summary", "Successfully retrieved the first page of news events.");
29+
return response;
30+
},
31+
};

components/predictleads/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/predictleads",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream PredictLeads Components",
55
"main": "predictleads.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.1.0"
1417
}
15-
}
18+
}
Lines changed: 151 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,158 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "predictleads",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
domain: {
8+
type: "string",
9+
label: "Domain",
10+
description: "The domain of the company to lookup (e.g., `google.com`).",
11+
},
12+
technologyId: {
13+
type: "string",
14+
label: "Technology",
15+
description: "Select a technology to search for.",
16+
async options({ page }) {
17+
const { data: technologies } = await this.retrieveTechnologies({
18+
params: {
19+
page,
20+
limit: 100,
21+
},
22+
});
23+
return technologies.map(({
24+
id: value,
25+
name: label,
26+
}) => ({
27+
label,
28+
value,
29+
}));
30+
},
31+
},
32+
},
533
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
34+
getUrl(path) {
35+
return `https://predictleads.com/api/v3${path}`;
36+
},
37+
getHeaders(headers) {
38+
return {
39+
"X-Api-Key": this.$auth.api_key,
40+
"X-Api-Token": this.$auth.api_token,
41+
...headers,
42+
};
43+
},
44+
_makeRequest({
45+
$ = this, path, headers, ...args
46+
}) {
47+
return axios($, {
48+
url: this.getUrl(path),
49+
headers: this.getHeaders(headers),
50+
...args,
51+
});
52+
},
53+
retrieveCompany({
54+
domain, ...args
55+
} = {}) {
56+
return this._makeRequest({
57+
path: `/companies/${domain}`,
58+
...args,
59+
});
60+
},
61+
retrieveTechnologies(args = {}) {
62+
return this._makeRequest({
63+
path: "/technologies",
64+
...args,
65+
});
66+
},
67+
retrieveCompaniesByTechnology({
68+
technologyId, ...args
69+
} = {}) {
70+
return this._makeRequest({
71+
path: `/discover/technologies/${technologyId}/technology_detections`,
72+
...args,
73+
});
74+
},
75+
retrieveJobOpenings({
76+
domain, ...args
77+
} = {}) {
78+
return this._makeRequest({
79+
path: `/companies/${domain}/job_openings`,
80+
...args,
81+
});
82+
},
83+
retrieveNewsEvents({
84+
domain, ...args
85+
} = {}) {
86+
return this._makeRequest({
87+
path: `/companies/${domain}/news_events`,
88+
...args,
89+
});
90+
},
91+
retrieveTechnologyDetections({
92+
domain, ...args
93+
} = {}) {
94+
return this._makeRequest({
95+
path: `/companies/${domain}/technology_detections`,
96+
...args,
97+
});
98+
},
99+
retrieveFinancingEvents({
100+
domain, ...args
101+
} = {}) {
102+
return this._makeRequest({
103+
path: `/companies/${domain}/financing_events`,
104+
...args,
105+
});
106+
},
107+
async *getIterations({
108+
resourceFn,
109+
resourceFnArgs,
110+
max = 300,
111+
}) {
112+
let page = 1;
113+
let resourcesCount = 0;
114+
const limit = 100;
115+
116+
while (true) {
117+
const response = await resourceFn({
118+
...resourceFnArgs,
119+
params: {
120+
...resourceFnArgs?.params,
121+
page,
122+
limit,
123+
},
124+
});
125+
126+
const resources = response.data;
127+
128+
if (!resources?.length) {
129+
console.log("No resources found");
130+
return;
131+
}
132+
133+
for (const resource of resources) {
134+
yield resource;
135+
resourcesCount += 1;
136+
if (resourcesCount >= max) {
137+
console.log("Max resources reached");
138+
return;
139+
}
140+
}
141+
142+
if (page * limit > response.meta.count) {
143+
console.log("Page limit reached");
144+
return;
145+
}
146+
147+
page += 1;
148+
}
149+
},
150+
async paginate(args) {
151+
const resources = [];
152+
for await (const resource of this.getIterations(args)) {
153+
resources.push(resource);
154+
}
155+
return resources;
9156
},
10157
},
11158
};

0 commit comments

Comments
 (0)