1 | class List {
|
2 | constructor(client) {
|
3 | this.client = client
|
4 | }
|
5 |
|
6 | get(options) {
|
7 | return this.client._request({
|
8 | method: 'GET',
|
9 | path: '/contacts/v1/lists',
|
10 | qs: options,
|
11 | })
|
12 | }
|
13 |
|
14 | getOne(id) {
|
15 | if (!id) {
|
16 | return Promise.reject(new Error('id parameter must be provided.'))
|
17 | }
|
18 |
|
19 | return this.client._request({
|
20 | method: 'GET',
|
21 | path: `/contacts/v1/lists/${id}`,
|
22 | })
|
23 | }
|
24 |
|
25 | create(data) {
|
26 | return this.client._request({
|
27 | method: 'POST',
|
28 | path: '/contacts/v1/lists',
|
29 | body: data,
|
30 | })
|
31 | }
|
32 |
|
33 | delete(listId) {
|
34 | return this.client._request({
|
35 | method: 'DELETE',
|
36 | path: `/contacts/v1/lists/${listId}`,
|
37 | })
|
38 | }
|
39 |
|
40 | getContacts(id, options) {
|
41 | if (!id) {
|
42 | return Promise.reject(new Error('id parameter must be provided.'))
|
43 | }
|
44 |
|
45 | return this.client._request({
|
46 | method: 'GET',
|
47 | path: `/contacts/v1/lists/${id}/contacts/all`,
|
48 | qs: options,
|
49 | qsStringifyOptions: { indices: false },
|
50 | })
|
51 | }
|
52 |
|
53 | getRecentContacts(id, options) {
|
54 | if (!id) {
|
55 | return Promise.reject(new Error('id parameter must be provided.'))
|
56 | }
|
57 |
|
58 | return this.client._request({
|
59 | method: 'GET',
|
60 | path: `/contacts/v1/lists/${id}/contacts/recent`,
|
61 | qs: options,
|
62 | qsStringifyOptions: { indices: false },
|
63 | })
|
64 | }
|
65 |
|
66 | addContacts(id, contactBody) {
|
67 | if (!id) {
|
68 | return Promise.reject(new Error('id parameter must be provided.'))
|
69 | }
|
70 | if (!contactBody) {
|
71 | return Promise.reject(new Error('contactBody parameter must be provided.'))
|
72 | }
|
73 |
|
74 | var body = contactBody
|
75 |
|
76 | return this.client._request({
|
77 | method: 'POST',
|
78 | path: `/contacts/v1/lists/${id}/add`,
|
79 | body,
|
80 | })
|
81 | }
|
82 | }
|
83 |
|
84 | module.exports = List
|