hydrawise.js 754 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. import rp from '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 = {api_key: this.api_key, ...params};
  15. return rp(options);
  16. }
  17. customerdetails() {
  18. return this.request('GET', 'customerdetails', {type: 'controllers'});
  19. }
  20. statusschedule(tag = '', hours = '168') {
  21. return this.request('GET', 'statusschedule', {tag, hours});
  22. }
  23. setcontroller(controller_id) {
  24. return this.request('GET', 'setcontroller', {controller_id, json: true});
  25. }
  26. }
  27. export default Hydrawise;