Coder Social home page Coder Social logo

feathers-openweathermap's Introduction

feathers-openweathermap

npm GitHub Workflow Status Code Climate maintainability Code Climate coverage David npm GitHub license

Ever needed weather information in your feathers.js app? No matter if historical, current or forecast data. This is thin layer around the OpenWeatherMap API wrapped in a feathers.js service.

Supported APIs

Installation

npm install feathers-openweathermap

Get your appid

Follow the instructions at: https://openweathermap.org/appid

Creating a service

const { Service } = require('feathers-openweathermap');

app.use("/weather", new Service({
  appid: "YOUR_APP_ID",
}))

Service options

  • appid (required) - your appid from openweathermap.org
  • v (optional, default: '2.5') - the version of openweathermap
  • mode (optional, default: 'json') - the results format (possible: 'json', 'xml', 'html')
  • lang (optional, default: 'en') - the language of the result. info
  • units (optional, default: 'standard') - Units of measurement. 'standard', 'metric' and 'imperial' units are available.

Methods

The service exposes two standard methods, find(params) and create(data, params) and custom methods for @feathersjs/feathers@5. These methods are functionally equivalent. The create() method is added so that you can take advantage of the .on('created') service event.

When using the find(params) method, include the query as the params to be passed to the underlying OpenWeatherMap method.

find(params)

// by city name https://openweathermap.org/current#name
app.service('weather').find({ 
  query: { 
    endpoint: 'weather', 
    cityName: "Munich", 
    stateCode: "DE"
  }
});

// by city id https://openweathermap.org/current#cityid
app.service('weather').find({ 
  query: { 
    endpoint: 'weather', 
    cityId: 2844588 
  } 
});

// by geo coordinates https://openweathermap.org/current#geo
app.service('weather').find({ 
  query: { 
    endpoint: 'weather', 
    lat: 52.520008
    lon: 13.404954
  } 
});

// by zip code https://openweathermap.org/current#zip
app.service('weather').find({ 
  query: { 
    endpoint: 'weather', 
    zipCode: "18057", 
    countryCode: "DE"
  } 
});
app.service('weather').find({ 
  query: { 
    endpoint: 'onecall', 
    lat: 52.520008, 
    lon: 13.404954
  } 
});
// by city name https://openweathermap.org/forecast5#name5
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast', 
    cityName: "Munich", 
    stateCode: "DE"
  }
});

// by city id https://openweathermap.org/forecast5#cityid5
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast', 
    cityId: 2844588 
  } 
});

// by geo coordinates https://openweathermap.org/forecast5#geo5
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast', 
    lat: 52.520008,
    lon: 13.404954
  } 
});

// by zip code https://openweathermap.org/forecast5#zip
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast', 
    zipCode: "18057", 
    countryCode: "DE"
  } 
});
// by city name https://openweathermap.org/api/hourly-forecast#name5
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/hourly', 
    cityName: "Munich", 
    stateCode: "DE"
  }
});

// by city id https://openweathermap.org/api/hourly-forecast#cityid5
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/hourly', 
    cityId: 2844588 
  } 
});

// by geo coordinates https://openweathermap.org/api/hourly-forecast#geo5
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/hourly', 
    lat: 52.520008,
    lon: 13.404954
  } 
});

// by zip code https://openweathermap.org/api/hourly-forecast#zip
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/hourly', 
    zipCode: "18057", 
    countryCode: "DE"
  } 
});
// by city name https://openweathermap.org/forecast16#name16
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/daily', 
    cityName: "Munich", 
    stateCode: "DE"
  }
});

// by city id https://openweathermap.org/forecast16#cityid16
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/daily', 
    cityId: 2844588 
  } 
});

// by geo coordinates https://openweathermap.org/forecast16#geo16
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/daily', 
    lat: 52.520008,
    lon: 13.404954
  } 
});

// by zip code https://openweathermap.org/forecast16#zip
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/daily', 
    zipCode: "18057", 
    countryCode: "DE"
  } 
});
// by city name https://openweathermap.org/api/forecast30#name-year
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/climatic', 
    cityName: "Munich", 
    stateCode: "DE"
  }
});

// by city id https://openweathermap.org/api/forecast30#cityid-year
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/climatic', 
    cityId: 2844588 
  } 
});

// by geo coordinates https://openweathermap.org/api/forecast30#geo-year
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/climatic', 
    lat: 52.520008,
    lon: 13.404954
  } 
});

// by zip code https://openweathermap.org/api/forecast30#zip-year
app.service('weather').find({ 
  query: { 
    endpoint: 'forecast/climatic', 
    zipCode: "18057", 
    countryCode: "DE"
  } 
});
// current air pollution https://openweathermap.org/api/air-pollution#current
app.service('weather').find({ 
  query: { 
    endpoint: "air_pollution", 
    lat: 52.520008, 
    lon: 13.404954 
  } 
});

// forecast air pollution https://openweathermap.org/api/air-pollution#current
app.service('weather').find({ 
  query: { 
    endpoint: "air_pollution/forecast", 
    lat: 52.520008, 
    lon: 13.404954 
  } 
});

// historical air pollution https://openweathermap.org/api/air-pollution#history
app.service('weather').find({ 
  query: { 
    endpoint: "air_pollution/history", 
    start: 1606223802, 
    end: 1606482999, 
    lat: 52.520008, 
    lon: 13.404954
  } 
});

create(data)

// by city name https://openweathermap.org/current#name
app.service('weather').create({ 
  endpoint: 'weather', 
  cityName: "Munich", 
  stateCode: "DE"
});

// by city id https://openweathermap.org/current#cityid
app.service('weather').create({ 
  endpoint: 'weather',
  cityId: 2844588
});

// by geo coordinates https://openweathermap.org/current#geo
app.service('weather').create({ 
  endpoint: 'weather', 
  lat: 52.520008,
  lon: 13.404954
});

// by zip code https://openweathermap.org/current#zip
app.service('weather').create({ 
  endpoint: 'weather', 
  zipCode: "18057", 
  countryCode: "DE"
});
app.service('weather').create({ 
  endpoint: 'onecall', 
  lat: 52.520008, 
  lon: 13.404954
});
// by city name https://openweathermap.org/forecast5#name5
app.service('weather').create({ 
  endpoint: 'forecast', 
  cityName: "Munich", 
  stateCode: "DE"
});

// by city id https://openweathermap.org/forecast5#cityid5
app.service('weather').create({ 
  endpoint: 'forecast', 
  cityId: 2844588 
});

// by geo coordinates https://openweathermap.org/forecast5#geo5
app.service('weather').create({ 
  endpoint: 'forecast', 
  lat: 52.520008,
  lon: 13.404954 
});

// by zip code https://openweathermap.org/forecast5#zip
app.service('weather').create({ 
  endpoint: 'forecast', 
  zipCode: "18057", 
  countryCode: "DE" 
});
// by city name https://openweathermap.org/api/hourly-forecast#name5
app.service('weather').create({ 
  endpoint: 'forecast/hourly', 
  cityName: "Munich", 
  stateCode: "DE"
});

// by city id https://openweathermap.org/api/hourly-forecast#cityid5
app.service('weather').create({ 
  endpoint: 'forecast/hourly', 
  cityId: 2844588  
});

// by geo coordinates https://openweathermap.org/api/hourly-forecast#geo5
app.service('weather').create({ 
  endpoint: 'forecast/hourly', 
  lat: 52.520008,
  lon: 13.404954 
});

// by zip code https://openweathermap.org/api/hourly-forecast#zip
app.service('weather').create({ 
  endpoint: 'forecast/hourly', 
  zipCode: "18057", 
  countryCode: "DE" 
});
// by city name https://openweathermap.org/forecast16#name16
app.service('weather').create({ 
  endpoint: 'forecast/daily', 
  cityName: "Munich", 
  stateCode: "DE"
});

// by city id https://openweathermap.org/forecast16#cityid16
app.service('weather').create({ 
  endpoint: 'forecast/daily', 
  cityId: 2844588 
});

// by geo coordinates https://openweathermap.org/forecast16#geo16
app.service('weather').create({ 
  endpoint: 'forecast/daily', 
  lat: 52.520008,
  lon: 13.404954 
});

// by zip code https://openweathermap.org/forecast16#zip
app.service('weather').create({ 
  endpoint: 'forecast/daily', 
  zipCode: "18057", 
  countryCode: "DE" 
});
// by city name https://openweathermap.org/api/forecast30#name-year
app.service('weather').create({ 
  endpoint: 'forecast/climatic', 
  cityName: "Munich", 
  stateCode: "DE"
});

// by city id https://openweathermap.org/api/forecast30#cityid-year
app.service('weather').create({ 
  endpoint: 'forecast/climatic', 
  cityId: 2844588 
});

// by geo coordinates https://openweathermap.org/api/forecast30#geo-year
app.service('weather').create({ 
  endpoint: 'forecast/climatic', 
  lat: 52.520008
  lon: 13.404954 
});

// by zip code https://openweathermap.org/api/forecast30#zip-year
app.service('weather').create({ 
  endpoint: 'forecast/climatic', 
  zipCode: "18057", 
  countryCode: "DE" 
});
// current air pollution https://openweathermap.org/api/air-pollution#current
app.service('weather').create({ 
  endpoint: "air_pollution",
  lat: 52.520008,
  lon: 13.404954
});

// forecast air pollution https://openweathermap.org/api/air-pollution#current
app.service('weather').create({ 
  endpoint: "air_pollution/forecast",
  lat: 52.520008,
  lon: 13.404954
});

// historical air pollution https://openweathermap.org/api/air-pollution#history
app.service('weather').create({
    endpoint: "air_pollution/history",
    start: 1606223802,
    end: 1606482999,
    lat: 52.520008,
    lon: 13.404954
});

currentWeatherData(data)

app.service('weather').currentWeatherData({ 
  cityId: 2844588
});

oneCall(data)

app.service('weather').oneCall({
  lat: 52.520008,
  lon: 13.404954
});

fiveDay3HourForecast(data)

app.service('weather').fiveDay3HourForecast({
  cityName: "Munich", 
  stateCode: "DE", 
  countryCode: "DE"
})

hourlyForecast4Days(data)

app.service('weather').hourlyForecast4Days({
  cityName: "Munich", 
  stateCode: "DE", 
  countryCode: "DE"
})

dailyForecast16Days(data)

app.service('weather').dailyForecast16Days({
  cityName: "Munich", 
  stateCode: "DE", 
  countryCode: "DE"
})

climaticForecast30Days(data)

app.service('weather').climaticForecast30Days({
  cityName: "Munich", 
  stateCode: "DE", 
  countryCode: "DE"
})

airPollutionCurrent(data)

app.service('weather').airPollutionCurrent({ 
  lat: 52.520008, 
  lon: 13.404954 
});

airPollutionForecast(data)

app.service('weather').airPollutionForecast({ 
  lat: 52.520008, 
  lon: 13.404954 
});

airPollutionHistorical(data)

app.service('weather').airPollutionCurrent({ 
  lat: 52.520008, 
  lon: 13.404954,
  start: 1606223802, 
  end: 1606482999
});

Testing

Simply run npm test and all your tests in the test/ directory will be run. This project is setup with vscode. You can use the debugger with breakpoints. To run tests locally, you'll need your own appid. You can get it here: https://openweathermap.org/appid. Add a .env file with:

APPID = YOUR_APP_ID

License

Licensed under the MIT license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.