-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GitHub #4 - Add example for time zone retrieval, command for getting …
…time zones
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
let huejay = require('../lib/Huejay'); | ||
let credentials = require('./.credentials.json'); | ||
|
||
let client = new huejay.Client(credentials.host, credentials.username); | ||
|
||
console.log('Retrieving supported time zones...'); | ||
|
||
client.getTimeZones() | ||
.then(timeZones => { | ||
console.log('Time Zones:'); | ||
for (let tz of timeZones) { | ||
console.log(` ${tz}`); | ||
} | ||
}) | ||
.catch(error => { | ||
console.log(error.stack); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Get time zones command | ||
* | ||
* Get a list of supported time zones | ||
*/ | ||
class GetTimeZones { | ||
/** | ||
* Invoke command | ||
* | ||
* @param {Client} client Client | ||
* | ||
* @return {Promise} Promise for chaining | ||
*/ | ||
invoke(client) { | ||
let options = { | ||
path: `api/${client.username}/info/timezones`, | ||
raw: true | ||
}; | ||
|
||
return client.getTransport() | ||
.sendRequest(options) | ||
.then(result => { | ||
return result; | ||
}); | ||
} | ||
} | ||
|
||
module.exports = GetTimeZones; |