-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccounts.go
More file actions
71 lines (57 loc) · 1.34 KB
/
accounts.go
File metadata and controls
71 lines (57 loc) · 1.34 KB
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
package form3
import (
"context"
"fmt"
)
const (
orgAccBasePath = "organisation/accounts"
)
type AccService service
func (as *AccService) GetByID(ctx context.Context, id string) (*AccountData, *Response, error) {
cl := as.form3Client
url := fmt.Sprintf("%s/%s", orgAccBasePath, id)
req, err := cl.GET(url, nil)
if err != nil {
return nil, nil, nil
}
account := &AccountData{}
res, err := cl.Do(ctx, req, account)
if err != nil {
return nil, res, err
}
return account, res, nil
}
func (as *AccService) NewAccount(ctx context.Context, acc *AccountData) (*AccountData, *Response, error) {
cl := as.form3Client
req, err := cl.POST(orgAccBasePath, acc)
if err != nil {
return nil, nil, err
}
account := &AccountData{}
res, err := cl.Do(ctx, req, account)
if err != nil {
return nil, res, err
}
return account, res, nil
}
func (as *AccService) DeleteByID(ctx context.Context, id string, version int) (*Response, error) {
cl := as.form3Client
url := fmt.Sprintf("%s/%s?version=%d", orgAccBasePath, id, version)
reqs, err := cl.DELETE(url, nil)
if err != nil {
return nil, nil
}
res, err := cl.Do(ctx, reqs, nil)
if err != nil {
return res, err
}
return res, nil
}
func LoadAccountsService(client *Client) *AccService {
if client == nil {
client = CreateClient(nil)
}
return &AccService{
form3Client: client,
}
}