1 | class Properties {
|
2 | constructor(client) {
|
3 | this.client = client
|
4 | }
|
5 |
|
6 | getAll(options) {
|
7 | return this.client._request({
|
8 | method: 'GET',
|
9 | path: '/properties/v1/contacts/properties',
|
10 | qs: options,
|
11 | })
|
12 | }
|
13 |
|
14 | get(options) {
|
15 | return this.getAll(options)
|
16 | }
|
17 |
|
18 | getByName(name) {
|
19 | return this.client._request({
|
20 | method: 'GET',
|
21 | path: `/properties/v1/contacts/properties/named/${name}`,
|
22 | })
|
23 | }
|
24 |
|
25 | create(data) {
|
26 | return this.client._request({
|
27 | method: 'POST',
|
28 | path: '/properties/v1/contacts/properties',
|
29 | body: data,
|
30 | })
|
31 | }
|
32 |
|
33 | update(name, data) {
|
34 | return this.client._request({
|
35 | method: 'PUT',
|
36 | path: `/properties/v1/contacts/properties/named/${name}`,
|
37 | body: data,
|
38 | })
|
39 | }
|
40 |
|
41 | delete(name) {
|
42 | return this.client._request({
|
43 | method: 'DELETE',
|
44 | path: `/properties/v1/contacts/properties/named/${name}`,
|
45 | })
|
46 | }
|
47 |
|
48 | upsert(data) {
|
49 | return this.create(data).catch((err) => {
|
50 | if (err.statusCode === 409) {
|
51 |
|
52 | return this.update(data.name, data)
|
53 | } else {
|
54 | throw err
|
55 | }
|
56 | })
|
57 | }
|
58 |
|
59 | getGroups() {
|
60 | return this.client._request({
|
61 | method: 'GET',
|
62 | path: '/properties/v1/contacts/groups',
|
63 | })
|
64 | }
|
65 |
|
66 | createGroup(data) {
|
67 | return this.client._request({
|
68 | method: 'POST',
|
69 | path: '/properties/v1/contacts/groups',
|
70 | body: data,
|
71 | })
|
72 | }
|
73 |
|
74 | updateGroup(name, data) {
|
75 | return this.client._request({
|
76 | method: 'PUT',
|
77 | path: `/properties/v1/contacts/groups/named/${name}`,
|
78 | body: data,
|
79 | })
|
80 | }
|
81 |
|
82 | deleteGroup(name) {
|
83 | return this.client._request({
|
84 | method: 'DELETE',
|
85 | path: `/properties/v1/contacts/groups/named/${name}`,
|
86 | })
|
87 | }
|
88 | }
|
89 |
|
90 | module.exports = Properties
|