Skip to content

Commit df51c52

Browse files
committed
Merge pull request #8 from intercom/BL/counts
Counts
2 parents 7c57aca + a82873f commit df51c52

File tree

4 files changed

+121
-0
lines changed

4 files changed

+121
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,26 @@ client.events.create({
154154
});
155155
```
156156

157+
## Counts
158+
159+
```node
160+
this.client.appCounts(callback);
161+
162+
this.client.conversationCounts(callback);
163+
164+
this.client.conversationAdminCounts(callback);
165+
166+
this.client.userTagCounts(callback);
167+
168+
this.client.userSegmentCounts(callback);
169+
170+
this.client.companyTagCounts(callback);
171+
172+
this.client.companySegmentCounts(callback);
173+
174+
this.client.companyUserCounts(callback);
175+
```
176+
157177
## Pagination
158178

159179
When listing, the Intercom API may return a pagination object:

lib/client.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {User} from './user';
33
import {Event} from './event';
44
import {Company} from './company';
55
import {Contact} from './contact';
6+
import {Counts} from './counts';
67

78
export class Client {
89
constructor(appId, appApiKey) {
@@ -12,6 +13,7 @@ export class Client {
1213
this.events = new Event(this);
1314
this.companies = new Company(this);
1415
this.contacts = new Contact(this);
16+
this.counts = new Counts(this);
1517
}
1618
ping(f) {
1719
unirest.get('https://api.intercom.io/admins')

lib/counts.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export class Counts {
2+
constructor(client) {
3+
this.client = client;
4+
}
5+
appCounts(f) {
6+
this.client.get('/counts', {}, f);
7+
}
8+
conversationCounts(f) {
9+
this.client.get('/counts', { type: 'conversation' }, f);
10+
}
11+
conversationAdminCounts(f) {
12+
this.client.get('/counts', { type: 'conversation', count: 'admin' }, f);
13+
}
14+
userTagCounts(f) {
15+
this.client.get('/counts', { type: 'user', count: 'tag' }, f);
16+
}
17+
userSegmentCounts(f) {
18+
this.client.get('/counts', { type: 'user', count: 'segment' }, f);
19+
}
20+
companyTagCounts(f) {
21+
this.client.get('/counts', { type: 'company', count: 'tag' }, f);
22+
}
23+
companySegmentCounts(f) {
24+
this.client.get('/counts', { type: 'company', count: 'segment' }, f);
25+
}
26+
companyUserCounts(f) {
27+
this.client.get('/counts', { type: 'company', count: 'user' }, f);
28+
}
29+
}

test/counts.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import assert from 'assert';
2+
import {Client} from '../lib';
3+
var nock = require('nock');
4+
5+
describe('counts', function () {
6+
it('app counts', function (done) {
7+
nock('https://api.intercom.io').get('/counts').reply(200, {});
8+
let client = new Client('foo', 'bar');
9+
client.counts.appCounts(function (r) {
10+
assert.equal(200, r.status);
11+
done();
12+
});
13+
});
14+
it('conversation app counts', function (done) {
15+
nock('https://api.intercom.io').get('/counts').query({ type: 'conversation' }).reply(200, {});
16+
let client = new Client('foo', 'bar');
17+
client.counts.conversationCounts(function (r) {
18+
assert.equal(200, r.status);
19+
done();
20+
});
21+
});
22+
it('conversation admin counts', function (done) {
23+
nock('https://api.intercom.io').get('/counts').query({ type: 'conversation', count: 'admin' }).reply(200, {});
24+
let client = new Client('foo', 'bar');
25+
client.counts.conversationAdminCounts(function (r) {
26+
assert.equal(200, r.status);
27+
done();
28+
});
29+
});
30+
it('user tag counts', function (done) {
31+
nock('https://api.intercom.io').get('/counts').query({ type: 'user', count: 'tag' }).reply(200, {});
32+
let client = new Client('foo', 'bar');
33+
client.counts.userTagCounts(function (r) {
34+
assert.equal(200, r.status);
35+
done();
36+
});
37+
});
38+
it('user segment counts', function (done) {
39+
nock('https://api.intercom.io').get('/counts').query({ type: 'user', count: 'segment' }).reply(200, {});
40+
let client = new Client('foo', 'bar');
41+
client.counts.userSegmentCounts(function (r) {
42+
assert.equal(200, r.status);
43+
done();
44+
});
45+
});
46+
it('company tag counts', function (done) {
47+
nock('https://api.intercom.io').get('/counts').query({ type: 'company', count: 'tag' }).reply(200, {});
48+
let client = new Client('foo', 'bar');
49+
client.counts.companyTagCounts(function (r) {
50+
assert.equal(200, r.status);
51+
done();
52+
});
53+
});
54+
it('company segment counts', function (done) {
55+
nock('https://api.intercom.io').get('/counts').query({ type: 'company', count: 'segment' }).reply(200, {});
56+
let client = new Client('foo', 'bar');
57+
client.counts.companySegmentCounts(function (r) {
58+
assert.equal(200, r.status);
59+
done();
60+
});
61+
});
62+
it('company user counts', function (done) {
63+
nock('https://api.intercom.io').get('/counts').query({ type: 'company', count: 'user' }).reply(200, {});
64+
let client = new Client('foo', 'bar');
65+
client.counts.companyUserCounts(function (r) {
66+
assert.equal(200, r.status);
67+
done();
68+
});
69+
});
70+
});

0 commit comments

Comments
 (0)