-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_api.go
69 lines (57 loc) · 1.58 KB
/
client_api.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
package exaroton
import (
"context"
"pkg.icikowski.pl/exaroton/model"
)
type apiClient struct {
*baseClient
}
func newAPIClient(base *baseClient) API {
return &apiClient{
baseClient: base,
}
}
// GetAccount implements API.
func (c *apiClient) GetAccount(ctx context.Context) (*model.AccountInfo, *RawResponse[model.AccountInfo], error) {
resp, err := c.do(c.rb.buildAccountGetRequest(ctx))
if err != nil {
return nil, nil, err
}
rawResp, err := decodeRawResponse[model.AccountInfo](resp)
if err != nil {
return nil, rawResp, err
}
return rawResp.Data, rawResp, nil
}
// GetServers implements API.
func (c *apiClient) GetServers(ctx context.Context) (model.Servers, *RawResponse[model.Servers], error) {
resp, err := c.do(c.rb.buildServersGetRequest(ctx))
if err != nil {
return nil, nil, err
}
rawResp, err := decodeRawResponse[model.Servers](resp)
if err != nil {
return nil, rawResp, err
}
return *rawResp.Data, rawResp, nil
}
// Server implements API.
func (c *apiClient) Server(id string) ServerAPI {
return newServerClient(c.baseClient, id)
}
// GetCreditPools implements API.
func (c *apiClient) GetCreditPools(ctx context.Context) (model.CreditPools, *RawResponse[model.CreditPools], error) {
resp, err := c.do(c.rb.buildCreditPoolsGetRequest(ctx))
if err != nil {
return nil, nil, err
}
rawResp, err := decodeRawResponse[model.CreditPools](resp)
if err != nil {
return nil, rawResp, err
}
return *rawResp.Data, rawResp, nil
}
// CreditPool implements API.
func (c *apiClient) CreditPool(id string) CreditPoolAPI {
return newCreditPoolClient(c.baseClient, id)
}