UNPKG

owm-onecall-api

Version:
145 lines (144 loc) 6.29 kB
import { OpenWeatherMapBase } from "./base"; import { RequestParams, TimeMachineDate, CurrentForecast, WeekForecast, DayForecast, HourForecast } from "../types"; /** * A `class` based wrapper for a [[OpenWeatherMapClient]] * * Example usage: * * ```typescript * const openWeatherMap = new OpenWeatherMap("api-token") * * const current = async () => { * const result = await openWeatherMap.current(42, -42, { units: Units.CA }) * // ... Handle result * } * ``` * * Example chaining usage: * * ```typescript * const request = new OpenWeatherMap("api-token").builder() * .units(Units.Metric) * .excludeHourly() * .excludeDaily() * .excludeMinutely() * * async function getCurrentForecast(lat: number, long: number): CurrentDataBlock { * const result = await request.execute() * if (!result.current) { * throw Error("Current can still be undefined if OpenWeatherMap doesn't return it") * } * return result.current * } * ``` */ export declare class OpenWeatherMap extends OpenWeatherMapBase { /** * Create a OpenWeatherMap request using method chaining. * * See [[buildOpenWeatherMapRequest]] for more info. * * @param lat The latitude of a location (in decimal degrees). * @param lon The longitude of a location (in decimal degrees). * @param params Optional query params for the request. */ builder(lat: number, lon: number, params?: RequestParams): import("./builder").OpenWeatherMapBuilder; /** * Gets the current forecast. * * See {@link https://openweathermap.org/api/one-call-api#how OpenWeatherMap Docs} for more info. * * @param lat The latitude of a location (in decimal degrees). * @param lon The longitude of a location (in decimal degrees). * @param params Optional query params for the request. * @returns Current forecast. */ forecast(lat: number, lon: number, params?: RequestParams): Promise<import("../types").Forecast>; /** * Gets the forecast for a specified date. * * **Note:** The historical API has some stipulations: * * > Please note that in order to get historical data for the last five days, you need to make five API calls (one call for each day). * * See {@link https://openweathermap.org/api/one-call-api#history OpenWeatherMap Docs} for more. * * @param lat The latitude of a location (in decimal degrees). * @param lon The longitude of a location (in decimal degrees). * @param time Specific time to get the weather for. * @param params Optional query params for the request. * @returns Forecast for the specified date. */ timeMachine(lat: number, lon: number, time: TimeMachineDate, params?: RequestParams): Promise<import("../types").Forecast>; /** * Gets the current weather conditions, excluding all other datablocks. * * Helper function for setting `exclude=minutely,daily,hourly` * * * Note: Will throw an error if OpenWeatherMap doesn't return a `current` data block for the request. * * See {@link https://openweathermap.org/api/one-call-api#how OpenWeatherMap Docs} for more. * * @param lat The latitude of a location (in decimal degrees). * @param lon The longitude of a location (in decimal degrees). * @param params Optional query params for the request. * @returns Current forecast conditions. * @throws HttpException if `CurrentForecast.current` doesn't exist. */ current(lat: number, lon: number, params?: RequestParams): Promise<CurrentForecast>; /** * Get the forecast for week, excluding all other datablocks. * * Helper function for setting `exclude=currently,minutely,hourly` * * * Note: Will throw an error if OpenWeatherMap doesn't return a `daily` data block for the request. * * See {@link https://openweathermap.org/api/one-call-api#how OpenWeatherMap Docs} for more. * * @param lat The latitude of a location (in decimal degrees). * @param lon The longitude of a location (in decimal degrees). * @param params Optional query params for the request. * @returns Forecast for the week. * @throws HttpException if [[WeekForecast.daily]] doesn't exist. */ week(lat: number, lon: number, params?: RequestParams): Promise<WeekForecast>; /** * Get the forecast for day, excluding all other datablocks. * * Helper function for setting `exclude=currently,daily,minutely` * * * Note: Will throw an error if OpenWeatherMap doesn't return a `hourly` data block for the request. * * See {@link https://openweathermap.org/api/one-call-api#how OpenWeatherMap Docs} for more. * * @param lat The latitude of a location (in decimal degrees). * @param lon The longitude of a location (in decimal degrees). * @param params Optional query params for the request. * @returns Forecast for the day. * @throws HttpException if [[DayForecast.hourly]] doesn't exist. */ day(lat: number, lon: number, params?: RequestParams): Promise<DayForecast>; /** * Get the forecast for hour, excluding all other datablocks. * * Helper function for setting `exclude=currently,daily,hourly` * * * Note: Will throw an error if OpenWeatherMap doesn't return a `Minutely` data block for the request. * * See {@link https://openweathermap.org/api/one-call-api#how OpenWeatherMap Docs} for more. * * @param lat The latitude of a location (in decimal degrees). * @param lon The longitude of a location (in decimal degrees). * @param params Optional query params for the request. * @returns Forecast for the hour. * @throws HttpException if [[HourForecast.Minutely]] doesn't exist. */ hour(lat: number, lon: number, params?: RequestParams): Promise<HourForecast>; /** * Merge the class [[RequestParams]] with the optional [[params]]. * * @param params Optional [[RequestParams]] to merge. * @returns Merged [[RequestParams]] object. */ private mergeParams; }