Comparing version 1.0.0 to 1.0.1
@@ -1,5 +0,2 @@ | ||
const request = require('request') | ||
const promise = require('bluebird') | ||
const config = require('config') | ||
const _ = require('lodash') | ||
const request = require('request-promise') | ||
@@ -18,3 +15,3 @@ class Gta { | ||
} | ||
_.assign(params, options) | ||
Object.assign(params, options) | ||
const data = Buffer.from(JSON.stringify(obj)).toString('base64') | ||
@@ -26,3 +23,3 @@ if (method === 'POST') { | ||
} | ||
return promise.promisify(request)(params) | ||
return request(params) | ||
} | ||
@@ -38,9 +35,2 @@ } | ||
} | ||
use (env) { | ||
if (env && config[env]) { | ||
this.url = config[env] | ||
} | ||
return this | ||
} | ||
} | ||
@@ -47,0 +37,0 @@ |
{ | ||
"name": "@tng/gta", | ||
"version": "1.0.0", | ||
"description": "TNG GTA 中间件 ==============", | ||
"version": "1.0.1", | ||
"description": "TNG GTA ==============", | ||
"main": "index.js", | ||
@@ -22,6 +22,4 @@ "scripts": { | ||
"dependencies": { | ||
"bluebird": "^3.5.1", | ||
"config": "^1.30.0", | ||
"lodash": "^4.17.10", | ||
"request": "^2.87.0" | ||
"request": "^2.87.0", | ||
"request-promise": "^4.2.2" | ||
}, | ||
@@ -28,0 +26,0 @@ "standard": { |
@@ -1,2 +0,2 @@ | ||
TNG GTA 中间件 | ||
TNG GTA | ||
============== | ||
@@ -7,3 +7,3 @@ | ||
yarn add @tng/gta | ||
重写的request模块 | ||
重写的request-promise模块 | ||
@@ -14,12 +14,14 @@ ``` | ||
```js | ||
const gta = require('@tng/gta').use('ga') // env: ga | ||
const { Gta } = require('@tng/gta') | ||
const gta = new Gta({url:'https://gta.teambition.net/v1/track/'}) | ||
// get方法 | ||
// @return promise | ||
console.log(yield gta.get({ user: 'abc' })) | ||
// {body: {event: 1, statusCode: 200}} | ||
console.log(yield gta.get({ param: 'abc' })) | ||
// {event: 1} | ||
// post方法 | ||
// @return promise | ||
console.log(yield gta.post({ user: 'abc' })) | ||
// {body: {event: 1, statusCode: 200}} | ||
console.log(yield gta.post({ param: 'abc' })) | ||
// {event: 1} | ||
``` | ||
@@ -35,36 +37,12 @@ | ||
// @return promise | ||
console.log(yield gta.get({ user: 'abc' }, options)) | ||
// {body: {event: 1, statusCode: 200}} | ||
console.log(yield gta.get({ param: 'abc' }, options)) | ||
// {event: 1} | ||
// post方法 | ||
// @return promise | ||
console.log(yield gta.post({ user: 'abc' }, options)) | ||
// {body: {event: 1, statusCode: 200}} | ||
console.log(yield gta.post({ param: 'abc' }, options)) | ||
// {event: 1} | ||
``` | ||
### 用法三 | ||
```js | ||
const { Gta } = require('@tng/gta') | ||
const gta = new Gta({url:'https://gta.teambition.net/v1/track/'}) | ||
// get方法 | ||
// @return promise | ||
console.log(yield gta.get({ user: 'abc' })) | ||
// {body: {event: 1, statusCode: 200}} | ||
// post方法 | ||
// @return promise | ||
console.log(yield gta.post({ user: 'abc' })) | ||
// {body: {event: 1, statusCode: 200}} | ||
``` | ||
## env | ||
```js | ||
{ | ||
"local": "http://localhost:8082/v1/track", | ||
"21": "http://gta.dev22/v1/track/", | ||
"ga": "https://gta.teambition.net/v1/track/", | ||
"release": "https://gta.teambition.net/v1/track/" | ||
} | ||
``` | ||
'use strict' | ||
const expect = require('should') | ||
const rewire = require('rewire') | ||
const GAT = rewire('../lib/gta') | ||
const gta = GAT.use('ga') | ||
const { Gta } = GAT | ||
const GTA = rewire('../lib/gta') | ||
const { Gta } = GTA | ||
const cgta = new Gta({url: 'http://gaohuifeng.cn/api'}) | ||
@@ -17,3 +16,3 @@ describe('gta', () => { | ||
before(() => { | ||
GAT.__set__('request', function (options, callback) { | ||
GTA.__set__('request', function (options) { | ||
expect(options).properties('method', 'url') | ||
@@ -34,3 +33,3 @@ if (options.method === 'GET') { | ||
} | ||
callback(null, {body: 'Hello World'}) | ||
return 'Hello World' | ||
}) | ||
@@ -41,3 +40,3 @@ }) | ||
const data = yield cgta.get(params) | ||
expect(data.body).eql('Hello World') | ||
expect(data).eql('Hello World') | ||
}) | ||
@@ -47,3 +46,3 @@ | ||
const data = yield cgta.get(params, options) | ||
expect(data.body).eql('Hello World') | ||
expect(data).eql('Hello World') | ||
}) | ||
@@ -53,14 +52,9 @@ | ||
const data = yield cgta.post(params) | ||
expect(data.body).eql('Hello World') | ||
expect(data).eql('Hello World') | ||
}) | ||
it('gta get should ok', function * () { | ||
const data = yield gta.get(params) | ||
expect(data.body).eql('Hello World') | ||
}) | ||
it('GAT get should ok', function * () { | ||
const data = yield GAT.get(params, options) | ||
expect(data.body).eql('Hello World') | ||
const data = yield GTA.get(params, options) | ||
expect(data).eql('Hello World') | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
3773
5
84
46
+ Addedrequest-promise@^4.2.2
+ Addedrequest-promise@4.2.6(transitive)
+ Addedrequest-promise-core@1.1.4(transitive)
+ Addedstealthy-require@1.1.1(transitive)
- Removedbluebird@^3.5.1
- Removedconfig@^1.30.0
- Removedlodash@^4.17.10
- Removedconfig@1.31.0(transitive)
- Removedjson5@1.0.2(transitive)
- Removedminimist@1.2.8(transitive)