Skip to content

Commit 687db38

Browse files
committed
Merge pull request #7 from intercom/BL/contacts
Contacts
2 parents 2688dac + 8184f41 commit 687db38

File tree

5 files changed

+144
-3
lines changed

5 files changed

+144
-3
lines changed

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,50 @@ client.users.find({ id: '1234' }, callback);
6868
client.users.delete({ id: '1234' }, callback);
6969
```
7070

71+
## Contacts
72+
73+
```node
74+
// Create a contact
75+
client.contacts.create(function (r) {
76+
console.log(r);
77+
});
78+
```
79+
80+
```node
81+
// Update a contact by id
82+
client.contacts.update({ id: '5435345', email: '[email protected]' }, callback);
83+
```
84+
85+
```node
86+
// List contacts
87+
client.contacts.list(callback);
88+
```
89+
90+
```node
91+
// List contacts by email
92+
client.contacts.listBy({ email: '[email protected]' }, callback);
93+
```
94+
95+
96+
```node
97+
// Find contact by id
98+
client.contacts.find({ id: '5342423' }, callback);
99+
```
100+
101+
```node
102+
// Delete contact by id
103+
client.contacts.find({ id: '5342423' }, callback);
104+
```
105+
106+
```node
107+
// Convert Contacts into Users
108+
var conversion = {
109+
contact: { user_id: '1234-5678-9876' },
110+
user: { email: '[email protected]' }
111+
};
112+
client.contacts.convert(conversion, callback);
113+
```
114+
71115
## Companies
72116

73117
```node
@@ -94,8 +138,9 @@ client.companies.find({ id: '1234' }, callback);
94138

95139
```node
96140
// List company users
97-
client.company.listUsers({ id: '1234' }, callback);
141+
client.companies.listUsers({ id: '1234' }, callback);
98142
```
143+
99144
## Events
100145

101146
```node

lib/client.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var unirest = require('unirest');
22
import {User} from './user';
33
import {Event} from './event';
44
import {Company} from './company';
5+
import {Contact} from './contact';
56

67
export class Client {
78
constructor(appId, appApiKey) {
@@ -10,6 +11,7 @@ export class Client {
1011
this.users = new User(this);
1112
this.events = new Event(this);
1213
this.companies = new Company(this);
14+
this.contacts = new Contact(this);
1315
}
1416
ping(f) {
1517
unirest.get('https://api.intercom.io/admins')

lib/contact.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export class Contact {
2+
constructor(client) {
3+
this.client = client;
4+
}
5+
create(f) {
6+
this.client.post('/contacts', {}, f);
7+
}
8+
update(params, f) {
9+
let id = params.id;
10+
delete params.id;
11+
this.client.post(`/contacts/${id}`, params, f);
12+
}
13+
list(f) {
14+
this.client.get('/contacts', {}, f);
15+
}
16+
listBy(params, f) {
17+
this.client.get('/contacts', params, f);
18+
}
19+
find(params, f) {
20+
this.client.get(`/contacts/${params.id}`, {}, f);
21+
}
22+
delete(params, f) {
23+
this.client.delete(`/contacts/${params.id}`, {}, f);
24+
}
25+
convert(params, f) {
26+
this.client.post('/contacts/convert', params, f);
27+
}
28+
}

test/contact.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import assert from 'assert';
2+
import {Client} from '../lib';
3+
var nock = require('nock');
4+
5+
describe('contacts', function () {
6+
it('should be created', function (done) {
7+
nock('https://api.intercom.io').post('/contacts').reply(200, {});
8+
let client = new Client('foo', 'bar');
9+
client.contacts.create(function (r) {
10+
assert.equal(200, r.status);
11+
done();
12+
});
13+
});
14+
it('should be updated', function (done) {
15+
nock('https://api.intercom.io').post('/contacts/baz', { email: '[email protected]' }).reply(200, {});
16+
let client = new Client('foo', 'bar');
17+
client.contacts.update({ id: 'baz', email: '[email protected]' }, function (r) {
18+
assert.equal(200, r.status);
19+
done();
20+
});
21+
});
22+
it('should list', function (done) {
23+
nock('https://api.intercom.io').get('/contacts').reply(200, {});
24+
let client = new Client('foo', 'bar');
25+
client.contacts.list(function (r) {
26+
assert.equal(200, r.status);
27+
done();
28+
});
29+
});
30+
it('should list by params', function (done) {
31+
nock('https://api.intercom.io').get('/contacts').query({ email: '[email protected]' }).reply(200, {});
32+
let client = new Client('foo', 'bar');
33+
client.contacts.listBy({ email: '[email protected]' }, function (r) {
34+
assert.equal(200, r.status);
35+
done();
36+
});
37+
});
38+
it('should find by id', function (done) {
39+
nock('https://api.intercom.io').get('/contacts/baz').reply(200, {});
40+
let client = new Client('foo', 'bar');
41+
client.contacts.find({ id: 'baz' }, function (r) {
42+
assert.equal(200, r.status);
43+
done();
44+
});
45+
});
46+
it('delete by id', function (done) {
47+
nock('https://api.intercom.io').delete('/contacts/baz').reply(200, {});
48+
let client = new Client('foo', 'bar');
49+
client.contacts.delete({ id: 'baz' }, function (r) {
50+
assert.equal(200, r.status);
51+
done();
52+
});
53+
});
54+
it('should convert', function (done) {
55+
let conversionObject = {
56+
contact: { user_id: 'baz' },
57+
user: { email: 'bang' }
58+
};
59+
nock('https://api.intercom.io').post('/contacts/convert', conversionObject).reply(200, {});
60+
let client = new Client('foo', 'bar');
61+
client.contacts.convert(conversionObject, function (r) {
62+
assert.equal(200, r.status);
63+
done();
64+
});
65+
});
66+
});

test/user.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ describe('users', function () {
2727
done();
2828
});
2929
});
30-
it('find users by id', function (done) {
30+
it('should find users by id', function (done) {
3131
nock('https://api.intercom.io').get('/users/baz').reply(200, {});
3232
let client = new Client('foo', 'bar');
3333
client.users.find({ id: 'baz' }, function (r) {
3434
assert.equal(200, r.status);
3535
done();
3636
});
3737
});
38-
it('deletes users by id', function (done) {
38+
it('should delete users by id', function (done) {
3939
nock('https://api.intercom.io').delete('/users/baz').reply(200, {});
4040
let client = new Client('foo', 'bar');
4141
client.users.delete({ id: 'baz' }, function (r) {

0 commit comments

Comments
 (0)