Skip to content

razvan-moldovan/angular-openweathermap-api-factory

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

angular-openweathermap-api-factory is an angularjs module with a OpenWeatherMap API promise factory.

npm version Bower version

Author: Jonathan Hornung (JohnnyTheTank)

Usage

  1. Install via either bower, npm or downloaded files:
    1. bower install --save angular-openweathermap-api-factory
    2. npm install --save angular-openweathermap-api-factory
    3. download angular-openweathermap-api-factory.zip
  2. Include dependencies in your HTML.
    1. When using bower:
    <script src="bower_components/angular-openweathermap-api-factory/dist/angular-openweathermap-api-factory.min.js"></script>
    1. When using npm:
    <script src="node_modules/angular-openweathermap-api-factory/dist/angular-openweathermap-api-factory.min.js"></script>
    1. when using downloaded files
    <script src="angular-openweathermap-api-factory.min.js"></script>
  3. Add jtt_openweathermap to your application's module dependencies.
  4. Use the factory openweathermapFactory

factory methods

current weather

current weather from city by name

// docs: http://openweathermap.org/current#name
openweathermapFactory.getWeatherFromCitySearchByName({
    q:"<CITY_NAME>,<COUNTRY_CODE>", //city name and country code divided by comma, use ISO 3166 country codes eg "London,uk"
    lang:"<LANGUAGE>", // (optional) http://openweathermap.org/current#multi
    units:"<UNITS>", // (optinal) http://openweathermap.org/current#data
    type:"<TYPE>", // (optional) 'like' = close result, 'accurate' = accurate result
    appid:"<APP_ID>"
}).then(function(_data){
    //on success
}).catch(function (_data) {
    //on error
});

current weather from city by id

// docs: http://openweathermap.org/current#cityid
openweathermapFactory.getWeatherFromCityById({
    id:"<CITY_ID>", //List of city ID can be downloaded here http://bulk.openweathermap.org/sample/city.list.json.gz
    lang:"<LANGUAGE>", // (optional) http://openweathermap.org/current#multi
    units:"<UNITS>", // (optinal) http://openweathermap.org/current#data
    appid:"<APP_ID>"
}).then(function(_data){
    //on success
}).catch(function (_data) {
    //on error
});

current weather from group of cities by id

// docs: http://openweathermap.org/current#severalid
openweathermapFactory.getWeatherFromGroupOfCitiesById({
    id:"<CITY_ID>,<CITY_ID>,<CITY_ID>,...", //List of city ID can be downloaded here http://bulk.openweathermap.org/sample/city.list.json.gz
    lang:"<LANGUAGE>", // (optional) http://openweathermap.org/current#multi
    units:"<UNITS>", // (optinal) http://openweathermap.org/current#data
    appid:"<APP_ID>"
}).then(function(_data){
    //on success
}).catch(function (_data) {
    //on error
});

current weather from location by coordinates

// docs: http://openweathermap.org/current#geo
openweathermapFactory.getWeatherFromLocationByCoordinates({
    lat:"<LAT>",
    lon:"<LONG>",
    lang:"<LANGUAGE>", // (optional) http://openweathermap.org/current#multi
    units:"<UNITS>", // (optinal) http://openweathermap.org/current#data
    appid:"<APP_ID>"
}).then(function(_data){
    //on success
}).catch(function (_data) {
    //on error
});

current weather from location by zipcode

// docs: http://openweathermap.org/current#zip
openweathermapFactory.getWeatherFromLocationByCoordinates({
    zip:"<ZIPCODE>,<COUNTRY_CODE>", //use ISO 3166 country codes
    lang:"<LANGUAGE>", // http://openweathermap.org/current#multi
    units:"<UNITS>", // (optinal) http://openweathermap.org/current#data
    appid:"<APP_ID>"
}).then(function(_data){
    //on success
}).catch(function (_data) {
    //on error
});

5-day-forecast

5-day-forecast from city by name

// docs: http://openweathermap.org/forecast5#name5
openweathermapFactory.cityForecast5SearchByName({
    q:"<CITY_NAME>,<COUNTRY_CODE>", //city name and country code divided by comma, use ISO 3166 country codes eg "London,uk"
    lang:"<LANGUAGE>", // (optional) http://openweathermap.org/current#multi
    units:"<UNITS>", // (optinal) http://openweathermap.org/current#data
    type:"<TYPE>", // (optional) 'like' = close result, 'accurate' = accurate result
    appid:"<APP_ID>"
}).then(function(_data){
    //on success
}).catch(function (_data) {
    //on error
});

5-day-forecast from city by id

// docs: http://openweathermap.org/forecast5#cityid5
openweathermapFactory.getForecast5FromCityById({
    id:"<CITY_ID>", //List of city ID can be downloaded here http://bulk.openweathermap.org/sample/city.list.json.gz
    lang:"<LANGUAGE>", // (optional) http://openweathermap.org/current#multi
    units:"<UNITS>", // (optinal) http://openweathermap.org/current#data
    appid:"<APP_ID>"
}).then(function(_data){
    //on success
}).catch(function (_data) {
    //on error
});

5-day-forecast from location by coordinates

// docs: http://openweathermap.org/forecast5#geo5
openweathermapFactory.getForecast5FromLocationByCoordinates({
    lat:"<LAT>",
    lon:"<LONG>",
    lang:"<LANGUAGE>", // (optional) http://openweathermap.org/current#multi
    units:"<UNITS>", // (optinal) http://openweathermap.org/current#data
    appid:"<APP_ID>"
}).then(function(_data){
    //on success
}).catch(function (_data) {
    //on error
});

change API url where to send params

openweathermapFactory.setApiBaseUrl('https://crossorigin.me/http://api.openweathermap.org/data/2.5/');

OpenWeatherMap JSON API

More angular-api-factories

bandsintown - dailymotion - facebook - flickr - footballdata - github - openweathermap - tumblr - vimeo - wikipedia - youtube

License

MIT

About

AngularJS Factory for OpenWeatherMap JSON REST API requests

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%