dark-sky-client-ts
A simple typescript client for Dark Sky API.
All types based off what is found in the official API documentation.
DISCLAIMER: This does not use a proxy and as such does not hide your api key during requests. If you would like to use a proxy approach there are several other packages that offer it.
Installation
npm install dark-sky-client-ts --save
Usage
import { DarkSkyApiClient } from "dark-sky-client-ts";
const dsApi = new DarkSkyApiClient(apiKey, params);
async getWeather() {
const weatherIsh = await dsApi.get();
const weather = await dsApi.getWeather();
}
async getHourly() {
const hourlyIsh = await dsApi.get("hourly");
const hourly = await dsApi.getHourly();
}
async getDaily() {
const daily = await dsApi.get("daily", {
latitude: -38.590451,
longitude: 175.541561,
lang: "zh",
units: "uk2"
});
}
DarkSkyApiClient
const dsApi = new DarkSkyApiClient(apiKey, params);
- apiKey (
string
) - Dark Sky API key. - params (
DarkSkyRequestObject
) - optional params for API request.
Methods
async get(
field?: DarkSkyRootField,
params?: DarkSkyRequestObject
)
Note: Responses are stored for the duration of the refresh rate, unless it is a Time Machine request.
getWeather(): Promise<DarkSkyResponseObject>
getCurrently(): Promise<DarkSkyCurrentlyResponse>
getMinutely(): Promise<DarkSkyDataBlockObject>
getHourly(): Promise<DarkSkyHourlyBlockObject>
getDaily(): Promise<DarkSkyDailyBlockObject>
getAlerts(): Promise<DarkSkyAlertObject[]>
getFlags(): Promise<DarkSkyFlagsObject>
getRequestParams(): DarkSkyRequestObject
setRequestParams(request: DarkSkyRequestObject)
getRefreshRate(): number
setRefreshRate(refreshRate: number)
setCoords(lat: number, lng: number)
setExcludes(excludes: DarkSkyRootField[])
Note: minutely
is excluded by default, because c'mon, really?
setLang(lang: DarkSkySupportedLanguage)
setUnits(units: DarkSkyUnitType)
setTime(time: number | string)
Note: time
is used for Time Machine requests and is reset to null after each call.
DarkSkyRequestObject
{
latitude?: number;
longitude?: number;
exclude?: DarkSkyRootField[];
lang?: DarkSkySupportedLanguage;
units?: DarkSkyUnitType;
timeSeconds?: number;
timeString?: string;
}
DarkSkyResponseObject
For the sake of brevity, I'm going to go ahead and say that all reponses should match what is outlined in the official API documentation. But for a general type skeleton:
DarkSkyResponseObject {
...
DarkSkyCurrentlyResponse
DarkSkyDataBlockObject {
...
DarkSkyDataPointObject[]
}
DarkSkyHourlyBlockObject {
...
DarkSkyHourlyResponse[]
}
DarkSkyDailyBlockObject {
...
DarkSkyDailyResponse[]
}
DarkSkyAlertObject[]
DarkSkyFlagsObject
}