owm-onecall-api
Version:
A wrapper for OpenWeatherMap's 'onecall' API.
137 lines (136 loc) • 4.22 kB
TypeScript
import { OpenWeatherMapBase, OpenWeatherMapOptions } from "./base";
import { RequestParams, TimeMachineDate, Units, Language, Exclude } from "../types";
/**
* An implementation of [[OpenWeatherMapBase]] that allows for chaining method calls to customize the request.
*
* * Note: Should only be used via [[buildOpenWeatherMapRequest]] or `OpenWeatherMap.builder`.
*
* @private
*/
export declare class OpenWeatherMapBuilder extends OpenWeatherMapBase {
/**
* The request options.
*/
private readonly request;
constructor(token: string, latitude: number, longitude: number, options?: OpenWeatherMapOptions);
/**
* Set multiple request query parameters at once using a RequestParams.
*
* **Warning**: This will **not** merge previously excluded data blocks. To add more
* excluded data blocks call `OpenWeatherMapBuilder.exclude`
*
* @param params Params to override the current Query parameters.
* @returns Chain
*/
params(params?: RequestParams): this;
/**
* Create a TimeMachine request instead of a current forecast.
*
* @param time Specific time to get the weather for.
* @returns Chain
*/
time(time: TimeMachineDate): this;
/**
* Set the units for the response.
*
* @see RequestParams
* @param units Units to use.
* @returns Chain
*/
units(units: Units): this;
/**
* Set the language for the response.
*
* @see RequestParams
* @param language Language to use.
* @returns Chain
*/
language(language: Language): this;
/**
* Exclude some number of data blocks from the API response.
*
* * Note: This will override any of the 'only' functions, ie `onlyCurrently`, etc.
*
* @see RequestParams
* @param exclude List of datablocks to exclude from the response.
*/
exclude(...exclude: Exclude[]): this;
/**
* Shorthand for excluding all datablocks except for the Currently.
*
* @returns Chain
*/
onlyCurrently(): this;
/**
* Helper function for excluding the `currently` data block.
*
* @returns Chain
*/
excludeCurrently(): this;
/**
* Shorthand for excluding all datablocks except for the Minutely.
*
* @returns Chain
*/
onlyMinutely(): this;
/**
* Helper function for excluding the `minutely` data block.
*
* @returns Chain
*/
excludeMinutely(): this;
/**
* Shorthand for excluding all datablocks except for the Hourly.
*
* @returns Chain
*/
onlyHourly(): this;
/**
* Helper function for excluding the `hourly` data block.
*
* @returns Chain
*/
excludeHourly(): this;
/**
* Shorthand for excluding all datablocks except for the Daily.
*
* @returns Chain
*/
onlyDaily(): this;
/**
* Helper function for excluding the `daily` data block.
*
* @returns Chain
*/
excludeDaily(): this;
/**
* Execute the request and return the response wrapped in a promise.
*/
execute(): Promise<import("../types").Forecast>;
/**
* Takes the list of excluded datablocks and adds all the time ones except for [[include]].
*
* @param include Exclude all datablocks except for this one.
*/
private excludeAllBut;
private addExlude;
}
/**
* Conveience function for creating a Request Chain.
*
* Example usage:
*
* ```typescript
* // Only get the hourly forecast, and extend it.
* buildOpenWeatherMapRequest("api-token", 42, -42)
* .units(Units.Metric)
* .onlyHourly()
* .execute()
* ```
*
* @param token OpenWeatherMap developer API token.
* @param latitude The latitude of a location (in decimal degrees).
* @param longitude The longitude of a location (in decimal degrees).
* @param options Optional query params for the request.
*/
export declare function buildOpenWeatherMapRequest(token: string, latitude: number, longitude: number, options?: OpenWeatherMapOptions): OpenWeatherMapBuilder;