-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_store.go
More file actions
95 lines (85 loc) · 2.09 KB
/
Copy pathapi_store.go
File metadata and controls
95 lines (85 loc) · 2.09 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package sova
import (
"context"
"errors"
"fmt"
)
var ErrNoSuccessFieldFound = errors.New("no success field found")
// StoreVerifyPlayer checks if player with this nickname exists.
//
// /api/store/verify-player/{nickname}
func (api *API) StoreVerifyPlayer(ctx context.Context, nickname string) (*StoreVerifyPlayerResponse, error) {
resp, err := getAndUnmarshal[struct {
//Data []interface{} `json:"data"`
Success *StoreVerifyPlayerResponse `json:"success,omitempty"`
}](
api, ctx,
f("store/verify-player/%s", nickname),
true,
)
if err != nil {
return nil, err
}
if resp.Success == nil {
return nil, ErrNoSuccessFieldFound
}
return resp.Success, nil
}
// StoreVerifyPlayerDirect ...
func (api *API) StoreVerifyPlayerDirect(ctx context.Context, nickname string) bool {
res, err := api.StoreVerifyPlayer(ctx, nickname)
if err != nil {
return false
}
return *res
}
type ErrNoAvailableRanks struct {
Player string
}
func (e ErrNoAvailableRanks) Error() string {
if e.Player == "" {
return "no available ranks"
}
return fmt.Sprintf("no available ranks for %s", e.Player)
}
// StoreRanks returns list of ranks for a specific player (nickname).
//
// /api/store/ranks/{nickname}
func (api *API) StoreRanks(ctx context.Context, nickname string) (StoreRanksResponse, error) {
resp, err := getAndUnmarshal[StoreRanksResponse](
api, ctx,
f("store/ranks/%s", nickname),
)
if err != nil {
return nil, err
}
if len(resp) == 0 {
return nil, ErrNoAvailableRanks{Player: nickname}
}
return resp, nil
}
type ErrNoItemsAvailable struct {
Player string
}
func (e ErrNoItemsAvailable) Error() string {
if e.Player == "" {
return "no items available"
}
return fmt.Sprintf("no items available for %s", e.Player)
}
// StoreItems ...
//
// /api/store/items/{nickname}
func (api *API) StoreItems(ctx context.Context, nickname string) (StoreItemsResponse, error) {
resp, err := getAndUnmarshal[StoreItemsResponse](
api, ctx,
f("store/items/%s", nickname),
)
if err != nil {
return nil, err
}
if len(resp) == 0 {
return nil, ErrNoItemsAvailable{Player: nickname}
}
return resp, nil
}