From 316f4fb2c7450883ac895a6e97994fcfbab09d3f Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Thu, 25 Jul 2024 10:56:41 -0300 Subject: [PATCH 1/3] Added actions --- .../get-weather-data/get-weather-data.mjs | 49 ++++++++++++++++ .../comoon/constants.mjs | 26 +++++++++ .../meteomatics_weather_api.app.mjs | 57 +++++++++++++++++-- .../meteomatics_weather_api/package.json | 7 ++- pnpm-lock.yaml | 5 +- 5 files changed, 137 insertions(+), 7 deletions(-) create mode 100644 components/meteomatics_weather_api/actions/get-weather-data/get-weather-data.mjs create mode 100644 components/meteomatics_weather_api/comoon/constants.mjs diff --git a/components/meteomatics_weather_api/actions/get-weather-data/get-weather-data.mjs b/components/meteomatics_weather_api/actions/get-weather-data/get-weather-data.mjs new file mode 100644 index 0000000000000..e7449265dbeec --- /dev/null +++ b/components/meteomatics_weather_api/actions/get-weather-data/get-weather-data.mjs @@ -0,0 +1,49 @@ +import app from "../../meteomatics_weather_api.app.mjs"; + +export default { + key: "meteomatics_weather_api-get-weather-data", + name: "Get Weather Data", + description: "Retrieve historic, current, and forecast data globally. [See the documentation](https://www.meteomatics.com/en/api/getting-started/)", + version: "0.0.1", + type: "action", + props: { + app, + validDateTime: { + propDefinition: [ + app, + "validDateTime", + ], + }, + parameters: { + propDefinition: [ + app, + "parameters", + ], + }, + locations: { + propDefinition: [ + app, + "locations", + ], + }, + format: { + propDefinition: [ + app, + "format", + ], + }, + }, + async run({ $ }) { + const response = await this.app.getWeatherData({ + $, + validdatetime: this.validDateTime.join("--"), + parameters: this.parameters.join(","), + locations: this.locations, + format: this.format, + }); + + $.export("$summary", `Successfully retrieved weather data for ${response.data.length} parameters`); + + return response; + }, +}; diff --git a/components/meteomatics_weather_api/comoon/constants.mjs b/components/meteomatics_weather_api/comoon/constants.mjs new file mode 100644 index 0000000000000..2623969109343 --- /dev/null +++ b/components/meteomatics_weather_api/comoon/constants.mjs @@ -0,0 +1,26 @@ +export default { + PARAMETERS: [ + { + label: "Instantaneous wind speed at 10m above ground", + value: "wind_speed_10m:ms", + }, + { + label: "Instantaneous temperature at 2m above ground in degrees Celsius", + value: "t_2m:C", + }, + { + label: "Precipitation accumulated over the past 24 hours in millimeter (equivalent to litres per square meter)", + value: "precip_24h:mm", + }, + { + label: "UV index", + value: "uv:idx", + }, + ], + FORMATS: [ + "csv", + "xml", + "json", + "png", + ], +}; diff --git a/components/meteomatics_weather_api/meteomatics_weather_api.app.mjs b/components/meteomatics_weather_api/meteomatics_weather_api.app.mjs index 0a2855b0f54ca..19d0b9cea8e04 100644 --- a/components/meteomatics_weather_api/meteomatics_weather_api.app.mjs +++ b/components/meteomatics_weather_api/meteomatics_weather_api.app.mjs @@ -1,11 +1,60 @@ +import { axios } from "@pipedream/platform"; +import constants from "./comoon/constants.mjs"; + export default { type: "app", app: "meteomatics_weather_api", - propDefinitions: {}, + propDefinitions: { + validDateTime: { + type: "string[]", + label: "Valid Date Time", + description: "A date or date range to retrieve the weather forecast for, i.e. `2017-05-28T13:00:00Z`", + }, + parameters: { + type: "string[]", + label: "Parameters", + description: "One or more parameters to be included in this request", + options: constants.PARAMETERS, + }, + locations: { + type: "string", + label: "Location", + description: "Geo-coordinates (latitude and longitude) in WGS-84 decimal format, i.e. `47.419708,9.358478`", + }, + format: { + type: "string", + label: "Format", + description: "The data format of the output", + options: constants.FORMATS, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.meteomatics.com"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + params, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + params: { + ...params, + access_token: `${this.$auth.oauth_access_token}`, + }, + }); + }, + async getWeatherData({ + validdatetime, parameters, locations, format, ...args + }) { + return this._makeRequest({ + path: `/${validdatetime}/${parameters}/${locations}/${format}`, + ...args, + }); }, }, }; diff --git a/components/meteomatics_weather_api/package.json b/components/meteomatics_weather_api/package.json index 2ef841e999aca..3ce7c6dcf1f67 100644 --- a/components/meteomatics_weather_api/package.json +++ b/components/meteomatics_weather_api/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/meteomatics_weather_api", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Meteomatics Weather API Components", "main": "meteomatics_weather_api.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.0" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1b5bf939bafcc..72943b2708520 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5560,7 +5560,10 @@ importers: '@pipedream/platform': 1.5.1 components/meteomatics_weather_api: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.0 + dependencies: + '@pipedream/platform': 3.0.0 components/mezmo: specifiers: {} From 405d2427b06178c40d81c628c83873d8235e150d Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Thu, 25 Jul 2024 11:17:14 -0300 Subject: [PATCH 2/3] Fixed requested changes --- .../meteomatics_weather_api/{comoon => common}/constants.mjs | 0 .../meteomatics_weather_api/meteomatics_weather_api.app.mjs | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename components/meteomatics_weather_api/{comoon => common}/constants.mjs (100%) diff --git a/components/meteomatics_weather_api/comoon/constants.mjs b/components/meteomatics_weather_api/common/constants.mjs similarity index 100% rename from components/meteomatics_weather_api/comoon/constants.mjs rename to components/meteomatics_weather_api/common/constants.mjs diff --git a/components/meteomatics_weather_api/meteomatics_weather_api.app.mjs b/components/meteomatics_weather_api/meteomatics_weather_api.app.mjs index 19d0b9cea8e04..93cd43e318198 100644 --- a/components/meteomatics_weather_api/meteomatics_weather_api.app.mjs +++ b/components/meteomatics_weather_api/meteomatics_weather_api.app.mjs @@ -1,5 +1,5 @@ import { axios } from "@pipedream/platform"; -import constants from "./comoon/constants.mjs"; +import constants from "./common/constants.mjs"; export default { type: "app", From 1244439c511d9857d40fc9fa1bee990f8dbc813f Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Tue, 30 Jul 2024 10:53:02 -0300 Subject: [PATCH 3/3] Fixed requested changes --- .../actions/get-weather-data/get-weather-data.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/meteomatics_weather_api/actions/get-weather-data/get-weather-data.mjs b/components/meteomatics_weather_api/actions/get-weather-data/get-weather-data.mjs index e7449265dbeec..abebe4e14db13 100644 --- a/components/meteomatics_weather_api/actions/get-weather-data/get-weather-data.mjs +++ b/components/meteomatics_weather_api/actions/get-weather-data/get-weather-data.mjs @@ -42,7 +42,7 @@ export default { format: this.format, }); - $.export("$summary", `Successfully retrieved weather data for ${response.data.length} parameters`); + $.export("$summary", "Successfully retrieved weather data"); return response; },