forked from getlago/lago-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group.go
67 lines (54 loc) · 1.41 KB
/
group.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
package lago
import (
"context"
"encoding/json"
"fmt"
"github.com/google/uuid"
)
type GroupRequest struct {
client *Client
}
type GroupResult struct {
Groups []Group `json:"groups,omitempty"`
Meta Metadata `json:"meta,omitempty"`
}
type GroupListInput struct {
PerPage int `json:"per_page,omitempty,string"`
Page int `json:"page,omitempty,string"`
Code string `json:"code,omitempty"`
}
type Group struct {
LagoID uuid.UUID `json:"lago_id,omitempty"`
Key string `json:"key,omitempty"`
Value string `json:"value,omitempty"`
}
func (c *Client) Group() *GroupRequest {
return &GroupRequest{
client: c,
}
}
func (cr *GroupRequest) GetList(ctx context.Context, groupListInput *GroupListInput) (*GroupResult, *Error) {
jsonQueryParams, err := json.Marshal(groupListInput)
if err != nil {
return nil, &Error{Err: err}
}
queryParams := make(map[string]string)
if err = json.Unmarshal(jsonQueryParams, &queryParams); err != nil {
return nil, &Error{Err: err}
}
subPath := fmt.Sprintf("%s/%s/%s", "billable_metrics", groupListInput.Code, "groups")
clientRequest := &ClientRequest{
Path: subPath,
QueryParams: queryParams,
Result: &GroupResult{},
}
result, clientErr := cr.client.Get(ctx, clientRequest)
if clientErr != nil {
return nil, clientErr
}
groupResult, ok := result.(*GroupResult)
if !ok {
return nil, &ErrorTypeAssert
}
return groupResult, nil
}