1
0
Эх сурвалжийг харах

Upgrade to using Node 6 engine and removing babel prebuild processes

Paul Molluzzo 9 жил өмнө
parent
commit
bb6d4f6202
6 өөрчлөгдсөн 30 нэмэгдсэн , 39 устгасан
  1. 0 4
      .babelrc
  2. 0 3
      .gitignore
  3. 8 8
      README.md
  4. 9 5
      index.js
  5. 4 10
      package.json
  6. 9 9
      test/index.js

+ 0 - 4
.babelrc

@@ -1,4 +0,0 @@
-{
-  "presets": ["es2015", "stage-2"],
-  "plugins": []
-}

+ 0 - 3
.gitignore

@@ -9,6 +9,3 @@ node_modules
 
 
 # Optional npm cache directory
 # Optional npm cache directory
 .npm
 .npm
-
-# ignore the output lib
-lib

+ 8 - 8
README.md

@@ -13,8 +13,8 @@ It provides access to the following endpoints:
 ### Initial Setup
 ### Initial Setup
 
 
 ```js
 ```js
-import Hydrawise from 'hydrawise-api';
-const hydrawise = new Hydrawise(YOUR_API_KEY);
+const Hydrawise = require('hydrawise-api');
+const myHydrawise = Hydrawise(YOUR_API_KEY);
 ```
 ```
 
 
 ### Customer Details
 ### Customer Details
@@ -22,7 +22,7 @@ const hydrawise = new Hydrawise(YOUR_API_KEY);
 Get cusetomer info.
 Get cusetomer info.
 
 
 ```js
 ```js
-hydrawise.customerdetails()
+myHydrawise.customerdetails()
   .then(data => console.log(data))
   .then(data => console.log(data))
   .catch(error => console.log(error));
   .catch(error => console.log(error));
 ```
 ```
@@ -32,7 +32,7 @@ hydrawise.customerdetails()
 Get the status of a controller. You can pass the param `hydrawise_all` or a specific tag or leave empty for the current controller. The second parameter is how far in advance (in hours) you want to get the schedule, and it will default to the maximum of 168.
 Get the status of a controller. You can pass the param `hydrawise_all` or a specific tag or leave empty for the current controller. The second parameter is how far in advance (in hours) you want to get the schedule, and it will default to the maximum of 168.
 
 
 ```js
 ```js
-hydrawise.statusschedule()
+myHydrawise.statusschedule()
   .then(data => console.log(data))
   .then(data => console.log(data))
   .catch(error => console.log(error));
   .catch(error => console.log(error));
 ```
 ```
@@ -44,7 +44,7 @@ Set a controller for controller-specific commands.
 **_Note: This endpoint seems to not respond with any data, so a non-error is a "pass" I guess?_**
 **_Note: This endpoint seems to not respond with any data, so a non-error is a "pass" I guess?_**
 
 
 ```js
 ```js
-hydrawise.setcontroller(controller_id)
+myHydrawise.setcontroller(controller_id)
   .then()
   .then()
   .catch(error => console.log(error));
   .catch(error => console.log(error));
 ```
 ```
@@ -55,17 +55,17 @@ This is how you set a zone to run, suspend, or stop. The params are an action an
 
 
 ```js
 ```js
 // run all for 10 minutes
 // run all for 10 minutes
-hydrawise.setzone('runall', {period_id: '666', custom: '600'})
+myHydrawise.setzone('runall', {period_id: '666', custom: '600'})
   .then(data => console.log(data))
   .then(data => console.log(data))
   .catch(error => console.log(error));
   .catch(error => console.log(error));
 
 
 // stop all
 // stop all
-hydrawise.setzone('stopall')
+myHydrawise.setzone('stopall')
   .then(data => console.log(data))
   .then(data => console.log(data))
   .catch(error => console.log(error));
   .catch(error => console.log(error));
 
 
 // run zone for 5 minutes
 // run zone for 5 minutes
-hydrawise.setzone('run', {period_id: '123', custom: '300', relay_id: your_relay_id})
+myHydrawise.setzone('run', {period_id: '123', custom: '300', relay_id: your_relay_id})
   .then(data => console.log(data))
   .then(data => console.log(data))
   .catch(error => console.log(error));
   .catch(error => console.log(error));
 ```
 ```

+ 9 - 5
src/hydrawise.js → index.js

@@ -1,6 +1,6 @@
 'use strict';
 'use strict';
 
 
-import rp from 'request-promise';
+const rp = require('request-promise');
 
 
 class Hydrawise {
 class Hydrawise {
   constructor(key) {
   constructor(key) {
@@ -15,7 +15,8 @@ class Hydrawise {
       json: true
       json: true
     };
     };
 
 
-    options.qs = {api_key: this.api_key, ...params};
+    options.qs = params;
+    options.qs.api_key = this.api_key;
     return rp(options);
     return rp(options);
   }
   }
 
 
@@ -31,9 +32,12 @@ class Hydrawise {
     return this.request('GET', 'setcontroller', {controllerid, json: true});
     return this.request('GET', 'setcontroller', {controllerid, json: true});
   }
   }
 
 
-  setzone(action, params) {
-    return this.request('GET', 'setzone', {action, ...params});
+  setzone(action, params = {}) {
+    params.action = action;
+    return this.request('GET', 'setzone', params);
   }
   }
 }
 }
 
 
-export default Hydrawise;
+module.exports = apiKey => {
+  return new Hydrawise(apiKey);
+};

+ 4 - 10
package.json

@@ -1,16 +1,14 @@
 {
 {
   "name": "hydrawise-api",
   "name": "hydrawise-api",
-  "version": "0.0.1",
+  "version": "0.1.0",
   "description": "Library for accessing the Hydrawise API",
   "description": "Library for accessing the Hydrawise API",
   "repository": {
   "repository": {
     "type": "git",
     "type": "git",
     "url": "https://github.com/paulmolluzzo/hydrawise-api.git"
     "url": "https://github.com/paulmolluzzo/hydrawise-api.git"
   },
   },
-  "main": "lib/index.js",
+  "main": "index.js",
   "scripts": {
   "scripts": {
-    "build": "./node_modules/.bin/babel -d lib src/",
-    "test": "xo && ava",
-    "prepublish": "npm run build"
+    "test": "xo && ava"
   },
   },
   "keywords": [
   "keywords": [
     "hydrawise",
     "hydrawise",
@@ -21,9 +19,6 @@
   "license": "MIT",
   "license": "MIT",
   "devDependencies": {
   "devDependencies": {
     "ava": "^0.14.0",
     "ava": "^0.14.0",
-    "babel-cli": "^6.8.0",
-    "babel-preset-es2015": "^6.6.0",
-    "babel-preset-stage-2": "^6.5.0",
     "xo": "^0.15.0"
     "xo": "^0.15.0"
   },
   },
   "xo": {
   "xo": {
@@ -35,11 +30,10 @@
       "new-cap": 0,
       "new-cap": 0,
       "camelcase": [0, {"properties": "always"}]
       "camelcase": [0, {"properties": "always"}]
     },
     },
-    "ignores": ["lib/**"],
     "space": true
     "space": true
   },
   },
   "engines": {
   "engines": {
-    "node": "4.4.0",
+    "node": ">=6.0.0",
     "npm": "3.8.0"
     "npm": "3.8.0"
   },
   },
   "dependencies": {
   "dependencies": {

+ 9 - 9
test/index.js

@@ -1,10 +1,10 @@
-import test from 'ava';
-import Hydrawise from '../lib/hydrawise';
+const test = require('ava');
+const hydrawise = require('../index');
 
 
-const hydrawise = new Hydrawise('53DC-7E24-07E8-CD7D');
+const h = hydrawise('53DC-7E24-07E8-CD7D');
 
 
 test('Customer Details', t => {
 test('Customer Details', t => {
-  return hydrawise.customerdetails().then(data => {
+  return h.customerdetails().then(data => {
     if (data.error_msg) {
     if (data.error_msg) {
       t.fail(`Error: ${data.error_msg}`);
       t.fail(`Error: ${data.error_msg}`);
     }
     }
@@ -13,7 +13,7 @@ test('Customer Details', t => {
 });
 });
 
 
 test('Status Schedule', t => {
 test('Status Schedule', t => {
-  return hydrawise.statusschedule().then(data => {
+  return h.statusschedule().then(data => {
     if (data.error_msg) {
     if (data.error_msg) {
       t.fail(`Error: ${data.error_msg}`);
       t.fail(`Error: ${data.error_msg}`);
     }
     }
@@ -22,7 +22,7 @@ test('Status Schedule', t => {
 });
 });
 
 
 test('Status Schedule All', t => {
 test('Status Schedule All', t => {
-  return hydrawise.statusschedule('hydrawise_all').then(data => {
+  return h.statusschedule('hydrawise_all').then(data => {
     if (data.error_msg) {
     if (data.error_msg) {
       t.fail(`Error: ${data.error_msg}`);
       t.fail(`Error: ${data.error_msg}`);
     }
     }
@@ -31,13 +31,13 @@ test('Status Schedule All', t => {
 });
 });
 
 
 test('Set Controller', t => {
 test('Set Controller', t => {
-  return hydrawise.setcontroller('11774').then(() => {
+  return h.setcontroller('11774').then(() => {
     t.pass();
     t.pass();
   });
   });
 });
 });
 
 
 test('Stop Zones', t => {
 test('Stop Zones', t => {
-  return hydrawise.setzone('stopall').then(data => {
+  return h.setzone('stopall').then(data => {
     if (data.message_type === 'error') {
     if (data.message_type === 'error') {
       t.fail(`Error: ${data.message}`);
       t.fail(`Error: ${data.message}`);
     }
     }
@@ -46,7 +46,7 @@ test('Stop Zones', t => {
 });
 });
 
 
 test('Run All Zones', t => {
 test('Run All Zones', t => {
-  return hydrawise.setzone('runall', {period_id: '999', custom: '60'}).then(data => {
+  return h.setzone('runall', {period_id: '999', custom: '60'}).then(data => {
     if (data.message_type === 'error') {
     if (data.message_type === 'error') {
       t.fail(`Error: ${data.message}`);
       t.fail(`Error: ${data.message}`);
     }
     }