-
Notifications
You must be signed in to change notification settings - Fork 1
/
cbibannercontroller.go
87 lines (77 loc) · 2.84 KB
/
cbibannercontroller.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
79
80
81
82
83
84
85
86
87
package cbibannercontroller
import (
"fmt"
"net/http"
"strings"
)
const (
cbiConfig = "/cbiconfig/cbi/api/customers/"
cbiBannerEndpoint = "/banner"
cbiBannersEndpoint = "/banners"
)
type CBIBannerController struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
PrimaryColor string `json:"primaryColor,omitempty"`
TextColor string `json:"textColor,omitempty"`
NotificationTitle string `json:"notificationTitle,omitempty"`
NotificationText string `json:"notificationText,omitempty"`
Logo string `json:"logo,omitempty"`
Banner bool `json:"banner,omitempty"`
IsDefault bool `json:"isDefault,omitempty"`
Persist bool `json:"persist,omitempty"`
}
func (service *Service) Get(bannerID string) (*CBIBannerController, *http.Response, error) {
v := new(CBIBannerController)
relativeURL := fmt.Sprintf("%s/%s", cbiConfig+service.Client.Config.CustomerID+cbiBannersEndpoint, bannerID)
resp, err := service.Client.NewRequestDo("GET", relativeURL, nil, nil, &v)
if err != nil {
return nil, nil, err
}
return v, resp, nil
}
func (service *Service) GetByName(bannerName string) (*CBIBannerController, *http.Response, error) {
list, resp, err := service.GetAll()
if err != nil {
return nil, nil, err
}
for _, banner := range list {
if strings.EqualFold(banner.Name, bannerName) {
return &banner, resp, nil
}
}
return nil, resp, fmt.Errorf("no cloud browser isolation banner named '%s' was found", bannerName)
}
func (service *Service) Create(cbiBanner *CBIBannerController) (*CBIBannerController, *http.Response, error) {
v := new(CBIBannerController)
resp, err := service.Client.NewRequestDo("POST", cbiConfig+service.Client.Config.CustomerID+cbiBannerEndpoint, nil, cbiBanner, &v)
if err != nil {
return nil, nil, err
}
return v, resp, nil
}
func (service *Service) Update(cbiBannerID string, cbiBanner *CBIBannerController) (*http.Response, error) {
path := fmt.Sprintf("%v/%v", cbiConfig+service.Client.Config.CustomerID+cbiBannersEndpoint, cbiBannerID)
resp, err := service.Client.NewRequestDo("PUT", path, nil, cbiBanner, nil)
if err != nil {
return nil, err
}
return resp, err
}
func (service *Service) Delete(cbiBannerID string) (*http.Response, error) {
path := fmt.Sprintf("%v/%v", cbiConfig+service.Client.Config.CustomerID+cbiBannersEndpoint, cbiBannerID)
resp, err := service.Client.NewRequestDo("DELETE", path, nil, nil, nil)
if err != nil {
return nil, err
}
return resp, err
}
func (service *Service) GetAll() ([]CBIBannerController, *http.Response, error) {
relativeURL := cbiConfig + service.Client.Config.CustomerID + cbiBannersEndpoint
var list []CBIBannerController
resp, err := service.Client.NewRequestDo("GET", relativeURL, nil, nil, &list)
if err != nil {
return nil, nil, err
}
return list, resp, nil
}