forked from getlago/lago-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mrr.go
62 lines (50 loc) · 1.26 KB
/
mrr.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
package lago
import (
"context"
"encoding/json"
)
type MrrRequest struct {
client *Client
}
type MrrListInput struct {
AmountCurrency string `json:"currency,omitempty,string"`
Months int `json:"months,omitempty,string"`
}
type MrrResult struct {
Mrr *Mrr `json:"mrr,omitempty"`
Mrrs []Mrr `json:"mrrs,omitempty"`
}
type Mrr struct {
Month string `json:"month,omitempty"`
AmountCents int `json:"amount_cents,omitempty"`
AmountCurrency Currency `json:"currency,omitempty"`
}
func (c *Client) Mrr() *MrrRequest {
return &MrrRequest{
client: c,
}
}
func (adr *MrrRequest) GetList(ctx context.Context, MrrListInput *MrrListInput) (*MrrResult, *Error) {
jsonQueryparams, err := json.Marshal(MrrListInput)
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}
}
clientRequest := &ClientRequest{
Path: "analytics/mrr",
QueryParams: queryParams,
Result: &MrrResult{},
}
result, clientErr := adr.client.Get(ctx, clientRequest)
if clientErr != nil {
return nil, clientErr
}
MrrResult, ok := result.(*MrrResult)
if !ok {
return nil, &ErrorTypeAssert
}
return MrrResult, nil
}