Skip to content

Commit 6647be1

Browse files
committed
geoapify init
1 parent 85d818c commit 6647be1

File tree

5 files changed

+286
-4
lines changed

5 files changed

+286
-4
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import geoapify from "../../geoapify.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "geoapify-get-ip-location",
6+
name: "Get IP Location",
7+
description: "Retrieves geographical coordinates for a given IP address. [See the documentation](https://apidocs.geoapify.com/docs/ip-geolocation/)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
geoapify,
12+
ipAddress: {
13+
propDefinition: [
14+
geoapify,
15+
"ipAddress",
16+
],
17+
},
18+
},
19+
async run({ $ }) {
20+
const response = await this.geoapify.geolocateIP({
21+
ipAddress: this.ipAddress,
22+
});
23+
$.export("$summary", `Retrieved location for IP: ${this.ipAddress}`);
24+
return response;
25+
},
26+
};
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import geoapify from "../../geoapify.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "geoapify-get-route",
6+
name: "Get Route",
7+
description: "Calculates a route between two sets of latitude and longitude points. [See the documentation](https://apidocs.geoapify.com/docs/routing/)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
geoapify,
12+
fromLatitude: {
13+
propDefinition: [
14+
geoapify,
15+
"fromLatitude",
16+
],
17+
},
18+
fromLongitude: {
19+
propDefinition: [
20+
geoapify,
21+
"fromLongitude",
22+
],
23+
},
24+
toLatitude: {
25+
propDefinition: [
26+
geoapify,
27+
"toLatitude",
28+
],
29+
},
30+
toLongitude: {
31+
propDefinition: [
32+
geoapify,
33+
"toLongitude",
34+
],
35+
},
36+
mode: {
37+
propDefinition: [
38+
geoapify,
39+
"mode",
40+
],
41+
optional: true,
42+
},
43+
type: {
44+
propDefinition: [
45+
geoapify,
46+
"type",
47+
],
48+
optional: true,
49+
},
50+
units: {
51+
propDefinition: [
52+
geoapify,
53+
"units",
54+
],
55+
optional: true,
56+
},
57+
format: {
58+
propDefinition: [
59+
geoapify,
60+
"format",
61+
],
62+
optional: true,
63+
},
64+
},
65+
async run({ $ }) {
66+
const route = await this.geoapify.calculateRoute({
67+
fromLatitude: this.fromLatitude,
68+
fromLongitude: this.fromLongitude,
69+
toLatitude: this.toLatitude,
70+
toLongitude: this.toLongitude,
71+
mode: this.mode,
72+
type: this.type,
73+
units: this.units,
74+
format: this.format,
75+
});
76+
77+
$.export("$summary", "Route calculated successfully");
78+
return route;
79+
},
80+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import geoapify from "../../geoapify.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "geoapify-search-address",
6+
name: "Search Address",
7+
description: "Retrieves geocoding information for a given address. [See the documentation](https://apidocs.geoapify.com/docs/geocoding/forward-geocoding/)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
geoapify,
12+
address: {
13+
propDefinition: [
14+
"geoapify",
15+
"address",
16+
],
17+
},
18+
type: {
19+
propDefinition: [
20+
"geoapify",
21+
"type",
22+
],
23+
},
24+
format: {
25+
propDefinition: [
26+
"geoapify",
27+
"format",
28+
],
29+
},
30+
},
31+
async run({ $ }) {
32+
const response = await this.geoapify.geocodeAddress({
33+
address: this.address,
34+
type: this.type,
35+
format: this.format,
36+
});
37+
$.export("$summary", `Successfully retrieved geocoding information for address ${this.address}`);
38+
return response;
39+
},
40+
};
Lines changed: 139 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,147 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "geoapify",
4-
propDefinitions: {},
6+
version: "0.0.{{ts}}",
7+
propDefinitions: {
8+
// Geocoding Props
9+
address: {
10+
type: "string",
11+
label: "Address",
12+
description: "The address to retrieve geocoding information for.",
13+
},
14+
type: {
15+
type: "string",
16+
label: "Type",
17+
description: "The type of geocoding request.",
18+
optional: true,
19+
},
20+
format: {
21+
type: "string",
22+
label: "Format",
23+
description: "The format of the response.",
24+
optional: true,
25+
},
26+
// Routing Props
27+
fromLatitude: {
28+
type: "string",
29+
label: "From Latitude",
30+
description: "The latitude of the starting point.",
31+
},
32+
fromLongitude: {
33+
type: "string",
34+
label: "From Longitude",
35+
description: "The longitude of the starting point.",
36+
},
37+
toLatitude: {
38+
type: "string",
39+
label: "To Latitude",
40+
description: "The latitude of the destination point.",
41+
},
42+
toLongitude: {
43+
type: "string",
44+
label: "To Longitude",
45+
description: "The longitude of the destination point.",
46+
},
47+
mode: {
48+
type: "string",
49+
label: "Mode",
50+
description: "The mode of transportation.",
51+
optional: true,
52+
},
53+
units: {
54+
type: "string",
55+
label: "Units",
56+
description: "The units of measurement.",
57+
optional: true,
58+
},
59+
// IP Geolocation Props
60+
ipAddress: {
61+
type: "string",
62+
label: "IP Address",
63+
description: "The IP address to retrieve geographical coordinates for.",
64+
},
65+
},
566
methods: {
6-
// this.$auth contains connected account data
67+
// Existing method
768
authKeys() {
869
console.log(Object.keys(this.$auth));
970
},
71+
// Base URL for the API
72+
_baseUrl() {
73+
return "https://api.geoapify.com";
74+
},
75+
// Method to make API requests
76+
async _makeRequest(opts = {}) {
77+
const {
78+
$ = this,
79+
method = "GET",
80+
path = "/",
81+
params = {},
82+
headers = {},
83+
...otherOpts
84+
} = opts;
85+
const allParams = {
86+
...params,
87+
apiKey: this.$auth.apiKey,
88+
};
89+
return axios($, {
90+
...otherOpts,
91+
method,
92+
url: this._baseUrl() + path,
93+
params: allParams,
94+
headers: {
95+
...headers,
96+
},
97+
});
98+
},
99+
// Geocoding Method
100+
async geocodeAddress({
101+
address, type, format,
102+
}) {
103+
const params = {
104+
text: address,
105+
};
106+
if (type) params.type = type;
107+
if (format) params.format = format;
108+
return this._makeRequest({
109+
path: "/v1/geocode/search",
110+
params,
111+
});
112+
},
113+
// Routing Method
114+
async calculateRoute({
115+
fromLatitude,
116+
fromLongitude,
117+
toLatitude,
118+
toLongitude,
119+
mode,
120+
type,
121+
units,
122+
format,
123+
}) {
124+
const waypoints = `${fromLongitude},${fromLatitude}|${toLongitude},${toLatitude}`;
125+
const params = {
126+
waypoints,
127+
};
128+
if (mode) params.mode = mode;
129+
if (type) params.type = type;
130+
if (units) params.units = units;
131+
if (format) params.format = format;
132+
return this._makeRequest({
133+
path: "/v1/routing",
134+
params,
135+
});
136+
},
137+
// IP Geolocation Method
138+
async geolocateIP({ ipAddress }) {
139+
return this._makeRequest({
140+
path: "/v1/ipinfo",
141+
params: {
142+
ip: ipAddress,
143+
},
144+
});
145+
},
10146
},
11-
};
147+
};

components/geoapify/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+
}

0 commit comments

Comments
 (0)