Skip to content

Commit

Permalink
add the possibility to upload files. Bump to version 0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitguigal committed Apr 12, 2017
1 parent 66ccb03 commit ec58acf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/FigureMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function figureMethod(spec) {
}
};

self._request(requestMethod, requestPath, options.data, options.query, options.headers, requestCallback);
self._request(requestMethod, requestPath, options.data, options.files, options.query, options.headers, requestCallback);

return deferred.promise;
}
Expand Down
13 changes: 12 additions & 1 deletion lib/FigureResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ FigureResource.prototype = {
callback(null, res.body)
},

_request: function(method, path, data, query, headers, callback) {
_request: function(method, path, data, files, query, headers, callback) {

var self = this;
var req;
Expand Down Expand Up @@ -129,6 +129,17 @@ FigureResource.prototype = {
req.send(data);
}

if (files) {
Object.keys(files).forEach(function(field) {
var file = files[field];
if (file.filename) {
req.attach(field, file.filepath, file.filename);
} else {
req.attach(field, file.filepath);
}
});
}

req.end(function(err, res) {
if (err && (err.code == 'ECONNREFUSED' || err.code == 'ECONNABORTED')) {
// Figure API is not available or internet connection is lost
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "figure-sdk",
"version": "0.2.1",
"version": "0.2.2",
"description": "The Figure JavaScript SDK",
"main": "lib/figure.js",
"homepage": "https://github.com/postcard/figure-sdk-node",
Expand Down

0 comments on commit ec58acf

Please sign in to comment.