Skip to content

Commit 0db0200

Browse files
committed
Remove Unirest from the codebase as it's unmaintained
1 parent a9b0e08 commit 0db0200

18 files changed

Lines changed: 119 additions & 109 deletions

lib/client.js

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import unirest from 'unirest';
1+
import request from 'request';
22
import Bluebird from 'bluebird';
33
import User from './user';
44
import Event from './event';
@@ -54,7 +54,7 @@ export default class Client {
5454
this.baseUrl = baseUrl;
5555
return this;
5656
}
57-
promiseProxy(f, req) {
57+
promiseProxy(f, args) {
5858
if (this.promises || !f) {
5959
const callbackHandler = this.callback;
6060
return new Bluebird((resolve, reject) => {
@@ -65,69 +65,79 @@ export default class Client {
6565
resolve(data);
6666
}
6767
};
68-
req.end(r => callbackHandler(resolver, r));
68+
this.request(args, (_, r) => {
69+
callbackHandler(resolver, r);
70+
});
6971
});
7072
} else {
71-
req.end(r => this.callback(f, r));
73+
this.request(args, (_, r) => this.callback(f, r));
7274
}
7375
}
7476
ping(f) {
75-
unirest.get(`${this.baseUrl}/admins`)
76-
.auth(this.usernamePart, this.passwordPart)
77-
.type('json')
78-
.header('Accept', 'application/json')
79-
.header('User-Agent', 'intercom-node-client/2.0.0')
80-
.end(r => f(r.status));
77+
this.request({
78+
uri: '/admins'
79+
}, (_, response) => f(response.statusCode));
8180
}
8281
put(endpoint, data, f) {
8382
return this.promiseProxy(f,
84-
unirest.put(`${this.baseUrl}${endpoint}`)
85-
.auth(this.usernamePart, this.passwordPart)
86-
.type('json')
87-
.send(data)
88-
.header('Accept', 'application/json')
89-
.header('User-Agent', 'intercom-node-client/2.0.0')
83+
{
84+
method: 'put',
85+
uri: endpoint,
86+
body: data
87+
}
9088
);
9189
}
9290
post(endpoint, data, f) {
9391
return this.promiseProxy(f,
94-
unirest.post(`${this.baseUrl}${endpoint}`)
95-
.auth(this.usernamePart, this.passwordPart)
96-
.type('json')
97-
.send(data)
98-
.header('Accept', 'application/json')
99-
.header('User-Agent', 'intercom-node-client/2.0.0')
92+
{
93+
method: 'post',
94+
uri: endpoint,
95+
body: data
96+
}
10097
);
10198
}
10299
get(endpoint, data, f) {
103100
return this.promiseProxy(f,
104-
unirest.get(`${this.baseUrl}${endpoint}`)
105-
.auth(this.usernamePart, this.passwordPart)
106-
.type('json')
107-
.query(data)
108-
.header('Accept', 'application/json')
109-
.header('User-Agent', 'intercom-node-client/2.0.0')
101+
{
102+
method: 'get',
103+
uri: endpoint,
104+
qs: data
105+
}
110106
);
111107
}
112108
nextPage(paginationObject, f) {
113109
return this.promiseProxy(f,
114-
unirest.get(paginationObject.next)
115-
.auth(this.usernamePart, this.passwordPart)
116-
.type('json')
117-
.header('Accept', 'application/json')
118-
.header('User-Agent', 'intercom-node-client/2.0.0')
110+
{
111+
method: 'get',
112+
uri: paginationObject.next,
113+
baseUrl: null
114+
}
119115
);
120116
}
121117
delete(endpoint, data, f) {
122118
return this.promiseProxy(f,
123-
unirest.delete(`${this.baseUrl}${endpoint}`)
124-
.auth(this.usernamePart, this.passwordPart)
125-
.type('json')
126-
.query(data)
127-
.header('Accept', 'application/json')
128-
.header('User-Agent', 'intercom-node-client/2.0.0')
119+
{
120+
method: 'delete',
121+
uri: endpoint,
122+
qs: data
123+
}
129124
);
130125
}
126+
request(args, callback) {
127+
const defaultArgs = {
128+
baseUrl: this.baseUrl,
129+
json: true,
130+
headers: {
131+
Accept: 'application/json',
132+
'User-Agent': 'intercom-node-client/2.0.0'
133+
}
134+
};
135+
136+
return request(
137+
Object.assign({}, defaultArgs, args),
138+
callback
139+
).auth(this.usernamePart, this.passwordPart);
140+
}
131141
callback(f, data) {
132142
if (!f) {
133143
return;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
],
2020
"dependencies": {
2121
"bluebird": "^3.3.4",
22-
"unirest": "^0.5.1"
22+
"request": "^2.83.0"
2323
},
2424
"devDependencies": {
2525
"babel-core": "^6.7.4",

test/admin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ describe('admins', () => {
77
nock('https://api.intercom.io').get('/admins').reply(200, {});
88
const client = new Client('foo', 'bar').usePromises();
99
client.admins.list().then(r => {
10-
assert.equal(200, r.status);
10+
assert.equal(200, r.statusCode);
1111
done();
1212
});
1313
});
1414
it('should find current admin', done => {
1515
nock('https://api.intercom.io').get('/me').reply(200, {});
1616
const client = new Client('foo', 'bar').usePromises();
1717
client.admins.me().then(r => {
18-
assert.equal(200, r.status);
18+
assert.equal(200, r.statusCode);
1919
done();
2020
});
2121
});
2222
it('should find admins by id', done => {
2323
nock('https://api.intercom.io').get('/admins/baz').reply(200, {});
2424
const client = new Client('foo', 'bar').usePromises();
2525
client.admins.find('baz').then(r => {
26-
assert.equal(200, r.status);
26+
assert.equal(200, r.statusCode);
2727
done();
2828
});
2929
});

test/base-url.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('base-url', () => {
1010
.useBaseUrl('http://local.test-server.com');
1111

1212
client.admins.list().then(r => {
13-
assert.equal(200, r.status);
13+
assert.equal(200, r.statusCode);
1414
done();
1515
});
1616
});

test/bulk.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('bulk', () => {
2727
{ create: { email: 'wash@serenity.io' }},
2828
{ create: { email: 'mal@serenity.io'}}
2929
]).then(r => {
30-
assert.equal(200, r.status);
30+
assert.equal(200, r.statusCode);
3131
done();
3232
});
3333
});
@@ -55,7 +55,7 @@ describe('bulk', () => {
5555
{ create: { foo: 'bar' }},
5656
{ create: { bar: 'baz'}}
5757
]).then(r => {
58-
assert.equal(200, r.status);
58+
assert.equal(200, r.statusCode);
5959
done();
6060
});
6161
});

test/client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ describe('clients', () => {
88
const client = new Client('foo', 'bar').usePromises();
99
assert.equal(true, client.promises);
1010
client.users.list().then(r => {
11-
assert.equal(200, r.status);
11+
assert.equal(200, r.statusCode);
1212
done();
1313
});
1414
});
1515
it('should use promises when callbacks are absent', done => {
1616
nock('https://api.intercom.io').get('/users').reply(200, {});
1717
const client = new Client('foo', 'bar');
1818
client.users.list().then(r => {
19-
assert.equal(200, r.status);
19+
assert.equal(200, r.statusCode);
2020
done();
2121
});
2222
});

test/company.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,71 +7,71 @@ describe('companies', () => {
77
nock('https://api.intercom.io').post('/companies', { name: 'baz' }).reply(200, {});
88
const client = new Client('foo', 'bar').usePromises();
99
client.companies.create({ name: 'baz' }).then(r => {
10-
assert.equal(200, r.status);
10+
assert.equal(200, r.statusCode);
1111
done();
1212
});
1313
});
1414
it('should list', done => {
1515
nock('https://api.intercom.io').get('/companies').reply(200, {});
1616
const client = new Client('foo', 'bar').usePromises();
1717
client.companies.list().then(r => {
18-
assert.equal(200, r.status);
18+
assert.equal(200, r.statusCode);
1919
done();
2020
});
2121
});
2222
it('should list by params', done => {
2323
nock('https://api.intercom.io').get('/companies').query({ tag_id: '1234' }).reply(200, {});
2424
const client = new Client('foo', 'bar').usePromises();
2525
client.companies.listBy({ tag_id: '1234' }).then(r => {
26-
assert.equal(200, r.status);
26+
assert.equal(200, r.statusCode);
2727
done();
2828
});
2929
});
3030
it('should find companies by id', done => {
3131
nock('https://api.intercom.io').get('/companies/baz').reply(200, {});
3232
const client = new Client('foo', 'bar').usePromises();
3333
client.companies.find({ id: 'baz' }).then(r => {
34-
assert.equal(200, r.status);
34+
assert.equal(200, r.statusCode);
3535
done();
3636
});
3737
});
3838
it('should find companies by company_id', done => {
3939
nock('https://api.intercom.io').get('/companies').query({ company_id: 'baz' }).reply(200, {});
4040
const client = new Client('foo', 'bar').usePromises();
4141
client.companies.find({ company_id: 'baz' }).then(r => {
42-
assert.equal(200, r.status);
42+
assert.equal(200, r.statusCode);
4343
done();
4444
});
4545
});
4646
it('should find companies by name', done => {
4747
nock('https://api.intercom.io').get('/companies').query({ name: 'baz' }).reply(200, {});
4848
const client = new Client('foo', 'bar').usePromises();
4949
client.companies.find({ name: 'baz' }).then(r => {
50-
assert.equal(200, r.status);
50+
assert.equal(200, r.statusCode);
5151
done();
5252
});
5353
});
5454
it('should list company users by id', done => {
5555
nock('https://api.intercom.io').get('/companies/baz/users').reply(200, {});
5656
const client = new Client('foo', 'bar').usePromises();
5757
client.companies.listUsers({ id: 'baz' }).then(r => {
58-
assert.equal(200, r.status);
58+
assert.equal(200, r.statusCode);
5959
done();
6060
});
6161
});
6262
it('should list company users by company_id', done => {
6363
nock('https://api.intercom.io').get('/companies').query({ company_id: 'baz', type: 'user' }).reply(200, {});
6464
const client = new Client('foo', 'bar').usePromises();
6565
client.companies.listUsers({ company_id: 'baz' }).then(r => {
66-
assert.equal(200, r.status);
66+
assert.equal(200, r.statusCode);
6767
done();
6868
});
6969
});
7070
it('should list company users by company name', done => {
7171
nock('https://api.intercom.io').get('/companies').query({ name: 'baz', type: 'user' }).reply(200, {});
7272
const client = new Client('foo', 'bar').usePromises();
7373
client.companies.listUsers({ name: 'baz' }).then(r => {
74-
assert.equal(200, r.status);
74+
assert.equal(200, r.statusCode);
7575
done();
7676
});
7777
});

test/contact.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,63 +12,63 @@ describe('contacts', () => {
1212
nock('https://api.intercom.io').post('/contacts').reply(200, {});
1313
const client = new Client('foo', 'bar').usePromises();
1414
client.leads.create().then(r => {
15-
assert.equal(200, r.status);
15+
assert.equal(200, r.statusCode);
1616
done();
1717
});
1818
});
1919
it('should be created with parameters', done => {
2020
nock('https://api.intercom.io').post('/contacts', { foo: 'bar' }).reply(200, {});
2121
const client = new Client('foo', 'bar').usePromises();
2222
client.leads.create({ foo: 'bar' }).then(r => {
23-
assert.equal(200, r.status);
23+
assert.equal(200, r.statusCode);
2424
done();
2525
});
2626
});
2727
it('should be updated', done => {
2828
nock('https://api.intercom.io').post('/contacts', { id: 'baz', email: 'foo@intercom.io' }).reply(200, {});
2929
const client = new Client('foo', 'bar').usePromises();
3030
client.leads.update({ id: 'baz', email: 'foo@intercom.io' }).then(r => {
31-
assert.equal(200, r.status);
31+
assert.equal(200, r.statusCode);
3232
done();
3333
});
3434
});
3535
it('should list', done => {
3636
nock('https://api.intercom.io').get('/contacts').reply(200, {});
3737
const client = new Client('foo', 'bar').usePromises();
3838
client.leads.list().then(r => {
39-
assert.equal(200, r.status);
39+
assert.equal(200, r.statusCode);
4040
done();
4141
});
4242
});
4343
it('should list by params', done => {
4444
nock('https://api.intercom.io').get('/contacts').query({ email: 'jayne@serenity.io' }).reply(200, {});
4545
const client = new Client('foo', 'bar').usePromises();
4646
client.leads.listBy({ email: 'jayne@serenity.io' }).then(r => {
47-
assert.equal(200, r.status);
47+
assert.equal(200, r.statusCode);
4848
done();
4949
});
5050
});
5151
it('should find by id', done => {
5252
nock('https://api.intercom.io').get('/contacts/baz').reply(200, {});
5353
const client = new Client('foo', 'bar').usePromises();
5454
client.leads.find({ id: 'baz' }).then(r => {
55-
assert.equal(200, r.status);
55+
assert.equal(200, r.statusCode);
5656
done();
5757
});
5858
});
5959
it('should find by user_id', done => {
6060
nock('https://api.intercom.io').get('/contacts?user_id=baz').reply(200, {});
6161
const client = new Client('foo', 'bar').usePromises();
6262
client.leads.find({ user_id: 'baz' }).then(r => {
63-
assert.equal(200, r.status);
63+
assert.equal(200, r.statusCode);
6464
done();
6565
});
6666
});
6767
it('delete by id', done => {
6868
nock('https://api.intercom.io').delete('/contacts/baz').reply(200, {});
6969
const client = new Client('foo', 'bar').usePromises();
7070
client.leads.delete({ id: 'baz' }).then(r => {
71-
assert.equal(200, r.status);
71+
assert.equal(200, r.statusCode);
7272
done();
7373
});
7474
});
@@ -80,7 +80,7 @@ describe('contacts', () => {
8080
nock('https://api.intercom.io').post('/contacts/convert', conversionObject).reply(200, {});
8181
const client = new Client('foo', 'bar').usePromises();
8282
client.leads.convert(conversionObject).then(r => {
83-
assert.equal(200, r.status);
83+
assert.equal(200, r.statusCode);
8484
done();
8585
});
8686
});

0 commit comments

Comments
 (0)