diff --git a/components/accuweather/accuweather.app.mjs b/components/accuweather/accuweather.app.mjs index 2813eb56011da..013e2bcd75795 100644 --- a/components/accuweather/accuweather.app.mjs +++ b/components/accuweather/accuweather.app.mjs @@ -1,11 +1,73 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "accuweather", - propDefinitions: {}, + propDefinitions: { + locationKey: { + type: "string", + label: "Location Key", + description: "The location key for the desired location. You can get this using the 'Get Location Key' action.", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "http://dataservice.accuweather.com"; + }, + _params(params = {}) { + return { + apikey: `${this.$auth.api_key}`, + ...params, + }; + }, + _makeRequest({ + $ = this, params, path, ...opts + }) { + return axios($, { + url: this._baseUrl() + path, + params: this._params(params), + ...opts, + }); + }, + searchLocation(opts = {}) { + return this._makeRequest({ + path: "/locations/v1/search", + ...opts, + }); + }, + getCurrentConditions({ + locationKey, ...opts + }) { + return this._makeRequest({ + path: `/currentconditions/v1/${locationKey}`, + ...opts, + }); + }, + getDailyForecast({ + days, locationKey, ...opts + }) { + return this._makeRequest({ + path: `/forecasts/v1/daily/${days}day/${locationKey}`, + ...opts, + }); + }, + getHourlyForecast({ + hours, locationKey, ...opts + }) { + return this._makeRequest({ + path: `/forecasts/v1/hourly/${hours}hour/${locationKey}`, + ...opts, + }); + }, + getHistoricalWeather({ + locationKey, time, ...opts + }) { + return this._makeRequest({ + path: `/currentconditions/v1/${locationKey}/historical${time === 24 + ? "/24" + : ""}`, + ...opts, + }); }, }, }; diff --git a/components/accuweather/actions/get-current-conditions/get-current-conditions.mjs b/components/accuweather/actions/get-current-conditions/get-current-conditions.mjs new file mode 100644 index 0000000000000..55365d061f627 --- /dev/null +++ b/components/accuweather/actions/get-current-conditions/get-current-conditions.mjs @@ -0,0 +1,26 @@ +import accuweather from "../../accuweather.app.mjs"; + +export default { + key: "accuweather-get-current-conditions", + name: "Get Current Conditions", + description: "Retrieve current weather conditions for a specific location using its location key. [See the documentation](https://developer.accuweather.com/accuweather-current-conditions-api/apis/get/currentconditions/v1/%7BlocationKey%7D)", + version: "0.0.1", + type: "action", + props: { + accuweather, + locationKey: { + propDefinition: [ + accuweather, + "locationKey", + ], + }, + }, + async run({ $ }) { + const response = await this.accuweather.getCurrentConditions({ + $, + locationKey: this.locationKey, + }); + $.export("$summary", `Retrieved current conditions for location key: ${this.locationKey}`); + return response; + }, +}; diff --git a/components/accuweather/actions/get-daily-forecast/get-daily-forecast.mjs b/components/accuweather/actions/get-daily-forecast/get-daily-forecast.mjs new file mode 100644 index 0000000000000..c20d38f00bdb1 --- /dev/null +++ b/components/accuweather/actions/get-daily-forecast/get-daily-forecast.mjs @@ -0,0 +1,41 @@ +import accuweather from "../../accuweather.app.mjs"; +import { FORECAST_DAYS_OPTIONS } from "../../common/constants.mjs"; + +export default { + key: "accuweather-get-daily-forecast", + name: "Get Daily Forecast", + description: "Get daily weather forecast for a specific location with temperature, precipitation, and conditions. [See the documentation](https://developer.accuweather.com/accuweather-forecast-api/apis)", + version: "0.0.1", + type: "action", + props: { + accuweather, + locationKey: { + propDefinition: [ + accuweather, + "locationKey", + ], + }, + forecastDays: { + type: "integer", + label: "Forecast Days", + description: "Number of days to forecast", + options: FORECAST_DAYS_OPTIONS, + }, + }, + async run({ $ }) { + const response = await this.accuweather.getDailyForecast({ + $, + locationKey: this.locationKey, + days: this.forecastDays, + params: { + details: true, + }, + }); + + $.export("$summary", `Retrieved forecast for ${this.forecastDays} day${this.forecastDays === 1 + ? "" + : "s"}`); + + return response; + }, +}; diff --git a/components/accuweather/actions/get-historical-weather/get-historical-weather.mjs b/components/accuweather/actions/get-historical-weather/get-historical-weather.mjs new file mode 100644 index 0000000000000..93662f6a9df98 --- /dev/null +++ b/components/accuweather/actions/get-historical-weather/get-historical-weather.mjs @@ -0,0 +1,35 @@ +import accuweather from "../../accuweather.app.mjs"; +import { HISTORICAL_TIME_OPTIONS } from "../../common/constants.mjs"; + +export default { + key: "accuweather-get-historical-weather", + name: "Get Historical Weather", + description: "Retrieve historical weather data for a specific location and date range. [See the documentation](https://developer.accuweather.com/accuweather-current-conditions-api/apis)", + version: "0.0.1", + type: "action", + props: { + accuweather, + locationKey: { + propDefinition: [ + accuweather, + "locationKey", + ], + }, + historicalTime: { + type: "integer", + label: "Historical Time", + description: "Historical time for weather data", + options: HISTORICAL_TIME_OPTIONS, + }, + }, + async run({ $ }) { + const response = await this.accuweather.getHistoricalWeather({ + $, + locationKey: this.locationKey, + time: this.historicalTime, + }); + + $.export("$summary", `Retrieved historical weather data for ${this.historicalTime} hours`); + return response; + }, +}; diff --git a/components/accuweather/actions/get-hourly-forecast/get-hourly-forecast.mjs b/components/accuweather/actions/get-hourly-forecast/get-hourly-forecast.mjs new file mode 100644 index 0000000000000..e4717c8d63210 --- /dev/null +++ b/components/accuweather/actions/get-hourly-forecast/get-hourly-forecast.mjs @@ -0,0 +1,41 @@ +import accuweather from "../../accuweather.app.mjs"; +import { FORECAST_HOURS_OPTIONS } from "../../common/constants.mjs"; + +export default { + key: "accuweather-get-hourly-forecast", + name: "Get Hourly Forecast", + description: "Retrieve hourly weather forecast (1-12 hours) for a specific location with detailed weather data. [See the documentation](https://developer.accuweather.com/accuweather-forecast-api/apis)", + version: "0.0.1", + type: "action", + props: { + accuweather, + locationKey: { + propDefinition: [ + accuweather, + "locationKey", + ], + }, + forecastHours: { + type: "integer", + label: "Forecast Hours", + description: "Number of hours to forecast", + options: FORECAST_HOURS_OPTIONS, + }, + }, + async run({ $ }) { + const response = await this.accuweather.getHourlyForecast({ + $, + locationKey: this.locationKey, + hours: this.forecastHours, + params: { + details: true, + }, + }); + + $.export("$summary", `Retrieved forecast for ${this.forecastHours} hour${this.forecastHours === 1 + ? "" + : "s"}`); + + return response; + }, +}; diff --git a/components/accuweather/actions/get-location-key/get-location-key.mjs b/components/accuweather/actions/get-location-key/get-location-key.mjs new file mode 100644 index 0000000000000..26b421199b1da --- /dev/null +++ b/components/accuweather/actions/get-location-key/get-location-key.mjs @@ -0,0 +1,36 @@ +import accuweather from "../../accuweather.app.mjs"; + +export default { + key: "accuweather-get-location-key", + name: "Get Location Key", + description: "Search for a location and retrieve its unique location key required for weather API calls. [See the documentation](https://developer.accuweather.com/accuweather-locations-api/apis/get/locations/v1/search)", + version: "0.0.1", + type: "action", + props: { + accuweather, + locationQuery: { + type: "string", + label: "Location Query", + description: "Search query for location (e.g., 'New York', 'London', 'Tokyo').", + }, + }, + async run({ $ }) { + const response = await this.accuweather.searchLocation({ + $, + params: { + q: this.locationQuery, + }, + }); + + let summary = `Successfully found ${response.length} location${response.length === 1 + ? "" + : "s"}`; + + if (response.length === 0) { + summary = `No location found for query: ${this.locationQuery}`; + } + + $.export("$summary", summary); + return response; + }, +}; diff --git a/components/accuweather/common/constants.mjs b/components/accuweather/common/constants.mjs new file mode 100644 index 0000000000000..f4f6f18e53042 --- /dev/null +++ b/components/accuweather/common/constants.mjs @@ -0,0 +1,32 @@ +export const FORECAST_DAYS_OPTIONS = [ + { + label: "1 Day", + value: 1, + }, + { + label: "5 Days", + value: 5, + }, +]; + +export const FORECAST_HOURS_OPTIONS = [ + { + label: "1 Hour", + value: 1, + }, + { + label: "12 Hours", + value: 12, + }, +]; + +export const HISTORICAL_TIME_OPTIONS = [ + { + label: "6 Hours", + value: 6, + }, + { + label: "24 Hours", + value: 24, + }, +]; diff --git a/components/accuweather/package.json b/components/accuweather/package.json index 677d8d7107c15..09790892b614d 100644 --- a/components/accuweather/package.json +++ b/components/accuweather/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/accuweather", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream AccuWeather Components", "main": "accuweather.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b19dba778b794..7eb0651705252 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -242,7 +242,11 @@ importers: specifier: ^3.0.0 version: 3.0.3 - components/accuweather: {} + components/accuweather: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/acelle_mail: {} @@ -11493,8 +11497,7 @@ importers: components/rewardful: {} - components/rewiser: - specifiers: {} + components/rewiser: {} components/rex: dependencies: @@ -37258,6 +37261,8 @@ snapshots: '@putout/operator-filesystem': 5.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3)) '@putout/operator-json': 2.2.0 putout: 36.13.1(eslint@8.57.1)(typescript@5.6.3) + transitivePeerDependencies: + - supports-color '@putout/operator-regexp@1.0.0(putout@36.13.1(eslint@8.57.1)(typescript@5.6.3))': dependencies: