-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
58 lines (46 loc) · 1.07 KB
/
client.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
package s10s
import (
"context"
api "github.com/ruudiRatlos/s10s/openapi"
)
// Client represents a retrying REST API Client for spacetraders
type Client struct {
*baseClient
AgentsAPI *AgentsAPI
SystemsAPI *SystemsAPI
FleetAPI *FleetAPI
ContractsAPI *ContractsAPI
FactionsAPI *FactionsAPI
}
// NewClient creates a new Spacetraders client
func NewClient(opts ...ClientOption) (*Client, error) {
bc := &baseClient{
cfg: api.NewConfiguration(),
}
bc.cfg.UserAgent = "s10s/v1/go"
c := &Client{
baseClient: bc,
AgentsAPI: &AgentsAPI{bc},
SystemsAPI: &SystemsAPI{bc},
FleetAPI: &FleetAPI{bc},
FactionsAPI: &FactionsAPI{bc},
ContractsAPI: &ContractsAPI{bc},
}
if len(opts) == 0 {
opts = DefaultOptions
}
for _, o := range opts {
err := o(c)
if err != nil {
return nil, err
}
}
bc.c = api.NewAPIClient(bc.cfg)
ctx := contextWithToken(context.Background(), c.token)
_, httpR, err := c.c.DefaultAPI.GetStatus(ctx).Execute() //nolint:bodyclose
err = enhanceErr(err, httpR)
if err != nil {
return nil, err
}
return c, nil
}