Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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");

return response;
},
};
Comment on lines +3 to +49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add error handling in the run method.

The run method correctly constructs the API call. However, error handling should be added to manage potential API call failures.

async run({ $ }) {
  try {
    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;
  } catch (error) {
    $.export("$summary", `Failed to retrieve weather data: ${error.message}`);
    throw error;
  }
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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");
return response;
},
};
async run({ $ }) {
try {
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;
} catch (error) {
$.export("$summary", `Failed to retrieve weather data: ${error.message}`);
throw error;
}
}

26 changes: 26 additions & 0 deletions components/meteomatics_weather_api/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -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",
],
};
57 changes: 53 additions & 4 deletions components/meteomatics_weather_api/meteomatics_weather_api.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,60 @@
import { axios } from "@pipedream/platform";
import constants from "./common/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}`,
},
});
},
Comment on lines +35 to +50
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure correct API request handling and error management.

The _makeRequest method correctly constructs and sends the API request using Axios. However, consider adding error handling to manage potential request failures.

async _makeRequest(opts = {}) {
  const {
    $ = this,
    path,
    params,
    ...otherOpts
  } = opts;
  try {
    return await axios($, {
      ...otherOpts,
      url: this._baseUrl() + path,
      params: {
        ...params,
        access_token: `${this.$auth.oauth_access_token}`,
      },
    });
  } catch (error) {
    $.export("$summary", `API request failed: ${error.message}`);
    throw error;
  }
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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 _makeRequest(opts = {}) {
const {
$ = this,
path,
params,
...otherOpts
} = opts;
try {
return await axios($, {
...otherOpts,
url: this._baseUrl() + path,
params: {
...params,
access_token: `${this.$auth.oauth_access_token}`,
},
});
} catch (error) {
$.export("$summary", `API request failed: ${error.message}`);
throw error;
}
},

async getWeatherData({
validdatetime, parameters, locations, format, ...args
}) {
return this._makeRequest({
path: `/${validdatetime}/${parameters}/${locations}/${format}`,
...args,
});
Comment on lines +51 to +57
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure correct weather data retrieval and error handling.

The getWeatherData method correctly constructs the request path and calls _makeRequest. However, consider adding error handling to manage potential request failures.

async getWeatherData({
  validdatetime, parameters, locations, format, ...args
}) {
  try {
    return await this._makeRequest({
      path: `/${validdatetime}/${parameters}/${locations}/${format}`,
      ...args,
    });
  } catch (error) {
    throw new Error(`Failed to retrieve weather data: ${error.message}`);
  }
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async getWeatherData({
validdatetime, parameters, locations, format, ...args
}) {
return this._makeRequest({
path: `/${validdatetime}/${parameters}/${locations}/${format}`,
...args,
});
async getWeatherData({
validdatetime, parameters, locations, format, ...args
}) {
try {
return await this._makeRequest({
path: `/${validdatetime}/${parameters}/${locations}/${format}`,
...args,
});
} catch (error) {
throw new Error(`Failed to retrieve weather data: ${error.message}`);
}
}

},
},
};
7 changes: 5 additions & 2 deletions components/meteomatics_weather_api/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.0"
}
}
}
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.