Class OpenWeatherMap

A class based wrapper for a OpenWeatherMapClient

Example usage:

const openWeatherMap = new OpenWeatherMap("api-token")

const current = async () => {
const result = await openWeatherMap.current(42, -42, { units: Units.CA })
// ... Handle result
}

Example chaining usage:

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
}

Hierarchy

  • OpenWeatherMapBase
    • OpenWeatherMap

Constructors

Properties

Client for interacting with the API.

requestParams: RequestParams

Optional request paramaters.

token: string

OpenWeatherMap developer API token.

Methods

  • Create a OpenWeatherMap request using method chaining.

    See buildOpenWeatherMapRequest for more info.

    Parameters

    • lat: number

      The latitude of a location (in decimal degrees).

    • lon: number

      The longitude of a location (in decimal degrees).

    • Optional params: RequestParams

      Optional query params for the request.

    Returns OpenWeatherMapBuilder

  • 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 OpenWeatherMap Docs for more.

    Returns

    Current forecast conditions.

    Throws

    HttpException if CurrentForecast.current doesn't exist.

    Parameters

    • lat: number

      The latitude of a location (in decimal degrees).

    • lon: number

      The longitude of a location (in decimal degrees).

    • Optional params: RequestParams

      Optional query params for the request.

    Returns Promise<CurrentForecast>

  • 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 OpenWeatherMap Docs for more.

    Returns

    Forecast for the day.

    Throws

    HttpException if DayForecast.hourly doesn't exist.

    Parameters

    • lat: number

      The latitude of a location (in decimal degrees).

    • lon: number

      The longitude of a location (in decimal degrees).

    • Optional params: RequestParams

      Optional query params for the request.

    Returns 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 OpenWeatherMap Docs for more.

    Returns

    Forecast for the hour.

    Throws

    HttpException if HourForecast.Minutely doesn't exist.

    Parameters

    • lat: number

      The latitude of a location (in decimal degrees).

    • lon: number

      The longitude of a location (in decimal degrees).

    • Optional params: RequestParams

      Optional query params for the request.

    Returns Promise<HourForecast>

  • 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 OpenWeatherMap Docs for more.

    Returns

    Forecast for the specified date.

    Parameters

    • lat: number

      The latitude of a location (in decimal degrees).

    • lon: number

      The longitude of a location (in decimal degrees).

    • time: TimeMachineDate

      Specific time to get the weather for.

    • Optional params: RequestParams

      Optional query params for the request.

    Returns Promise<Forecast>

  • 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 OpenWeatherMap Docs for more.

    Returns

    Forecast for the week.

    Throws

    HttpException if WeekForecast.daily doesn't exist.

    Parameters

    • lat: number

      The latitude of a location (in decimal degrees).

    • lon: number

      The longitude of a location (in decimal degrees).

    • Optional params: RequestParams

      Optional query params for the request.

    Returns Promise<WeekForecast>

Generated using TypeDoc