-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
139 lines (117 loc) · 4.32 KB
/
client.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Package customer provides the records APIs
package records
import (
"errors"
"net/http"
"strings"
"github.com/Eyup-Devop/cloudns"
"github.com/Eyup-Devop/cloudns/auth"
)
type Client struct {
B cloudns.Backend
}
func GetRecordsStatistics() (*cloudns.RecordsStatisticsResponse, error) {
return getC().GetRecordsStatistics()
}
func (c Client) GetRecordsStatistics() (*cloudns.RecordsStatisticsResponse, error) {
recordsStatistics := &cloudns.RecordsStatisticsResponse{}
params := &auth.Auth{}
err := c.B.Call(http.MethodPost, "/dns/get-records-stats.json", params, recordsStatistics, false)
return recordsStatistics, err
}
func GetRecord(params *cloudns.RecordParams) (*cloudns.RecordResponse, error) {
return getC().GetRecord(params)
}
func (c Client) GetRecord(params *cloudns.RecordParams) (*cloudns.RecordResponse, error) {
validateError := cloudns.ValidateParams(params)
if validateError != nil {
return nil, errors.New(strings.Join(validateError, ","))
}
response := &cloudns.RecordResponse{}
err := c.B.Call(http.MethodPost, "/dns/get-record.json", params, response, false)
return response, err
}
func GetRecordList(params *cloudns.RecordListParams) (*cloudns.RecordListResponse, error) {
return getC().GetRecordList(params)
}
func (c Client) GetRecordList(params *cloudns.RecordListParams) (*cloudns.RecordListResponse, error) {
validateError := cloudns.ValidateParams(params)
if validateError != nil {
return nil, errors.New(strings.Join(validateError, ","))
}
result := &cloudns.RecordListResponse{
Page: params.Page,
RowsPerPage: params.RowsPerPage,
}
if params.RowsPerPage != nil && params.Page != nil {
pageCountParams := &cloudns.RecordsPagesCountParams{
DomainName: params.DomainName,
Host: params.Host,
Type: params.Type,
RowsPerPage: params.RowsPerPage,
}
pageCount, pageCountError := c.GetRecordsPageCount(pageCountParams)
if pageCount == nil {
return nil, pageCountError
}
result.PageCount = pageCount
if *params.Page > *pageCount {
return nil, errors.New("page is greater than the total pages")
}
}
recordList := map[string]*cloudns.Record{}
err := c.B.Call(http.MethodPost, "/dns/records.json", params, &recordList, false)
result.Records = recordList
return result, err
}
func GetRecordsPageCount(params *cloudns.RecordsPagesCountParams) (*int, error) {
return getC().GetRecordsPageCount(params)
}
func (c Client) GetRecordsPageCount(params *cloudns.RecordsPagesCountParams) (*int, error) {
validateError := cloudns.ValidateParams(params)
if validateError != nil {
return nil, errors.New(strings.Join(validateError, ","))
}
var result int
err := c.B.Call(http.MethodPost, "/dns/get-records-pages-count.json", params, &result, true)
return &result, err
}
func AddRecord(params *cloudns.AddRecordParams) (*cloudns.AddRecordResponse, error) {
return getC().AddRecord(params)
}
func (c Client) AddRecord(params *cloudns.AddRecordParams) (*cloudns.AddRecordResponse, error) {
validateError := cloudns.ValidateParams(params)
if validateError != nil {
return nil, errors.New(strings.Join(validateError, ","))
}
response := &cloudns.AddRecordResponse{}
err := c.B.Call(http.MethodPost, "/dns/add-record.json", params, response, false)
return response, err
}
func DeleteRecord(params *cloudns.DeleteRecordParams) (*cloudns.DeleteRecordResponse, error) {
return getC().DeleteRecord(params)
}
func (c Client) DeleteRecord(params *cloudns.DeleteRecordParams) (*cloudns.DeleteRecordResponse, error) {
validateError := cloudns.ValidateParams(params)
if validateError != nil {
return nil, errors.New(strings.Join(validateError, ","))
}
response := &cloudns.DeleteRecordResponse{}
err := c.B.Call(http.MethodPost, "/dns/delete-record.json", params, response, false)
return response, err
}
func ModifyRecord(params *cloudns.ModifyRecordParams) (*cloudns.ModifyRecordResponse, error) {
return getC().ModifyRecord(params)
}
func (c Client) ModifyRecord(params *cloudns.ModifyRecordParams) (*cloudns.ModifyRecordResponse, error) {
validateError := cloudns.ValidateParams(params)
if validateError != nil {
return nil, errors.New(strings.Join(validateError, ","))
}
response := &cloudns.ModifyRecordResponse{}
err := c.B.Call(http.MethodPost, "/dns/mod-record.json", params, response, false)
return response, err
}
func getC() Client {
return Client{cloudns.GetBackend()}
}