-
Notifications
You must be signed in to change notification settings - Fork 2
/
event.go
138 lines (124 loc) · 4.75 KB
/
event.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package moderntreasury
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"time"
"github.com/Modern-Treasury/modern-treasury-go/v2/internal/apijson"
"github.com/Modern-Treasury/modern-treasury-go/v2/internal/apiquery"
"github.com/Modern-Treasury/modern-treasury-go/v2/internal/param"
"github.com/Modern-Treasury/modern-treasury-go/v2/internal/requestconfig"
"github.com/Modern-Treasury/modern-treasury-go/v2/option"
"github.com/Modern-Treasury/modern-treasury-go/v2/packages/pagination"
)
// EventService contains methods and other services that help with interacting with
// the Modern Treasury API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewEventService] method instead.
type EventService struct {
Options []option.RequestOption
}
// NewEventService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewEventService(opts ...option.RequestOption) (r *EventService) {
r = &EventService{}
r.Options = opts
return
}
// get event
func (r *EventService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *Event, err error) {
opts = append(r.Options[:], opts...)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("api/events/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// list events
func (r *EventService) List(ctx context.Context, query EventListParams, opts ...option.RequestOption) (res *pagination.Page[Event], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "api/events"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// list events
func (r *EventService) ListAutoPaging(ctx context.Context, query EventListParams, opts ...option.RequestOption) *pagination.PageAutoPager[Event] {
return pagination.NewPageAutoPager(r.List(ctx, query, opts...))
}
type Event struct {
ID string `json:"id,required" format:"uuid"`
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// The body of the event.
Data map[string]interface{} `json:"data,required"`
// The ID of the entity for the event.
EntityID string `json:"entity_id,required" format:"uuid"`
// The name of the event.
EventName string `json:"event_name,required"`
// The time of the event.
EventTime time.Time `json:"event_time,required" format:"date-time"`
// This field will be true if this object exists in the live environment or false
// if it exists in the test environment.
LiveMode bool `json:"live_mode,required"`
Object string `json:"object,required"`
// The type of resource for the event.
Resource string `json:"resource,required"`
UpdatedAt time.Time `json:"updated_at,required" format:"date-time"`
JSON eventJSON `json:"-"`
}
// eventJSON contains the JSON metadata for the struct [Event]
type eventJSON struct {
ID apijson.Field
CreatedAt apijson.Field
Data apijson.Field
EntityID apijson.Field
EventName apijson.Field
EventTime apijson.Field
LiveMode apijson.Field
Object apijson.Field
Resource apijson.Field
UpdatedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Event) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r eventJSON) RawJSON() string {
return r.raw
}
type EventListParams struct {
AfterCursor param.Field[string] `query:"after_cursor"`
EntityID param.Field[string] `query:"entity_id"`
EventName param.Field[string] `query:"event_name"`
// An inclusive upper bound for when the event occurred
EventTimeEnd param.Field[time.Time] `query:"event_time_end" format:"date-time"`
// An inclusive lower bound for when the event occurred
EventTimeStart param.Field[time.Time] `query:"event_time_start" format:"date-time"`
PerPage param.Field[int64] `query:"per_page"`
Resource param.Field[string] `query:"resource"`
}
// URLQuery serializes [EventListParams]'s query parameters as `url.Values`.
func (r EventListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}