diff --git a/.idea/misc.xml b/.idea/misc.xml
index eabe228..28a804d 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -3,14 +3,4 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index ad25c92..811b234 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,72 +1,127 @@
-
-
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+ noConflict
+ reqCountMap
+ timeout
+ config
+
+ _resolveFromExecutor
+ promiseFromYieldHandler
+ PromiseSpawn
+ tryConvertToPromise
+ reduceReqCountFn
+ onAfter
+ timeOffset
+ getToken
+ const
+ let
+ get customerData should be success
+ token
+
+
+ onAfterHandle
+ var
+
+
+ $PROJECT_DIR$/node_modules
+
+
+
+
+
+
+
+
+
-
-
+
+
true
+ DEFINITION_ORDER
-
-
-
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
-
-
+
+
+
+
+
+
+
+
+
+
-
+
@@ -189,12 +223,6 @@
-
-
-
-
-
-
@@ -202,28 +230,117 @@
-
-
-
-
-
+ project
+
+
+
+
-
+
+ node
$PROJECT_DIR$
true
-
bdd
DIRECTORY
false
-
+
+
+
+ node
+
+ $PROJECT_DIR$
+ true
+ bdd
+
+ SUITE
+ $PROJECT_DIR$/test/auth.test.js
+
+
+
+
+
+ node
+
+ $PROJECT_DIR$
+ true
+ bdd
+
+ SUITE
+ $PROJECT_DIR$/test/request.test.js
+
+
+
+
+
+
+
+ node
+
+ $PROJECT_DIR$
+ true
+ bdd
+
+ SUITE
+ $PROJECT_DIR$/test/request.test.js
+
+
+
+
+
+
+
+ node
+
+ $PROJECT_DIR$
+ true
+ bdd
+
+ TEST
+ $PROJECT_DIR$/test/request.test.js
+
+
+
+
+
+
+
+ node
+
+ $PROJECT_DIR$
+ true
+ bdd
+
+ TEST
+ $PROJECT_DIR$/test/request.test.js
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
@@ -232,32 +349,429 @@
1466654777532
+
1466654777532
+
+
+
+
+
+ 1543374846281
+
+
+
+ 1543374846281
+
+
+ 1543374869339
+
+
+
+ 1543374869339
+
+
+ 1543375027395
+
+
+
+ 1543375027395
+
+
+ 1543817267924
+
+
+
+ 1543817267924
+
+
+ 1543831752697
+
+
+
+ 1543831752697
+
+
+ 1543831779293
+
+
+
+ 1543831779293
+
+
+ 1543831853819
+
+
+
+ 1543831853819
+
+
+ 1543831882307
+
+
+
+ 1543831882307
+
+
+ 1543832647138
+
+
+
+ 1543832647138
+
+
+ 1543837431526
+
+
+
+ 1543837431526
+
+
+ 1543837659419
+
+
+
+ 1543837659419
+
+
+ 1543838725738
+
+
+
+ 1543838725738
+
+
+ 1543838750258
+
+
+
+ 1543838750258
+
+
+ 1543838774935
+
+
+
+ 1543838774935
+
+
+ 1543839825971
+
+
+
+ 1543839825971
+
+
+ 1543895463933
+
+
+
+ 1543895463933
+
+
+ 1543895548009
+
+
+
+ 1543895548009
+
+
+ 1543895727667
+
+
+
+ 1543895727667
+
+
+ 1543896248520
+
+
+
+ 1543896248520
+
+
+ 1543903958914
+
+
+
+ 1543903958914
+
+
+ 1543904306526
+
+
+
+ 1543904306526
+
+
+ 1543904358411
+
+
+
+ 1543904358411
+
+
+ 1543911134183
+
+
+
+ 1543911134183
+
+ 1543914494250
+
+
+
+ 1543914494250
+
+
+ 1543914634478
+
+
+
+ 1543914634479
+
+
+ 1543914946377
+
+
+
+ 1543914946377
+
+
+ 1543914972403
+
+
+
+ 1543914972403
+
+
+ 1543915815169
+
+
+
+ 1543915815169
+
+
+ 1543916019381
+
+
+
+ 1543916019381
+
+
+ 1543916084412
+
+
+
+ 1543916084412
+
+
+ 1543916173007
+
+
+
+ 1543916173007
+
+
+ 1543916353502
+
+
+
+ 1543916353502
+
+
+ 1543917077738
+
+
+
+ 1543917077738
+
+
+ 1543917534283
+
+
+
+ 1543917534284
+
+
+ 1543917693899
+
+
+
+ 1543917693899
+
+
+ 1543919077301
+
+
+
+ 1543919077301
+
+
+ 1543919093902
+
+
+
+ 1543919093902
+
+
+ 1543919112686
+
+
+
+ 1543919112686
+
+
+ 1543919162387
+
+
+
+ 1543919162387
+
+
+ 1543930370273
+
+
+
+ 1543930370273
+
+
+ 1543930385708
+
+
+
+ 1543930385708
+
+
+ 1543977124118
+
+
+
+ 1543977124118
+
+
+ 1544000990085
+
+
+
+ 1544000990085
+
+
+ 1544001025467
+
+
+
+ 1544001025467
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -270,96 +784,211 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
+
+
-
+
-
-
-
+
+
-
+
+
+
+
+
-
-
-
+
+
-
+
+
+
+
+
+
-
-
-
+
+
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
+
+
-
+
-
-
-
+
+
diff --git a/README.md b/README.md
index 22cd27e..920ebc3 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,8 @@
# yhsd-api-node
-友好速搭 API SDK for Node
+友好速搭 API SDK for Node(v4.9.1)
+支持`Promise`依赖[bluebird](https://github.com/petkaantonov/bluebird)。
+
[![Build status](https://img.shields.io/travis/yeezon/yhsd-api-node.svg?style=flat-square)](https://travis-ci.org/yeezon/yhsd-api-node)
[![Coverage Status](https://img.shields.io/coveralls/yeezon/yhsd-api-node.svg?style=flat-square)](https://coveralls.io/repos/yeezon/yhsd-api-node)
@@ -20,22 +22,22 @@ var Yhsd = require('yhsd-api');
/**
* 初始化
- * @param {Object} options
+ * @param {object} options
+ * @param {string} options.appKey 应用的appKey
+ * @param {string} options.appSecret 应用的appSecret
+ * @param {string} options.callbackUrl 用于开放应用,应用管理后台设置的回调地址
+ * @param {string} options.redirectUrl 用于开放应用,可选,自定义回调地址,默认同 callbackUrl
+ * @param {Array} options.scope 用于开放应用,可选,权限范围,默认为 ['read_basic']
+ * @param {Boolean} options.private 可选,是否为私有应用,默认为 false
+ * @param {string} options.protocol 可选,'http'或者'https',默认'https'
+ * @param {string} options.host 可选,授权接口域名,默认'apps.youhaosuda.com'
* @constructor
- *
- * options 可选值:
- * appKey {string} 应用的appKey
- * appSecret {string} 应用的appSecret
- * callbackUrl {string} 用于开放应用,应用管理后台设置的回调地址
- * redirectUrl {string} 用于开放应用,可选,自定义回调地址,默认同 callbackUrl
- * scope {Array} 用于开放应用,可选,权限范围,默认为 ['read_basic']
- * private {boolean} 可选,是否为私有应用,默认为 false
*/
var auth = new Yhsd.Auth(options);
/**
* 验证 Hmac
- * @param {Object} queryObj 回调地址的参数对象
+ * @param {object} queryObj 回调地址的参数对象
* @return {boolean}
*/
auth.verifyHmac(queryObj);
@@ -51,9 +53,9 @@ auth.getAuthorizeUrl(shopKey, state);
/**
* 获取 token
* @param {string} [code],用于开放应用
- * @param {Function} callback(err, token)
+ * @returns {Object}
*/
-auth.getToken(code, callback);
+auth.getToken(code);
```
详见
@@ -66,10 +68,10 @@ var Yhsd = require('yhsd-api');
var auth = new Yhsd.Auth({
appKey: '8fce436b6fe74d5c8e2317**********',
appSecret: '3c91e9bd912145de953e0d**********',
- private: true
+ private: true
});
-auth.getToken(function(err, token) {
- console.log(token);
+auth.getToken().then(function (token) {
+ console.log(token);
});
```
@@ -81,6 +83,11 @@ var Yhsd = require('yhsd-api');
/**
* 初始化
* @param {string} token
+ * @param {object} option
+ * @param {string} option.protocol 可选,'http'或者'https',默认'https'
+ * @param {string} option.host 可选,开发 API 接口域名,默认'api.youhaosuda.com'
+ * @param {function} option.getRequestCount 获取请求数函数
+ * @param {function} option.saveRequestCount 存储请求数函数
* @constructor
*/
var api = new Yhsd.Api(token);
@@ -88,33 +95,33 @@ var api = new Yhsd.Api(token);
/**
* 发送 GET 请求
* @param {string} path
- * @param {Object} [query]
- * @param {Function} callback(err, data)
+ * @param {object} [query]
+ * @returns {Object}
*/
-api.get(path, query, callback);
+api.get(path, query);
/**
* 发送 PUT 请求
* @param {string} path
- * @param {Object} data
- * @param {Function} callback
+ * @param {object} data
+ * @returns {Object}
*/
-api.put(path, data, callback);
+api.put(path, data);
/**
* 发送 POST 请求
* @param {string} path
- * @param {Object} data
- * @param {Function} callback
+ * @param {object} data
+ * @returns {Object}
*/
-api.post(path, data, callback);
+api.post(path, data);
/**
* 发送 DELETE 请求
* @param {string} path
- * @param {Function} callback
+ * @returns {Object}
*/
-api.delete(path, callback);
+api.delete(path);
```
详见
@@ -124,13 +131,22 @@ https://docs.youhaosuda.com/app/553e335f0abc3e6f3e000023
```javascript
var Yhsd = require('yhsd-api');
-var api = new Yhsd.Api('2be799bf87144c2fbb881a**********');
+var reqCountMap = {};
+var api = new Yhsd.Api('2be799bf87144c2fbb881a**********',{
+ getRequestCount: function (token){
+ return reqCountMap[token];
+ },
+ saveRequestCount: function (token, count){
+ reqCountMap[token] = count;
+ return count;
+ }
+});
// 获取顾客列表
-api.get('customers', { fields: 'id,name' }, function(err, data) {
+api.get('customers', { fields: 'id,name' }).then(function (data) {
console.log(data);
});
// 获取指定顾客
-api.get('customers/100', function(err, data) {
+api.get('customers/100').then(function (data) {
console.log(data);
});
```
diff --git a/coverage/coverage.json b/coverage/coverage.json
index e53ff79..00a3d61 100644
--- a/coverage/coverage.json
+++ b/coverage/coverage.json
@@ -1 +1 @@
-{"/Users/calvin/source/yeezon/yhsd-api-node/index.js":{"path":"/Users/calvin/source/yeezon/yhsd-api-node/index.js","s":{"1":1},"b":{},"f":{},"fnMap":{},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":6,"column":2}}},"branchMap":{}},"/Users/calvin/source/yeezon/yhsd-api-node/lib/config.js":{"path":"/Users/calvin/source/yeezon/yhsd-api-node/lib/config.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":4,"7":0,"8":4,"9":0,"10":4,"11":0,"12":0,"13":1,"14":1},"b":{"1":[0,4],"2":[0,4],"3":[0,4]},"f":{"1":4},"fnMap":{"1":{"name":"(anonymous_1)","line":6,"loc":{"start":{"line":6,"column":21},"end":{"line":6,"column":42}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":36}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":35}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":28}},"4":{"start":{"line":4,"column":0},"end":{"line":4,"column":27}},"5":{"start":{"line":6,"column":0},"end":{"line":17,"column":3}},"6":{"start":{"line":7,"column":2},"end":{"line":9,"column":3}},"7":{"start":{"line":8,"column":4},"end":{"line":8,"column":38}},"8":{"start":{"line":10,"column":2},"end":{"line":12,"column":3}},"9":{"start":{"line":11,"column":4},"end":{"line":11,"column":38}},"10":{"start":{"line":13,"column":2},"end":{"line":16,"column":3}},"11":{"start":{"line":14,"column":4},"end":{"line":14,"column":27}},"12":{"start":{"line":15,"column":4},"end":{"line":15,"column":26}},"13":{"start":{"line":20,"column":0},"end":{"line":26,"column":2}},"14":{"start":{"line":27,"column":0},"end":{"line":27,"column":24}}},"branchMap":{"1":{"line":7,"type":"if","locations":[{"start":{"line":7,"column":2},"end":{"line":7,"column":2}},{"start":{"line":7,"column":2},"end":{"line":7,"column":2}}]},"2":{"line":10,"type":"if","locations":[{"start":{"line":10,"column":2},"end":{"line":10,"column":2}},{"start":{"line":10,"column":2},"end":{"line":10,"column":2}}]},"3":{"line":13,"type":"if","locations":[{"start":{"line":13,"column":2},"end":{"line":13,"column":2}},{"start":{"line":13,"column":2},"end":{"line":13,"column":2}}]}}},"/Users/calvin/source/yeezon/yhsd-api-node/lib/Auth.js":{"path":"/Users/calvin/source/yeezon/yhsd-api-node/lib/Auth.js","s":{"1":1,"2":1,"3":12,"4":1,"5":11,"6":8,"7":1,"8":7,"9":10,"10":1,"11":2,"12":1,"13":1,"14":1,"15":1,"16":2,"17":1,"18":1,"19":5,"20":5,"21":3,"22":1,"23":2,"24":2,"25":2,"26":2,"27":1,"28":1,"29":3,"30":3,"31":0,"32":3,"33":2,"34":1,"35":0,"36":1,"37":1,"38":1,"39":1,"40":1,"41":1},"b":{"1":[1,11],"2":[12,12,12],"3":[8,3],"4":[1,7],"5":[7,7],"6":[1,1],"7":[1,0],"8":[1,1],"9":[3,2],"10":[1,2],"11":[1,1],"12":[0,1],"13":[0,3],"14":[2,1],"15":[0,1]},"f":{"1":12,"2":2,"3":2,"4":5,"5":3,"6":1},"fnMap":{"1":{"name":"(anonymous_1)","line":21,"loc":{"start":{"line":21,"column":11},"end":{"line":21,"column":30}}},"2":{"name":"(anonymous_2)","line":40,"loc":{"start":{"line":40,"column":16},"end":{"line":40,"column":36}}},"3":{"name":"(anonymous_3)","line":57,"loc":{"start":{"line":57,"column":21},"end":{"line":57,"column":47}}},"4":{"name":"(anonymous_4)","line":75,"loc":{"start":{"line":75,"column":14},"end":{"line":75,"column":40}}},"5":{"name":"(anonymous_5)","line":103,"loc":{"start":{"line":103,"column":19},"end":{"line":103,"column":40}}},"6":{"name":"(anonymous_6)","line":118,"loc":{"start":{"line":118,"column":18},"end":{"line":118,"column":55}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":6,"column":35}},"2":{"start":{"line":21,"column":0},"end":{"line":32,"column":2}},"3":{"start":{"line":22,"column":4},"end":{"line":24,"column":5}},"4":{"start":{"line":23,"column":8},"end":{"line":23,"column":25}},"5":{"start":{"line":25,"column":4},"end":{"line":30,"column":5}},"6":{"start":{"line":26,"column":8},"end":{"line":28,"column":9}},"7":{"start":{"line":27,"column":12},"end":{"line":27,"column":29}},"8":{"start":{"line":29,"column":8},"end":{"line":29,"column":58}},"9":{"start":{"line":31,"column":4},"end":{"line":31,"column":27}},"10":{"start":{"line":34,"column":0},"end":{"line":124,"column":2}},"11":{"start":{"line":41,"column":8},"end":{"line":43,"column":9}},"12":{"start":{"line":42,"column":12},"end":{"line":42,"column":29}},"13":{"start":{"line":44,"column":8},"end":{"line":44,"column":33}},"14":{"start":{"line":45,"column":8},"end":{"line":45,"column":29}},"15":{"start":{"line":46,"column":8},"end":{"line":49,"column":32}},"16":{"start":{"line":58,"column":8},"end":{"line":60,"column":9}},"17":{"start":{"line":59,"column":12},"end":{"line":59,"column":29}},"18":{"start":{"line":61,"column":8},"end":{"line":68,"column":55}},"19":{"start":{"line":76,"column":8},"end":{"line":77,"column":76}},"20":{"start":{"line":78,"column":8},"end":{"line":97,"column":9}},"21":{"start":{"line":79,"column":12},"end":{"line":81,"column":13}},"22":{"start":{"line":80,"column":16},"end":{"line":80,"column":33}},"23":{"start":{"line":82,"column":12},"end":{"line":82,"column":36}},"24":{"start":{"line":83,"column":12},"end":{"line":83,"column":129}},"25":{"start":{"line":84,"column":12},"end":{"line":86,"column":14}},"26":{"start":{"line":88,"column":12},"end":{"line":90,"column":13}},"27":{"start":{"line":89,"column":16},"end":{"line":89,"column":33}},"28":{"start":{"line":91,"column":12},"end":{"line":96,"column":14}},"29":{"start":{"line":98,"column":8},"end":{"line":116,"column":11}},"30":{"start":{"line":104,"column":12},"end":{"line":106,"column":13}},"31":{"start":{"line":105,"column":15},"end":{"line":105,"column":36}},"32":{"start":{"line":108,"column":12},"end":{"line":110,"column":13}},"33":{"start":{"line":109,"column":15},"end":{"line":109,"column":43}},"34":{"start":{"line":112,"column":12},"end":{"line":114,"column":13}},"35":{"start":{"line":113,"column":16},"end":{"line":113,"column":45}},"36":{"start":{"line":115,"column":12},"end":{"line":115,"column":39}},"37":{"start":{"line":119,"column":8},"end":{"line":119,"column":57}},"38":{"start":{"line":120,"column":8},"end":{"line":120,"column":68}},"39":{"start":{"line":121,"column":8},"end":{"line":121,"column":65}},"40":{"start":{"line":122,"column":8},"end":{"line":122,"column":35}},"41":{"start":{"line":127,"column":0},"end":{"line":127,"column":22}}},"branchMap":{"1":{"line":22,"type":"if","locations":[{"start":{"line":22,"column":4},"end":{"line":22,"column":4}},{"start":{"line":22,"column":4},"end":{"line":22,"column":4}}]},"2":{"line":22,"type":"binary-expr","locations":[{"start":{"line":22,"column":8},"end":{"line":22,"column":28}},{"start":{"line":22,"column":32},"end":{"line":22,"column":47}},{"start":{"line":22,"column":51},"end":{"line":22,"column":69}}]},"3":{"line":25,"type":"if","locations":[{"start":{"line":25,"column":4},"end":{"line":25,"column":4}},{"start":{"line":25,"column":4},"end":{"line":25,"column":4}}]},"4":{"line":26,"type":"if","locations":[{"start":{"line":26,"column":8},"end":{"line":26,"column":8}},{"start":{"line":26,"column":8},"end":{"line":26,"column":8}}]},"5":{"line":29,"type":"binary-expr","locations":[{"start":{"line":29,"column":8},"end":{"line":29,"column":21}},{"start":{"line":29,"column":26},"end":{"line":29,"column":56}}]},"6":{"line":41,"type":"if","locations":[{"start":{"line":41,"column":8},"end":{"line":41,"column":8}},{"start":{"line":41,"column":8},"end":{"line":41,"column":8}}]},"7":{"line":46,"type":"binary-expr","locations":[{"start":{"line":46,"column":16},"end":{"line":46,"column":81}},{"start":{"line":47,"column":13},"end":{"line":49,"column":30}}]},"8":{"line":58,"type":"if","locations":[{"start":{"line":58,"column":8},"end":{"line":58,"column":8}},{"start":{"line":58,"column":8},"end":{"line":58,"column":8}}]},"9":{"line":78,"type":"if","locations":[{"start":{"line":78,"column":8},"end":{"line":78,"column":8}},{"start":{"line":78,"column":8},"end":{"line":78,"column":8}}]},"10":{"line":79,"type":"if","locations":[{"start":{"line":79,"column":12},"end":{"line":79,"column":12}},{"start":{"line":79,"column":12},"end":{"line":79,"column":12}}]},"11":{"line":88,"type":"if","locations":[{"start":{"line":88,"column":12},"end":{"line":88,"column":12}},{"start":{"line":88,"column":12},"end":{"line":88,"column":12}}]},"12":{"line":95,"type":"cond-expr","locations":[{"start":{"line":95,"column":57},"end":{"line":95,"column":81}},{"start":{"line":95,"column":84},"end":{"line":95,"column":108}}]},"13":{"line":104,"type":"if","locations":[{"start":{"line":104,"column":12},"end":{"line":104,"column":12}},{"start":{"line":104,"column":12},"end":{"line":104,"column":12}}]},"14":{"line":108,"type":"if","locations":[{"start":{"line":108,"column":12},"end":{"line":108,"column":12}},{"start":{"line":108,"column":12},"end":{"line":108,"column":12}}]},"15":{"line":112,"type":"if","locations":[{"start":{"line":112,"column":12},"end":{"line":112,"column":12}},{"start":{"line":112,"column":12},"end":{"line":112,"column":12}}]}}},"/Users/calvin/source/yeezon/yhsd-api-node/lib/request.js":{"path":"/Users/calvin/source/yeezon/yhsd-api-node/lib/request.js","s":{"1":1,"2":4,"3":1,"4":10,"5":0,"6":0,"7":10,"8":10,"9":10,"10":10,"11":10,"12":10,"13":10,"14":0,"15":10,"16":10,"17":10,"18":10,"19":10,"20":0,"21":10,"22":6,"23":6,"24":3,"25":3,"26":3,"27":3,"28":6,"29":10,"30":1},"b":{"1":[0,10],"2":[6,4],"3":[3,3],"4":[6,6],"5":[2,3]},"f":{"1":4,"2":10,"3":10,"4":10,"5":10,"6":0},"fnMap":{"1":{"name":"(anonymous_1)","line":4,"loc":{"start":{"line":4,"column":25},"end":{"line":4,"column":36}}},"2":{"name":"(anonymous_2)","line":8,"loc":{"start":{"line":8,"column":14},"end":{"line":8,"column":50}}},"3":{"name":"(anonymous_3)","line":14,"loc":{"start":{"line":14,"column":41},"end":{"line":14,"column":55}}},"4":{"name":"(anonymous_4)","line":16,"loc":{"start":{"line":16,"column":18},"end":{"line":16,"column":29}}},"5":{"name":"(anonymous_5)","line":27,"loc":{"start":{"line":27,"column":19},"end":{"line":27,"column":34}}},"6":{"name":"(anonymous_6)","line":30,"loc":{"start":{"line":30,"column":20},"end":{"line":30,"column":34}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":6,"column":4}},"2":{"start":{"line":5,"column":4},"end":{"line":5,"column":19}},"3":{"start":{"line":8,"column":0},"end":{"line":49,"column":2}},"4":{"start":{"line":9,"column":2},"end":{"line":12,"column":3}},"5":{"start":{"line":10,"column":4},"end":{"line":10,"column":56}},"6":{"start":{"line":11,"column":4},"end":{"line":11,"column":11}},"7":{"start":{"line":13,"column":2},"end":{"line":13,"column":17}},"8":{"start":{"line":14,"column":2},"end":{"line":33,"column":5}},"9":{"start":{"line":15,"column":4},"end":{"line":15,"column":17}},"10":{"start":{"line":16,"column":4},"end":{"line":26,"column":7}},"11":{"start":{"line":17,"column":6},"end":{"line":17,"column":47}},"12":{"start":{"line":18,"column":6},"end":{"line":24,"column":7}},"13":{"start":{"line":19,"column":8},"end":{"line":19,"column":32}},"14":{"start":{"line":21,"column":8},"end":{"line":21,"column":22}},"15":{"start":{"line":23,"column":8},"end":{"line":23,"column":118}},"16":{"start":{"line":25,"column":6},"end":{"line":25,"column":27}},"17":{"start":{"line":27,"column":4},"end":{"line":29,"column":7}},"18":{"start":{"line":28,"column":6},"end":{"line":28,"column":21}},"19":{"start":{"line":30,"column":4},"end":{"line":32,"column":7}},"20":{"start":{"line":31,"column":6},"end":{"line":31,"column":20}},"21":{"start":{"line":34,"column":2},"end":{"line":47,"column":3}},"22":{"start":{"line":35,"column":4},"end":{"line":35,"column":18}},"23":{"start":{"line":36,"column":4},"end":{"line":45,"column":5}},"24":{"start":{"line":37,"column":6},"end":{"line":37,"column":40}},"25":{"start":{"line":39,"column":6},"end":{"line":44,"column":7}},"26":{"start":{"line":42,"column":10},"end":{"line":42,"column":37}},"27":{"start":{"line":43,"column":10},"end":{"line":43,"column":16}},"28":{"start":{"line":46,"column":4},"end":{"line":46,"column":33}},"29":{"start":{"line":48,"column":2},"end":{"line":48,"column":12}},"30":{"start":{"line":51,"column":0},"end":{"line":51,"column":25}}},"branchMap":{"1":{"line":9,"type":"if","locations":[{"start":{"line":9,"column":2},"end":{"line":9,"column":2}},{"start":{"line":9,"column":2},"end":{"line":9,"column":2}}]},"2":{"line":34,"type":"if","locations":[{"start":{"line":34,"column":2},"end":{"line":34,"column":2}},{"start":{"line":34,"column":2},"end":{"line":34,"column":2}}]},"3":{"line":36,"type":"if","locations":[{"start":{"line":36,"column":4},"end":{"line":36,"column":4}},{"start":{"line":36,"column":4},"end":{"line":36,"column":4}}]},"4":{"line":36,"type":"binary-expr","locations":[{"start":{"line":36,"column":8},"end":{"line":36,"column":39}},{"start":{"line":36,"column":43},"end":{"line":36,"column":127}}]},"5":{"line":39,"type":"switch","locations":[{"start":{"line":40,"column":8},"end":{"line":40,"column":20}},{"start":{"line":41,"column":8},"end":{"line":43,"column":16}}]}}},"/Users/calvin/source/yeezon/yhsd-api-node/lib/Api.js":{"path":"/Users/calvin/source/yeezon/yhsd-api-node/lib/Api.js","s":{"1":1,"2":1,"3":2,"4":1,"5":1,"6":1,"7":3,"8":1,"9":2,"10":1,"11":1,"12":2,"13":2,"14":2,"15":1,"16":1,"17":1,"18":3,"19":1,"20":2,"21":2,"22":3,"23":1,"24":2,"25":2,"26":7,"27":7,"28":0,"29":7,"30":1,"31":6,"32":1},"b":{"1":[1,1],"2":[1,2],"3":[1,1],"4":[1,1],"5":[2,2],"6":[1,1],"7":[1,1],"8":[1,1],"9":[0,1],"10":[1,2],"11":[2,2],"12":[0,2],"13":[1,2],"14":[2,2],"15":[0,7],"16":[1,6]},"f":{"1":2,"2":3,"3":2,"4":2,"5":1,"6":3,"7":2,"8":3,"9":2,"10":7,"11":7},"fnMap":{"1":{"name":"(anonymous_1)","line":11,"loc":{"start":{"line":11,"column":10},"end":{"line":11,"column":26}}},"2":{"name":"(anonymous_2)","line":25,"loc":{"start":{"line":25,"column":7},"end":{"line":25,"column":39}}},"3":{"name":"(anonymous_3)","line":32,"loc":{"start":{"line":32,"column":92},"end":{"line":32,"column":112}}},"4":{"name":"(anonymous_4)","line":42,"loc":{"start":{"line":42,"column":7},"end":{"line":42,"column":38}}},"5":{"name":"(anonymous_5)","line":46,"loc":{"start":{"line":46,"column":40},"end":{"line":46,"column":60}}},"6":{"name":"(anonymous_6)","line":56,"loc":{"start":{"line":56,"column":8},"end":{"line":56,"column":39}}},"7":{"name":"(anonymous_7)","line":60,"loc":{"start":{"line":60,"column":41},"end":{"line":60,"column":61}}},"8":{"name":"(anonymous_8)","line":69,"loc":{"start":{"line":69,"column":10},"end":{"line":69,"column":35}}},"9":{"name":"(anonymous_9)","line":73,"loc":{"start":{"line":73,"column":43},"end":{"line":73,"column":57}}},"10":{"name":"(anonymous_10)","line":83,"loc":{"start":{"line":83,"column":15},"end":{"line":83,"column":56}}},"11":{"name":"(anonymous_11)","line":92,"loc":{"start":{"line":92,"column":15},"end":{"line":92,"column":35}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":4,"column":33}},"2":{"start":{"line":11,"column":0},"end":{"line":16,"column":2}},"3":{"start":{"line":12,"column":2},"end":{"line":14,"column":3}},"4":{"start":{"line":13,"column":4},"end":{"line":13,"column":21}},"5":{"start":{"line":15,"column":2},"end":{"line":15,"column":21}},"6":{"start":{"line":18,"column":0},"end":{"line":103,"column":2}},"7":{"start":{"line":26,"column":4},"end":{"line":31,"column":5}},"8":{"start":{"line":27,"column":6},"end":{"line":27,"column":23}},"9":{"start":{"line":28,"column":11},"end":{"line":31,"column":5}},"10":{"start":{"line":29,"column":6},"end":{"line":29,"column":23}},"11":{"start":{"line":30,"column":6},"end":{"line":30,"column":19}},"12":{"start":{"line":32,"column":4},"end":{"line":34,"column":7}},"13":{"start":{"line":33,"column":6},"end":{"line":33,"column":53}},"14":{"start":{"line":43,"column":4},"end":{"line":45,"column":5}},"15":{"start":{"line":44,"column":6},"end":{"line":44,"column":23}},"16":{"start":{"line":46,"column":4},"end":{"line":48,"column":7}},"17":{"start":{"line":47,"column":6},"end":{"line":47,"column":53}},"18":{"start":{"line":57,"column":4},"end":{"line":59,"column":5}},"19":{"start":{"line":58,"column":6},"end":{"line":58,"column":23}},"20":{"start":{"line":60,"column":4},"end":{"line":62,"column":7}},"21":{"start":{"line":61,"column":6},"end":{"line":61,"column":53}},"22":{"start":{"line":70,"column":4},"end":{"line":72,"column":5}},"23":{"start":{"line":71,"column":6},"end":{"line":71,"column":23}},"24":{"start":{"line":73,"column":4},"end":{"line":75,"column":7}},"25":{"start":{"line":74,"column":6},"end":{"line":74,"column":34}},"26":{"start":{"line":84,"column":4},"end":{"line":101,"column":7}},"27":{"start":{"line":93,"column":6},"end":{"line":95,"column":7}},"28":{"start":{"line":94,"column":8},"end":{"line":94,"column":29}},"29":{"start":{"line":96,"column":6},"end":{"line":100,"column":7}},"30":{"start":{"line":97,"column":8},"end":{"line":97,"column":23}},"31":{"start":{"line":99,"column":8},"end":{"line":99,"column":29}},"32":{"start":{"line":105,"column":0},"end":{"line":105,"column":21}}},"branchMap":{"1":{"line":12,"type":"if","locations":[{"start":{"line":12,"column":2},"end":{"line":12,"column":2}},{"start":{"line":12,"column":2},"end":{"line":12,"column":2}}]},"2":{"line":26,"type":"if","locations":[{"start":{"line":26,"column":4},"end":{"line":26,"column":4}},{"start":{"line":26,"column":4},"end":{"line":26,"column":4}}]},"3":{"line":28,"type":"if","locations":[{"start":{"line":28,"column":11},"end":{"line":28,"column":11}},{"start":{"line":28,"column":11},"end":{"line":28,"column":11}}]},"4":{"line":32,"type":"cond-expr","locations":[{"start":{"line":32,"column":36},"end":{"line":32,"column":77}},{"start":{"line":32,"column":80},"end":{"line":32,"column":84}}]},"5":{"line":33,"type":"binary-expr","locations":[{"start":{"line":33,"column":6},"end":{"line":33,"column":14}},{"start":{"line":33,"column":19},"end":{"line":33,"column":51}}]},"6":{"line":33,"type":"cond-expr","locations":[{"start":{"line":33,"column":39},"end":{"line":33,"column":43}},{"start":{"line":33,"column":46},"end":{"line":33,"column":50}}]},"7":{"line":43,"type":"if","locations":[{"start":{"line":43,"column":4},"end":{"line":43,"column":4}},{"start":{"line":43,"column":4},"end":{"line":43,"column":4}}]},"8":{"line":47,"type":"binary-expr","locations":[{"start":{"line":47,"column":6},"end":{"line":47,"column":14}},{"start":{"line":47,"column":19},"end":{"line":47,"column":51}}]},"9":{"line":47,"type":"cond-expr","locations":[{"start":{"line":47,"column":39},"end":{"line":47,"column":43}},{"start":{"line":47,"column":46},"end":{"line":47,"column":50}}]},"10":{"line":57,"type":"if","locations":[{"start":{"line":57,"column":4},"end":{"line":57,"column":4}},{"start":{"line":57,"column":4},"end":{"line":57,"column":4}}]},"11":{"line":61,"type":"binary-expr","locations":[{"start":{"line":61,"column":6},"end":{"line":61,"column":14}},{"start":{"line":61,"column":19},"end":{"line":61,"column":51}}]},"12":{"line":61,"type":"cond-expr","locations":[{"start":{"line":61,"column":39},"end":{"line":61,"column":43}},{"start":{"line":61,"column":46},"end":{"line":61,"column":50}}]},"13":{"line":70,"type":"if","locations":[{"start":{"line":70,"column":4},"end":{"line":70,"column":4}},{"start":{"line":70,"column":4},"end":{"line":70,"column":4}}]},"14":{"line":74,"type":"binary-expr","locations":[{"start":{"line":74,"column":6},"end":{"line":74,"column":14}},{"start":{"line":74,"column":19},"end":{"line":74,"column":32}}]},"15":{"line":93,"type":"if","locations":[{"start":{"line":93,"column":6},"end":{"line":93,"column":6}},{"start":{"line":93,"column":6},"end":{"line":93,"column":6}}]},"16":{"line":96,"type":"if","locations":[{"start":{"line":96,"column":6},"end":{"line":96,"column":6}},{"start":{"line":96,"column":6},"end":{"line":96,"column":6}}]}}},"/Users/calvin/source/yeezon/yhsd-api-node/lib/WebHook.js":{"path":"/Users/calvin/source/yeezon/yhsd-api-node/lib/WebHook.js","s":{"1":1,"2":1,"3":2,"4":1,"5":1,"6":1,"7":2,"8":1,"9":1,"10":1},"b":{"1":[1,1],"2":[1,1]},"f":{"1":2,"2":2},"fnMap":{"1":{"name":"(anonymous_1)","line":8,"loc":{"start":{"line":8,"column":14},"end":{"line":8,"column":37}}},"2":{"name":"(anonymous_2)","line":22,"loc":{"start":{"line":22,"column":14},"end":{"line":22,"column":39}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":2,"column":33}},"2":{"start":{"line":8,"column":0},"end":{"line":13,"column":2}},"3":{"start":{"line":9,"column":2},"end":{"line":11,"column":3}},"4":{"start":{"line":10,"column":4},"end":{"line":10,"column":21}},"5":{"start":{"line":12,"column":2},"end":{"line":12,"column":28}},"6":{"start":{"line":15,"column":0},"end":{"line":28,"column":2}},"7":{"start":{"line":23,"column":4},"end":{"line":25,"column":5}},"8":{"start":{"line":24,"column":6},"end":{"line":24,"column":23}},"9":{"start":{"line":26,"column":4},"end":{"line":26,"column":87}},"10":{"start":{"line":30,"column":0},"end":{"line":30,"column":25}}},"branchMap":{"1":{"line":9,"type":"if","locations":[{"start":{"line":9,"column":2},"end":{"line":9,"column":2}},{"start":{"line":9,"column":2},"end":{"line":9,"column":2}}]},"2":{"line":23,"type":"if","locations":[{"start":{"line":23,"column":4},"end":{"line":23,"column":4}},{"start":{"line":23,"column":4},"end":{"line":23,"column":4}}]}}}}
\ No newline at end of file
+{"/Users/am/WebstormProjects/yhsd-api-node/index.js":{"path":"/Users/am/WebstormProjects/yhsd-api-node/index.js","s":{"1":1},"b":{},"f":{},"fnMap":{},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":6,"column":2}}},"branchMap":{}},"/Users/am/WebstormProjects/yhsd-api-node/lib/config.js":{"path":"/Users/am/WebstormProjects/yhsd-api-node/lib/config.js","s":{"1":1,"2":1,"3":1,"4":1,"5":4,"6":0,"7":4,"8":0,"9":4,"10":0,"11":4,"12":0,"13":1,"14":1},"b":{"1":[0,4],"2":[0,4],"3":[0,4],"4":[0,4]},"f":{"1":4},"fnMap":{"1":{"name":"(anonymous_1)","line":5,"loc":{"start":{"line":5,"column":21},"end":{"line":5,"column":42}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":36}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":35}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":27}},"4":{"start":{"line":5,"column":0},"end":{"line":18,"column":3}},"5":{"start":{"line":6,"column":2},"end":{"line":8,"column":3}},"6":{"start":{"line":7,"column":4},"end":{"line":7,"column":38}},"7":{"start":{"line":9,"column":2},"end":{"line":11,"column":3}},"8":{"start":{"line":10,"column":4},"end":{"line":10,"column":38}},"9":{"start":{"line":12,"column":2},"end":{"line":14,"column":3}},"10":{"start":{"line":13,"column":4},"end":{"line":13,"column":26}},"11":{"start":{"line":15,"column":2},"end":{"line":17,"column":3}},"12":{"start":{"line":16,"column":4},"end":{"line":16,"column":27}},"13":{"start":{"line":21,"column":0},"end":{"line":27,"column":2}},"14":{"start":{"line":28,"column":0},"end":{"line":28,"column":24}}},"branchMap":{"1":{"line":6,"type":"if","locations":[{"start":{"line":6,"column":2},"end":{"line":6,"column":2}},{"start":{"line":6,"column":2},"end":{"line":6,"column":2}}]},"2":{"line":9,"type":"if","locations":[{"start":{"line":9,"column":2},"end":{"line":9,"column":2}},{"start":{"line":9,"column":2},"end":{"line":9,"column":2}}]},"3":{"line":12,"type":"if","locations":[{"start":{"line":12,"column":2},"end":{"line":12,"column":2}},{"start":{"line":12,"column":2},"end":{"line":12,"column":2}}]},"4":{"line":15,"type":"if","locations":[{"start":{"line":15,"column":2},"end":{"line":15,"column":2}},{"start":{"line":15,"column":2},"end":{"line":15,"column":2}}]}}},"/Users/am/WebstormProjects/yhsd-api-node/lib/Auth.js":{"path":"/Users/am/WebstormProjects/yhsd-api-node/lib/Auth.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":13,"9":1,"10":12,"11":10,"12":1,"13":9,"14":11,"15":11,"16":11,"17":11,"18":11,"19":11,"20":11,"21":11,"22":11,"23":1,"24":4,"25":1,"26":3,"27":3,"28":3,"29":2,"30":1,"31":1,"32":4,"33":4,"34":4,"35":2,"36":2,"37":2,"38":1,"39":1,"40":3,"41":3,"42":3,"43":0,"44":1,"45":1,"46":1,"47":1,"48":1,"49":1},"b":{"1":[1,12],"2":[13,13,13],"3":[10,2],"4":[1,9],"5":[9,9],"6":[11,0],"7":[11,0],"8":[11,9],"9":[11,2],"10":[11,2],"11":[11,11],"12":[11,11],"13":[11,11],"14":[1,3],"15":[3,2],"16":[1,1],"17":[2,2],"18":[1,1],"19":[0,1],"20":[0,1]},"f":{"1":13,"2":4,"3":2,"4":4,"5":3,"6":1},"fnMap":{"1":{"name":"(anonymous_1)","line":21,"loc":{"start":{"line":21,"column":11},"end":{"line":21,"column":30}}},"2":{"name":"(anonymous_2)","line":51,"loc":{"start":{"line":51,"column":14},"end":{"line":51,"column":34}}},"3":{"name":"(anonymous_3)","line":68,"loc":{"start":{"line":68,"column":19},"end":{"line":68,"column":45}}},"4":{"name":"(anonymous_4)","line":86,"loc":{"start":{"line":86,"column":12},"end":{"line":86,"column":28}}},"5":{"name":"(anonymous_5)","line":114,"loc":{"start":{"line":114,"column":54},"end":{"line":114,"column":70}}},"6":{"name":"(anonymous_6)","line":121,"loc":{"start":{"line":121,"column":16},"end":{"line":121,"column":53}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":41}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":31}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":33}},"4":{"start":{"line":4,"column":0},"end":{"line":4,"column":35}},"5":{"start":{"line":5,"column":0},"end":{"line":5,"column":32}},"6":{"start":{"line":6,"column":0},"end":{"line":6,"column":35}},"7":{"start":{"line":21,"column":0},"end":{"line":43,"column":2}},"8":{"start":{"line":22,"column":2},"end":{"line":24,"column":3}},"9":{"start":{"line":23,"column":4},"end":{"line":23,"column":21}},"10":{"start":{"line":25,"column":2},"end":{"line":30,"column":3}},"11":{"start":{"line":26,"column":4},"end":{"line":28,"column":5}},"12":{"start":{"line":27,"column":6},"end":{"line":27,"column":23}},"13":{"start":{"line":29,"column":4},"end":{"line":29,"column":54}},"14":{"start":{"line":32,"column":2},"end":{"line":32,"column":38}},"15":{"start":{"line":33,"column":2},"end":{"line":33,"column":44}},"16":{"start":{"line":34,"column":2},"end":{"line":34,"column":42}},"17":{"start":{"line":35,"column":2},"end":{"line":35,"column":48}},"18":{"start":{"line":36,"column":2},"end":{"line":36,"column":35}},"19":{"start":{"line":37,"column":2},"end":{"line":37,"column":48}},"20":{"start":{"line":38,"column":2},"end":{"line":38,"column":58}},"21":{"start":{"line":39,"column":2},"end":{"line":39,"column":45}},"22":{"start":{"line":40,"column":2},"end":{"line":42,"column":5}},"23":{"start":{"line":45,"column":0},"end":{"line":127,"column":2}},"24":{"start":{"line":52,"column":4},"end":{"line":54,"column":5}},"25":{"start":{"line":53,"column":6},"end":{"line":53,"column":23}},"26":{"start":{"line":55,"column":4},"end":{"line":55,"column":29}},"27":{"start":{"line":56,"column":4},"end":{"line":56,"column":25}},"28":{"start":{"line":57,"column":4},"end":{"line":60,"column":24}},"29":{"start":{"line":69,"column":4},"end":{"line":71,"column":5}},"30":{"start":{"line":70,"column":6},"end":{"line":70,"column":23}},"31":{"start":{"line":72,"column":4},"end":{"line":79,"column":49}},"32":{"start":{"line":87,"column":4},"end":{"line":87,"column":15}},"33":{"start":{"line":88,"column":4},"end":{"line":88,"column":74}},"34":{"start":{"line":91,"column":4},"end":{"line":106,"column":5}},"35":{"start":{"line":92,"column":6},"end":{"line":92,"column":109}},"36":{"start":{"line":93,"column":6},"end":{"line":95,"column":8}},"37":{"start":{"line":97,"column":6},"end":{"line":99,"column":7}},"38":{"start":{"line":98,"column":8},"end":{"line":98,"column":25}},"39":{"start":{"line":100,"column":6},"end":{"line":105,"column":8}},"40":{"start":{"line":108,"column":4},"end":{"line":113,"column":6}},"41":{"start":{"line":114,"column":4},"end":{"line":119,"column":7}},"42":{"start":{"line":115,"column":6},"end":{"line":117,"column":7}},"43":{"start":{"line":116,"column":8},"end":{"line":116,"column":37}},"44":{"start":{"line":118,"column":6},"end":{"line":118,"column":24}},"45":{"start":{"line":122,"column":4},"end":{"line":122,"column":53}},"46":{"start":{"line":123,"column":4},"end":{"line":123,"column":64}},"47":{"start":{"line":124,"column":4},"end":{"line":124,"column":61}},"48":{"start":{"line":125,"column":4},"end":{"line":125,"column":31}},"49":{"start":{"line":130,"column":0},"end":{"line":130,"column":22}}},"branchMap":{"1":{"line":22,"type":"if","locations":[{"start":{"line":22,"column":2},"end":{"line":22,"column":2}},{"start":{"line":22,"column":2},"end":{"line":22,"column":2}}]},"2":{"line":22,"type":"binary-expr","locations":[{"start":{"line":22,"column":6},"end":{"line":22,"column":26}},{"start":{"line":22,"column":30},"end":{"line":22,"column":45}},{"start":{"line":22,"column":49},"end":{"line":22,"column":67}}]},"3":{"line":25,"type":"if","locations":[{"start":{"line":25,"column":2},"end":{"line":25,"column":2}},{"start":{"line":25,"column":2},"end":{"line":25,"column":2}}]},"4":{"line":26,"type":"if","locations":[{"start":{"line":26,"column":4},"end":{"line":26,"column":4}},{"start":{"line":26,"column":4},"end":{"line":26,"column":4}}]},"5":{"line":29,"type":"binary-expr","locations":[{"start":{"line":29,"column":4},"end":{"line":29,"column":17}},{"start":{"line":29,"column":22},"end":{"line":29,"column":52}}]},"6":{"line":32,"type":"binary-expr","locations":[{"start":{"line":32,"column":17},"end":{"line":32,"column":31}},{"start":{"line":32,"column":35},"end":{"line":32,"column":37}}]},"7":{"line":33,"type":"binary-expr","locations":[{"start":{"line":33,"column":20},"end":{"line":33,"column":37}},{"start":{"line":33,"column":41},"end":{"line":33,"column":43}}]},"8":{"line":34,"type":"binary-expr","locations":[{"start":{"line":34,"column":17},"end":{"line":34,"column":32}},{"start":{"line":34,"column":36},"end":{"line":34,"column":41}}]},"9":{"line":35,"type":"binary-expr","locations":[{"start":{"line":35,"column":22},"end":{"line":35,"column":41}},{"start":{"line":35,"column":45},"end":{"line":35,"column":47}}]},"10":{"line":36,"type":"binary-expr","locations":[{"start":{"line":36,"column":15},"end":{"line":36,"column":28}},{"start":{"line":36,"column":32},"end":{"line":36,"column":34}}]},"11":{"line":37,"type":"binary-expr","locations":[{"start":{"line":37,"column":22},"end":{"line":37,"column":41}},{"start":{"line":37,"column":45},"end":{"line":37,"column":47}}]},"12":{"line":38,"type":"binary-expr","locations":[{"start":{"line":38,"column":18},"end":{"line":38,"column":34}},{"start":{"line":38,"column":38},"end":{"line":38,"column":57}}]},"13":{"line":39,"type":"binary-expr","locations":[{"start":{"line":39,"column":14},"end":{"line":39,"column":26}},{"start":{"line":39,"column":30},"end":{"line":39,"column":44}}]},"14":{"line":52,"type":"if","locations":[{"start":{"line":52,"column":4},"end":{"line":52,"column":4}},{"start":{"line":52,"column":4},"end":{"line":52,"column":4}}]},"15":{"line":57,"type":"binary-expr","locations":[{"start":{"line":57,"column":12},"end":{"line":57,"column":77}},{"start":{"line":58,"column":7},"end":{"line":60,"column":22}}]},"16":{"line":69,"type":"if","locations":[{"start":{"line":69,"column":4},"end":{"line":69,"column":4}},{"start":{"line":69,"column":4},"end":{"line":69,"column":4}}]},"17":{"line":91,"type":"if","locations":[{"start":{"line":91,"column":4},"end":{"line":91,"column":4}},{"start":{"line":91,"column":4},"end":{"line":91,"column":4}}]},"18":{"line":97,"type":"if","locations":[{"start":{"line":97,"column":6},"end":{"line":97,"column":6}},{"start":{"line":97,"column":6},"end":{"line":97,"column":6}}]},"19":{"line":104,"type":"cond-expr","locations":[{"start":{"line":104,"column":42},"end":{"line":104,"column":59}},{"start":{"line":104,"column":62},"end":{"line":104,"column":79}}]},"20":{"line":115,"type":"if","locations":[{"start":{"line":115,"column":6},"end":{"line":115,"column":6}},{"start":{"line":115,"column":6},"end":{"line":115,"column":6}}]}}},"/Users/am/WebstormProjects/yhsd-api-node/lib/Request.js":{"path":"/Users/am/WebstormProjects/yhsd-api-node/lib/Request.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":7,"9":7,"10":4,"11":3,"12":3,"13":3,"14":7,"15":1,"16":208,"17":208,"18":208,"19":1,"20":207,"21":207,"22":207,"23":0,"24":207,"25":1,"26":15,"27":15,"28":15,"29":15,"30":1,"31":212,"32":212,"33":212,"34":212,"35":212,"36":212,"37":212,"38":7,"39":7,"40":212,"41":212,"42":212,"43":211,"44":211,"45":211,"46":211,"47":211,"48":0,"49":211,"50":211,"51":211,"52":211,"53":211,"54":212,"55":212,"56":208,"57":208,"58":208,"59":0,"60":208,"61":4,"62":211,"63":211,"64":207,"65":207,"66":4,"67":1},"b":{"1":[4,3],"2":[7,7],"3":[2,3],"4":[208,208],"5":[207,8],"6":[207,0],"7":[15,14],"8":[15,14],"9":[15,3],"10":[15,14],"11":[0,212],"12":[7,205],"13":[208,4],"14":[208,208],"15":[0,208],"16":[207,4],"17":[207,0],"18":[207,207]},"f":{"1":7,"2":208,"3":207,"4":15,"5":212,"6":212,"7":212,"8":212,"9":211,"10":211,"11":211,"12":212,"13":208,"14":211},"fnMap":{"1":{"name":"genStringify","line":15,"loc":{"start":{"line":15,"column":0},"end":{"line":15,"column":31}}},"2":{"name":"increment","line":36,"loc":{"start":{"line":36,"column":0},"end":{"line":36,"column":26}}},"3":{"name":"decrement","line":45,"loc":{"start":{"line":45,"column":0},"end":{"line":45,"column":26}}},"4":{"name":"(anonymous_4)","line":56,"loc":{"start":{"line":56,"column":14},"end":{"line":56,"column":32}}},"5":{"name":"(anonymous_5)","line":69,"loc":{"start":{"line":69,"column":11},"end":{"line":69,"column":38}}},"6":{"name":"(anonymous_6)","line":73,"loc":{"start":{"line":73,"column":12},"end":{"line":73,"column":24}}},"7":{"name":"(anonymous_7)","line":76,"loc":{"start":{"line":76,"column":27},"end":{"line":76,"column":54}}},"8":{"name":"(anonymous_8)","line":98,"loc":{"start":{"line":98,"column":17},"end":{"line":98,"column":44}}},"9":{"name":"(anonymous_9)","line":101,"loc":{"start":{"line":101,"column":11},"end":{"line":101,"column":26}}},"10":{"name":"(anonymous_10)","line":104,"loc":{"start":{"line":104,"column":20},"end":{"line":104,"column":32}}},"11":{"name":"(anonymous_11)","line":119,"loc":{"start":{"line":119,"column":21},"end":{"line":119,"column":37}}},"12":{"name":"(anonymous_12)","line":127,"loc":{"start":{"line":127,"column":18},"end":{"line":127,"column":30}}},"13":{"name":"(anonymous_13)","line":132,"loc":{"start":{"line":132,"column":14},"end":{"line":132,"column":31}}},"14":{"name":"(anonymous_14)","line":150,"loc":{"start":{"line":150,"column":17},"end":{"line":150,"column":34}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":34}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":41}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":33}},"4":{"start":{"line":5,"column":0},"end":{"line":5,"column":16}},"5":{"start":{"line":6,"column":0},"end":{"line":6,"column":16}},"6":{"start":{"line":7,"column":0},"end":{"line":7,"column":50}},"7":{"start":{"line":15,"column":0},"end":{"line":29,"column":1}},"8":{"start":{"line":16,"column":2},"end":{"line":16,"column":18}},"9":{"start":{"line":17,"column":2},"end":{"line":27,"column":3}},"10":{"start":{"line":19,"column":4},"end":{"line":19,"column":40}},"11":{"start":{"line":21,"column":4},"end":{"line":26,"column":5}},"12":{"start":{"line":24,"column":8},"end":{"line":24,"column":37}},"13":{"start":{"line":25,"column":8},"end":{"line":25,"column":14}},"14":{"start":{"line":28,"column":2},"end":{"line":28,"column":21}},"15":{"start":{"line":36,"column":0},"end":{"line":40,"column":1}},"16":{"start":{"line":37,"column":2},"end":{"line":37,"column":21}},"17":{"start":{"line":38,"column":2},"end":{"line":38,"column":19}},"18":{"start":{"line":39,"column":2},"end":{"line":39,"column":15}},"19":{"start":{"line":45,"column":0},"end":{"line":53,"column":1}},"20":{"start":{"line":46,"column":2},"end":{"line":46,"column":21}},"21":{"start":{"line":47,"column":2},"end":{"line":51,"column":3}},"22":{"start":{"line":48,"column":4},"end":{"line":48,"column":14}},"23":{"start":{"line":50,"column":4},"end":{"line":50,"column":21}},"24":{"start":{"line":52,"column":2},"end":{"line":52,"column":15}},"25":{"start":{"line":56,"column":0},"end":{"line":61,"column":2}},"26":{"start":{"line":57,"column":2},"end":{"line":57,"column":58}},"27":{"start":{"line":58,"column":2},"end":{"line":58,"column":60}},"28":{"start":{"line":59,"column":2},"end":{"line":59,"column":63}},"29":{"start":{"line":60,"column":2},"end":{"line":60,"column":44}},"30":{"start":{"line":63,"column":0},"end":{"line":164,"column":2}},"31":{"start":{"line":70,"column":4},"end":{"line":70,"column":20}},"32":{"start":{"line":72,"column":4},"end":{"line":90,"column":9}},"33":{"start":{"line":76,"column":8},"end":{"line":89,"column":11}},"34":{"start":{"line":77,"column":10},"end":{"line":77,"column":85}},"35":{"start":{"line":78,"column":10},"end":{"line":78,"column":81}},"36":{"start":{"line":80,"column":10},"end":{"line":80,"column":34}},"37":{"start":{"line":83,"column":10},"end":{"line":86,"column":11}},"38":{"start":{"line":84,"column":12},"end":{"line":84,"column":50}},"39":{"start":{"line":85,"column":12},"end":{"line":85,"column":41}},"40":{"start":{"line":88,"column":10},"end":{"line":88,"column":20}},"41":{"start":{"line":99,"column":4},"end":{"line":99,"column":20}},"42":{"start":{"line":101,"column":4},"end":{"line":122,"column":6}},"43":{"start":{"line":102,"column":6},"end":{"line":102,"column":19}},"44":{"start":{"line":104,"column":6},"end":{"line":117,"column":9}},"45":{"start":{"line":105,"column":8},"end":{"line":105,"column":49}},"46":{"start":{"line":106,"column":8},"end":{"line":115,"column":9}},"47":{"start":{"line":107,"column":10},"end":{"line":107,"column":34}},"48":{"start":{"line":109,"column":10},"end":{"line":109,"column":22}},"49":{"start":{"line":112,"column":10},"end":{"line":112,"column":101}},"50":{"start":{"line":113,"column":10},"end":{"line":113,"column":36}},"51":{"start":{"line":116,"column":8},"end":{"line":116,"column":22}},"52":{"start":{"line":119,"column":6},"end":{"line":121,"column":9}},"53":{"start":{"line":120,"column":8},"end":{"line":120,"column":23}},"54":{"start":{"line":128,"column":4},"end":{"line":128,"column":20}},"55":{"start":{"line":130,"column":4},"end":{"line":142,"column":5}},"56":{"start":{"line":131,"column":6},"end":{"line":141,"column":37}},"57":{"start":{"line":133,"column":10},"end":{"line":133,"column":29}},"58":{"start":{"line":135,"column":10},"end":{"line":137,"column":11}},"59":{"start":{"line":136,"column":12},"end":{"line":136,"column":82}},"60":{"start":{"line":138,"column":10},"end":{"line":138,"column":23}},"61":{"start":{"line":144,"column":4},"end":{"line":144,"column":29}},"62":{"start":{"line":151,"column":4},"end":{"line":151,"column":48}},"63":{"start":{"line":153,"column":4},"end":{"line":160,"column":5}},"64":{"start":{"line":154,"column":6},"end":{"line":159,"column":39}},"65":{"start":{"line":155,"column":8},"end":{"line":159,"column":39}},"66":{"start":{"line":162,"column":4},"end":{"line":162,"column":29}},"67":{"start":{"line":167,"column":0},"end":{"line":167,"column":25}}},"branchMap":{"1":{"line":17,"type":"if","locations":[{"start":{"line":17,"column":2},"end":{"line":17,"column":2}},{"start":{"line":17,"column":2},"end":{"line":17,"column":2}}]},"2":{"line":17,"type":"binary-expr","locations":[{"start":{"line":17,"column":6},"end":{"line":17,"column":37}},{"start":{"line":18,"column":4},"end":{"line":18,"column":89}}]},"3":{"line":21,"type":"switch","locations":[{"start":{"line":22,"column":6},"end":{"line":22,"column":18}},{"start":{"line":23,"column":6},"end":{"line":25,"column":14}}]},"4":{"line":37,"type":"binary-expr","locations":[{"start":{"line":37,"column":10},"end":{"line":37,"column":15}},{"start":{"line":37,"column":19},"end":{"line":37,"column":20}}]},"5":{"line":46,"type":"binary-expr","locations":[{"start":{"line":46,"column":10},"end":{"line":46,"column":15}},{"start":{"line":46,"column":19},"end":{"line":46,"column":20}}]},"6":{"line":47,"type":"if","locations":[{"start":{"line":47,"column":2},"end":{"line":47,"column":2}},{"start":{"line":47,"column":2},"end":{"line":47,"column":2}}]},"7":{"line":57,"type":"binary-expr","locations":[{"start":{"line":57,"column":25},"end":{"line":57,"column":31}},{"start":{"line":57,"column":35},"end":{"line":57,"column":57}}]},"8":{"line":58,"type":"binary-expr","locations":[{"start":{"line":58,"column":26},"end":{"line":58,"column":32}},{"start":{"line":58,"column":36},"end":{"line":58,"column":59}}]},"9":{"line":59,"type":"binary-expr","locations":[{"start":{"line":59,"column":17},"end":{"line":59,"column":37}},{"start":{"line":59,"column":41},"end":{"line":59,"column":62}}]},"10":{"line":60,"type":"binary-expr","locations":[{"start":{"line":60,"column":18},"end":{"line":60,"column":24}},{"start":{"line":60,"column":28},"end":{"line":60,"column":43}}]},"11":{"line":77,"type":"cond-expr","locations":[{"start":{"line":77,"column":50},"end":{"line":77,"column":65}},{"start":{"line":77,"column":68},"end":{"line":77,"column":84}}]},"12":{"line":83,"type":"if","locations":[{"start":{"line":83,"column":10},"end":{"line":83,"column":10}},{"start":{"line":83,"column":10},"end":{"line":83,"column":10}}]},"13":{"line":130,"type":"if","locations":[{"start":{"line":130,"column":4},"end":{"line":130,"column":4}},{"start":{"line":130,"column":4},"end":{"line":130,"column":4}}]},"14":{"line":133,"type":"binary-expr","locations":[{"start":{"line":133,"column":18},"end":{"line":133,"column":23}},{"start":{"line":133,"column":27},"end":{"line":133,"column":28}}]},"15":{"line":135,"type":"if","locations":[{"start":{"line":135,"column":10},"end":{"line":135,"column":10}},{"start":{"line":135,"column":10},"end":{"line":135,"column":10}}]},"16":{"line":153,"type":"if","locations":[{"start":{"line":153,"column":4},"end":{"line":153,"column":4}},{"start":{"line":153,"column":4},"end":{"line":153,"column":4}}]},"17":{"line":154,"type":"if","locations":[{"start":{"line":154,"column":6},"end":{"line":154,"column":6}},{"start":{"line":154,"column":6},"end":{"line":154,"column":6}}]},"18":{"line":154,"type":"binary-expr","locations":[{"start":{"line":154,"column":10},"end":{"line":154,"column":30}},{"start":{"line":154,"column":34},"end":{"line":154,"column":55}}]}}},"/Users/am/WebstormProjects/yhsd-api-node/lib/Api.js":{"path":"/Users/am/WebstormProjects/yhsd-api-node/lib/Api.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":1,"9":1,"10":2,"11":0,"12":1,"13":15,"14":1,"15":22,"16":22,"17":1,"18":4,"19":37,"20":37,"21":37,"22":1,"23":3,"24":1,"25":2,"26":2,"27":2,"28":2,"29":2,"30":2,"31":1,"32":4,"33":1,"34":3,"35":2,"36":1,"37":1,"38":3,"39":1,"40":2,"41":3,"42":1,"43":2,"44":8,"45":1},"b":{"1":[0,2],"2":[2,1,1,0,0],"3":[1,2],"4":[2,1,1],"5":[2,1,2],"6":[2,1,2],"7":[2,1,1],"8":[1,3],"9":[1,2],"10":[1,1],"11":[1,2],"12":[1,2]},"f":{"1":2,"2":15,"3":22,"4":4,"5":37,"6":3,"7":4,"8":2,"9":3,"10":3,"11":8},"fnMap":{"1":{"name":"check","line":12,"loc":{"start":{"line":12,"column":0},"end":{"line":12,"column":23}}},"2":{"name":"(anonymous_2)","line":25,"loc":{"start":{"line":25,"column":24},"end":{"line":25,"column":41}}},"3":{"name":"(anonymous_3)","line":35,"loc":{"start":{"line":35,"column":25},"end":{"line":35,"column":49}}},"4":{"name":"(anonymous_4)","line":46,"loc":{"start":{"line":46,"column":19},"end":{"line":46,"column":40}}},"5":{"name":"(anonymous_5)","line":47,"loc":{"start":{"line":47,"column":9},"end":{"line":47,"column":21}}},"6":{"name":"(anonymous_6)","line":66,"loc":{"start":{"line":66,"column":10},"end":{"line":66,"column":35}}},"7":{"name":"(anonymous_7)","line":92,"loc":{"start":{"line":92,"column":7},"end":{"line":92,"column":30}}},"8":{"name":"(anonymous_8)","line":104,"loc":{"start":{"line":104,"column":7},"end":{"line":104,"column":29}}},"9":{"name":"(anonymous_9)","line":116,"loc":{"start":{"line":116,"column":8},"end":{"line":116,"column":30}}},"10":{"name":"(anonymous_10)","line":127,"loc":{"start":{"line":127,"column":10},"end":{"line":127,"column":26}}},"11":{"name":"(anonymous_11)","line":140,"loc":{"start":{"line":140,"column":11},"end":{"line":140,"column":43}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":41}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":34}},"3":{"start":{"line":4,"column":0},"end":{"line":4,"column":29}},"4":{"start":{"line":5,"column":0},"end":{"line":5,"column":33}},"5":{"start":{"line":6,"column":0},"end":{"line":6,"column":35}},"6":{"start":{"line":8,"column":0},"end":{"line":8,"column":21}},"7":{"start":{"line":9,"column":0},"end":{"line":9,"column":31}},"8":{"start":{"line":10,"column":0},"end":{"line":10,"column":77}},"9":{"start":{"line":12,"column":0},"end":{"line":18,"column":1}},"10":{"start":{"line":13,"column":2},"end":{"line":17,"column":3}},"11":{"start":{"line":16,"column":4},"end":{"line":16,"column":23}},"12":{"start":{"line":25,"column":0},"end":{"line":27,"column":2}},"13":{"start":{"line":26,"column":2},"end":{"line":26,"column":28}},"14":{"start":{"line":35,"column":0},"end":{"line":38,"column":2}},"15":{"start":{"line":36,"column":2},"end":{"line":36,"column":29}},"16":{"start":{"line":37,"column":2},"end":{"line":37,"column":28}},"17":{"start":{"line":46,"column":0},"end":{"line":54,"column":2}},"18":{"start":{"line":47,"column":2},"end":{"line":53,"column":4}},"19":{"start":{"line":49,"column":4},"end":{"line":49,"column":53}},"20":{"start":{"line":51,"column":4},"end":{"line":51,"column":24}},"21":{"start":{"line":52,"column":4},"end":{"line":52,"column":45}},"22":{"start":{"line":66,"column":0},"end":{"line":83,"column":2}},"23":{"start":{"line":67,"column":2},"end":{"line":69,"column":3}},"24":{"start":{"line":68,"column":4},"end":{"line":68,"column":21}},"25":{"start":{"line":70,"column":2},"end":{"line":70,"column":16}},"26":{"start":{"line":72,"column":2},"end":{"line":72,"column":21}},"27":{"start":{"line":73,"column":2},"end":{"line":73,"column":56}},"28":{"start":{"line":75,"column":2},"end":{"line":75,"column":79}},"29":{"start":{"line":76,"column":2},"end":{"line":76,"column":82}},"30":{"start":{"line":78,"column":2},"end":{"line":82,"column":5}},"31":{"start":{"line":85,"column":0},"end":{"line":151,"column":2}},"32":{"start":{"line":93,"column":4},"end":{"line":95,"column":5}},"33":{"start":{"line":94,"column":6},"end":{"line":94,"column":23}},"34":{"start":{"line":96,"column":4},"end":{"line":96,"column":95}},"35":{"start":{"line":105,"column":4},"end":{"line":107,"column":5}},"36":{"start":{"line":106,"column":6},"end":{"line":106,"column":23}},"37":{"start":{"line":108,"column":4},"end":{"line":108,"column":43}},"38":{"start":{"line":117,"column":4},"end":{"line":119,"column":5}},"39":{"start":{"line":118,"column":6},"end":{"line":118,"column":23}},"40":{"start":{"line":120,"column":4},"end":{"line":120,"column":44}},"41":{"start":{"line":128,"column":4},"end":{"line":130,"column":5}},"42":{"start":{"line":129,"column":6},"end":{"line":129,"column":23}},"43":{"start":{"line":131,"column":4},"end":{"line":131,"column":46}},"44":{"start":{"line":141,"column":4},"end":{"line":149,"column":15}},"45":{"start":{"line":153,"column":0},"end":{"line":153,"column":21}}},"branchMap":{"1":{"line":13,"type":"if","locations":[{"start":{"line":13,"column":2},"end":{"line":13,"column":2}},{"start":{"line":13,"column":2},"end":{"line":13,"column":2}}]},"2":{"line":13,"type":"binary-expr","locations":[{"start":{"line":13,"column":6},"end":{"line":13,"column":12}},{"start":{"line":14,"column":5},"end":{"line":14,"column":27}},{"start":{"line":14,"column":31},"end":{"line":14,"column":54}},{"start":{"line":15,"column":5},"end":{"line":15,"column":45}},{"start":{"line":15,"column":49},"end":{"line":15,"column":90}}]},"3":{"line":67,"type":"if","locations":[{"start":{"line":67,"column":2},"end":{"line":67,"column":2}},{"start":{"line":67,"column":2},"end":{"line":67,"column":2}}]},"4":{"line":73,"type":"binary-expr","locations":[{"start":{"line":73,"column":15},"end":{"line":73,"column":21}},{"start":{"line":73,"column":25},"end":{"line":73,"column":36}},{"start":{"line":73,"column":41},"end":{"line":73,"column":55}}]},"5":{"line":75,"type":"binary-expr","locations":[{"start":{"line":75,"column":25},"end":{"line":75,"column":31}},{"start":{"line":75,"column":35},"end":{"line":75,"column":57}},{"start":{"line":75,"column":61},"end":{"line":75,"column":78}}]},"6":{"line":76,"type":"binary-expr","locations":[{"start":{"line":76,"column":26},"end":{"line":76,"column":32}},{"start":{"line":76,"column":36},"end":{"line":76,"column":59}},{"start":{"line":76,"column":63},"end":{"line":76,"column":81}}]},"7":{"line":79,"type":"binary-expr","locations":[{"start":{"line":79,"column":15},"end":{"line":79,"column":21}},{"start":{"line":79,"column":25},"end":{"line":79,"column":40}},{"start":{"line":79,"column":45},"end":{"line":79,"column":64}}]},"8":{"line":93,"type":"if","locations":[{"start":{"line":93,"column":4},"end":{"line":93,"column":4}},{"start":{"line":93,"column":4},"end":{"line":93,"column":4}}]},"9":{"line":96,"type":"cond-expr","locations":[{"start":{"line":96,"column":39},"end":{"line":96,"column":80}},{"start":{"line":96,"column":83},"end":{"line":96,"column":87}}]},"10":{"line":105,"type":"if","locations":[{"start":{"line":105,"column":4},"end":{"line":105,"column":4}},{"start":{"line":105,"column":4},"end":{"line":105,"column":4}}]},"11":{"line":117,"type":"if","locations":[{"start":{"line":117,"column":4},"end":{"line":117,"column":4}},{"start":{"line":117,"column":4},"end":{"line":117,"column":4}}]},"12":{"line":128,"type":"if","locations":[{"start":{"line":128,"column":4},"end":{"line":128,"column":4}},{"start":{"line":128,"column":4},"end":{"line":128,"column":4}}]}}},"/Users/am/WebstormProjects/yhsd-api-node/lib/util.js":{"path":"/Users/am/WebstormProjects/yhsd-api-node/lib/util.js","s":{"1":1,"2":0,"3":0,"4":0},"b":{"1":[0,0,0]},"f":{"1":0,"2":0,"3":0},"fnMap":{"1":{"name":"(anonymous_1)","line":2,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":31}}},"2":{"name":"(anonymous_2)","line":5,"loc":{"start":{"line":5,"column":12},"end":{"line":5,"column":30}}},"3":{"name":"(anonymous_3)","line":8,"loc":{"start":{"line":8,"column":14},"end":{"line":8,"column":28}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":11,"column":2}},"2":{"start":{"line":3,"column":4},"end":{"line":3,"column":75}},"3":{"start":{"line":6,"column":4},"end":{"line":6,"column":38}},"4":{"start":{"line":9,"column":4},"end":{"line":9,"column":36}}},"branchMap":{"1":{"line":3,"type":"binary-expr","locations":[{"start":{"line":3,"column":11},"end":{"line":3,"column":17}},{"start":{"line":3,"column":21},"end":{"line":3,"column":42}},{"start":{"line":3,"column":46},"end":{"line":3,"column":74}}]}}},"/Users/am/WebstormProjects/yhsd-api-node/lib/WebHook.js":{"path":"/Users/am/WebstormProjects/yhsd-api-node/lib/WebHook.js","s":{"1":1,"2":1,"3":1,"4":2,"5":1,"6":1,"7":1,"8":4,"9":1,"10":3,"11":3,"12":1},"b":{"1":[1,1],"2":[1,3]},"f":{"1":2,"2":4},"fnMap":{"1":{"name":"(anonymous_1)","line":8,"loc":{"start":{"line":8,"column":14},"end":{"line":8,"column":37}}},"2":{"name":"(anonymous_2)","line":22,"loc":{"start":{"line":22,"column":14},"end":{"line":22,"column":39}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":31}},"3":{"start":{"line":8,"column":0},"end":{"line":13,"column":2}},"4":{"start":{"line":9,"column":2},"end":{"line":11,"column":3}},"5":{"start":{"line":10,"column":4},"end":{"line":10,"column":21}},"6":{"start":{"line":12,"column":2},"end":{"line":12,"column":28}},"7":{"start":{"line":15,"column":0},"end":{"line":29,"column":2}},"8":{"start":{"line":23,"column":4},"end":{"line":25,"column":5}},"9":{"start":{"line":24,"column":6},"end":{"line":24,"column":23}},"10":{"start":{"line":26,"column":4},"end":{"line":26,"column":107}},"11":{"start":{"line":27,"column":4},"end":{"line":27,"column":35}},"12":{"start":{"line":31,"column":0},"end":{"line":31,"column":25}}},"branchMap":{"1":{"line":9,"type":"if","locations":[{"start":{"line":9,"column":2},"end":{"line":9,"column":2}},{"start":{"line":9,"column":2},"end":{"line":9,"column":2}}]},"2":{"line":23,"type":"if","locations":[{"start":{"line":23,"column":4},"end":{"line":23,"column":4}},{"start":{"line":23,"column":4},"end":{"line":23,"column":4}}]}}}}
\ No newline at end of file
diff --git a/coverage/lcov.info b/coverage/lcov.info
index 4988832..b92648e 100644
--- a/coverage/lcov.info
+++ b/coverage/lcov.info
@@ -1,5 +1,5 @@
TN:
-SF:/Users/calvin/source/yeezon/yhsd-api-node/index.js
+SF:/Users/am/WebstormProjects/yhsd-api-node/index.js
FNF:0
FNH:0
DA:1,1
@@ -9,309 +9,444 @@ BRF:0
BRH:0
end_of_record
TN:
-SF:/Users/calvin/source/yeezon/yhsd-api-node/lib/config.js
-FN:6,(anonymous_1)
+SF:/Users/am/WebstormProjects/yhsd-api-node/lib/config.js
+FN:5,(anonymous_1)
FNF:1
FNH:1
FNDA:4,(anonymous_1)
DA:1,1
DA:2,1
DA:3,1
-DA:4,1
-DA:6,1
-DA:7,4
-DA:8,0
-DA:10,4
-DA:11,0
-DA:13,4
-DA:14,0
-DA:15,0
-DA:20,1
-DA:27,1
+DA:5,1
+DA:6,4
+DA:7,0
+DA:9,4
+DA:10,0
+DA:12,4
+DA:13,0
+DA:15,4
+DA:16,0
+DA:21,1
+DA:28,1
LF:14
LH:10
-BRDA:7,1,0,0
-BRDA:7,1,1,4
-BRDA:10,2,0,0
-BRDA:10,2,1,4
-BRDA:13,3,0,0
-BRDA:13,3,1,4
-BRF:6
-BRH:3
+BRDA:6,1,0,0
+BRDA:6,1,1,4
+BRDA:9,2,0,0
+BRDA:9,2,1,4
+BRDA:12,3,0,0
+BRDA:12,3,1,4
+BRDA:15,4,0,0
+BRDA:15,4,1,4
+BRF:8
+BRH:4
end_of_record
TN:
-SF:/Users/calvin/source/yeezon/yhsd-api-node/lib/Auth.js
+SF:/Users/am/WebstormProjects/yhsd-api-node/lib/Auth.js
FN:21,(anonymous_1)
-FN:40,(anonymous_2)
-FN:57,(anonymous_3)
-FN:75,(anonymous_4)
-FN:103,(anonymous_5)
-FN:118,(anonymous_6)
+FN:51,(anonymous_2)
+FN:68,(anonymous_3)
+FN:86,(anonymous_4)
+FN:114,(anonymous_5)
+FN:121,(anonymous_6)
FNF:6
FNH:6
-FNDA:12,(anonymous_1)
-FNDA:2,(anonymous_2)
+FNDA:13,(anonymous_1)
+FNDA:4,(anonymous_2)
FNDA:2,(anonymous_3)
-FNDA:5,(anonymous_4)
+FNDA:4,(anonymous_4)
FNDA:3,(anonymous_5)
FNDA:1,(anonymous_6)
DA:1,1
+DA:2,1
+DA:3,1
+DA:4,1
+DA:5,1
+DA:6,1
DA:21,1
-DA:22,12
+DA:22,13
DA:23,1
-DA:25,11
-DA:26,8
+DA:25,12
+DA:26,10
DA:27,1
-DA:29,7
-DA:31,10
-DA:34,1
-DA:41,2
-DA:42,1
-DA:44,1
+DA:29,9
+DA:32,11
+DA:33,11
+DA:34,11
+DA:35,11
+DA:36,11
+DA:37,11
+DA:38,11
+DA:39,11
+DA:40,11
DA:45,1
-DA:46,1
-DA:58,2
-DA:59,1
-DA:61,1
-DA:76,5
-DA:78,5
-DA:79,3
-DA:80,1
-DA:82,2
-DA:83,2
-DA:84,2
-DA:88,2
-DA:89,1
-DA:91,1
-DA:98,3
-DA:104,3
-DA:105,0
+DA:52,4
+DA:53,1
+DA:55,3
+DA:56,3
+DA:57,3
+DA:69,2
+DA:70,1
+DA:72,1
+DA:87,4
+DA:88,4
+DA:91,4
+DA:92,2
+DA:93,2
+DA:97,2
+DA:98,1
+DA:100,1
DA:108,3
-DA:109,2
-DA:112,1
-DA:113,0
-DA:115,1
-DA:119,1
-DA:120,1
-DA:121,1
+DA:114,3
+DA:115,3
+DA:116,0
+DA:118,1
DA:122,1
-DA:127,1
-LF:41
-LH:39
+DA:123,1
+DA:124,1
+DA:125,1
+DA:130,1
+LF:49
+LH:48
BRDA:22,1,0,1
-BRDA:22,1,1,11
-BRDA:22,2,0,12
-BRDA:22,2,1,12
-BRDA:22,2,2,12
-BRDA:25,3,0,8
-BRDA:25,3,1,3
+BRDA:22,1,1,12
+BRDA:22,2,0,13
+BRDA:22,2,1,13
+BRDA:22,2,2,13
+BRDA:25,3,0,10
+BRDA:25,3,1,2
BRDA:26,4,0,1
-BRDA:26,4,1,7
-BRDA:29,5,0,7
-BRDA:29,5,1,7
-BRDA:41,6,0,1
-BRDA:41,6,1,1
-BRDA:46,7,0,1
-BRDA:46,7,1,0
-BRDA:58,8,0,1
-BRDA:58,8,1,1
-BRDA:78,9,0,3
-BRDA:78,9,1,2
-BRDA:79,10,0,1
-BRDA:79,10,1,2
-BRDA:88,11,0,1
-BRDA:88,11,1,1
-BRDA:95,12,0,0
-BRDA:95,12,1,1
-BRDA:104,13,0,0
-BRDA:104,13,1,3
-BRDA:108,14,0,2
-BRDA:108,14,1,1
-BRDA:112,15,0,0
-BRDA:112,15,1,1
-BRF:31
-BRH:27
+BRDA:26,4,1,9
+BRDA:29,5,0,9
+BRDA:29,5,1,9
+BRDA:32,6,0,11
+BRDA:32,6,1,0
+BRDA:33,7,0,11
+BRDA:33,7,1,0
+BRDA:34,8,0,11
+BRDA:34,8,1,9
+BRDA:35,9,0,11
+BRDA:35,9,1,2
+BRDA:36,10,0,11
+BRDA:36,10,1,2
+BRDA:37,11,0,11
+BRDA:37,11,1,11
+BRDA:38,12,0,11
+BRDA:38,12,1,11
+BRDA:39,13,0,11
+BRDA:39,13,1,11
+BRDA:52,14,0,1
+BRDA:52,14,1,3
+BRDA:57,15,0,3
+BRDA:57,15,1,2
+BRDA:69,16,0,1
+BRDA:69,16,1,1
+BRDA:91,17,0,2
+BRDA:91,17,1,2
+BRDA:97,18,0,1
+BRDA:97,18,1,1
+BRDA:104,19,0,0
+BRDA:104,19,1,1
+BRDA:115,20,0,0
+BRDA:115,20,1,1
+BRF:41
+BRH:37
end_of_record
TN:
-SF:/Users/calvin/source/yeezon/yhsd-api-node/lib/request.js
-FN:4,(anonymous_1)
-FN:8,(anonymous_2)
-FN:14,(anonymous_3)
-FN:16,(anonymous_4)
-FN:27,(anonymous_5)
-FN:30,(anonymous_6)
-FNF:6
-FNH:5
-FNDA:4,(anonymous_1)
-FNDA:10,(anonymous_2)
-FNDA:10,(anonymous_3)
-FNDA:10,(anonymous_4)
-FNDA:10,(anonymous_5)
-FNDA:0,(anonymous_6)
+SF:/Users/am/WebstormProjects/yhsd-api-node/lib/Request.js
+FN:15,genStringify
+FN:36,increment
+FN:45,decrement
+FN:56,(anonymous_4)
+FN:69,(anonymous_5)
+FN:73,(anonymous_6)
+FN:76,(anonymous_7)
+FN:98,(anonymous_8)
+FN:101,(anonymous_9)
+FN:104,(anonymous_10)
+FN:119,(anonymous_11)
+FN:127,(anonymous_12)
+FN:132,(anonymous_13)
+FN:150,(anonymous_14)
+FNF:14
+FNH:14
+FNDA:7,genStringify
+FNDA:208,increment
+FNDA:207,decrement
+FNDA:15,(anonymous_4)
+FNDA:212,(anonymous_5)
+FNDA:212,(anonymous_6)
+FNDA:212,(anonymous_7)
+FNDA:212,(anonymous_8)
+FNDA:211,(anonymous_9)
+FNDA:211,(anonymous_10)
+FNDA:211,(anonymous_11)
+FNDA:212,(anonymous_12)
+FNDA:208,(anonymous_13)
+FNDA:211,(anonymous_14)
DA:1,1
-DA:5,4
-DA:8,1
-DA:9,10
-DA:10,0
-DA:11,0
-DA:13,10
-DA:14,10
-DA:15,10
-DA:16,10
-DA:17,10
-DA:18,10
-DA:19,10
-DA:21,0
-DA:23,10
-DA:25,10
-DA:27,10
-DA:28,10
-DA:30,10
-DA:31,0
-DA:34,10
-DA:35,6
-DA:36,6
-DA:37,3
-DA:39,3
-DA:42,3
-DA:43,3
-DA:46,6
-DA:48,10
-DA:51,1
-LF:30
-LH:26
-BRDA:9,1,0,0
-BRDA:9,1,1,10
-BRDA:34,2,0,6
-BRDA:34,2,1,4
-BRDA:36,3,0,3
-BRDA:36,3,1,3
-BRDA:36,4,0,6
-BRDA:36,4,1,6
-BRDA:39,5,0,2
-BRDA:39,5,1,3
-BRF:10
-BRH:9
+DA:2,1
+DA:3,1
+DA:5,1
+DA:6,1
+DA:7,1
+DA:15,1
+DA:16,7
+DA:17,7
+DA:19,4
+DA:21,3
+DA:24,3
+DA:25,3
+DA:28,7
+DA:36,1
+DA:37,208
+DA:38,208
+DA:39,208
+DA:45,1
+DA:46,207
+DA:47,207
+DA:48,207
+DA:50,0
+DA:52,207
+DA:56,1
+DA:57,15
+DA:58,15
+DA:59,15
+DA:60,15
+DA:63,1
+DA:70,212
+DA:72,212
+DA:76,212
+DA:77,212
+DA:78,212
+DA:80,212
+DA:83,212
+DA:84,7
+DA:85,7
+DA:88,212
+DA:99,212
+DA:101,212
+DA:102,211
+DA:104,211
+DA:105,211
+DA:106,211
+DA:107,211
+DA:109,0
+DA:112,211
+DA:113,211
+DA:116,211
+DA:119,211
+DA:120,211
+DA:128,212
+DA:130,212
+DA:131,208
+DA:133,208
+DA:135,208
+DA:136,0
+DA:138,208
+DA:144,4
+DA:151,211
+DA:153,211
+DA:154,207
+DA:155,207
+DA:162,4
+DA:167,1
+LF:67
+LH:64
+BRDA:17,1,0,4
+BRDA:17,1,1,3
+BRDA:17,2,0,7
+BRDA:17,2,1,7
+BRDA:21,3,0,2
+BRDA:21,3,1,3
+BRDA:37,4,0,208
+BRDA:37,4,1,208
+BRDA:46,5,0,207
+BRDA:46,5,1,8
+BRDA:47,6,0,207
+BRDA:47,6,1,0
+BRDA:57,7,0,15
+BRDA:57,7,1,14
+BRDA:58,8,0,15
+BRDA:58,8,1,14
+BRDA:59,9,0,15
+BRDA:59,9,1,3
+BRDA:60,10,0,15
+BRDA:60,10,1,14
+BRDA:77,11,0,0
+BRDA:77,11,1,212
+BRDA:83,12,0,7
+BRDA:83,12,1,205
+BRDA:130,13,0,208
+BRDA:130,13,1,4
+BRDA:133,14,0,208
+BRDA:133,14,1,208
+BRDA:135,15,0,0
+BRDA:135,15,1,208
+BRDA:153,16,0,207
+BRDA:153,16,1,4
+BRDA:154,17,0,207
+BRDA:154,17,1,0
+BRDA:154,18,0,207
+BRDA:154,18,1,207
+BRF:36
+BRH:32
end_of_record
TN:
-SF:/Users/calvin/source/yeezon/yhsd-api-node/lib/Api.js
-FN:11,(anonymous_1)
+SF:/Users/am/WebstormProjects/yhsd-api-node/lib/Api.js
+FN:12,check
FN:25,(anonymous_2)
-FN:32,(anonymous_3)
-FN:42,(anonymous_4)
-FN:46,(anonymous_5)
-FN:56,(anonymous_6)
-FN:60,(anonymous_7)
-FN:69,(anonymous_8)
-FN:73,(anonymous_9)
-FN:83,(anonymous_10)
-FN:92,(anonymous_11)
+FN:35,(anonymous_3)
+FN:46,(anonymous_4)
+FN:47,(anonymous_5)
+FN:66,(anonymous_6)
+FN:92,(anonymous_7)
+FN:104,(anonymous_8)
+FN:116,(anonymous_9)
+FN:127,(anonymous_10)
+FN:140,(anonymous_11)
FNF:11
FNH:11
-FNDA:2,(anonymous_1)
-FNDA:3,(anonymous_2)
-FNDA:2,(anonymous_3)
-FNDA:2,(anonymous_4)
-FNDA:1,(anonymous_5)
+FNDA:2,check
+FNDA:15,(anonymous_2)
+FNDA:22,(anonymous_3)
+FNDA:4,(anonymous_4)
+FNDA:37,(anonymous_5)
FNDA:3,(anonymous_6)
-FNDA:2,(anonymous_7)
-FNDA:3,(anonymous_8)
-FNDA:2,(anonymous_9)
-FNDA:7,(anonymous_10)
-FNDA:7,(anonymous_11)
+FNDA:4,(anonymous_7)
+FNDA:2,(anonymous_8)
+FNDA:3,(anonymous_9)
+FNDA:3,(anonymous_10)
+FNDA:8,(anonymous_11)
DA:1,1
-DA:11,1
-DA:12,2
-DA:13,1
-DA:15,1
-DA:18,1
-DA:26,3
-DA:27,1
-DA:28,2
-DA:29,1
-DA:30,1
-DA:32,2
-DA:33,2
-DA:43,2
-DA:44,1
+DA:2,1
+DA:4,1
+DA:5,1
+DA:6,1
+DA:8,1
+DA:9,1
+DA:10,1
+DA:12,1
+DA:13,2
+DA:16,0
+DA:25,1
+DA:26,15
+DA:35,1
+DA:36,22
+DA:37,22
DA:46,1
-DA:47,1
-DA:57,3
-DA:58,1
-DA:60,2
-DA:61,2
-DA:70,3
-DA:71,1
+DA:47,4
+DA:49,37
+DA:51,37
+DA:52,37
+DA:66,1
+DA:67,3
+DA:68,1
+DA:70,2
+DA:72,2
DA:73,2
-DA:74,2
-DA:84,7
-DA:93,7
-DA:94,0
-DA:96,7
-DA:97,1
-DA:99,6
-DA:105,1
-LF:32
-LH:31
-BRDA:12,1,0,1
-BRDA:12,1,1,1
-BRDA:26,2,0,1
-BRDA:26,2,1,2
-BRDA:28,3,0,1
-BRDA:28,3,1,1
-BRDA:32,4,0,1
-BRDA:32,4,1,1
-BRDA:33,5,0,2
-BRDA:33,5,1,2
-BRDA:33,6,0,1
-BRDA:33,6,1,1
-BRDA:43,7,0,1
-BRDA:43,7,1,1
-BRDA:47,8,0,1
-BRDA:47,8,1,1
-BRDA:47,9,0,0
-BRDA:47,9,1,1
-BRDA:57,10,0,1
-BRDA:57,10,1,2
-BRDA:61,11,0,2
-BRDA:61,11,1,2
-BRDA:61,12,0,0
-BRDA:61,12,1,2
-BRDA:70,13,0,1
-BRDA:70,13,1,2
-BRDA:74,14,0,2
-BRDA:74,14,1,2
-BRDA:93,15,0,0
-BRDA:93,15,1,7
-BRDA:96,16,0,1
-BRDA:96,16,1,6
-BRF:32
-BRH:29
+DA:75,2
+DA:76,2
+DA:78,2
+DA:85,1
+DA:93,4
+DA:94,1
+DA:96,3
+DA:105,2
+DA:106,1
+DA:108,1
+DA:117,3
+DA:118,1
+DA:120,2
+DA:128,3
+DA:129,1
+DA:131,2
+DA:141,8
+DA:153,1
+LF:45
+LH:44
+BRDA:13,1,0,0
+BRDA:13,1,1,2
+BRDA:13,2,0,2
+BRDA:13,2,1,1
+BRDA:13,2,2,1
+BRDA:13,2,3,0
+BRDA:13,2,4,0
+BRDA:67,3,0,1
+BRDA:67,3,1,2
+BRDA:73,4,0,2
+BRDA:73,4,1,1
+BRDA:73,4,2,1
+BRDA:75,5,0,2
+BRDA:75,5,1,1
+BRDA:75,5,2,2
+BRDA:76,6,0,2
+BRDA:76,6,1,1
+BRDA:76,6,2,2
+BRDA:79,7,0,2
+BRDA:79,7,1,1
+BRDA:79,7,2,1
+BRDA:93,8,0,1
+BRDA:93,8,1,3
+BRDA:96,9,0,1
+BRDA:96,9,1,2
+BRDA:105,10,0,1
+BRDA:105,10,1,1
+BRDA:117,11,0,1
+BRDA:117,11,1,2
+BRDA:128,12,0,1
+BRDA:128,12,1,2
+BRF:31
+BRH:28
end_of_record
TN:
-SF:/Users/calvin/source/yeezon/yhsd-api-node/lib/WebHook.js
+SF:/Users/am/WebstormProjects/yhsd-api-node/lib/util.js
+FN:2,(anonymous_1)
+FN:5,(anonymous_2)
+FN:8,(anonymous_3)
+FNF:3
+FNH:0
+FNDA:0,(anonymous_1)
+FNDA:0,(anonymous_2)
+FNDA:0,(anonymous_3)
+DA:1,1
+DA:3,0
+DA:6,0
+DA:9,0
+LF:4
+LH:1
+BRDA:3,1,0,0
+BRDA:3,1,1,0
+BRDA:3,1,2,0
+BRF:3
+BRH:0
+end_of_record
+TN:
+SF:/Users/am/WebstormProjects/yhsd-api-node/lib/WebHook.js
FN:8,(anonymous_1)
FN:22,(anonymous_2)
FNF:2
FNH:2
FNDA:2,(anonymous_1)
-FNDA:2,(anonymous_2)
+FNDA:4,(anonymous_2)
DA:1,1
+DA:2,1
DA:8,1
DA:9,2
DA:10,1
DA:12,1
DA:15,1
-DA:23,2
+DA:23,4
DA:24,1
-DA:26,1
-DA:30,1
-LF:10
-LH:10
+DA:26,3
+DA:27,3
+DA:31,1
+LF:12
+LH:12
BRDA:9,1,0,1
BRDA:9,1,1,1
BRDA:23,2,0,1
-BRDA:23,2,1,1
+BRDA:23,2,1,3
BRF:4
BRH:4
end_of_record
diff --git a/lib/Api.js b/lib/Api.js
index ec2cc9d..233e012 100644
--- a/lib/Api.js
+++ b/lib/Api.js
@@ -1,104 +1,152 @@
-var querystring = require('querystring'),
- config = require('./config'),
- request = require('./request'),
- paramError = new Error('缺少参数');
+var querystring = require('querystring');
+var Promise = require('bluebird');
+
+var util = require('./util');
+var config = require('./config');
+var Request = require('./Request');
+
+var reqCountMap = {};
+paramError = new Error('缺少参数');
+promiseError = new Error('`getRequestCount`和`saveRequestCount`必须是 function');
+
+function check(option) {
+ if (option &&
+ (option.getRequestCount || option.saveRequestCount) &&
+ (!util.isFunction(option.getRequestCount) || !util.isFunction(option.saveRequestCount))) {
+ throw promiseError;
+ }
+}
+
+/**
+ * 请求数的读取操作
+ * @param token 商店 token
+ * @type {null|Function}
+ */
+var getReqCountHandle = function (token) {
+ return reqCountMap[token];
+};
+
+/**
+ * 请求数的保存操作
+ * @param token 商店 token
+ * @param count 需要保存的请求数
+ * @type {null|Function}
+ */
+var saveReqCountHandle = function (token, count) {
+ reqCountMap[token] = count;
+ return reqCountMap[token];
+};
+
+/**
+ * 包装 token 函数
+ * @param token
+ * @param fn
+ * @returns {function()}
+ */
+var reqCountWrap = function (token, fn) {
+ return function () {
+ // arguments 转成数组
+ var args = Array.prototype.slice.call(arguments);
+ // 插入 token
+ args.unshift(token);
+ return Promise.cast(fn.call(null, args));
+ };
+};
/**
* 初始化
* @param {string} token
+ * @param {object} option
+ * @param {string} option.protocol 可选,'http'或者'https',默认'https'
+ * @param {string} option.host 可选,开发 API 接口域名,默认'api.youhaosuda.com'
+ * @param {function} option.getRequestCount 获取请求数函数
+ * @param {function} option.saveRequestCount 存储请求数函数
* @constructor
*/
-var Api = function(token) {
+var Api = function (token, option) {
if (arguments.length < 1) {
throw paramError;
}
+ check(option);
+
this.token = token;
+ this.host = (option && option.host) || config.apiHost;
+ // 存取请求数的回调函数
+ this.getRequestCount = option && option.getRequestCount || getReqCountHandle;
+ this.saveRequestCount = option && option.saveRequestCount || saveReqCountHandle;
+ // 请求实例
+ this._request = new Request({
+ protocol: (option && option.protocol) || config.httpProtocol,
+ getRequestCount: reqCountWrap(this.token, this.getRequestCount),
+ saveRequestCount: reqCountWrap(this.token, this.saveRequestCount),
+ });
};
Api.prototype = {
/**
* 发送 GET 请求
* @param {string} path
- * @param {Object} [query]
- * @param {Function} callback
+ * @param {object} query
+ * @returns {Object}
*/
- get: function(path, query, callback) {
- if (arguments.length < 2) {
+ get: function (path, query) {
+ if (arguments.length < 1) {
throw paramError;
- } else if (arguments.length < 3) {
- callback = query;
- query = null;
}
- this.httpRequest('GET', query ? path + '?' + querystring.stringify(query) : path, null, function(err, data) {
- callback && (callback(err, err ? null : data));
- });
+ return this.request('GET', query ? path + '?' + querystring.stringify(query) : path, null);
},
/**
* 发送 PUT 请求
* @param {string} path
- * @param {Object} data
- * @param {Function} callback
+ * @param {object} data
+ * @returns {Object}
*/
- put: function(path, data, callback) {
- if (arguments.length < 3) {
+ put: function (path, data) {
+ if (arguments.length < 2) {
throw paramError;
}
- this.httpRequest('PUT', path, data, function(err, data) {
- callback && (callback(err, err ? null : data));
- });
+ return this.request('PUT', path, data);
},
/**
* 发送 POST 请求
* @param {string} path
- * @param {Object} data
- * @param {Function} callback
+ * @param {object} data
+ * @returns {Object}
*/
- post: function(path, data, callback) {
- if (arguments.length < 3) {
+ post: function (path, data) {
+ if (arguments.length < 2) {
throw paramError;
}
- this.httpRequest('POST', path, data, function(err, data) {
- callback && (callback(err, err ? null : data));
- });
+ return this.request('POST', path, data);
},
/**
* 发送 DELETE 请求
* @param {string} path
- * @param {Function} callback
+ * @returns {Object}
*/
- delete: function(path, callback) {
- if (arguments.length < 2) {
+ delete: function (path) {
+ if (arguments.length < 1) {
throw paramError;
}
- this.httpRequest('DELETE', path, null, function(err) {
- callback && (callback(err));
- });
+ return this.request('DELETE', path, null);
},
/**
+ * 请求函数
* @param {string} method
* @param {string} path
- * @param {Object} [params]
- * @param {Function} callback
+ * @param {object} params
+ * @returns {Object}
*/
- httpRequest: function(method, path, params, callback) {
- request({
- hostname: config.apiHost,
+ request: function (method, path, params) {
+ return this._request.request({
+ hostname: this.host,
path: '/v1/' + path,
method: method,
headers: {
'Content-Type': 'application/json',
'X-API-ACCESS-TOKEN': this.token
}
- }, params, function(err, data) {
- if (err) {
- return callback(err);
- }
- if (data.code) {
- callback(data);
- } else {
- callback(null, data);
- }
- });
+ }, params);
}
};
diff --git a/lib/Auth.js b/lib/Auth.js
index 6d94a99..4bb112f 100644
--- a/lib/Auth.js
+++ b/lib/Auth.js
@@ -1,126 +1,129 @@
-var querystring = require('querystring'),
- crypto = require('crypto'),
- config = require('./config'),
- request = require('./request'),
- timeOffset = 1000 * 60 * 10,
- paramError = new Error('缺少参数');
+var querystring = require('querystring');
+var crypto = require('crypto');
+var config = require('./config');
+var Request = require('./Request');
+var timeOffset = 1000 * 60 * 10;
+var paramError = new Error('缺少参数');
/**
- * 初始化
+ * 构造函数
* @param {Object} options
+ * @param {string} options.appKey 应用的appKey
+ * @param {string} options.appSecret 应用的appSecret
+ * @param {string} options.callbackUrl 用于开放应用,应用管理后台设置的回调地址
+ * @param {string} options.redirectUrl 用于开放应用,可选,自定义回调地址,默认同 callbackUrl
+ * @param {Array} options.scope 用scope 于开放应用,可选,权限范围,默认为 ['read_basic']
+ * @param {Boolean} options.private 可选,是否为私有应用,默认为 false
+ * @param {string} options.protocol 可选,'http'或者'https',默认'https'
+ * @param {string} options.host 可选,开发 API 接口域名,默认'api.youhaosuda.com'
* @constructor
- *
- * options 可选值:
- * appKey {string} 应用的appKey
- * appSecret {string} 应用的appSecret
- * callbackUrl {string} 用于开放应用,应用管理后台设置的回调地址
- * redirectUrl {string} 用于开放应用,可选,自定义回调地址,默认同 callbackUrl
- * scope {Array} 用于开放应用,可选,权限范围,默认为 ['read_basic']
- * private {boolean} 可选,是否为私有应用,默认为 false
*/
var Auth = function (options) {
- if (arguments.length < 1 || !options.appKey || !options.appSecret) {
- throw paramError;
- }
- if (!options.private) {
- if (!options.callbackUrl) {
- throw paramError;
- }
- options.scope || (options.scope = ['read_basic']);
+ if (arguments.length < 1 || !options.appKey || !options.appSecret) {
+ throw paramError;
+ }
+ if (!options.private) {
+ if (!options.callbackUrl) {
+ throw paramError;
}
- this.options = options;
+ options.scope || (options.scope = ['read_basic']);
+ }
+
+ this.app_key = options.appKey || '';
+ this.app_secret = options.appSecret || '';
+ this.private = options.private || false;
+ this.callback_url = options.callbackUrl || '';
+ this.scope = options.scope || '';
+ this.redirect_url = options.redirectUrl || '';
+ this.protocol = options.protocol || config.httpProtocol;
+ this.host = options.host || config.appHost;
+ this._request = new Request({
+ protocol: this.protocol,
+ });
};
Auth.prototype = {
- /**
- * 验证 Hmac
- * @param {Object} queryObj 回调地址的参数对象
- * @return {boolean}
- */
- verifyHmac: function (queryObj) {
- if (arguments.length < 1) {
- throw paramError;
- }
- var hmac = queryObj.hmac;
- delete queryObj.hmac;
- return (Date.now() - new Date(queryObj.time_stamp).getTime() < timeOffset) &&
- (hmac === crypto.createHmac('sha256', this.options.appSecret)
- .update(decodeURIComponent(querystring.stringify(queryObj)), 'utf8')
- .digest('hex'));
- },
- /**
- * 获取应用授权页面地址,用于开放应用
- * @param {string} shopKey
- * @param {string} state
- * @return {string}
- */
- getAuthorizeUrl: function (shopKey, state) {
- if (arguments.length < 1) {
- throw paramError;
- }
- return config.httpProtocol + '://' + config.appHost + '/oauth2/authorize?' + querystring.stringify({
- response_type: 'code',
- client_id: this.options.appKey,
- shop_key: shopKey,
- scope: this.options.scope.join(','),
- state: state,
- redirect_uri: this.options.redirectUrl
- }, null, null, {encodeURIComponent: null});
- },
- /**
- * 获取 token
- * @param {string} code,用于开放应用
- * @param {Function} callback(err, token)
- */
- getToken: function (code, callback) {
- var params,
- headers = {'Content-Type': 'application/x-www-form-urlencoded'};
- if (this.options.private) {
- if (arguments.length < 1) {
- throw paramError;
- }
- callback = arguments[0];
- headers.Authorization = 'Basic ' + new Buffer(this.options.appKey + ':' + this.options.appSecret).toString('base64');
- params = {
- grant_type: 'client_credentials'
- };
- } else {
- if (arguments.length < 2) {
- throw paramError;
- }
- params = {
- grant_type: 'authorization_code',
- code: code,
- client_id: this.options.appKey,
- redirect_uri: this.options.redirectUrl ? this.options.redirectUrl : this.options.callbackUrl
- };
- }
- request({
- hostname: config.appHost,
- path: '/oauth2/token',
- method: 'POST',
- headers: headers
- }, params, function (err, data) {
- if (err) {
- return callback(err);
- }
+ /**
+ * 验证 Hmac
+ * @param {Object} queryObj 回调地址的参数对象
+ * @return {boolean}
+ */
+ verifyHmac: function (queryObj) {
+ if (arguments.length < 1) {
+ throw paramError;
+ }
+ var hmac = queryObj.hmac;
+ delete queryObj.hmac;
+ return (Date.now() - new Date(queryObj.time_stamp).getTime() < timeOffset) &&
+ (hmac === crypto.createHmac('sha256', this.app_secret)
+ .update(decodeURIComponent(querystring.stringify(queryObj)), 'utf8')
+ .digest('hex'));
+ },
+ /**
+ * 获取应用授权页面地址,用于开放应用
+ * @param {string} shopKey
+ * @param {string} state
+ * @return {string}
+ */
+ getAuthorizeUrl: function (shopKey, state) {
+ if (arguments.length < 1) {
+ throw paramError;
+ }
+ return this.protocol + '://' + this.host + '/oauth2/authorize?' + querystring.stringify({
+ response_type: 'code',
+ client_id: this.app_key,
+ shop_key: shopKey,
+ scope: this.scope.join(','),
+ state: state,
+ redirect_uri: this.redirect_url
+ }, null, null, { encodeURIComponent: null });
+ },
+ /**
+ * 获取 token
+ * @param {string} code,用于开放应用
+ * @returns {Object}
+ */
+ getToken: function (code) {
+ var params;
+ var headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
- if(data.error) {
- return callback(data.error);
- }
- if (!data.token.length) {
- return callback('无效的 token');
- }
- callback(null, data.token);
- });
- },
- customerData: function (secret_key, customer_data) {
- var customer_str = JSON.stringify(customer_data);
- var cipher = crypto.createCipher('aes-256-cbc', secret_key);
- var crypted = cipher.update(customer_str, 'utf8', 'hex');
- return cipher.final('hex');
+ if (this.private) {
+ headers.Authorization = 'Basic ' + new Buffer(this.app_key + ':' + this.app_secret).toString('base64');
+ params = {
+ grant_type: 'client_credentials'
+ };
+ } else {
+ if (arguments.length < 1) {
+ throw paramError;
+ }
+ params = {
+ grant_type: 'authorization_code',
+ code: code,
+ client_id: this.app_key,
+ redirect_uri: this.redirect_url ? this.redirect_url : this.callback_url
+ };
}
+
+ var option = {
+ hostname: this.host,
+ path: '/oauth2/token',
+ method: 'POST',
+ headers: headers
+ };
+ return this._request.request(option, params).then(function (data) {
+ if (!data.token.length) {
+ throw new Error('无效的 token');
+ }
+ return data.token;
+ });
+ },
+ customerData: function (secret_key, customer_data) {
+ var customer_str = JSON.stringify(customer_data);
+ var cipher = crypto.createCipher('aes-256-cbc', secret_key);
+ var crypted = cipher.update(customer_str, 'utf8', 'hex');
+ return cipher.final('hex');
+ }
};
diff --git a/lib/Request.js b/lib/Request.js
new file mode 100644
index 0000000..0e324ce
--- /dev/null
+++ b/lib/Request.js
@@ -0,0 +1,167 @@
+var Promise = require('bluebird');
+var querystring = require('querystring');
+var config = require('./config');
+
+var MINUEND = 1; // 每次漏出的数量
+var SUMMAND = 1; // 每次恢复数量
+var API_CALL_LIMIT = 'x-yhsd-shop-api-call-limit'; // yhsd 接口返回的请求量 header
+
+
+/**
+ * stringify 参数
+ * @param options
+ * @returns {*}
+ */
+function genStringify(options) {
+ var stringifyFn;
+ if (options.headers['Content-Type'] &&
+ options.headers['Content-Type'].toLowerCase() === 'application/x-www-form-urlencoded') {
+ stringifyFn = querystring.stringify;
+ } else {
+ switch (options.method.toUpperCase()) {
+ case 'POST':
+ case 'PUT':
+ stringifyFn = JSON.stringify;
+ break;
+ }
+ }
+ return stringifyFn;
+}
+
+/**
+ * 增加1个请求
+ * @param count
+ * @returns {*}
+ */
+function increment(count) {
+ count = count || 0;
+ count += SUMMAND;
+ return count;
+}
+
+/**
+ * 释放1个请求
+ */
+function decrement(count) {
+ count = count || 0;
+ if (count <= MINUEND) {
+ count = 0;
+ } else {
+ count -= MINUEND;
+ }
+ return count;
+}
+
+
+var Request = function (option) {
+ this.getRequestCount = option && option.getRequestCount;
+ this.saveRequestCount = option && option.saveRequestCount;
+ this.counted = this.getRequestCount && this.saveRequestCount;
+ this.protocol = option && option.protocol;
+};
+
+Request.prototype = {
+ /**
+ * 请求操作
+ * @param options
+ * @param params
+ */
+ request: function (options, params) {
+ var self = this;
+
+ return this.onBeforeHandle()
+ .then(function () {
+
+ // 请求 Promise
+ return new Promise(function (resolve, reject) {
+ var client = this.protocol === 'http' ? require('http') : require('https');
+ var req = client.request(options, self.genResponseFn(resolve, reject));
+
+ req.on('error', reject);
+
+ // 发送参数
+ if (params) {
+ var stringify = genStringify(options);
+ req.write(stringify(params));
+ }
+
+ req.end();
+ });
+ });
+ },
+ /**
+ * response 操作
+ * @param resolve
+ * @param reject
+ * @returns {Function}
+ */
+ genResponseFn: function (resolve, reject) {
+ var self = this;
+
+ return function (res) {
+ var buf = [];
+
+ res.on('end', function () {
+ var data = Buffer.concat(buf).toString();
+ try {
+ data = JSON.parse(data);
+ } catch (err) {
+ reject(err);
+ } finally {
+ //释放当前请求数
+ var count = +(config.requestLimit * (eval(res.headers[API_CALL_LIMIT]) + 1e-6)).toFixed(0);
+ self.onAfterHandle(count);
+ //返回结果
+ }
+ resolve(data);
+ });
+
+ res.on('data', function (data) {
+ buf.push(data);
+ });
+ };
+ },
+ /**
+ * 请求前的操作
+ */
+ onBeforeHandle: function () {
+ var self = this;
+
+ if (this.counted) {
+ return this.getRequestCount()
+ .then(function (count) {
+ count = count || 0;
+ //如果请求数超过限制则 setTimeout 排队
+ if (count >= config.requestLimit) {
+ return Promise.delay(config.requestTimeout).then(self.onBeforeHandle);
+ }
+ return count;
+ })
+ .then(increment)
+ .then(this.saveRequestCount);
+ }
+
+ return Promise.resolve();
+ },
+ /**
+ * 请求后的操作
+ * @param count
+ */
+ onAfterHandle: function (count) {
+ var delayMs = count * config.requestTimeout;
+
+ if (this.counted) {
+ if (this.getRequestCount && this.saveRequestCount)
+ return this.saveRequestCount(count)
+ .delay(delayMs)
+ .then(this.getRequestCount)
+ .then(decrement)
+ .then(this.saveRequestCount);
+ }
+
+ return Promise.resolve();
+ }
+};
+
+
+module.exports = Request;
diff --git a/lib/WebHook.js b/lib/WebHook.js
index 298d08e..3eeb189 100644
--- a/lib/WebHook.js
+++ b/lib/WebHook.js
@@ -1,5 +1,5 @@
var paramError = new Error('缺少参数');
-const crypto = require('crypto');
+var crypto = require('crypto');
/**
* 初始化
diff --git a/lib/config.js b/lib/config.js
index b02a803..ebab051 100644
--- a/lib/config.js
+++ b/lib/config.js
@@ -1,6 +1,5 @@
var appHost = 'apps.youhaosuda.com';
var apiHost = 'api.youhaosuda.com';
-var http = require('https');
var httpProtocol = 'https';
process.argv.forEach(function (val,index) {
@@ -11,18 +10,19 @@ process.argv.forEach(function (val,index) {
apiHost = process.argv[index + 1];
}
if(val === '-http'){
- http = require('http');
httpProtocol = 'http';
}
+ if(val === '-https'){
+ httpProtocol = 'https';
+ }
});
var config = {
- http: http,
httpProtocol: httpProtocol,
appHost: appHost,
apiHost: apiHost,
- requestLimit: 40,
- requestTimeout: 510
+ requestLimit: 100, // 每秒请求数限制
+ requestTimeout: 100, // 每个请求数释放所消耗的 ms
};
module.exports = config;
diff --git a/lib/request.js b/lib/request.js
deleted file mode 100644
index 2de896c..0000000
--- a/lib/request.js
+++ /dev/null
@@ -1,58 +0,0 @@
-var querystring = require('querystring'),
- config = require('./config'),
- requestCount = 0,
- fnReduceRequestCount = function() {
- requestCount--;
- };
-
-var request = function(options, params, callback) {
- if (requestCount == config.requestLimit) {
- setTimeout(request, config.requestTimeout, options, params, callback);
- return;
- }
- requestCount++;
- var req = config.http.request(options, function(res) {
- var buf = [];
- res.on('end', function() {
- var data = Buffer.concat(buf).toString();
- try {
- data = JSON.parse(data);
- } catch (err) {
- callback(err);
- } finally {
- setTimeout(fnReduceRequestCount, config.requestLimit * config.requestTimeout * eval(res.headers['x-yhsd-shop-api-call-limit']));
- }
- callback(null, data);
- });
- res.on('data', function(data) {
- buf.push(data);
- });
- res.on('error', function(err) {
- //response error event
- callback(err);
- });
- });
-
- req.on('error', function(err) {
- //request error event
- callback(err);
- });
-
- if (params) {
- var stringify;
- if (options.headers['Content-Type'] && options.headers['Content-Type'].toLowerCase() == 'application/x-www-form-urlencoded') {
- stringify = querystring.stringify;
- } else {
- switch(options.method.toUpperCase()) {
- case 'POST':
- case 'PUT':
- stringify = JSON.stringify;
- break;
- }
- }
- req.write(stringify(params));
- }
- req.end();
-};
-
-module.exports = request;
diff --git a/lib/util.js b/lib/util.js
new file mode 100644
index 0000000..13b37ca
--- /dev/null
+++ b/lib/util.js
@@ -0,0 +1,11 @@
+module.exports = {
+ isPromise: function (object) {
+ return object && this.isObject(object) && this.isFunction(object.then);
+ },
+ isObject: function (object) {
+ return typeof object === 'object';
+ },
+ isFunction: function (fn) {
+ return typeof fn === 'function';
+ }
+};
\ No newline at end of file
diff --git a/package.json b/package.json
index f302d0e..112cd12 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "yhsd-api",
- "version": "1.0.6",
+ "version": "2.0.0",
"description": "Youhaosuda API SDK for node.",
"main": "index.js",
"repository": {
@@ -26,5 +26,6 @@
"should": "^8.0.2"
},
"dependencies": {
+ "bluebird": "^3.5.1"
}
}
diff --git a/test/api.test.js b/test/api.test.js
index 8f68991..3958a21 100644
--- a/test/api.test.js
+++ b/test/api.test.js
@@ -5,154 +5,122 @@ var should = require('should');
var Yhsd = require('../index');
describe('test/api.test.js', function () {
- var api;
- before(function () {
- api = new Yhsd.Api('fbc7f83524f14e358a325a5066acd741');
- });
+ var api;
+ before(function () {
+ api = new Yhsd.Api('5e242b4b41d14a2d8f4d80a9c6b05bea');
+ });
- it('get api instance should throw error', function () {
- (function () {
- new Yhsd.Api()
- }).should.throw('缺少参数');
- });
+ it('get api instance should throw error', function () {
+ (function () {
+ new Yhsd.Api();
+ }).should.throw('缺少参数');
+ });
- it('http get should be throw error', function () {
- (function () {
- api.get()
- }).should.throw('缺少参数');
- });
+ it('http get should be throw error', function () {
+ (function () {
+ api.get();
+ }).should.throw('缺少参数');
+ });
- it('http get should be success', function (done) {
- api.get('products', {fields: 'id'}, function (err, body) {
- should.not.exist(err);
- should.exist(body);
- done();
- //13576
- })
+ it('http get should be success', function (done) {
+ api.get('products', { fields: 'id' }).then(function (body) {
+ should.exist(body);
+ done();
+ //13576
});
+ });
- it('http put should be throw error', function () {
- (function () {
- api.put()
- }).should.throw('缺少参数');
- });
+ it('http put should be throw error', function () {
+ (function () {
+ api.put();
+ }).should.throw('缺少参数');
+ });
- it('http put should be success', function (done) {
- api.put('themes/13576', {"theme": {"name": "测试主题"}}, function (err, body) {
- should.not.exist(err);
- should.exist(body);
- done();
- //13576
- })
+ it('http put should be success', function (done) {
+ api.put('themes/13576', { "theme": { "name": "测试主题" } }).then(function (body) {
+ should.exist(body);
+ done();
+ //13576
});
+ });
- it('http post should be throw error', function () {
- (function () {
- api.post()
- }).should.throw('缺少参数');
- });
+ it('http post should be throw error', function () {
+ (function () {
+ api.post();
+ }).should.throw('缺少参数');
+ });
- it('http post should be success', function (done) {
- var obj = {
- meta: {
- name: new Date().getTime() + '',
- owner_id: '0',
- owner_resource: 'shop',
- fields: {'test': 'test'},
- descriptions: 'test'
- }
- };
- api.post('metas', obj, function (err, body) {
- should.not.exist(err);
- should.exist(body);
- var id = body.meta.id;
- api.delete('metas/' + id, function (err) {
- should.not.exist(err);
- done();
- })
- })
+ it('http post should be success', function (done) {
+ var obj = {
+ meta: {
+ name: new Date().getTime() + '',
+ owner_id: '0',
+ owner_resource: 'shop',
+ fields: { 'test': 'test' },
+ descriptions: 'test'
+ }
+ };
+ api.post('metas', obj).then(function (body) {
+ should.exist(body);
+ var id = body.meta.id;
+ api.delete('metas/' + id).then(function (body) {
+ should.exist(body);
+ done();
+ });
});
+ });
+
+ it('http delete should be throw error', function () {
+ (function () {
+ api.delete();
+ }).should.throw('缺少参数');
+ });
- it('http delete should be throw error', function () {
- (function () {
- api.delete()
- }).should.throw('缺少参数');
+ it('http delete should be success', function (done) {
+ var obj = {
+ meta: {
+ name: new Date().getTime() + '',
+ owner_id: '0',
+ owner_resource: 'shop',
+ fields: { 'test': 'test' },
+ descriptions: 'test'
+ }
+ };
+ api.post('metas', obj).then(function (body) {
+ should.exist(body);
+ var id = body.meta.id;
+ api.delete('metas/' + id).then(function (body) {
+ should.exist(body);
+ done();
+ });
});
+ });
- it('http delete should be success', function (done) {
- var obj = {
- meta: {
- name: new Date().getTime() + '',
- owner_id: '0',
- owner_resource: 'shop',
- fields: {'test': 'test'},
- descriptions: 'test'
- }
- };
- api.post('metas', obj, function (err, body) {
- should.not.exist(err);
- should.exist(body);
- var id = body.meta.id;
- api.delete('metas/' + id, function (err) {
- should.not.exist(err);
- done();
- })
- })
+ it('api should be return error code 404', function (done) {
+ api.get('12345').then(function (body) {
+ body.code.should.equal(404);
+ done();
});
+ });
- it('api should be return error code 404', function (done) {
- api.get('12345', function (err, body) {
- err.code.should.equal(404);
- done();
- })
+ it('api should be throw ENOTFOUND error', function (done) {
+ var api = new Yhsd.Api('5e242b4b41d14a2d8f4d80a9c6b05bea',{
+ host: 'localhost:32876',
+ protocol: 'http'
});
-
- it('api should be throw ENOTFOUND error', function (done) {
- Yhsd.config.apiHost = 'localhost:32876';
- Yhsd.config.appHost = 'localhost:32876';
- Yhsd.config.httpProtocol = 'http';
- api.get('products',function (err, token) {
- if (err){
- // console.log(err.message);
- var eResult = err.message.indexOf('ENOTFOUND');
- if (eResult > 0) {
- (eResult).should.be.ok();
- done();
- return;
- }
- }
- console.log(token);
- done(new Error('没有捕捉到错误!'));
- });
+ api.get('products').then(function (body) {
+ console.log(body);
+ should.not.exist(body);
+ done(new Error('没有捕捉到错误!'));
+ }).catch(function (err) {
+ // console.log(err.message);
+ var eResult = err.message.indexOf('ENOTFOUND');
+ if (eResult > 0) {
+ (eResult).should.be.ok();
+ done();
+ return;
+ }
});
-
- //it('api should be return error code 429', function (done) {
- // var total = 0;
- // function _request() {
- // var index = 0;
- // api.get('shop', function (err, body) {
- // ++index;
- // if(index == 3) round()
- // });
- // api.get('shop', function (err, body) {
- // ++index;
- // if(index == 3) round()
- //
- // });
- // api.get('shop', function (err, body) {
- // ++index;
- // if(index == 3) round()
- // });
- // }
- // function round(){
- // total++;
- // if(total < 20){
- // setTimeout(_request,1000);
- // } else {
- // done();
- // }
- // }
- // _request();
- //});
+ });
});
diff --git a/test/auth.test.js b/test/auth.test.js
index 4afcb0d..6c1e2e3 100644
--- a/test/auth.test.js
+++ b/test/auth.test.js
@@ -26,17 +26,6 @@ describe('test/auth.test.js', function () {
//缺少callbackUrl
});
- it('get token should throw error', function () {
- (function () {
- new Yhsd.Auth({
- appKey: '548e29e46091449e949a8e1ffe4e4167',
- appSecret: 'b9fec3d128064ea89f1e9b8324eeabc5',
- private: true
- }).getToken()
- }).should.throw('缺少参数');
- //缺少参数
- });
-
it('get public token should throw error', function () {
(function () {
new Yhsd.Auth({
@@ -54,8 +43,7 @@ describe('test/auth.test.js', function () {
appSecret: 'b9fec3d128064ea89f1e9b8324eeabc5',
private: true
});
- auth.getToken(function (err, token) {
- should.not.exist(err);
+ auth.getToken().then(function (token) {
token.should.equal('fbc7f83524f14e358a325a5066acd741');
done();
});
@@ -68,7 +56,7 @@ describe('test/auth.test.js', function () {
appSecret: 'b9fec3d128064ea89f1e9b8324eeabc5' + 'error',
private: true
});
- auth.getToken(function (err, token) {
+ auth.getToken().catch(function (err) {
should.exist(err);
done();
});
@@ -81,7 +69,7 @@ describe('test/auth.test.js', function () {
appSecret: 'b9fec3d128064ea89f1e9b8324eeabc5' + 'error',
callbackUrl: 'http://your.app.url'
});
- auth.getToken('your code', function (err, token) {
+ auth.getToken('your code').catch(function (err) {
should.exist(err);
done();
});
diff --git a/test/request.test.js b/test/request.test.js
new file mode 100644
index 0000000..9bec36e
--- /dev/null
+++ b/test/request.test.js
@@ -0,0 +1,78 @@
+/**
+ * Created by obzerg on 16/1/5.
+ */
+var Promise = require('bluebird');
+var should = require('should');
+
+var Request = require('../lib/Request');
+var Yhsd = require('../index');
+var reqCountMap = {};
+var token = '5e242b4b41d14a2d8f4d80a9c6b05bea';
+
+describe('test/request.test.js', function () {
+ describe('auth request', function () {
+ var _request = new Request();
+ it('should return token', function (done) {
+ console.time('complete');
+ _request.request({
+ hostname: Yhsd.config.appHost,
+ path: '/oauth2/token',
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ Authorization: 'Basic NGQwYzZkMmMxMjQ1NDI4NGJjYzVjNDViMTQyODZkOTM6ZWQ5NDY5NDI2MGEwNGZmY2EwMTVhNzVmM2Q4MmUzMDA=',
+ }
+ }, {
+ grant_type: 'client_credentials',
+ }).then(function (data) {
+ // console.timeEnd('complete');
+ // console.log('token', data);
+ should.ok(data);
+ token = data;
+ done();
+ });
+ });
+ });
+
+ describe('api request', function () {
+ var _request = new Request({
+ getRequestCount: function () {
+ return Promise.resolve(reqCountMap[token] || 0);
+ },
+ saveRequestCount: function (count) {
+ reqCountMap[token] = count;
+ return Promise.resolve(count);
+ },
+ });
+ it('should return ok', function (done) {
+ var i = 0;
+
+ function request() {
+ console.time('complete');
+ _request.request({
+ hostname: Yhsd.config.apiHost,
+ path: '/v1/shop',
+ method: 'GET',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'X-API-ACCESS-TOKEN': token
+ }
+ })
+ .then(function () {
+ // console.timeEnd('complete');
+ // console.log(reqCountMap[token], i);
+ })
+ .then(function () {
+ if (i < 200) {
+ request();
+ return;
+ }
+ done();
+ });
+ i++;
+ }
+
+ request();
+ });
+ });
+});