2.0.5 • Published 1 year ago

@shodlik_shomuratov/openweather-sdk v2.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Open Weather SDK in Node.js

Introduction

Open Weather SDK is used to work with famous weather forecaster Open Weather features using Node.js, TypeScript. The package provides method(s) to get weather condition by city name.

This page presents the installation, basic usage and examples with different type of modes.

Used technologies:

Contents

Installation

  • npm - npm install @shodlik_shomuratov/openweather-sdk
  • yarn - yarn add @shodlik_shomuratov/openweather-sdk
  • pnpm - pnpm add @shodlik_shomuratov/openweather-sdk

Configuration

  1. Obtain your API_KEY from OpenWeather to use package properly!
  2. Instantiate SDK client and pass it to KameleoonProvider
import SDK from "@shodlik_shomuratov/openweather-sdk";

const sdk = new SDK("your_api_key");

async function outputWeather() {
	const weatherData = await sdk.getCurrentWeather("Tashkent");
	console.log(weatherData);
}

outputWeather();

Modes

  1. Default mode. In this mode you every time call the getCurrentWeather() method SDK makes a new request.
import SDK from "@shodlik_shomuratov/openweather-sdk";

cosnt sdk = new SDK("your_api_key", {
    mode: "default"
});

async function outputWeather () {
    const weatherData = await sdk.getCurrentWeather("Tashkent");
    console.log(weatherData);
}

outputWeather();
  1. Polling mode. In polling mode in order to maintenance zero latency response, you get data from stored weather data and SDK makes a new request for you every 10 minutes.
import SDK from "@shodlik_shomuratov/openweather-sdk";

cosnt sdk = new SDK("your_api_key", {
    mode: "polling"
});

async function outputWeather () {
    const weatherData = await sdk.getCurrentWeather("Tashkent");
    console.log(weatherData);
}

outputWeather();

Redis Store

If you want you can save updated weather data in your redis store. Only thing you have to do is give SDK redis options in the redis field.

import SDK from "@shodlik_shomuratov/openweather-sdk";

cosnt sdk = new SDK("your_api_key", {
    mode: "polling",
    redis: {
        host: "127.0.0.1", // your redis host
        port: 6379, // your redis port
        username: "my_redis_username", // optional, if you have one
        password: "my_redis_password", // optional, if you have one
    }
});

async function outputWeather () {
    const weatherData = await sdk.getCurrentWeather("Tashkent");
    console.log(weatherData);
}

outputWeather();

Testing purposes

  1. You have to clone this repository into your local machine and install dependencies
    npm install
  1. Change .env.sample into .env and write your credentials in it.
    OPEN_WEATHER_API_KEY=my_api_key
  1. Run test command
    npm run test

Created by Shodlik Shomuratov

2.0.5

1 year ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.0

1 year ago