Skip to content

Commit ffbdc51

Browse files
committed
wip
1 parent 7851ded commit ffbdc51

File tree

6 files changed

+170
-19
lines changed

6 files changed

+170
-19
lines changed

components/oxylabs/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import oxylabs from "../../oxylabs.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
4+
export default {
5+
key: "oxylabs-create-proxy-session",
6+
name: "Create Proxy Session",
7+
description: "Establish a proxy session using the Residential Proxy endpoint. [See the documentation](https://developers.oxylabs.io/proxies/residential-proxies/session-control#establishing-session)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
oxylabs,
12+
username: {
13+
type: "string",
14+
label: "Username",
15+
description: "The username for the proxy user",
16+
},
17+
password: {
18+
type: "string",
19+
label: "Password",
20+
description: "The password for the proxy user",
21+
},
22+
sessid: {
23+
type: "string",
24+
label: "Session ID",
25+
description: "Session ID to keep the same IP with upcoming queries. The session expires in 10 minutes. After that, a new IP address is assigned to that session ID. Random string, 0-9, and A-Z characters are supported.",
26+
},
27+
cc: {
28+
type: "string",
29+
label: "Country Code",
30+
description: "Case insensitive country code in 2-letter [3166-1 alpha-2 format](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)",
31+
optional: true,
32+
},
33+
city: {
34+
type: "string",
35+
label: "City",
36+
description: "Case insensitive city name in English. This parameter must be accompanied by cc for better accuracy.",
37+
optional: true,
38+
},
39+
st: {
40+
type: "string",
41+
label: "State",
42+
description: "Case insensitive US state name with us_ in the beginning, for example, `us_california`, `us_illinois`",
43+
optional: true,
44+
},
45+
sstime: {
46+
type: "string",
47+
label: "Session Time",
48+
description: "Session time in minutes. The session time parameter keeps the same IP for a certain period. The maximum session time is 30 minutes.",
49+
optional: true,
50+
},
51+
},
52+
async run({ $ }) {
53+
const {
54+
username,
55+
password,
56+
sessid,
57+
cc,
58+
city,
59+
st,
60+
sstime,
61+
} = this;
62+
63+
if (city && !cc) {
64+
throw new ConfigurationError("City must be accompanied by country code");
65+
}
66+
67+
const proxyUrl = `http://customer-${username}${cc
68+
? `-cc-${cc}`
69+
: ""}${city
70+
? `-city-${city}`
71+
: ""}${st
72+
? `-st-${st}`
73+
: ""}${sessid
74+
? `-sessid-${sessid}`
75+
: ""}${sstime
76+
? `-sstime-${sstime}`
77+
: ""}:${password}@pr.oxylabs.io:7777`;
78+
const response = await this.oxylabs.createSession({
79+
$,
80+
proxyUrl,
81+
});
82+
$.export("$summary", `Successfully created proxy session with session ID: ${this.sessid}`);
83+
return response;
84+
},
85+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import oxylabs from "../../oxylabs.app.mjs";
2+
3+
export default {
4+
key: "oxylabs-scrape-url",
5+
name: "Scrape URL",
6+
description: "Scrape a URL. [See the documentation](https://developers.oxylabs.io/scraping-solutions/web-scraper-api)",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
oxylabs,
11+
url: {
12+
type: "string",
13+
label: "URL",
14+
description: "The URL to scrape",
15+
},
16+
geoLocation: {
17+
type: "string",
18+
label: "Geo Location",
19+
description: "The geo locatio to scrape from. E.g. `United States`",
20+
optional: true,
21+
},
22+
},
23+
async run({ $ }) {
24+
const response = await this.oxylabs.scrapeUrl({
25+
$,
26+
data: {
27+
source: "universal",
28+
url: this.url,
29+
geo_location: this.geoLocation,
30+
},
31+
});
32+
$.export("$summary", `Successfully scraped URL: ${this.url}`);
33+
return response;
34+
},
35+
};

components/oxylabs/app/oxylabs.app.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

components/oxylabs/oxylabs.app.mjs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { axios } from "@pipedream/platform";
2+
import { HttpsProxyAgent } from "https-proxy-agent";
3+
4+
export default {
5+
type: "app",
6+
app: "oxylabs",
7+
propDefinitions: {},
8+
methods: {
9+
_getBaseUrl() {
10+
return `https://${this.$auth.api_name}.oxylabs.io/v1`;
11+
},
12+
_makeRequest({
13+
$ = this, path, ...opts
14+
}) {
15+
return axios($, {
16+
url: `${this._getBaseUrl()}${path}`,
17+
headers: {
18+
"Content-Type": "application/json",
19+
},
20+
auth: {
21+
username: `${this.$auth.username}`,
22+
password: `${this.$auth.password}`,
23+
},
24+
...opts,
25+
});
26+
},
27+
scrapeUrl(opts = {}) {
28+
return this._makeRequest({
29+
method: "POST",
30+
path: "/queries",
31+
...opts,
32+
});
33+
},
34+
async createSession({
35+
$ = this, proxyUrl, ...opts
36+
}) {
37+
const agent = new HttpsProxyAgent(proxyUrl);
38+
return axios($, {
39+
url: "https://ip.oxylabs.io/location",
40+
httpsAgent: agent,
41+
...opts,
42+
});
43+
},
44+
},
45+
};

components/oxylabs/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
22
"name": "@pipedream/oxylabs",
3-
"version": "0.0.2",
3+
"version": "0.1.0",
44
"description": "Pipedream Oxylabs Components",
5-
"main": "dist/app/oxylabs.app.mjs",
5+
"main": "oxylabs.app.mjs",
66
"keywords": [
77
"pipedream",
88
"oxylabs"
99
],
10-
"files": ["dist"],
1110
"homepage": "https://pipedream.com/apps/oxylabs",
1211
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1312
"publishConfig": {
1413
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1517
}
1618
}

0 commit comments

Comments
 (0)