Skip to content

Commit cd5ef78

Browse files
authored
Merge pull request #327 from lukasbals/lu/implement-list-subscription-types
Implement the list all subscripition types functionality
2 parents ad548d9 + bb931b8 commit cd5ef78

5 files changed

Lines changed: 62 additions & 0 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,14 @@ const response = await client.segments.list({
11011101
});
11021102
```
11031103

1104+
1105+
### Subscriptions
1106+
1107+
#### [List all subscription types](https://developers.intercom.com/intercom-api-reference/reference/list-all-subscription-types)
1108+
1109+
```typescript
1110+
const response = await client.subscriptions.listTypes();
1111+
```
11041112
### PhoneCallRedirects
11051113

11061114
#### [Create a phone call redirect](https://developers.intercom.com/intercom-api-reference/reference/create-a-phone-switch)

lib/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import HelpCenter from './helpCenter';
1414
import Message from './message';
1515
import Note from './note';
1616
import Segment from './segment';
17+
import Subscription from './subscription';
1718
import Team from './team';
1819
import Tag from './tag';
1920
import Visitor from './visitor';
@@ -66,6 +67,7 @@ export default class Client {
6667
messages: Message;
6768
notes: Note;
6869
segments: Segment;
70+
subscriptions: Subscription;
6971
passwordPart?: string;
7072
propertiesToOmitInRequestOpts: string[];
7173
requestOpts: Partial<AxiosDefaults>;
@@ -100,6 +102,7 @@ export default class Client {
100102
this.messages = new Message(this);
101103
this.notes = new Note(this);
102104
this.segments = new Segment(this);
105+
this.subscriptions = new Subscription(this);
103106
this.tags = new Tag(this);
104107
this.teams = new Team(this);
105108
this.visitors = new Visitor(this);

lib/subscription.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Client } from '.';
2+
import { SubscriptionObject } from './subscription/subscription.types';
3+
4+
export default class Subscription {
5+
public readonly baseUrl = 'subscription_types';
6+
7+
constructor(private readonly client: Client) {
8+
this.client = client;
9+
}
10+
listTypes() {
11+
return this.client.get<ListResponse>({
12+
url: `/${this.baseUrl}`,
13+
});
14+
}
15+
}
16+
17+
interface ListResponse {
18+
type: 'list';
19+
data: SubscriptionObject[];
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Client } from '../../dist';
2+
import assert from 'assert';
3+
import { token } from './utils/config';
4+
5+
describe('Subscriptions', () => {
6+
const client = new Client({ tokenAuth: { token } });
7+
8+
it('listTypes', async () => {
9+
const response = await client.subscriptions.listTypes();
10+
11+
assert.notEqual(response, undefined);
12+
});
13+
});

test/unit/subscription.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import assert from 'assert';
2+
import { Client } from '../../lib';
3+
import nock from 'nock';
4+
5+
describe('subscriptions', () => {
6+
const client = new Client({
7+
usernameAuth: { username: 'foo', password: 'bar' },
8+
});
9+
10+
it('should be listed', async () => {
11+
nock('https://api.intercom.io')
12+
.get('/subscription_types')
13+
.reply(200, { type: 'list', data: [] });
14+
const response = await client.subscriptions.listTypes();
15+
16+
assert.deepStrictEqual({ type: 'list', data: [] }, response);
17+
});
18+
});

0 commit comments

Comments
 (0)