Skip to content

Commit

Permalink
Implements new interface
Browse files Browse the repository at this point in the history
  • Loading branch information
zrrrzzt committed Jul 2, 2017
1 parent 54d7206 commit f298ee4
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 66 deletions.
10 changes: 2 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
###########################################################
#
# Dockerfile for osanywhereweather
#
###########################################################

# Setting the base to nodejs 4.8.0
FROM node:4.8.0-alpine
# Setting the base to nodejs 6.11.0
FROM node:6.11.0-alpine

# Maintainer
MAINTAINER Geir Gåsodden
Expand Down
139 changes: 90 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,65 @@ This version supports viewing the live data from your weatherstation as well as
## Installation

```bash
$ npm install osanywhereweather --save
$ npm i osanywhereweather --save
```

## Usage

The module exposes four methods: login, getLiveData, getHistoryData and exportData.
The module exposes three methods: live, history, and export.
All methods supports promises and callbacks.

### login
### live

Use this to retrieve a sessionKey. Pass in an options object.
Use this to retrieve live data from your weatherstation. Pass in an options object.

**email** the email for your osanywhereweather account

**password** the password for your osanywhereweather account

This method returns a data object.
**stationId** the Id for the weatherstation you will get data from. It's the mac address for the station.

### getLiveData
This method returns your weatherdata as json.

Use this to retrieve live data from your weatherstation. Pass in an options object.
#### Promises

**sessionKey** the sessionKey returned from login
```JavaScript
'use strict'

**stationId** the Id for the weatherstation you will get data from. It's the mac address for the station.
const osa = require('osanywhereweather')
const options = {
'stationId': 'your-station-id',
'email': 'your-email@example.com',
'password': 'YourTopSecretPassword'
}

This method returns your weatherdata as json.
osa.live(options)
.then(json => console.log(json))
.catch(error => console.error(error))
```

#### Callback

```JavaScript
'use strict'

var osa = require('osanywhereweather')
var options = {
const osa = require('osanywhereweather')
const options = {
'stationId': 'your-station-id',
'email': 'your-email@example.com',
'password': 'YourTopSecretPassword'
}

osa.login(options, function (error, data) {
osa.live(options, (error, json) => {
if (error) {
console.error(error)
} else {
osa.getLiveData({stationId: options.stationId, sessionKey: data.sessionKey}, function (err, json) {
if (err) {
console.error(err)
} else {
console.log(json)
}
})
console.log(json)
}
})
```

Example of returned data:
#### Example of returned data for live

```JavaScript
{ status: 200,
Expand All @@ -84,11 +90,13 @@ Example of returned data:
}
```

## getHistoryData
### history

Use this to retrieve historic data from your weatherstation. Pass in an options object.

**sessionKey** the sessionKey returned from login
**email** the email for your osanywhereweather account

**password** the password for your osanywhereweather account

**stationId** the Id for the weatherstation you will get data from. It's the mac address for the station.

Expand All @@ -100,11 +108,13 @@ Use this to retrieve historic data from your weatherstation. Pass in an options

This method returns your weatherdata as json.

#### Promises

```JavaScript
'use strict'

var osa = require('osanywhereweather')
var options = {
const osa = require('osanywhereweather')
const options = {
'stationId': 'your-station-id',
'email': 'your-email@example.com',
'password': 'YourTopSecretPassword',
Expand All @@ -113,23 +123,36 @@ var options = {
'duration': '@week'
}

osa.login(options, function (error, data) {
osa.history(options)
.then(json => console.log(json))
.catch(error => console.error(error))
```

#### Callback

```JavaScript
'use strict'

const osa = require('osanywhereweather')
const options = {
'stationId': 'your-station-id',
'email': 'your-email@example.com',
'password': 'YourTopSecretPassword',
'type': 'temperature',
'channel': '1',
'duration': '@week'
}

osa.history(options, (error, json) => {
if (error) {
console.error(error)
} else {
options.sessionKey = data.sessionKey
osa.getHistoryData(options, function (err, json){
if (err) {
console.error(err)
} else {
console.log(json)
}
})
console.log(json)
}
})
```

Example of returned data:
#### Example of returned data for history

```JavaScript
{ status: 200,
Expand Down Expand Up @@ -173,10 +196,12 @@ Example of returned data:
}
```

## exportData
### export
Use this to export historic data from your weatherstation. Pass in an options object.

**sessionKey** the sessionKey returned from login
**email** the email for your osanywhereweather account

**password** the password for your osanywhereweather account

**stationId** the Id for the weatherstation you will get data from. It's the mac address for the station.

Expand All @@ -190,11 +215,34 @@ Use this to export historic data from your weatherstation. Pass in an options ob

This method returns your weatherdata as csv.

#### Promises

```JavaScript
'use strict'

const osa = require('osanywhereweather')
const options = {
'stationId': 'your-station-id',
'email': 'your-email@example.com',
'password': 'YourTopSecretPassword',
'type': 'temperature',
'channel': '1',
'fromdate': '2015-04-01',
'todate': '2015-04-30'
}

osa.export(options)
.then(data => console.log(data))
.catch(error => console.error(error))
```

#### Callback

```JavaScript
'use strict'

var osa = require('osanywhereweather')
var options = {
const osa = require('osanywhereweather')
const options = {
'stationId': 'your-station-id',
'email': 'your-email@example.com',
'password': 'YourTopSecretPassword',
Expand All @@ -204,23 +252,16 @@ var options = {
'todate': '2015-04-30'
}

osa.login(options, function (error, data) {
osa.export(options, (error, data) => {
if (error) {
console.error(error)
} else {
options.sessionKey = data.sessionKey
osa.exportData(options, function (err, data) {
if (err) {
console.error(err)
} else {
console.log(data)
}
})
console.log(data)
}
})
```

Example of returned data:
#### Example of returned data for export

```bash
All data are in 5 minute block.,,,
Expand Down
32 changes: 24 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
'use strict'

const login = require('./lib/login')
const getCredentials = require('./lib/get-credentials')
const getLiveData = require('./lib/get-livedata')
const getHistoryData = require('./lib/get-historydata')
const exportData = require('./lib/export-data')

module.exports.login = login
module.exports.live = (options, callback) => {
return new Promise((resolve, reject) => {
getCredentials(options)
.then(getLiveData)
.then(json => callback ? callback(null, json) : resolve(json))
.catch(error => callback ? callback(error, null) : reject(error))
})
}

module.exports.getCredentials = getCredentials
module.exports.history = (options, callback) => {
return new Promise((resolve, reject) => {
getCredentials(options)
.then(getHistoryData)
.then(json => callback ? callback(null, json) : resolve(json))
.catch(error => callback ? callback(error, null) : reject(error))
})
}

module.exports.getLiveData = getLiveData

module.exports.getHistoryData = getHistoryData

module.exports.exportData = exportData
module.exports.export = (options, callback) => {
return new Promise((resolve, reject) => {
getCredentials(options)
.then(exportData)
.then(data => callback ? callback(null, data) : resolve(data))
.catch(error => callback ? callback(error, null) : reject(error))
})
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "osanywhereweather",
"description": "Get your weatherdata from osanywhereweather",
"version": "2.0.1",
"version": "3.0.0",
"license": "MIT",
"author": {
"name": "Geir Gåsodden",
Expand Down

0 comments on commit f298ee4

Please sign in to comment.