Skip to content

Commit c198d22

Browse files
authored
Merge branch 'master' into master
2 parents f6d7388 + 912c10f commit c198d22

File tree

6 files changed

+83
-138
lines changed

6 files changed

+83
-138
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,19 @@ To run unit tests, execute
2323
npm run test
2424
```
2525

26+
To run integration tests, execute
27+
```bash
28+
export PIPEDRIVE_API_TOKEN=YOUR_API_TOKEN
29+
npm run test:integration
30+
```
31+
32+
__Important!__ Integration tests will add data to the account, so please run with caution!
33+
2634
## Licence
2735
This Pipedrive API client is distributed under the MIT licence.
2836

2937
## Contribution
30-
- Run tests
38+
- Run unit and integration tests
3139
- Make PR
3240

3341
## Options

lib/rest.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
qs = require('qs'),
66
log = require(__dirname + '/log'),
77
util = require('util'),
8-
bundle = require('../package.json'),
98
EventEmitter= require('events').EventEmitter,
109
urllib = require('url'),
1110
userAgent = require(__dirname + '/userAgent'),
1211
_ = require('lodash'),
13-
mime = require('mime'),
1412
fs = require('fs'),
1513
async = require('async'),
14+
FormData = require('form-data'),
1615
requestRate = 5;
1716

1817
module.exports = {
@@ -47,31 +46,22 @@
4746
}
4847

4948
this.url = urllib.parse(url);
50-
var boundary = 'JWBBV0Q07j8njeiL';
5149

5250
if (this.options.multipart) {
53-
headers['content-type'] = 'multipart/form-data; boundary='+boundary;
54-
payload = '';
51+
var form = new FormData();
5552

5653
_.each(this.options.data, function(value, inputName) {
57-
payload += '--'+boundary+'\r\n'+
58-
'Content-Disposition: form-data;';
59-
if(inputName == 'file_path' && fs.existsSync(value)) {
60-
var parts = value.split(/\/|\\/);
54+
if (inputName === 'file_path' && fs.existsSync(value)) {
55+
var parts = value.split(/[\/\\]/);
6156
var fileName = parts[parts.length - 1];
62-
63-
payload += 'name="file"; filename="'+fileName.replace(/"/g, '\"')+'"\r\n';
64-
payload += 'Content-Type: '+mime.lookup(value);
65-
66-
value = fs.readFileSync(value);
57+
form.append('file', fs.readFileSync(value), fileName);
6758
} else {
68-
payload += ' name="'+inputName.replace(/"/g, '\"')+'"';
59+
form.append(inputName, value);
6960
}
70-
71-
payload += '\r\n\r\n'+value+'\r\n';
7261
});
73-
payload += '--'+boundary+'--';
7462

63+
headers = form.getHeaders(headers);
64+
payload = form.getBuffer();
7565
}
7666
else if (this.options.data) {
7767
if (typeof this.options.data == 'string') {
@@ -102,7 +92,7 @@
10292
rejectUnauthorized: process.env.PIPEDRIVE_API_HOST == 'api.pipedrive.com' ? true : false
10393
};
10494

105-
log('Performing API request: ' + JSON.stringify(_.extend(requestOptions, { url: url }), null, 4));
95+
log('Adding API request to queue: ' + JSON.stringify(_.extend(_.omit(requestOptions, this.options.multipart ? ['payload'] : []), { url: url }), null, 4));
10696

10797
requestQueue.push({ url: url, requestOptions: requestOptions }, (function(err, meta, body) {
10898
if (!meta) {

package-lock.json

Lines changed: 43 additions & 101 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pipedrive",
3-
"version": "9.0.0",
3+
"version": "9.1.1",
44
"description": "Pipedrive REST client for NodeJS",
55
"keywords": [
66
"pipedrive",
@@ -16,23 +16,23 @@
1616
"homepage": "https://github.com/pipedrive/client-nodejs",
1717
"main": "./lib/Pipedrive",
1818
"engines": {
19-
"node": ">=6.0"
19+
"node": ">=8.0"
2020
},
2121
"repository": {
2222
"type": "git",
2323
"url": "http://github.com/pipedrive/client-nodejs.git"
2424
},
2525
"scripts": {
26-
"test": "./node_modules/mocha/bin/mocha ./test/unit"
26+
"test": "./node_modules/mocha/bin/mocha ./test/unit",
27+
"test:integration": "./node_modules/mocha/bin/mocha --timeout 10000 ./test/integration"
2728
},
2829
"dependencies": {
2930
"async": "~0.9.0",
3031
"fetch": "~0.3.6",
32+
"form-data": "^3.0.0",
33+
"inflection": "^1.12.0",
3134
"lodash": "^4.17.15",
32-
"mime": "~1.4.1",
33-
"qs": "~6.0.4",
34-
"sockjs-client": "^1.3.0",
35-
"inflection": "^1.12.0"
35+
"qs": "~6.0.4"
3636
},
3737
"devDependencies": {
3838
"chai": "^4.1.2",

0 commit comments

Comments
 (0)