forked from dilutedev/doppler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkplace.go
80 lines (65 loc) · 1.39 KB
/
workplace.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
package doppler
import (
"bytes"
"encoding/json"
"net/http"
)
type Workplace struct {
Workplace WorkplaceClass `json:"workplace"`
Success bool `json:"success"`
}
type WorkplaceClass struct {
ID string `json:"id"`
Name string `json:"name"`
BillingEmail string `json:"billing_email"`
}
type WorkplaceParams struct {
Name string `json:"name,omitempty"`
BillingEmail string `json:"billing_email,omitempty"`
}
// get workplace info
func (dp *doppler) GetWorkplace() (*Workplace, error) {
var (
request, err = http.NewRequest(
http.MethodGet,
"/v3/workplace",
nil,
)
workplace = Workplace{}
)
if err != nil {
return nil, err
}
body, err := dp.makeApiRequest(request)
if err != nil {
return nil, err
}
if err := json.Unmarshal(body, &workplace); err != nil {
return nil, err
}
return &workplace, nil
}
// update work place info
func (dp *doppler) UpdateWorkplace(params WorkplaceParams) (*Workplace, error) {
payload, err := json.Marshal(params)
if err != nil {
return nil, err
}
request, err := http.NewRequest(
http.MethodPost,
"/v3/workplace",
bytes.NewReader(payload),
)
workplace := Workplace{}
if err != nil {
return nil, err
}
body, err := dp.makeApiRequest(request)
if err != nil {
return nil, err
}
if err := json.Unmarshal(body, &workplace); err != nil {
return nil, err
}
return &workplace, nil
}