-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsent.go
74 lines (63 loc) · 3.43 KB
/
consent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package igcclient
import (
"fmt"
"net/http"
"net/url"
"github.com/moonwalker/igcclient/models"
"github.com/moonwalker/logger"
)
type ConsentService service
// Get All Consents by Language X-Api-Key is required.
func (s *ConsentService) GetConsents(languageAlpha2Code string, headers map[string]string, log logger.Logger) (response models.OperationResponseOfListOfPublicConsentModel, err error) {
q := url.Values{}
q.Add("languageAlpha2Code", languageAlpha2Code)
err = s.client.apiReq(http.MethodPost, "/Consent/GetConsents", &q, nil, &response, &headers, log)
return
}
// Checks if user has any pending mandatory consents
func (s *ConsentService) HasPendingConsents(headers map[string]string, log logger.Logger) (response models.OperationResponseOfBoolean, err error) {
err = s.client.apiReq(http.MethodPost, "/Consent/HasPendingConsents", nil, nil, &response, &headers, log)
return
}
// Checks if user has any migrated consents that require and update
func (s *ConsentService) RequiresLegacyUpdate(headers map[string]string, log logger.Logger) (response models.OperationResponseOfBoolean, err error) {
err = s.client.apiReq(http.MethodPost, "/Consent/RequiresLegacyUpdate", nil, nil, &response, &headers, log)
return
}
// Gets mandatory consents with content which user need to consent to by language
func (s *ConsentService) UserPendingConsents(languageAlpha2Code string, headers map[string]string, log logger.Logger) (response models.OperationResponseOfPublicUserConsentsListModel, err error) {
q := url.Values{}
q.Add("languageAlpha2Code", languageAlpha2Code)
err = s.client.apiReq(http.MethodPost, "/Consent/UserPendingConsents", &q, nil, &response, &headers, log)
return
}
// Save user consents
func (s *ConsentService) SaveUserConsents(body []models.ConsentVersionSaveModel, userID int64, headers map[string]string, log logger.Logger) (response models.OperationResponseOfBoolean, err error) {
q := url.Values{}
q.Add("userId", fmt.Sprintf("%d", userID))
err = s.client.apiReq(http.MethodPost, "/Consent/SaveUserConsents", &q, &body, &response, &headers, log)
return
}
// Gets list of user consents with content and user's acceptance
func (s *ConsentService) UserConsents(languageAlpha2Code string, headers map[string]string, log logger.Logger) (response models.OperationResponseOfPublicUserConsentsListModel, err error) {
q := url.Values{}
q.Add("languageAlpha2Code", languageAlpha2Code)
err = s.client.apiReq(http.MethodPost, "/Consent/UserConsents", &q, nil, &response, &headers, log)
return
}
// Unsubscribe all Consents by trigger code This will require CRM X-api key:
func (s *ConsentService) Unsubscribe(triggerCode string, userID int64, headers map[string]string, log logger.Logger) (response models.OperationResponseOfObject, err error) {
q := url.Values{}
q.Add("triggerCode", triggerCode)
q.Add("userId", fmt.Sprintf("%d", userID))
err = s.client.apiReq(http.MethodPost, "/Consent/Unsubscribe", &q, nil, &response, &headers, log)
return
}
// Gets list of user consents with content and user's acceptence X-Api-Key is required
func (s *ConsentService) UserConsentsByUserID(languageAlpha2Code string, userID int64, headers map[string]string, log logger.Logger) (response models.OperationResponseOfPublicUserConsentsListModel, err error) {
q := url.Values{}
q.Add("languageAlpha2Code", languageAlpha2Code)
q.Add("userId", fmt.Sprintf("%d", userID))
err = s.client.apiReq(http.MethodPost, "/Consent/UserConsents", &q, nil, &response, &headers, log)
return
}