Skip to content

Commit 0c597a5

Browse files
committed
Merge pull request #5 from intercom/BL/company
Company support
2 parents eb4c9d2 + d75b6de commit 0c597a5

File tree

5 files changed

+97
-1
lines changed

5 files changed

+97
-1
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,35 @@ client.users.find({ id: '1234' }, callback);
6767
// Delete user by id
6868
client.users.delete({ id: '1234' }, callback);
6969
```
70+
71+
## Companies
72+
73+
```node
74+
// Create/update a company
75+
client.companies.create({ company_id: "1234", name: "serenity" }, function (r) {
76+
console.log(r);
77+
});
78+
```
79+
80+
```node
81+
// List companies
82+
client.companies.list(callback);
83+
```
84+
85+
```node
86+
// List companies by tag or segment
87+
client.companies.listBy({ tag_id: 'haven' }, callback);
88+
```
89+
90+
```node
91+
// Find company by id
92+
client.companies.find({ id: '1234' }, callback);
93+
```
94+
95+
```node
96+
// List company users
97+
client.company.listUsers({ id: '1234' }, callback);
98+
```
7099
## Events
71100

72101
```node

gulpfile.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ gulp.task('test', ['pre-test'], function (cb) {
3939
.on('error', function (err) {
4040
mochaErr = err;
4141
})
42-
.pipe(istanbul.writeReports())
4342
.on('end', function () {
4443
cb(mochaErr);
4544
});

lib/client.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
var unirest = require('unirest');
22
import {User} from './user';
33
import {Event} from './event';
4+
import {Company} from './company';
45

56
export class Client {
67
constructor(appId, appApiKey) {
78
this.appId = appId;
89
this.appApiKey = appApiKey;
910
this.users = new User(this);
1011
this.events = new Event(this);
12+
this.companies = new Company(this);
1113
}
1214
ping(f) {
1315
unirest.get('https://api.intercom.io/admins')

lib/company.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export class Company {
2+
constructor(client) {
3+
this.client = client;
4+
}
5+
create(data, f) {
6+
this.client.post('/companies', data, f);
7+
}
8+
list(f) {
9+
this.client.get('/companies', {}, f);
10+
}
11+
listBy(params, f) {
12+
this.client.get('/companies', params, f);
13+
}
14+
find(params, f) {
15+
this.client.get(`/companies/${params.id}`, {}, f);
16+
}
17+
listUsers(params, f) {
18+
this.client.get(`/companies/${params.id}/users`, {}, f);
19+
}
20+
}

test/company.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import assert from 'assert';
2+
import {Client} from '../lib';
3+
var nock = require('nock');
4+
5+
describe('companies', function () {
6+
it('should be created', function (done) {
7+
nock('https://api.intercom.io').post('/companies', { name: 'baz' }).reply(200, {});
8+
let client = new Client('foo', 'bar');
9+
client.companies.create({ name: 'baz' }, function (r) {
10+
assert.equal(200, r.status);
11+
done();
12+
});
13+
});
14+
it('should list', function (done) {
15+
nock('https://api.intercom.io').get('/companies').reply(200, {});
16+
let client = new Client('foo', 'bar');
17+
client.companies.list(function (r) {
18+
assert.equal(200, r.status);
19+
done();
20+
});
21+
});
22+
it('should list by params', function (done) {
23+
nock('https://api.intercom.io').get('/companies').query({ tag_id: '1234' }).reply(200, {});
24+
let client = new Client('foo', 'bar');
25+
client.companies.listBy({ tag_id: '1234' }, function (r) {
26+
assert.equal(200, r.status);
27+
done();
28+
});
29+
});
30+
it('find companies by id', function (done) {
31+
nock('https://api.intercom.io').get('/companies/baz').reply(200, {});
32+
let client = new Client('foo', 'bar');
33+
client.companies.find({ id: 'baz' }, function (r) {
34+
assert.equal(200, r.status);
35+
done();
36+
});
37+
});
38+
it('list company users by id', function (done) {
39+
nock('https://api.intercom.io').get('/companies/baz/users').reply(200, {});
40+
let client = new Client('foo', 'bar');
41+
client.companies.listUsers({ id: 'baz' }, function (r) {
42+
assert.equal(200, r.status);
43+
done();
44+
});
45+
});
46+
});

0 commit comments

Comments
 (0)