Skip to content

Commit 10f75cf

Browse files
committed
Parsera: added new action components
1 parent 1261174 commit 10f75cf

File tree

5 files changed

+172
-8
lines changed

5 files changed

+172
-8
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import app from "../../parsera.app.mjs";
2+
3+
export default {
4+
key: "parsera-extract",
5+
name: "Extract",
6+
description: "Extract data from a given URL. [See the documentation](https://docs.parsera.org/api/getting-started/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
url: {
12+
type: "string",
13+
label: "URL",
14+
description: "The URL to extract information from.",
15+
},
16+
attributes: {
17+
propDefinition: [
18+
app,
19+
"attributes",
20+
],
21+
},
22+
proxyCountry: {
23+
propDefinition: [
24+
app,
25+
"proxyCountry",
26+
],
27+
},
28+
},
29+
methods: {
30+
extract(args = {}) {
31+
return this.app.post({
32+
path: "/extract",
33+
...args,
34+
});
35+
},
36+
},
37+
async run({ $ }) {
38+
const {
39+
extract,
40+
url,
41+
attributes,
42+
proxyCountry,
43+
} = this;
44+
45+
const response = await extract({
46+
$,
47+
data: {
48+
url,
49+
attributes: Array.isArray(attributes) && attributes.map(JSON.parse),
50+
proxy_country: proxyCountry,
51+
},
52+
});
53+
$.export("$summary", "Successfully extracted data from url.");
54+
return response;
55+
},
56+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import app from "../../parsera.app.mjs";
2+
3+
export default {
4+
key: "parsera-parse",
5+
name: "Parse",
6+
description: "Parse data using pre-defined attributes. [See the documentation](https://docs.parsera.org/api/getting-started/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
content: {
12+
type: "string",
13+
label: "Content",
14+
description: "The content to parse. HTML or text content. Eg. `<h1>Hello World</h1>`.",
15+
},
16+
attributes: {
17+
propDefinition: [
18+
app,
19+
"attributes",
20+
],
21+
},
22+
},
23+
methods: {
24+
parse(args = {}) {
25+
return this.app.post({
26+
path: "/parse",
27+
...args,
28+
});
29+
},
30+
},
31+
async run({ $ }) {
32+
const {
33+
parse,
34+
content,
35+
attributes,
36+
} = this;
37+
38+
const response = await parse({
39+
$,
40+
data: {
41+
content,
42+
attributes: Array.isArray(attributes) && attributes.map(JSON.parse),
43+
},
44+
});
45+
46+
$.export("$summary", "Successfully parsed content.");
47+
48+
return response;
49+
},
50+
};

components/parsera/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/parsera",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Parsera Components",
55
"main": "parsera.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.3"
1417
}
15-
}
18+
}

components/parsera/parsera.app.mjs

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,63 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "parsera",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
proxyCountry: {
8+
type: "string",
9+
label: "Proxy Country",
10+
description: "Set a specific proxy country for the request.",
11+
optional: true,
12+
async options() {
13+
const response = await this.listProxyCountries();
14+
return Object.entries(response)
15+
.map(([
16+
value,
17+
label,
18+
]) => ({
19+
label,
20+
value,
21+
}));
22+
},
23+
},
24+
attributes: {
25+
type: "string[]",
26+
label: "Attributes",
27+
description: "List of attributes to extract or parse from the content. Format each attribute as a JSON string. Eg. `{\"name\": \"Title\",\"description\": \"News title\"}`.",
28+
},
29+
},
530
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
31+
getUrl(path) {
32+
return `https://api.parsera.org/v1${path}`;
33+
},
34+
getHeaders(headers) {
35+
return {
36+
"Content-Type": "application/json",
37+
...headers,
38+
"X-API-KEY": this.$auth.api_key,
39+
};
40+
},
41+
_makeRequest({
42+
$ = this, path, headers, ...args
43+
} = {}) {
44+
return axios($, {
45+
...args,
46+
url: this.getUrl(path),
47+
headers: this.getHeaders(headers),
48+
});
49+
},
50+
post(args = {}) {
51+
return this._makeRequest({
52+
method: "POST",
53+
...args,
54+
});
55+
},
56+
listProxyCountries(args = {}) {
57+
return this._makeRequest({
58+
path: "/proxy-countries",
59+
...args,
60+
});
961
},
1062
},
11-
};
63+
};

pnpm-lock.yaml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)