Skip to content

Commit

Permalink
Merge pull request #11 from atlantismonk/v2
Browse files Browse the repository at this point in the history
v2
  • Loading branch information
calvinxiao authored Dec 20, 2018
2 parents f9659ff + 9c0dfe2 commit 77b499d
Show file tree
Hide file tree
Showing 16 changed files with 1,828 additions and 852 deletions.
10 changes: 0 additions & 10 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,007 changes: 818 additions & 189 deletions .idea/workspace.xml

Large diffs are not rendered by default.

76 changes: 46 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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);
Expand All @@ -51,9 +53,9 @@ auth.getAuthorizeUrl(shopKey, state);
/**
* 获取 token
* @param {string} [code],用于开放应用
* @param {Function} callback(err, token)
* @returns {Object<Promise>}
*/
auth.getToken(code, callback);
auth.getToken(code);
```

详见
Expand All @@ -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);
});
```

Expand All @@ -81,40 +83,45 @@ 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);

/**
* 发送 GET 请求
* @param {string} path
* @param {Object} [query]
* @param {Function} callback(err, data)
* @param {object} [query]
* @returns {Object<Promise>}
*/
api.get(path, query, callback);
api.get(path, query);

/**
* 发送 PUT 请求
* @param {string} path
* @param {Object} data
* @param {Function} callback
* @param {object} data
* @returns {Object<Promise>}
*/
api.put(path, data, callback);
api.put(path, data);

/**
* 发送 POST 请求
* @param {string} path
* @param {Object} data
* @param {Function} callback
* @param {object} data
* @returns {Object<Promise>}
*/
api.post(path, data, callback);
api.post(path, data);

/**
* 发送 DELETE 请求
* @param {string} path
* @param {Function} callback
* @returns {Object<Promise>}
*/
api.delete(path, callback);
api.delete(path);
```

详见
Expand All @@ -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);
});
```
Expand Down
2 changes: 1 addition & 1 deletion coverage/coverage.json

Large diffs are not rendered by default.

Loading

0 comments on commit 77b499d

Please sign in to comment.