-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2a77e52
Showing
13 changed files
with
691 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.debug.js | ||
*.min.js | ||
node_modules/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"rules": { | ||
"indent": [ | ||
2, | ||
2 | ||
], | ||
"quotes": [ | ||
2, | ||
"single" | ||
], | ||
"linebreak-style": [ | ||
2, | ||
"unix" | ||
], | ||
"semi": [2, "always"], | ||
"strict": [2, "global"], | ||
"curly": 2, | ||
"eqeqeq": 2, | ||
"no-eval": 2, | ||
"guard-for-in": 2, | ||
"no-caller": 2, | ||
"no-else-return": 2, | ||
"no-eq-null": 2, | ||
"no-extend-native": 2, | ||
"no-extra-bind": 2, | ||
"no-floating-decimal": 2, | ||
"no-implied-eval": 2, | ||
"no-labels": 2, | ||
"no-with": 2, | ||
"no-loop-func": 1, | ||
"no-native-reassign": 2, | ||
"no-redeclare": [2, {"builtinGlobals": true}], | ||
"no-delete-var": 2, | ||
"no-shadow-restricted-names": 2, | ||
"no-undef-init": 2, | ||
"no-use-before-define": 2, | ||
"no-unused-vars": 2, | ||
"no-undef": 2, | ||
"callback-return": [2, ["callback", "cb", "next"]], | ||
"global-require": 0, | ||
"no-console": 0, | ||
"no-constant-condition": 0, | ||
"generator-star-spacing": ["error", "after"] | ||
}, | ||
"env": { | ||
"es6": true, | ||
"node": true, | ||
"browser": true | ||
}, | ||
"globals": { | ||
"describe": true, | ||
"it": true, | ||
"before": true, | ||
"after": true | ||
}, | ||
"extends": "eslint:recommended" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
out | ||
coverage | ||
test/config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# $@ = target file | ||
# $< = first dependency | ||
# $^ = all dependencies | ||
|
||
TESTS = test/*.test.js | ||
REPORTER = spec | ||
TIMEOUT = 20000 | ||
ISTANBUL = ./node_modules/.bin/istanbul | ||
MOCHA = ./node_modules/mocha/bin/_mocha | ||
COVERALLS = ./node_modules/coveralls/bin/coveralls.js | ||
DOXMATE = ./node_modules/.bin/doxmate | ||
PATH := ./node_modules/.bin:$(PATH) | ||
|
||
lint: | ||
@eslint --fix lib test | ||
|
||
doc: | ||
@$(DOXMATE) build -o out | ||
|
||
test: | ||
@NODE_ENV=test ./node_modules/.bin/mocha \ | ||
--reporter $(REPORTER) \ | ||
--require co-mocha \ | ||
--timeout $(TIMEOUT) \ | ||
$(MOCHA_OPTS) \ | ||
$(TESTS) | ||
|
||
test-debug: | ||
@NODE_ENV=test ./node_modules/.bin/mocha -d \ | ||
--reporter $(REPORTER) \ | ||
--require co-mocha \ | ||
--timeout $(TIMEOUT) \ | ||
$(MOCHA_OPTS) \ | ||
$(TESTS) | ||
|
||
test-cov: | ||
@NODE_ENV=test node \ | ||
node_modules/.bin/istanbul cover --report html \ | ||
./node_modules/.bin/_mocha -- \ | ||
--reporter $(REPORTER) \ | ||
--require co-mocha \ | ||
--timeout $(TIMEOUT) \ | ||
$(MOCHA_OPTS) \ | ||
$(TESTS) | ||
|
||
test-coveralls: | ||
@$(ISTANBUL) cover --report lcovonly $(MOCHA) -- -t $(TIMEOUT) -R spec $(TESTS) | ||
@echo TRAVIS_JOB_ID $(TRAVIS_JOB_ID) | ||
@cat ./coverage/lcov.info | $(COVERALLS) && rm -rf ./coverage | ||
|
||
test-all: test test-coveralls | ||
|
||
.PHONY: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
Aliyun API Gateway SDK for Node.js | ||
================================== | ||
|
||
API 网关(API Gateway),提供高性能、高可用的 API 托管服务,帮助用户对外开放其部署在 ECS、容器服务等阿里云产品上的应用,提供完整的 API 发布、管理、维护生命周期管理。用户只需简单操作,即可快速、低成本、低风险的开放数据或服务。 | ||
|
||
## Installation | ||
|
||
You can install it as dependency with npm/cnpm. | ||
|
||
```sh | ||
$ # save into package.json dependencies with -S | ||
$ npm install aliyun-api-gateway -S | ||
$ # you can use cnpm for fast install | ||
$ cnpm install aliyun-api-gateway -S | ||
``` | ||
|
||
## Usage | ||
|
||
The SDK contains Simple client(authrozied by appcode) and Normal client(authrozied by appid & appsecret). | ||
|
||
### Simple client | ||
|
||
```js | ||
// require it | ||
var SimpleClient = require('aliyun-api-gateway').SimpleClient; | ||
|
||
// create client instance with appcode | ||
var client = new SimpleClient('appcode'); | ||
|
||
// send GET request | ||
it('should ok get(url)', function* () { | ||
var url = 'https://dm-81.data.aliyun.com/rest/160601/ip/getIpInfo.json?ip=210.75.225.254'; | ||
var result = yield client.get(url); | ||
}); | ||
|
||
it('should ok with post(url)', function* () { | ||
var url = 'https://dm-72.data.aliyun.com/rest/160601/int_image/matching.json'; | ||
var result = yield client.post(url, { | ||
data: { | ||
'image': { | ||
'dataType': 10, | ||
'dataValue': 'base64 content' | ||
} | ||
} | ||
}); | ||
}); | ||
``` | ||
|
||
### Client (recommend) | ||
|
||
```js | ||
// require it | ||
var Client = require('aliyun-api-gateway').Client; | ||
|
||
// create client instance with appkey and appsecret | ||
var client = new Client('appKey', 'appSecret'); | ||
|
||
// send GET request | ||
it('should ok get(url)', function* () { | ||
var url = 'https://dm-81.data.aliyun.com/rest/160601/ip/getIpInfo.json?ip=210.75.225.254'; | ||
var result = yield client.get(url); | ||
}); | ||
|
||
it('should ok with post(url)', function* () { | ||
var url = 'https://dm-72.data.aliyun.com/rest/160601/int_image/matching.json'; | ||
var result = yield client.post(url, { | ||
data: { | ||
'image': { | ||
'dataType': 10, | ||
'dataValue': 'base64 content' | ||
} | ||
} | ||
}); | ||
}); | ||
``` | ||
|
||
## Question? | ||
|
||
Please submit an issue. | ||
|
||
## License | ||
|
||
The MIT License |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
exports.Client = require('./lib/client'); | ||
|
||
exports.SimpleClient = require('./lib/simple-client'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
const parse = require('url').parse; | ||
const querystring = require('querystring'); | ||
|
||
/** | ||
* API Gateway Client | ||
*/ | ||
class Base { | ||
constructor() { | ||
} | ||
|
||
* get(url, opts) { | ||
opts || (opts = {}); | ||
var parsed = parse(url, true); | ||
if (opts && opts.data) { | ||
// append data into querystring | ||
Object.assign(parsed.query, opts.data); | ||
parsed.path = parsed.pathname + '?' + querystring.stringify(parsed.query); | ||
opts.data = null; | ||
} | ||
return yield* this.request('GET', parsed, opts); | ||
} | ||
|
||
* post(url, opts) { | ||
opts.data = JSON.stringify(opts.data); | ||
return yield* this.request('POST', url, opts); | ||
} | ||
} | ||
|
||
module.exports = Base; |
Oops, something went wrong.