-
Notifications
You must be signed in to change notification settings - Fork 11
/
website_base.go
91 lines (67 loc) · 2.29 KB
/
website_base.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
88
89
90
91
// Copyright 2018 Crisp IM SAS All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package crisp
import (
"fmt"
"net/url"
)
// WebsiteData mapping
type WebsiteData struct {
Data *Website `json:"data,omitempty"`
}
// Website mapping
type Website struct {
WebsiteID *string `json:"website_id,omitempty"`
Name *string `json:"name,omitempty"`
Domain *string `json:"domain,omitempty"`
Logo *string `json:"logo,omitempty"`
}
// WebsiteCreate mapping
type WebsiteCreate struct {
Name string `json:"name,omitempty"`
Domain string `json:"domain,omitempty"`
}
// WebsiteRemove mapping
type WebsiteRemove struct {
Verify *string `json:"verify,omitempty"`
}
// String returns the string representation of Website
func (instance Website) String() string {
return Stringify(instance)
}
// CheckWebsiteExists checks if given website exists (by domain).
func (service *WebsiteService) CheckWebsiteExists(domain string) (*Response, error) {
url := fmt.Sprintf("website?domain=%s", url.QueryEscape(domain))
req, _ := service.client.NewRequest("HEAD", url, nil)
return service.client.Do(req, nil)
}
// CreateWebsite creates a new website.
func (service *WebsiteService) CreateWebsite(websiteData WebsiteCreate) (*Website, *Response, error) {
url := "website"
req, _ := service.client.NewRequest("POST", url, websiteData)
website := new(WebsiteData)
resp, err := service.client.Do(req, website)
if err != nil {
return nil, resp, err
}
return website.Data, resp, err
}
// GetWebsite resolves an existing website information.
func (service *WebsiteService) GetWebsite(websiteID string) (*Website, *Response, error) {
url := fmt.Sprintf("website/%s", websiteID)
req, _ := service.client.NewRequest("GET", url, nil)
website := new(WebsiteData)
resp, err := service.client.Do(req, website)
if err != nil {
return nil, resp, err
}
return website.Data, resp, err
}
// DeleteWebsite deletes an existing website.
func (service *WebsiteService) DeleteWebsite(websiteID string, verify string) (*Response, error) {
url := fmt.Sprintf("website/%s", websiteID)
req, _ := service.client.NewRequest("DELETE", url, WebsiteRemove{Verify: &verify})
return service.client.Do(req, nil)
}