Browse Source

Upgrade to using Node 6 engine and removing babel prebuild processes

Paul Molluzzo 9 năm trước cách đây
mục cha
commit
bb6d4f6202
6 tập tin đã thay đổi với 30 bổ sung39 xóa
  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
 .npm
-
-# ignore the output lib
-lib

+ 8 - 8
README.md

@@ -13,8 +13,8 @@ It provides access to the following endpoints:
 ### Initial Setup
 
 ```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
@@ -22,7 +22,7 @@ const hydrawise = new Hydrawise(YOUR_API_KEY);
 Get cusetomer info.
 
 ```js
-hydrawise.customerdetails()
+myHydrawise.customerdetails()
   .then(data => console.log(data))
   .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.
 
 ```js
-hydrawise.statusschedule()
+myHydrawise.statusschedule()
   .then(data => console.log(data))
   .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?_**
 
 ```js
-hydrawise.setcontroller(controller_id)
+myHydrawise.setcontroller(controller_id)
   .then()
   .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
 // 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))
   .catch(error => console.log(error));
 
 // stop all
-hydrawise.setzone('stopall')
+myHydrawise.setzone('stopall')
   .then(data => console.log(data))
   .catch(error => console.log(error));
 
 // 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))
   .catch(error => console.log(error));
 ```

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

@@ -1,6 +1,6 @@
 'use strict';
 
-import rp from 'request-promise';
+const rp = require('request-promise');
 
 class Hydrawise {
   constructor(key) {
@@ -15,7 +15,8 @@ class Hydrawise {
       json: true
     };
 
-    options.qs = {api_key: this.api_key, ...params};
+    options.qs = params;
+    options.qs.api_key = this.api_key;
     return rp(options);
   }
 
@@ -31,9 +32,12 @@ class Hydrawise {
     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",
-  "version": "0.0.1",
+  "version": "0.1.0",
   "description": "Library for accessing the Hydrawise API",
   "repository": {
     "type": "git",
     "url": "https://github.com/paulmolluzzo/hydrawise-api.git"
   },
-  "main": "lib/index.js",
+  "main": "index.js",
   "scripts": {
-    "build": "./node_modules/.bin/babel -d lib src/",
-    "test": "xo && ava",
-    "prepublish": "npm run build"
+    "test": "xo && ava"
   },
   "keywords": [
     "hydrawise",
@@ -21,9 +19,6 @@
   "license": "MIT",
   "devDependencies": {
     "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": {
@@ -35,11 +30,10 @@
       "new-cap": 0,
       "camelcase": [0, {"properties": "always"}]
     },
-    "ignores": ["lib/**"],
     "space": true
   },
   "engines": {
-    "node": "4.4.0",
+    "node": ">=6.0.0",
     "npm": "3.8.0"
   },
   "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 => {
-  return hydrawise.customerdetails().then(data => {
+  return h.customerdetails().then(data => {
     if (data.error_msg) {
       t.fail(`Error: ${data.error_msg}`);
     }
@@ -13,7 +13,7 @@ test('Customer Details', t => {
 });
 
 test('Status Schedule', t => {
-  return hydrawise.statusschedule().then(data => {
+  return h.statusschedule().then(data => {
     if (data.error_msg) {
       t.fail(`Error: ${data.error_msg}`);
     }
@@ -22,7 +22,7 @@ test('Status Schedule', t => {
 });
 
 test('Status Schedule All', t => {
-  return hydrawise.statusschedule('hydrawise_all').then(data => {
+  return h.statusschedule('hydrawise_all').then(data => {
     if (data.error_msg) {
       t.fail(`Error: ${data.error_msg}`);
     }
@@ -31,13 +31,13 @@ test('Status Schedule All', t => {
 });
 
 test('Set Controller', t => {
-  return hydrawise.setcontroller('11774').then(() => {
+  return h.setcontroller('11774').then(() => {
     t.pass();
   });
 });
 
 test('Stop Zones', t => {
-  return hydrawise.setzone('stopall').then(data => {
+  return h.setzone('stopall').then(data => {
     if (data.message_type === 'error') {
       t.fail(`Error: ${data.message}`);
     }
@@ -46,7 +46,7 @@ test('Stop 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') {
       t.fail(`Error: ${data.message}`);
     }