Skip to content

Commit e9d56f3

Browse files
committed
Update README
1 parent c034165 commit e9d56f3

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
[![license: AGPLv3](https://img.shields.io/badge/license-AGPLv3-blue.svg)](https://www.gnu.org/licenses/agpl-3.0)
44
[![GitHub release](https://img.shields.io/github/release/nioc/netatmo-nodejs-api.svg)](https://github.com/nioc/netatmo-nodejs-api/releases/latest)
5+
[![npm](https://img.shields.io/npm/dt/netatmo-nodejs-api)](https://www.npmjs.com/package/netatmo-nodejs-api)
6+
[![npms.io (final)](https://img.shields.io/npms-io/final-score/netatmo-nodejs-api)](https://www.npmjs.com/package/netatmo-nodejs-api)
57

68
Node.js API wrapper for Netatmo API.
79

@@ -57,6 +59,37 @@ try {
5759
}
5860
```
5961

62+
### Authenticate wrapper (try access token, refresh token or client credentials)
63+
64+
You can use the `authenticate` method which wrap 3 authentication methods.
65+
66+
```js
67+
const { NetatmoClient, SCOPE_BASIC_CAMERA } = require('netatmo-nodejs-api')
68+
69+
// you need to set your own information
70+
const clientId = '60...'
71+
const clientSecret = 'abc...'
72+
const username = 'user@domain'
73+
const password = 'pass'
74+
let refreshToken = ''
75+
let accessToken = ''
76+
let expiresInTimestamp = 0
77+
78+
try {
79+
// create client
80+
const client = new NetatmoClient(clientId, clientSecret, SCOPE_BASIC_CAMERA, { timeout: 1000 })
81+
82+
// authenticate
83+
({ accessToken, refreshToken, expiresInTimestamp } = await client.authenticate(accessToken, refreshToken, expiresInTimestamp, username, password))
84+
// you should store accessToken, refreshToken, expiresInTimestamp for further request
85+
86+
// get data
87+
const homes = await client.getHomes()
88+
} catch (error) {
89+
console.log(error)
90+
}
91+
```
92+
6093
## Versioning
6194

6295
netatmo-nodejs-api is maintained under the [semantic versioning](https://semver.org/) guidelines.

0 commit comments

Comments
 (0)