forked from trycourier/courier-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofiles.go
50 lines (45 loc) · 1 KB
/
profiles.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
package courier
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
type Profile struct {
Profile interface{} `json:"profile"`
}
func (s *Client) GetProfile(id string) (*Profile, error) {
url := fmt.Sprintf(s.BaseUrl+"/profiles/%s", id)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
bytes, err := s.doRequest(req)
if err != nil {
return nil, err
}
var data Profile
err = json.Unmarshal(bytes, &data)
if err != nil {
return nil, err
}
return &data, nil
}
func (s *Client) MergeProfile(id string, profile []byte) error {
url := fmt.Sprintf(s.BaseUrl+"/profiles/%s", id)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(profile))
if err != nil {
return err
}
_, err = s.doRequest(req)
return err
}
func (s *Client) UpdateProfile(id string, profile []byte) error {
url := fmt.Sprintf(s.BaseUrl+"/profiles/%s", id)
req, err := http.NewRequest("PUT", url, bytes.NewBuffer(profile))
if err != nil {
return err
}
_, err = s.doRequest(req)
return err
}