-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-data-points.go
93 lines (74 loc) · 2.41 KB
/
custom-data-points.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
package authsignal
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
type CustomDataPoint struct {
Id NullableJsonInput[string] `json:"id,omitempty"`
Name NullableJsonInput[string] `json:"name,omitempty"`
DataType NullableJsonInput[string] `json:"dataType,omitempty"`
ModelType NullableJsonInput[string] `json:"modelType,omitempty"`
Description NullableJsonInput[string] `json:"description,omitempty"`
}
type CustomDataPointResponse struct {
Id string `json:"id"`
Name string `json:"name"`
DataType string `json:"dataType"`
ModelType string `json:"modelType"`
Description string `json:"description"`
}
func (c Client) CreateCustomDataPoint(customDataPoint CustomDataPoint) (*CustomDataPointResponse, int, error) {
createBody, err := json.Marshal(customDataPoint)
if err != nil {
return nil, 0, err
}
request, err := http.NewRequest("POST", fmt.Sprintf("%s/custom-data-points", c.Host), bytes.NewReader(createBody))
if err != nil {
return nil, 0, err
}
request.Header.Set("Content-Type", "application/json")
body, statusCode, err := c.makeRequest(request, c.ApiSecret)
if err != nil {
return nil, statusCode, err
}
var createdCustomDataPoint CustomDataPointResponse
err = json.Unmarshal(body, &createdCustomDataPoint)
if err != nil {
return nil, statusCode, err
}
return &createdCustomDataPoint, statusCode, nil
}
func (c Client) GetCustomDataPoint(id string) (*CustomDataPointResponse, int, error) {
request, err := http.NewRequest("GET", fmt.Sprintf("%s/custom-data-points/%s", c.Host, id), nil)
if err != nil {
return nil, 0, err
}
body, statusCode, err := c.makeRequest(request, c.ApiSecret)
if err != nil {
return nil, statusCode, err
}
var customDataPoint CustomDataPointResponse
err = json.Unmarshal(body, &customDataPoint)
if err != nil {
return nil, statusCode, err
}
return &customDataPoint, statusCode, nil
}
func (c Client) DeleteCustomDataPoint(id string) (*HttpStatusResponse, int, error) {
request, err := http.NewRequest("DELETE", fmt.Sprintf("%s/custom-data-points/%s", c.Host, id), nil)
if err != nil {
return nil, 0, err
}
body, statusCode, err := c.makeRequest(request, c.ApiSecret)
if err != nil {
return nil, statusCode, err
}
var httpStatusResponse HttpStatusResponse
err = json.Unmarshal(body, &httpStatusResponse)
if err != nil {
return nil, statusCode, err
}
return &httpStatusResponse, statusCode, nil
}