-
Notifications
You must be signed in to change notification settings - Fork 0
/
userVoice.go
78 lines (71 loc) · 1.98 KB
/
userVoice.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
75
76
77
78
package connect
import "encoding/json"
// UserVoiceSettings - Settings of UserVoice
type UserVoiceSettings struct {
Name string `json:"name"`
Email string `json:"email"`
}
// UserVoice accounts management
// UserVoiceGet - Obtain settings of User Voice.
// Return
// settings - structure with settings
func (s *ServerConnection) UserVoiceGet() (*UserVoiceSettings, error) {
data, err := s.CallRaw("UserVoice.get", nil)
if err != nil {
return nil, err
}
settings := struct {
Result struct {
Settings UserVoiceSettings `json:"settings"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &settings)
return &settings.Result.Settings, err
}
// UserVoiceGetStatus - Get status of registration of user voice.
// Return
// isSet - true if user voice is set
func (s *ServerConnection) UserVoiceGetStatus() (bool, error) {
data, err := s.CallRaw("UserVoice.getStatus", nil)
if err != nil {
return false, err
}
isSet := struct {
Result struct {
IsSet bool `json:"isSet"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &isSet)
return isSet.Result.IsSet, err
}
// UserVoiceGetUrl - Parameters name and email can be empty strings.
// name - user displayname for userVoice
// email - user email address for userVoice
// Return
// url - URL to userVoice with single sign on token
func (s *ServerConnection) UserVoiceGetUrl(name string, email string) (string, error) {
params := struct {
Name string `json:"name"`
Email string `json:"email"`
}{name, email}
data, err := s.CallRaw("UserVoice.getUrl", params)
if err != nil {
return "", err
}
url := struct {
Result struct {
Url string `json:"url"`
} `json:"result"`
}{}
err = json.Unmarshal(data, &url)
return url.Result.Url, err
}
// UserVoiceSet - Set settings of User Voice.
// settings - structure with settings
func (s *ServerConnection) UserVoiceSet(settings UserVoiceSettings) error {
params := struct {
Settings UserVoiceSettings `json:"settings"`
}{settings}
_, err := s.CallRaw("UserVoice.set", params)
return err
}