-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathptr_records.go
86 lines (56 loc) · 1.91 KB
/
ptr_records.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
package vscale_api_go
import (
"encoding/json"
"fmt"
"net/http"
"strconv"
)
type PTRRecordService struct {
client Client
}
type PTRRecord struct {
Content string `json:"content,omitempty"`
UserID int64 `json:"user_id,omitempty"`
IP string `json:"ip,omitempty"`
ID int64 `json:"id,omitempty"`
}
func (p *PTRRecordService) Create(content, ip string) (*PTRRecord, *http.Response, error) {
ptrRecord := new(PTRRecord)
body := struct {
Content string `json:"content,omitempty"`
IP string `json:"ip,omitempty"`
}{content, ip}
b, _ := json.Marshal(body)
res, err := p.client.ExecuteRequest("POST", "domains/ptr/", b, ptrRecord)
return ptrRecord, res, err
}
func (p *PTRRecordService) List() (*[]PTRRecord, *http.Response, error) {
ptrRecords := new([]PTRRecord)
res, err := p.client.ExecuteRequest("GET", "domains/ptr/", []byte{}, ptrRecords)
return ptrRecords, res, err
}
func (p *PTRRecordService) Get(recordID int64) (*PTRRecord, *http.Response, error) {
ptrRecord := new(PTRRecord)
url := fmt.Sprint("domains/ptr/", strconv.FormatInt(recordID, 10))
res, err := p.client.ExecuteRequest("GET", url, []byte{}, ptrRecord)
return ptrRecord, res, err
}
func (p *PTRRecordService) Update(recordID int64, content, ip string) (*PTRRecord, *http.Response, error) {
ptrRecord := new(PTRRecord)
body := struct {
Content string `json:"content,omitempty"`
IP string `json:"ip,omitempty"`
}{content, ip}
b, _ := json.Marshal(body)
url := fmt.Sprint("domains/ptr/", strconv.FormatInt(recordID, 10))
res, err := p.client.ExecuteRequest("PUT", url, b, ptrRecord)
return ptrRecord, res, err
}
func (p *PTRRecordService) Remove(recordID int64) (bool, *http.Response, error) {
url := fmt.Sprint("domains/ptr/", strconv.FormatInt(recordID, 10))
res, err := p.client.ExecuteRequest("DELETE", url, []byte{}, struct{}{})
if err != nil {
return false, res, err
}
return true, res, err
}