Skip to content

Commit

Permalink
Merge pull request #5 from evanshortiss/dev
Browse files Browse the repository at this point in the history
prepare for 1.0. improve tests. faster xml parsing. clean code. move to promises. increase coverage
  • Loading branch information
evanshortiss committed Apr 27, 2017
2 parents 34d5c5e + 81f1783 commit 47285c1
Show file tree
Hide file tree
Showing 12 changed files with 16,591 additions and 420 deletions.
39 changes: 39 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"env": {
"node": true,
"mocha": true,
"es6": true
},
"rules": {
"array-bracket-spacing": [2, "never"],
"arrow-body-style": 1,
"arrow-parens": 1,
"brace-style": [2, "1tbs"],
"camelcase": 2,
"comma-dangle": 2,
"comma-spacing": 2,
"computed-property-spacing": [2, "never"],
"curly": 2,
"dot-notation": 2,
"eol-last": 0,
"eqeqeq": [2, "smart"],
"no-extra-parens": 1,
"no-floating-decimal": 2,
"no-debugger": 2,
"no-redeclare": 2,
"no-spaced-func": 2,
"no-undef": 1,
"no-underscore-dangle": 0,
"no-unused-vars": [2, {"vars": "all", "args": "after-used"}],
"no-use-before-define": [2, "nofunc"],
"no-warning-comments": 0,
"object-curly-spacing": [2, "never"],
"prefer-const": ["error"],
"quotes": [2, "single"],
"semi": [2, "always"],
"keyword-spacing": [2, { "after": true }],
"space-infix-ops": 2,
"strict": 0,
"valid-jsdoc": 0
}
}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules
.DS_Store
.DS_Store
coverage
.nyc_output
*.log
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js

node_js:
- "7"
- "6"
- "5"
- "4"

after_success:
- npm run coveralls
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# CHANGELOG

Dates use DD/MM/YYYY format.


# 1.0.0 26/04/2017
* Change to Promise based interface.
* Make the module a factory function.
* Use `pixl-xml` to increase XML parsing speed and lower memory usage. Yay for
better performance!
* Improved unit tests. Tests no longer require an internet connection.
* Removed `getCurrentSummary` in favour of simply using `getForecastForTime` and
passing the current timestamp. Simplifies API footprint.


# < 1.0.0
* Undocumented. Sorry.
35 changes: 18 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
The MIT License (MIT)
(The MIT License)

Copyright (c) 2013 Evan Shortiss
Copyright (c) 2013-2017 Evan Shortiss <evanshortiss@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
100 changes: 79 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,90 @@
yr.no-forecast
=============
==============

Wrapper to easily get weather data for a specified location in JSON format. Uses [yr.no-interface](https://github.com/evanshortiss/yr.no-interface) under the hood. See the API docs at [yr.no](http://api.yr.no/weatherapi/locationforecast/1.8/documentation).
![TravisCI](https://travis-ci.org/evanshortiss/yr.no-forecast.svg) [![npm version](https://badge.fury.io/js/yr.no-forecast.svg)](https://badge.fury.io/js/yr.no-forecast) [![Coverage Status](https://coveralls.io/repos/github/evanshortiss/yr.no-forecast/badge.svg?branch=master)](https://coveralls.io/github/evanshortiss/yr.no-forecast?branch=master)

Wrapper to easily get weather data for a specified location in JSON format. Uses [yr.no-interface](https://github.com/evanshortiss/yr.no-interface) under the
hood. See the API docs at [yr.no](http://api.yr.no/weatherapi/locationforecast/1.9/documentation).

###Usage
Use the ```getWeather(queryStringParams, callback|stream, [VERSION])``` function to get a LocationForecast object, where version represents the version of the "locationforecast" service to use. This object has functions that take a callback as parameter and are detailed in the example below.

```
var yrno = require('yr.no-forecast');
yrno.getWeather({
## Usage
Use the ```getWeather(queryParams)``` function to get a
LocationForecast object by calling the "locationforecast" API.

Here's an example:


```js
const yrno = require('yr.no-forecast')({
version: '1.9' // this is the default if not provided
});

const LOCATION = {
// This is Dublin, Ireland
lat: 53.3478,
lon: 6.2597
}, function(err, location) {
// Weather for next five days (Array with five object)
location.getFiveDaySummary(cb);
// Current conditions
location.getCurrentSummary(cb);
// Weather anytime from now till future
location.getForecastForTime(time, cb);
}, [VERSION]);
```
### Weather JSON Format
Format is somewhat inspired by that of [forecast.io](https://developer.forecast.io/) service. Not all fields will always be available. Fields that no data was retrieved for contain the null value;
};

yrno.getWeather(LOCATION)
.then((weather) => {
// Get general weather for next five days (Array with five objects)
weather.getFiveDaySummary()
.then((data) => console.log('five day summary', data));

// Get a weather data point for a given time between now and 9 days ahead
weather.getForecastForTime(new Date())
.then((data) => console.log('current weather', data));
})
.catch((e) => {
console.log('an error occurred!', e);
});
```
{

## API

### module(config)
This module exports a single factory function that can be used to get a
configured instance that exports the `getWeather` function.

Currently supported config options:

* version - This will be passed when making a call to the met.no API


### module.getWeather(params)
Returns a Promise that will resolve with a `LocationForecast` object that
contains functions to get weather data.

### LocationForecast.getFiveDaySummary()
Returns a Promise that resolves to an Array of 5 weather data Objects.

### LocationForecast.getForecastForTime(time)
Returns a Promise that resolves to a weather data Object that is closest to the
provided `time` argument. The `time` argument will be passed to `moment.utc` so
many time formats will work, but a millisecond timestamp or ISO formatted date
string are both ideal options to use use.

### LocationForecast.getXml()
Returns the XML string that the locationforecast API returned.

### LocationForecast.getJson()
Returns the JSON representation of a locationforecast response.

### LocationForecast.getFirstDateInPayload()
Returns the first date string that is available in the data returned from the
locationforecast call.


## Weather JSON Format
Format is somewhat inspired by that of the
[forecast.io](https://developer.forecast.io/) service.

Some fields will be undefined depending on the weather conditions. Always
verify the field you need exists by using `data.hasOwnProperty('fog')`
or similar techniques.

```js
{
icon: 'PARTLYCLOUD',
to: '2013-11-15T18:00:00Z',
from: '2013-11-15T12:00:00Z',
Expand All @@ -40,7 +99,6 @@ Format is somewhat inspired by that of [forecast.io](https://developer.forecast.
lowClouds: '0.0%',
mediumClouds: '0.0%',
highClouds: '0.0%',
dewpointTemperature: '-8.3 celcius',
...
dewpointTemperature: '-8.3 celcius'
}
```
139 changes: 139 additions & 0 deletions fixtures/five-day-oslo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
[
{
"icon": "PartlyCloud",
"to": "2017-04-18T12:00:00Z",
"from": "2017-04-18T11:00:00Z",
"rain": "0.0 mm",
"temperature": "6.0 celsius",
"windDirection": {
"deg": "200.7",
"name": "S"
},
"windSpeed": {
"mps": "1.5",
"beaufort": "1",
"name": "Flau vind"
},
"windGust": {
"mps": "3.7"
},
"humidity": "63.5 percent",
"pressure": "1033.6 hPa",
"cloudiness": "72.6%",
"fog": "0.0%",
"lowClouds": "72.6%",
"mediumClouds": "0.0%",
"highClouds": "0.0%",
"temperatureProbability": "0 probabilitycode",
"windProbability": "0 probabilitycode",
"dewpointTemperature": "-0.6 celsius"
},
{
"icon": "Cloud",
"to": "2017-04-19T12:00:00Z",
"from": "2017-04-19T11:00:00Z",
"rain": "0.0 mm",
"temperature": "8.5 celsius",
"windDirection": {
"deg": "201.9",
"name": "S"
},
"windSpeed": {
"mps": "5.0",
"beaufort": "3",
"name": "Lett bris"
},
"windGust": {
"mps": "7.3"
},
"humidity": "69.8 percent",
"pressure": "1033.5 hPa",
"cloudiness": "100.0%",
"fog": "0.0%",
"lowClouds": "34.1%",
"mediumClouds": "1.6%",
"highClouds": "99.9%",
"temperatureProbability": "0 probabilitycode",
"windProbability": "0 probabilitycode",
"dewpointTemperature": "3.2 celsius"
},
{
"icon": "Cloud",
"to": "2017-04-20T12:00:00Z",
"from": "2017-04-20T11:00:00Z",
"rain": "0.0 mm",
"temperature": "10.9 celsius",
"windDirection": {
"deg": "202.4",
"name": "S"
},
"windSpeed": {
"mps": "6.6",
"beaufort": "4",
"name": "Laber bris"
},
"windGust": {
"mps": "9.5"
},
"humidity": "73.5 percent",
"pressure": "1019.8 hPa",
"cloudiness": "99.8%",
"fog": "0.0%",
"lowClouds": "4.8%",
"mediumClouds": "89.3%",
"highClouds": "98.1%",
"temperatureProbability": "1 probabilitycode",
"windProbability": "0 probabilitycode",
"dewpointTemperature": "6.3 celsius"
},
{
"icon": "PartlyCloud",
"to": "2017-04-21T12:00:00Z",
"from": "2017-04-21T06:00:00Z",
"rain": "0.0 mm",
"temperature": "10.3 celsius",
"windDirection": {
"deg": "281.8",
"name": "W"
},
"windSpeed": {
"mps": "6.3",
"beaufort": "4",
"name": "Laber bris"
},
"humidity": "29.2 percent",
"pressure": "1002.0 hPa",
"cloudiness": "79.7%",
"lowClouds": "0.0%",
"mediumClouds": "74.6%",
"highClouds": "0.8%",
"temperatureProbability": "1 probabilitycode",
"windProbability": "0 probabilitycode",
"dewpointTemperature": "-7.2 celsius"
},
{
"icon": "PartlyCloud",
"to": "2017-04-22T12:00:00Z",
"from": "2017-04-22T06:00:00Z",
"rain": "0.0 mm",
"temperature": "9.9 celsius",
"windDirection": {
"deg": "327.2",
"name": "NW"
},
"windSpeed": {
"mps": "5.7",
"beaufort": "4",
"name": "Laber bris"
},
"humidity": "31.5 percent",
"pressure": "1005.7 hPa",
"cloudiness": "73.4%",
"lowClouds": "0.0%",
"mediumClouds": "58.6%",
"highClouds": "12.5%",
"temperatureProbability": "1 probabilitycode",
"windProbability": "1 probabilitycode",
"dewpointTemperature": "-6.5 celsius"
}
]
Loading

0 comments on commit 47285c1

Please sign in to comment.