Comparing version 1.0.3 to 1.0.4
@@ -7,2 +7,3 @@ const request = require('request-promise') | ||
this.url = options.url | ||
this.token = options.token | ||
} | ||
@@ -34,4 +35,13 @@ | ||
} | ||
send (event, data, options) { | ||
data.token = this.token | ||
const obj = { | ||
event, | ||
properties: data | ||
} | ||
return this.get(obj, options) | ||
} | ||
} | ||
module.exports = GTA |
{ | ||
"name": "@tng/gta", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "TNG GTA ==============", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -12,19 +12,20 @@ TNG GTA | ||
const GTA = require('@tng/gta') | ||
const gta = new GTA({url:'https://gta.teambition.net/v1/track/'}) | ||
const gta = new GTA({url:'https://gta.teambition.net/v1/track/', token: '1234567890'}) | ||
// get方法 | ||
// send方法 (get) | ||
// @return promise | ||
console.log(yield gta.get({ param: 'abc' })) | ||
console.log(yield gta.send('event', { param: 'abc' })) | ||
// {event: 1} | ||
// post方法 | ||
// @return promise | ||
console.log(yield gta.post({ param: 'abc' })) | ||
// {event: 1} | ||
// 指定 options | ||
const gta = new GTA() | ||
const options = { url: 'https://gta.teambition.net/v1/track/' } | ||
console.log(yield gta.get({ param: 'abc' }, options)) | ||
const options = { url: 'https://gta.teambition.net/v1/track/', token: '1234567890'}) | ||
console.log(yield gta.send('event', { param: 'abc' }, options)) | ||
// get/post方法 | ||
const gta = new GTA() | ||
const options = { url: 'https://gta.teambition.net/v1/track/'}) | ||
yield gta.get('event', { token: '1234567890', params: 'abc' }, options) | ||
yield gta.post('event', { token: '1234567890', params: 'abc' }, options) | ||
``` |
@@ -5,7 +5,6 @@ 'use strict' | ||
const GTA = rewire('../lib/gta') | ||
const gta = new GTA({url: 'http://gaohuifeng.cn/api'}) | ||
const gta = new GTA({url: 'http://gaohuifeng.cn/api', token: '1234567890'}) | ||
describe('gta', () => { | ||
const params = { | ||
user: 'abc', | ||
token: '1234567890' | ||
user: 'abc' | ||
} | ||
@@ -50,2 +49,24 @@ const options = { | ||
}) | ||
describe('gta send', () => { | ||
before(() => { | ||
GTA.__set__('request', function (options) { | ||
expect(options).properties('method', 'url') | ||
expect(options.url).match(/\?data=/) | ||
expect(options.url).not.match(/undefined/) | ||
const base64Data = options.url.split('?data=')[1] | ||
// eslint-disable-next-line | ||
let obj = new Buffer.from(base64Data, 'base64').toString() | ||
obj = JSON.parse(obj) | ||
expect(obj).properties('event', 'properties') | ||
expect(obj.properties).deepEqual({'user': 'abc', 'token': '1234567890'}) | ||
return 'Hello World' | ||
}) | ||
}) | ||
it('gta send should ok', function * () { | ||
const data = yield gta.send('event', params) | ||
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
4511
105
31