Jelajahi Sumber

initial commit

Paul Molluzzo 9 tahun lalu
melakukan
317addd0af
9 mengubah file dengan 134 tambahan dan 0 penghapusan
  1. 4 0
      .babelrc
  2. 12 0
      .editorconfig
  3. 14 0
      .gitignore
  4. 1 0
      .npmignore
  5. 0 0
      .travis.yml
  6. 15 0
      README.md
  7. 47 0
      package.json
  8. 28 0
      src/hydrawise.js
  9. 13 0
      test/index.js

+ 4 - 0
.babelrc

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

+ 12 - 0
.editorconfig

@@ -0,0 +1,12 @@
+root = true
+
+[*]
+indent_style = space
+indent_size = 2
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[.md]
+insert_final_newline = false

+ 14 - 0
.gitignore

@@ -0,0 +1,14 @@
+.DS_Store
+
+# Logs
+logs
+*.log
+npm-debug.log*
+
+node_modules
+
+# Optional npm cache directory
+.npm
+
+# ignore the output lib
+lib

+ 1 - 0
.npmignore

@@ -0,0 +1 @@
+.npmignore

+ 0 - 0
.travis.yml


+ 15 - 0
README.md

@@ -0,0 +1,15 @@
+# Hydrawise API
+
+This is a client for the [Hydrawise](https://hydrawise.com/) API. Hydrawise is an internet-controlled home irrigation system.
+
+It provides access to the following endpoints:
+* Status Schedule
+* Customer Details
+* Set Controller
+* Set Zone
+
+------
+
+MIT
+
+©2016 Paul Molluzzo

+ 47 - 0
package.json

@@ -0,0 +1,47 @@
+{
+  "name": "hydrawise-api",
+  "version": "0.0.1",
+  "description": "Library for accessing the Hydrawise API",
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/paulmolluzzo/hydrawise-api.git"
+  },
+  "main": "lib/index.js",
+  "scripts": {
+    "build": "./node_modules/.bin/babel -d lib src/",
+    "test": "xo && ava",
+    "prepublish": "npm run build"
+  },
+  "keywords": [
+    "hydrawise",
+    "api"
+  ],
+  "author": "Paul Molluzzo (https://paul.molluzzo.com)",
+  "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": {
+    "esnext": true,
+    "envs": [
+      "browser"
+    ],
+    "rules": {
+      "new-cap": 0,
+      "camelcase": [0, {"properties": "always"}]
+    },
+    "ignores": ["lib/**"],
+    "space": true
+  },
+  "engines": {
+    "node": "4.4.0",
+    "npm": "3.8.0"
+  },
+  "dependencies": {
+    "request-promise": "^3.0.0"
+  }
+}

+ 28 - 0
src/hydrawise.js

@@ -0,0 +1,28 @@
+'use strict';
+
+import rp from 'request-promise';
+
+class Hydrawise {
+  constructor(key) {
+    this.url = 'https://hydrawise.com/api/v1/';
+    this.api_key = key;
+  }
+
+  request(method = 'GET', url = '', params = {}) {
+    const options = {
+      method,
+      uri: `${this.url}${url}.php`,
+      json: true
+    };
+
+    options.qs = {...params};
+    options.qs.api_key = this.api_key;
+    return rp(options);
+  }
+
+  customerdetails() {
+    return this.request('GET', 'customerdetails', {type: 'controllers'});
+  }
+}
+
+export default Hydrawise;

+ 13 - 0
test/index.js

@@ -0,0 +1,13 @@
+import test from 'ava';
+import Hydrawise from '../lib/hydrawise';
+
+const hydrawise = new Hydrawise('53DC-7E24-07E8-CD7D');
+
+test('Customer Details', t => {
+  return hydrawise.customerdetails().then(data => {
+    if (data.error_msg) {
+      t.fail(`Error: ${data.error_msg}`);
+    }
+    t.pass();
+  });
+});