Skip to content

Commit ad37d81

Browse files
authored
New Components - geoapify (#15537)
* geoapify init * new components * pnpm-lock.yaml
1 parent c6707c7 commit ad37d81

File tree

7 files changed

+278
-8
lines changed

7 files changed

+278
-8
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import geoapify from "../../geoapify.app.mjs";
2+
3+
export default {
4+
key: "geoapify-get-ip-location",
5+
name: "Get IP Location",
6+
description: "Retrieves geographical coordinates for a given IP address. [See the documentation](https://apidocs.geoapify.com/docs/ip-geolocation/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
geoapify,
11+
ipAddress: {
12+
type: "string",
13+
label: "IP Address",
14+
description: "The IP address to lookup",
15+
optional: true,
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.geoapify.geolocateIP({
20+
$,
21+
params: {
22+
ipAddress: this.ipAddress,
23+
},
24+
});
25+
$.export("$summary", `Retrieved location for IP: ${response.ip}`);
26+
return response;
27+
},
28+
};
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import geoapify from "../../geoapify.app.mjs";
2+
3+
export default {
4+
key: "geoapify-get-route",
5+
name: "Get Route",
6+
description: "Calculates a route between two sets of latitude and longitude points. [See the documentation](https://apidocs.geoapify.com/docs/routing/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
geoapify,
11+
fromLatitude: {
12+
type: "string",
13+
label: "From Latitude",
14+
description: "The latitude of the starting point",
15+
},
16+
fromLongitude: {
17+
type: "string",
18+
label: "From Longitude",
19+
description: "The longitude of the starting point",
20+
},
21+
toLatitude: {
22+
type: "string",
23+
label: "To Latitude",
24+
description: "The latitude of the destination point",
25+
},
26+
toLongitude: {
27+
type: "string",
28+
label: "To Longitude",
29+
description: "The longitude of the destination point",
30+
},
31+
mode: {
32+
propDefinition: [
33+
geoapify,
34+
"mode",
35+
],
36+
},
37+
type: {
38+
propDefinition: [
39+
geoapify,
40+
"routeOptimizationType",
41+
],
42+
},
43+
units: {
44+
propDefinition: [
45+
geoapify,
46+
"units",
47+
],
48+
},
49+
format: {
50+
propDefinition: [
51+
geoapify,
52+
"format",
53+
],
54+
},
55+
},
56+
async run({ $ }) {
57+
const route = await this.geoapify.calculateRoute({
58+
$,
59+
params: {
60+
waypoints: `${this.fromLatitude},${this.fromLongitude}|${this.toLatitude},${this.toLongitude}`,
61+
mode: this.mode,
62+
type: this.type,
63+
units: this.units,
64+
format: this.format,
65+
},
66+
});
67+
$.export("$summary", "Route calculated successfully");
68+
return route;
69+
},
70+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import geoapify from "../../geoapify.app.mjs";
2+
3+
export default {
4+
key: "geoapify-search-address",
5+
name: "Search Address",
6+
description: "Retrieves geocoding information for a given address. [See the documentation](https://apidocs.geoapify.com/docs/geocoding/forward-geocoding/)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
geoapify,
11+
address: {
12+
type: "string",
13+
label: "Address",
14+
description: "The address to search. E.g. `44 Montgomery St., San Francisco, CA 94104`",
15+
},
16+
type: {
17+
propDefinition: [
18+
geoapify,
19+
"locationType",
20+
],
21+
},
22+
format: {
23+
propDefinition: [
24+
geoapify,
25+
"format",
26+
],
27+
},
28+
},
29+
async run({ $ }) {
30+
const response = await this.geoapify.geocodeAddress({
31+
$,
32+
params: {
33+
text: this.address,
34+
type: this.type,
35+
format: this.format,
36+
},
37+
});
38+
$.export("$summary", `Successfully retrieved geocoding information for address: ${this.address}`);
39+
return response;
40+
},
41+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const LOCATION_TYPES = [
2+
"country",
3+
"state",
4+
"city",
5+
"postcode",
6+
"street",
7+
"amenity",
8+
"locality",
9+
];
10+
11+
const FORMATS = [
12+
"json",
13+
"xml",
14+
"geojson",
15+
];
16+
17+
const TRANSPORTATION_MODES = [
18+
"drive",
19+
"light_truck",
20+
"medium_truck",
21+
"truck",
22+
"heavy_truck",
23+
"truck_dangerous_goods",
24+
"long_truck",
25+
"bus",
26+
"scooter",
27+
"motorcycle",
28+
"bicycle",
29+
"mountain_bike",
30+
"road_bike",
31+
"walk",
32+
"hike",
33+
"transit",
34+
"approximated_transit",
35+
];
36+
37+
const ROUTE_OPTIMIZATION_TYPES = [
38+
"balanced",
39+
"short",
40+
"less_maneuvers",
41+
];
42+
43+
const UNITS = [
44+
"metric",
45+
"imperial",
46+
];
47+
48+
export default {
49+
LOCATION_TYPES,
50+
FORMATS,
51+
TRANSPORTATION_MODES,
52+
ROUTE_OPTIMIZATION_TYPES,
53+
UNITS,
54+
};
Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,81 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "geoapify",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
locationType: {
9+
type: "string",
10+
label: "Type",
11+
description: "The location type. If set to `locality`, returns administrative areas including postcodes, districts, cities, counties, and states.",
12+
options: constants.LOCATION_TYPES,
13+
optional: true,
14+
},
15+
format: {
16+
type: "string",
17+
label: "Format",
18+
description: "The format of the response, default value is `geojson`",
19+
options: constants.FORMATS,
20+
optional: true,
21+
},
22+
mode: {
23+
type: "string",
24+
label: "Mode",
25+
description: "The mode of transportation",
26+
options: constants.TRANSPORTATION_MODES,
27+
},
28+
routeOptimizationType: {
29+
type: "string",
30+
label: "Type",
31+
description: "The route optimization type",
32+
options: constants.ROUTE_OPTIMIZATION_TYPES,
33+
optional: true,
34+
},
35+
units: {
36+
type: "string",
37+
label: "Units",
38+
description: "Distance units for the calculated route, the default value is `metric`",
39+
options: constants.UNITS,
40+
optional: true,
41+
},
42+
},
543
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
44+
_baseUrl() {
45+
return "https://api.geoapify.com/v1";
46+
},
47+
_makeRequest({
48+
$ = this,
49+
path,
50+
params,
51+
...otherOpts
52+
}) {
53+
return axios($, {
54+
...otherOpts,
55+
url: `${this._baseUrl()}${path}`,
56+
params: {
57+
...params,
58+
apiKey: this.$auth.api_key,
59+
},
60+
});
61+
},
62+
geocodeAddress(opts = {}) {
63+
return this._makeRequest({
64+
path: "/geocode/search",
65+
...opts,
66+
});
67+
},
68+
calculateRoute(opts = {}) {
69+
return this._makeRequest({
70+
path: "/routing",
71+
...opts,
72+
});
73+
},
74+
geolocateIP(opts = {}) {
75+
return this._makeRequest({
76+
path: "/ipinfo",
77+
...opts,
78+
});
979
},
1080
},
11-
};
81+
};

components/geoapify/package.json

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

pnpm-lock.yaml

Lines changed: 5 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)