Skip to content

Commit

Permalink
GitHub #4 - Add example for time zone retrieval, command for getting …
Browse files Browse the repository at this point in the history
…time zones
  • Loading branch information
sqmk committed Oct 24, 2015
1 parent f3fdecd commit d2d210b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
21 changes: 21 additions & 0 deletions examples/get-time-zones.js
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);
});
30 changes: 30 additions & 0 deletions lib/Command/GetTimeZones.js
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;

0 comments on commit d2d210b

Please sign in to comment.