Skip to content

Commit

Permalink
add new method requestSync + update dependencies + update test + upda…
Browse files Browse the repository at this point in the history
…te license copyright
  • Loading branch information
gablau committed Oct 2, 2021
1 parent 7f215aa commit 5eaa3cd
Show file tree
Hide file tree
Showing 7 changed files with 816 additions and 634 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
NODE_ENV=test
WU_APY_KEY=B5792DB9271ED8697F671F8FBBE49E43
WU_APY_KEY=B5792DB9271ED8697F671F8FBBE49E43
WU_STATION_ID=YOUR_STATION_ID_HERE
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2019 Gabriele Lauricella
Copyright (c) 2019-2021 Gabriele Lauricella

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ var wunderground = new WeatherUndergroundNode(myApyKey);

## How To Use
The syntax follows a simple pattern:

wunderground.[resource call(s)].request(callback);

```js
wunderground.[resource call(s)].request(function (err, response) {
console.log(response);
}););
```
or with sync method
```js
const result = await wunderground.[resource call(s)].requestSync();
```
The available resource calls are the following (you must include one in your request):

- PWSCurrentConditions
Expand All @@ -54,10 +60,10 @@ The available resource calls are the following (you must include one in your req

The documentation for each resource can be found here: [APIs documentation for PWS Contributors](https://docs.google.com/document/d/1eKCnKXI9xnoMGRRzOL1xPCBihNV2rOet08qpE_gArAY/edit).

So to get the current conditions you would use the following code, where `IROME288` is a PWS station ID:
So to get the current conditions you would use the following code, where `IROME7475` is a PWS station ID:

```js
wunderground.PWSCurrentConditions("IROME228").request(function (err, response) {
wunderground.PWSCurrentConditions("IROME7475").request(function (err, response) {
console.log(response);
});
```
Expand All @@ -73,14 +79,14 @@ wunderground.ForecastDaily().FiveDay().ByPostalCode("00178", "IT").Language("en-
To get 5 day forecast by geocode wit Italian language:

```js
wunderground.ForecastDaily().FiveDay().ByGeocode("41.860", "12.470").Language("it-IT").request(function (err, response) {(function (err, response) {
wunderground.ForecastDaily().FiveDay().ByGeocode("41.89", "12.444").Language("it-IT").request(function (err, response) {(function (err, response) {
console.log(response);
});
```
To get daily historic data:
```js
wunderground.PWSHistoryDaily("IROME228", "20190309").request(function (err, response) {
wunderground.PWSHistoryDaily("IROME7475", "20190309").request(function (err, response) {
console.log(response);
});
```
Expand All @@ -90,7 +96,12 @@ Imperial/english units can be requested by adding `InImperialUnits()` or `InEngl
## Running Unit Tests and Code coverage
In order to run unit tests you need to include your apykey in .env file in the root directory.
In order to run unit tests you need to include your apykey and your PWS station id in .env file and set in the root directory.
```bash
NODE_ENV=test
WU_APY_KEY=B5792DB9271ED8697F671F8FBBE49E43
WU_STATION_ID=YOUR_STATION_ID_HERE
```
Then simply run test this command: ```npm run test```
Expand Down
22 changes: 20 additions & 2 deletions lib/weather-underground-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ var WeatherUndergroundNode = function(apikey, debug) {
this.chainedParams.push("locid="+code);
return this;
};

that.LocationNear = function(lat, lon, type) { //type: pws, airport, ski
this.chainedRequests.push("/v3/location/near");
this.chainedParams.push("geocode="+lat+","+lon);
Expand Down Expand Up @@ -326,7 +326,25 @@ var WeatherUndergroundNode = function(apikey, debug) {
});

};


that.requestSync = async function(){

let promise = new Promise(function (resolve, reject) {

that.request(function (err, response) {
if(err) reject(err);
else resolve(response)
});

});

let result = promise.catch(function(e){
e.error = true
return e
});
return result
};

};

module.exports = WeatherUndergroundNode;
Loading

0 comments on commit 5eaa3cd

Please sign in to comment.