$ npm install --save ngnono-web-client-g
var ngnonoWebClient = require('ngnono-web-client-g');
let setting = {
consumerKey: 'xxxxdefault'
secretKey: '998998'
baseUrl: 'http://192.168.18.31:8080/api'
};
let route = {
'sign.testGet': {
uri: '/sign/testGet',
method: 'GET',
json: true
},
'sign.testPost': {
uri: '/sign/testPost',
method: 'POST',
json: true
},
'upload.upload': {
uri: '/upload/upload',
method: 'POST'
},
'upload.upload1': {
uri: '/upload/upload1',
method: 'POST'
}
};
var p = gsbClient.sign.testGet({
qs: {
a: 1,
b: 'adadf'
},
headers: {
'X-Token': 'sxxxx'
}
});
p.then(function (body) {
//console.log('body:%s', JSON.stringify(body));
expect(body).to.not.equal(null);
expect(body).to.have.property('status').that.equal(true);
//OK
}, function (err) {
// reject
}).catch(function (err) {
//err
});
var p = gsbClient.sign.testPost( {
qs: {
a: 1,
b: 'adadf'
},
body: {
json: 'xxfffasdf', ppppp: 12343434,
xml: '没有'
},
headers: {
'X-Token': 'sxxxx'
}
});
p.then(function (body) {
//console.log('body:%s', JSON.stringify(body));
expect(body).to.not.equal(null);
expect(body).to.have.property('status').that.equal(true);
//OK
}, function (err) {
//reject
}).catch(function (err) {
//error
});
var formData = {
my_field: 'my_value',
my_file: fs.createReadStream(__dirname + '/config/default.yml')
};
var p = gsbClient.upload.upload1({
formData: formData,
json: true,
qs: {a: 'w', xy: 6, c: 5}
});
p.then(function (body) {
//console.log('body:%s', JSON.stringify(body));
expect(body).to.not.equal(null);
expect(body).to.have.property('status').that.equal(true);
//ok
}, function (err) {
//reject
}).catch(function (err) {
console.error(err);
//error
});
sdk copy from li-sdk
Apache-2.0 © lianghongpeng