-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccountservice.go
66 lines (59 loc) · 1.5 KB
/
accountservice.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
package form3_api_client
import (
"context"
"fmt"
"net/http"
)
const (
CreateURL = "v1/organisation/accounts"
FetchURL = "v1/organisation/accounts/%s"
DeleteUrl = "v1/organisation/accounts/%s?version=%d"
)
type AccountService struct {
client *client
}
func NewAccountService(baseURL string) *AccountService{
if baseURL == "" {
baseURL = BaseUrlEnvVariable
}
return &AccountService{
client: newClient(nil, baseURL),
}
}
func (s *AccountService) Create(ctx context.Context, account *AccountData) (*AccountData, *response, error) {
req, err := s.client.newRequest(http.MethodPost, CreateURL, account)
if err != nil {
return nil, nil, err
}
acc := &AccountData{}
resp, err := s.client.do(ctx, req, acc)
if err != nil {
return nil, resp, err
}
return acc, resp, nil
}
func (s *AccountService) Fetch(ctx context.Context, id string) (*AccountData, *response, error) {
path := fmt.Sprintf(FetchURL, id)
req, err := s.client.newRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
account := &AccountData{}
resp, err := s.client.do(ctx, req, account)
if err != nil {
return nil, resp, err
}
return account, resp, err
}
func (s *AccountService) Delete(ctx context.Context, id string, version *int64) (*response, error) {
path := fmt.Sprintf(DeleteUrl, id, *version)
req, err := s.client.newRequest(http.MethodDelete, path, nil)
if err != nil {
return nil, err
}
resp, err := s.client.do(ctx, req, nil)
if err != nil {
return nil, err
}
return resp, err
}