diff --git a/components/geoapify/actions/get-ip-location/get-ip-location.mjs b/components/geoapify/actions/get-ip-location/get-ip-location.mjs new file mode 100644 index 0000000000000..3632a88e13948 --- /dev/null +++ b/components/geoapify/actions/get-ip-location/get-ip-location.mjs @@ -0,0 +1,28 @@ +import geoapify from "../../geoapify.app.mjs"; + +export default { + key: "geoapify-get-ip-location", + name: "Get IP Location", + description: "Retrieves geographical coordinates for a given IP address. [See the documentation](https://apidocs.geoapify.com/docs/ip-geolocation/)", + version: "0.0.1", + type: "action", + props: { + geoapify, + ipAddress: { + type: "string", + label: "IP Address", + description: "The IP address to lookup", + optional: true, + }, + }, + async run({ $ }) { + const response = await this.geoapify.geolocateIP({ + $, + params: { + ipAddress: this.ipAddress, + }, + }); + $.export("$summary", `Retrieved location for IP: ${response.ip}`); + return response; + }, +}; diff --git a/components/geoapify/actions/get-route/get-route.mjs b/components/geoapify/actions/get-route/get-route.mjs new file mode 100644 index 0000000000000..d6e06c6c9482b --- /dev/null +++ b/components/geoapify/actions/get-route/get-route.mjs @@ -0,0 +1,70 @@ +import geoapify from "../../geoapify.app.mjs"; + +export default { + key: "geoapify-get-route", + name: "Get Route", + description: "Calculates a route between two sets of latitude and longitude points. [See the documentation](https://apidocs.geoapify.com/docs/routing/)", + version: "0.0.1", + type: "action", + props: { + geoapify, + fromLatitude: { + type: "string", + label: "From Latitude", + description: "The latitude of the starting point", + }, + fromLongitude: { + type: "string", + label: "From Longitude", + description: "The longitude of the starting point", + }, + toLatitude: { + type: "string", + label: "To Latitude", + description: "The latitude of the destination point", + }, + toLongitude: { + type: "string", + label: "To Longitude", + description: "The longitude of the destination point", + }, + mode: { + propDefinition: [ + geoapify, + "mode", + ], + }, + type: { + propDefinition: [ + geoapify, + "routeOptimizationType", + ], + }, + units: { + propDefinition: [ + geoapify, + "units", + ], + }, + format: { + propDefinition: [ + geoapify, + "format", + ], + }, + }, + async run({ $ }) { + const route = await this.geoapify.calculateRoute({ + $, + params: { + waypoints: `${this.fromLatitude},${this.fromLongitude}|${this.toLatitude},${this.toLongitude}`, + mode: this.mode, + type: this.type, + units: this.units, + format: this.format, + }, + }); + $.export("$summary", "Route calculated successfully"); + return route; + }, +}; diff --git a/components/geoapify/actions/search-address/search-address.mjs b/components/geoapify/actions/search-address/search-address.mjs new file mode 100644 index 0000000000000..602868683baa6 --- /dev/null +++ b/components/geoapify/actions/search-address/search-address.mjs @@ -0,0 +1,41 @@ +import geoapify from "../../geoapify.app.mjs"; + +export default { + key: "geoapify-search-address", + name: "Search Address", + description: "Retrieves geocoding information for a given address. [See the documentation](https://apidocs.geoapify.com/docs/geocoding/forward-geocoding/)", + version: "0.0.1", + type: "action", + props: { + geoapify, + address: { + type: "string", + label: "Address", + description: "The address to search. E.g. `44 Montgomery St., San Francisco, CA 94104`", + }, + type: { + propDefinition: [ + geoapify, + "locationType", + ], + }, + format: { + propDefinition: [ + geoapify, + "format", + ], + }, + }, + async run({ $ }) { + const response = await this.geoapify.geocodeAddress({ + $, + params: { + text: this.address, + type: this.type, + format: this.format, + }, + }); + $.export("$summary", `Successfully retrieved geocoding information for address: ${this.address}`); + return response; + }, +}; diff --git a/components/geoapify/common/constants.mjs b/components/geoapify/common/constants.mjs new file mode 100644 index 0000000000000..7a955ff5b0055 --- /dev/null +++ b/components/geoapify/common/constants.mjs @@ -0,0 +1,54 @@ +const LOCATION_TYPES = [ + "country", + "state", + "city", + "postcode", + "street", + "amenity", + "locality", +]; + +const FORMATS = [ + "json", + "xml", + "geojson", +]; + +const TRANSPORTATION_MODES = [ + "drive", + "light_truck", + "medium_truck", + "truck", + "heavy_truck", + "truck_dangerous_goods", + "long_truck", + "bus", + "scooter", + "motorcycle", + "bicycle", + "mountain_bike", + "road_bike", + "walk", + "hike", + "transit", + "approximated_transit", +]; + +const ROUTE_OPTIMIZATION_TYPES = [ + "balanced", + "short", + "less_maneuvers", +]; + +const UNITS = [ + "metric", + "imperial", +]; + +export default { + LOCATION_TYPES, + FORMATS, + TRANSPORTATION_MODES, + ROUTE_OPTIMIZATION_TYPES, + UNITS, +}; diff --git a/components/geoapify/geoapify.app.mjs b/components/geoapify/geoapify.app.mjs index f5878f9c247c5..460541e6ffd88 100644 --- a/components/geoapify/geoapify.app.mjs +++ b/components/geoapify/geoapify.app.mjs @@ -1,11 +1,81 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + export default { type: "app", app: "geoapify", - propDefinitions: {}, + propDefinitions: { + locationType: { + type: "string", + label: "Type", + description: "The location type. If set to `locality`, returns administrative areas including postcodes, districts, cities, counties, and states.", + options: constants.LOCATION_TYPES, + optional: true, + }, + format: { + type: "string", + label: "Format", + description: "The format of the response, default value is `geojson`", + options: constants.FORMATS, + optional: true, + }, + mode: { + type: "string", + label: "Mode", + description: "The mode of transportation", + options: constants.TRANSPORTATION_MODES, + }, + routeOptimizationType: { + type: "string", + label: "Type", + description: "The route optimization type", + options: constants.ROUTE_OPTIMIZATION_TYPES, + optional: true, + }, + units: { + type: "string", + label: "Units", + description: "Distance units for the calculated route, the default value is `metric`", + options: constants.UNITS, + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.geoapify.com/v1"; + }, + _makeRequest({ + $ = this, + path, + params, + ...otherOpts + }) { + return axios($, { + ...otherOpts, + url: `${this._baseUrl()}${path}`, + params: { + ...params, + apiKey: this.$auth.api_key, + }, + }); + }, + geocodeAddress(opts = {}) { + return this._makeRequest({ + path: "/geocode/search", + ...opts, + }); + }, + calculateRoute(opts = {}) { + return this._makeRequest({ + path: "/routing", + ...opts, + }); + }, + geolocateIP(opts = {}) { + return this._makeRequest({ + path: "/ipinfo", + ...opts, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/geoapify/package.json b/components/geoapify/package.json index cadcacf92506c..bade1a758a129 100644 --- a/components/geoapify/package.json +++ b/components/geoapify/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/geoapify", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Geoapify Components", "main": "geoapify.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0e68b82abb07d..1d4b7f0fab98e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3258,8 +3258,7 @@ importers: specifier: ^0.12.7 version: 0.12.7 - components/elastic_cloud: - specifiers: {} + components/elastic_cloud: {} components/elastic_email: {} @@ -4058,7 +4057,11 @@ importers: specifier: ^4.0.0 version: 4.0.1 - components/geoapify: {} + components/geoapify: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/geodb_cities: dependencies: @@ -4209,8 +4212,7 @@ importers: components/glide: {} - components/globalping: - specifiers: {} + components/globalping: {} components/gloria_ai: dependencies: @@ -6339,8 +6341,7 @@ importers: specifier: ^3.0.0 version: 3.0.3 - components/mailtrap: - specifiers: {} + components/mailtrap: {} components/mailwizz: dependencies: @@ -9902,8 +9903,7 @@ importers: components/simplybook_me: {} - components/sinch_messagemedia: - specifiers: {} + components/sinch_messagemedia: {} components/sitecreator_io: dependencies: