1 | const Property = require('./contact_property')
|
2 |
|
3 | class Contact {
|
4 | constructor(client) {
|
5 | this.client = client
|
6 | this.properties = new Property(this.client)
|
7 | }
|
8 |
|
9 | get(options) {
|
10 | return this.client._request({
|
11 | method: 'GET',
|
12 | path: '/contacts/v1/lists/all/contacts/all',
|
13 | qs: options,
|
14 | })
|
15 | }
|
16 |
|
17 | getAll(options) {
|
18 | return this.get(options)
|
19 | }
|
20 |
|
21 | getRecentlyModified(options) {
|
22 | return this.client._request({
|
23 | method: 'GET',
|
24 | path: '/contacts/v1/lists/recently_updated/contacts/recent',
|
25 | qs: options,
|
26 | })
|
27 | }
|
28 |
|
29 | getRecentlyCreated(options) {
|
30 | return this.client._request({
|
31 | method: 'GET',
|
32 | path: '/contacts/v1/lists/all/contacts/recent',
|
33 | qs: options,
|
34 | })
|
35 | }
|
36 |
|
37 | getByEmail(email) {
|
38 | return this.client._request({
|
39 | method: 'GET',
|
40 | path: `/contacts/v1/contact/email/${email}/profile`,
|
41 | })
|
42 | }
|
43 |
|
44 | getByEmailBatch(emails) {
|
45 | return this.client._request({
|
46 | method: 'GET',
|
47 | path: '/contacts/v1/contact/emails/batch',
|
48 | qs: { email: emails },
|
49 | qsStringifyOptions: { indices: false },
|
50 | })
|
51 | }
|
52 |
|
53 | getById(id, options) {
|
54 | return this.client._request({
|
55 | method: 'GET',
|
56 | path: `/contacts/v1/contact/vid/${id}/profile`,
|
57 | qs: options,
|
58 | })
|
59 | }
|
60 |
|
61 | getByIdBatch(ids) {
|
62 | return this.client._request({
|
63 | method: 'GET',
|
64 | path: '/contacts/v1/contact/vids/batch',
|
65 | qs: { vid: ids },
|
66 | qsStringifyOptions: { indices: false },
|
67 | })
|
68 | }
|
69 |
|
70 | getByToken(token) {
|
71 | return this.client._request({
|
72 | method: 'GET',
|
73 | path: `/contacts/v1/contact/utk/${token}/profile`,
|
74 | })
|
75 | }
|
76 |
|
77 | delete(id) {
|
78 | return this.client._request({
|
79 | method: 'DELETE',
|
80 | path: `/contacts/v1/contact/vid/${id}`,
|
81 | })
|
82 | }
|
83 |
|
84 | update(id, data) {
|
85 | return this.client._request({
|
86 | method: 'POST',
|
87 | path: `/contacts/v1/contact/vid/${id}/profile`,
|
88 | body: data,
|
89 | })
|
90 | }
|
91 |
|
92 | create(data) {
|
93 | return this.client._request({
|
94 | method: 'POST',
|
95 | path: '/contacts/v1/contact',
|
96 | body: data,
|
97 | })
|
98 | }
|
99 |
|
100 | createOrUpdate(email, data) {
|
101 | return this.client._request({
|
102 | method: 'POST',
|
103 | path: `/contacts/v1/contact/createOrUpdate/email/${email}`,
|
104 | body: data,
|
105 | })
|
106 | }
|
107 |
|
108 | updateByEmail(email, data) {
|
109 | return this.client._request({
|
110 | method: 'POST',
|
111 | path: `/contacts/v1/contact/email/${email}/profile`,
|
112 | body: data,
|
113 | })
|
114 | }
|
115 |
|
116 |
|
117 | createOrUpdateBatch(data) {
|
118 | return this.client._request({
|
119 | method: 'POST',
|
120 | path: '/contacts/v1/contact/batch',
|
121 | body: data,
|
122 | })
|
123 | }
|
124 |
|
125 | merge(primaryVid, secondaryVid) {
|
126 | const data = {
|
127 | vidToMerge: secondaryVid,
|
128 | }
|
129 | return this.client._request({
|
130 | method: 'POST',
|
131 | path: `/contacts/v1/contact/merge-vids/${primaryVid}`,
|
132 | body: data,
|
133 | })
|
134 | }
|
135 |
|
136 | search(query, options) {
|
137 | if (!options) options = {}
|
138 | options.q = query
|
139 | return this.client._request({
|
140 | method: 'GET',
|
141 | path: '/contacts/v1/search/query',
|
142 | qs: options,
|
143 | })
|
144 | }
|
145 | }
|
146 |
|
147 | module.exports = Contact
|