Skip to content

Commit 0be4cf5

Browse files
committed
Implement the list all subscripition types functionality
1 parent 9ef9ff3 commit 0be4cf5

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ If you are using the european instance of intercom and would like to call it dir
8282
```typescript
8383
const client = new Client({ tokenAuth: { token: 'my_token' } });
8484
client.useRequestOpts({
85-
baseUrl: 'https://api.eu.intercom.io'
86-
})
85+
baseUrl: 'https://api.eu.intercom.io',
86+
});
8787
```
8888

8989
## Examples
@@ -1078,6 +1078,14 @@ const response = await client.segments.list({
10781078
});
10791079
```
10801080

1081+
### Subscriptions
1082+
1083+
#### [List all subscription types](https://developers.intercom.com/intercom-api-reference/reference/list-all-subscription-types)
1084+
1085+
```typescript
1086+
const response = await client.subscriptions.listTypes();
1087+
```
1088+
10811089
### Tags
10821090

10831091
#### [Create or update a tag](https://developers.intercom.com/intercom-api-reference/reference/create-and-update-tags)

lib/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import HelpCenter from './helpCenter';
1313
import Message from './message';
1414
import Note from './note';
1515
import Segment from './segment';
16+
import Subscription from './subscription';
1617
import Team from './team';
1718
import Tag from './tag';
1819
import Visitor from './visitor';
@@ -63,6 +64,7 @@ export default class Client {
6364
messages: Message;
6465
notes: Note;
6566
segments: Segment;
67+
subscriptions: Subscription;
6668
passwordPart?: string;
6769
propertiesToOmitInRequestOpts: string[];
6870
requestOpts: Partial<AxiosDefaults>;
@@ -95,6 +97,7 @@ export default class Client {
9597
this.messages = new Message(this);
9698
this.notes = new Note(this);
9799
this.segments = new Segment(this);
100+
this.subscriptions = new Subscription(this);
98101
this.tags = new Tag(this);
99102
this.teams = new Team(this);
100103
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)