1
0

index.js 923 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. const rp = require('request-promise');
  3. class Hydrawise {
  4. constructor(key) {
  5. this.url = 'https://hydrawise.com/api/v1/';
  6. this.api_key = key;
  7. }
  8. request(method = 'GET', url = '', params = {}) {
  9. const options = {
  10. method,
  11. uri: `${this.url}${url}.php`,
  12. json: true
  13. };
  14. options.qs = params;
  15. options.qs.api_key = this.api_key;
  16. return rp(options);
  17. }
  18. customerdetails() {
  19. return this.request('GET', 'customerdetails', {type: 'controllers'});
  20. }
  21. statusschedule(tag = '', hours = '168') {
  22. return this.request('GET', 'statusschedule', {tag, hours});
  23. }
  24. setcontroller(controllerid) {
  25. return this.request('GET', 'setcontroller', {controllerid, json: true});
  26. }
  27. setzone(action, params = {}) {
  28. params.action = action;
  29. return this.request('GET', 'setzone', params);
  30. }
  31. }
  32. module.exports = apiKey => {
  33. return new Hydrawise(apiKey);
  34. };