svb-client
Advanced tools
Comparing version 2.2.2 to 2.3.2
@@ -105,2 +105,28 @@ // | ||
}); | ||
}, | ||
upload: function(path, readstream, callback) { | ||
let stringedpost = readstream.read(); | ||
let headers = this._getHeaders("POST", path, "", stringedpost); | ||
headers['Content-Type'] = 'multipart/form-data'; | ||
request({ | ||
url: this.baseurl + path, | ||
method: 'POST', | ||
headers: headers, | ||
formData: { | ||
file: readstream | ||
} | ||
}, (err, response, body) => { | ||
if (err) { | ||
return callback(err); | ||
} | ||
if (typeof body === 'string') { | ||
body = JSON.parse(body); | ||
} | ||
if (body.error || body.fault) { | ||
return callback(body.error || body.fault, null); | ||
} | ||
callback(null, body); | ||
}); | ||
} | ||
@@ -107,0 +133,0 @@ }; |
{ | ||
"name": "svb-client", | ||
"version": "2.2.2", | ||
"version": "2.3.2", | ||
"description": "NodeJS request client for SVB API", | ||
@@ -5,0 +5,0 @@ "main": "client.js", |
## svb-client | ||
For NodeJS | ||
NodeJS library which helps you make GET and POST requests to the SVB API. | ||
@@ -14,5 +14,5 @@ ## Installation | ||
```javascript | ||
const SVBRequest = require('svb-client'); | ||
const SVB = require('svb-client'); | ||
let req = new SVBRequest({ | ||
let client = new SVB({ | ||
API_KEY: '', | ||
@@ -26,9 +26,16 @@ HMAC_SECRET: '', | ||
}); | ||
req.get('/v1', 'test=1', (err, data) => { | ||
client.get('/v1', 'test=1', (err, data) => { | ||
... | ||
}); | ||
req.post('/v1', { "data": "foo" }, (err, data) => { | ||
client.post('/v1', { "data": "foo" }, (err, data) => { | ||
... | ||
}); | ||
// uploading a file | ||
const fs = require('fs'); | ||
client.upload('/v1/files', fs.createReadStream(__dirname + '/file.png'), (err, data) => { | ||
... | ||
}); | ||
``` |
4331
121
40