-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathledgereventhandler.go
410 lines (362 loc) · 15.6 KB
/
ledgereventhandler.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
// 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"
)
// LedgerEventHandlerService 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 [NewLedgerEventHandlerService] method instead.
type LedgerEventHandlerService struct {
Options []option.RequestOption
}
// NewLedgerEventHandlerService 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 NewLedgerEventHandlerService(opts ...option.RequestOption) (r *LedgerEventHandlerService) {
r = &LedgerEventHandlerService{}
r.Options = opts
return
}
// create ledger_event_handler
func (r *LedgerEventHandlerService) New(ctx context.Context, body LedgerEventHandlerNewParams, opts ...option.RequestOption) (res *LedgerEventHandler, err error) {
opts = append(r.Options[:], opts...)
path := "api/ledger_event_handlers"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Get details on a single ledger event handler.
func (r *LedgerEventHandlerService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *LedgerEventHandler, err error) {
opts = append(r.Options[:], opts...)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("api/ledger_event_handlers/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Get a list of ledger event handlers.
func (r *LedgerEventHandlerService) List(ctx context.Context, query LedgerEventHandlerListParams, opts ...option.RequestOption) (res *pagination.Page[LedgerEventHandler], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "api/ledger_event_handlers"
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
}
// Get a list of ledger event handlers.
func (r *LedgerEventHandlerService) ListAutoPaging(ctx context.Context, query LedgerEventHandlerListParams, opts ...option.RequestOption) *pagination.PageAutoPager[LedgerEventHandler] {
return pagination.NewPageAutoPager(r.List(ctx, query, opts...))
}
// Archive a ledger event handler.
func (r *LedgerEventHandlerService) Delete(ctx context.Context, id string, opts ...option.RequestOption) (res *LedgerEventHandler, err error) {
opts = append(r.Options[:], opts...)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("api/ledger_event_handlers/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return
}
// Deprecated: deprecated
type LedgerEventHandler struct {
ID string `json:"id,required" format:"uuid"`
// Deprecated: deprecated
Conditions LedgerEventHandlerConditions `json:"conditions,required,nullable"`
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// An optional description.
Description string `json:"description,required,nullable"`
DiscardedAt time.Time `json:"discarded_at,required,nullable" format:"date-time"`
// The id of the ledger that this event handler belongs to.
LedgerID string `json:"ledger_id,required,nullable"`
// Deprecated: deprecated
LedgerTransactionTemplate LedgerEventHandlerLedgerTransactionTemplate `json:"ledger_transaction_template,required"`
// 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"`
// Additional data represented as key-value pairs. Both the key and value must be
// strings.
Metadata map[string]string `json:"metadata,required,nullable"`
// Name of the ledger event handler.
Name string `json:"name,required"`
Object string `json:"object,required"`
UpdatedAt time.Time `json:"updated_at,required" format:"date-time"`
// Deprecated: deprecated
Variables map[string]LedgerEventHandlerVariable `json:"variables,required,nullable"`
JSON ledgerEventHandlerJSON `json:"-"`
}
// ledgerEventHandlerJSON contains the JSON metadata for the struct
// [LedgerEventHandler]
type ledgerEventHandlerJSON struct {
ID apijson.Field
Conditions apijson.Field
CreatedAt apijson.Field
Description apijson.Field
DiscardedAt apijson.Field
LedgerID apijson.Field
LedgerTransactionTemplate apijson.Field
LiveMode apijson.Field
Metadata apijson.Field
Name apijson.Field
Object apijson.Field
UpdatedAt apijson.Field
Variables apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LedgerEventHandler) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r ledgerEventHandlerJSON) RawJSON() string {
return r.raw
}
// Deprecated: deprecated
type LedgerEventHandlerConditions struct {
// The LHS of the conditional.
Field string `json:"field,required"`
// What the operator between the `field` and `value` is.
Operator string `json:"operator,required"`
// The RHS of the conditional.
Value string `json:"value,required"`
JSON ledgerEventHandlerConditionsJSON `json:"-"`
}
// ledgerEventHandlerConditionsJSON contains the JSON metadata for the struct
// [LedgerEventHandlerConditions]
type ledgerEventHandlerConditionsJSON struct {
Field apijson.Field
Operator apijson.Field
Value apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LedgerEventHandlerConditions) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r ledgerEventHandlerConditionsJSON) RawJSON() string {
return r.raw
}
// Deprecated: deprecated
type LedgerEventHandlerLedgerTransactionTemplate struct {
// An optional description for internal use.
Description string `json:"description,required,nullable"`
// The timestamp (ISO8601 format) at which the ledger transaction happened for
// reporting purposes.
EffectiveAt string `json:"effective_at,required,nullable"`
// An array of ledger entry objects.
LedgerEntries []LedgerEventHandlerLedgerTransactionTemplateLedgerEntry `json:"ledger_entries,required"`
// To post a ledger transaction at creation, use `posted`.
Status string `json:"status,required,nullable"`
JSON ledgerEventHandlerLedgerTransactionTemplateJSON `json:"-"`
}
// ledgerEventHandlerLedgerTransactionTemplateJSON contains the JSON metadata for
// the struct [LedgerEventHandlerLedgerTransactionTemplate]
type ledgerEventHandlerLedgerTransactionTemplateJSON struct {
Description apijson.Field
EffectiveAt apijson.Field
LedgerEntries apijson.Field
Status apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LedgerEventHandlerLedgerTransactionTemplate) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r ledgerEventHandlerLedgerTransactionTemplateJSON) RawJSON() string {
return r.raw
}
// Deprecated: deprecated
type LedgerEventHandlerLedgerTransactionTemplateLedgerEntry struct {
// The LHS of the conditional.
Amount string `json:"amount,required"`
// What the operator between the `field` and `value` is.
Direction string `json:"direction,required"`
// The RHS of the conditional.
LedgerAccountID string `json:"ledger_account_id,required"`
JSON ledgerEventHandlerLedgerTransactionTemplateLedgerEntryJSON `json:"-"`
}
// ledgerEventHandlerLedgerTransactionTemplateLedgerEntryJSON contains the JSON
// metadata for the struct [LedgerEventHandlerLedgerTransactionTemplateLedgerEntry]
type ledgerEventHandlerLedgerTransactionTemplateLedgerEntryJSON struct {
Amount apijson.Field
Direction apijson.Field
LedgerAccountID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LedgerEventHandlerLedgerTransactionTemplateLedgerEntry) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r ledgerEventHandlerLedgerTransactionTemplateLedgerEntryJSON) RawJSON() string {
return r.raw
}
// Deprecated: deprecated
type LedgerEventHandlerVariable struct {
// Deprecated: deprecated
Query LedgerEventHandlerVariableQuery `json:"query,required"`
// The type of object this variable is. Currently, only "ledger_account" is
// supported.
Type string `json:"type,required"`
JSON ledgerEventHandlerVariableJSON `json:"-"`
}
// ledgerEventHandlerVariableJSON contains the JSON metadata for the struct
// [LedgerEventHandlerVariable]
type ledgerEventHandlerVariableJSON struct {
Query apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LedgerEventHandlerVariable) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r ledgerEventHandlerVariableJSON) RawJSON() string {
return r.raw
}
// Deprecated: deprecated
type LedgerEventHandlerVariableQuery struct {
// The LHS of the conditional.
Field string `json:"field,required"`
// What the operator between the `field` and `value` is.
Operator string `json:"operator,required"`
// The RHS of the conditional.
Value string `json:"value,required"`
JSON ledgerEventHandlerVariableQueryJSON `json:"-"`
}
// ledgerEventHandlerVariableQueryJSON contains the JSON metadata for the struct
// [LedgerEventHandlerVariableQuery]
type ledgerEventHandlerVariableQueryJSON struct {
Field apijson.Field
Operator apijson.Field
Value apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *LedgerEventHandlerVariableQuery) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r ledgerEventHandlerVariableQueryJSON) RawJSON() string {
return r.raw
}
// Deprecated: deprecated
type LedgerEventHandlerVariableParam struct {
// Deprecated: deprecated
Query param.Field[LedgerEventHandlerVariableQueryParam] `json:"query,required"`
// The type of object this variable is. Currently, only "ledger_account" is
// supported.
Type param.Field[string] `json:"type,required"`
}
func (r LedgerEventHandlerVariableParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Deprecated: deprecated
type LedgerEventHandlerVariableQueryParam struct {
// The LHS of the conditional.
Field param.Field[string] `json:"field,required"`
// What the operator between the `field` and `value` is.
Operator param.Field[string] `json:"operator,required"`
// The RHS of the conditional.
Value param.Field[string] `json:"value,required"`
}
func (r LedgerEventHandlerVariableQueryParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type LedgerEventHandlerNewParams struct {
LedgerTransactionTemplate param.Field[LedgerEventHandlerNewParamsLedgerTransactionTemplate] `json:"ledger_transaction_template,required"`
// Name of the ledger event handler.
Name param.Field[string] `json:"name,required"`
Conditions param.Field[LedgerEventHandlerNewParamsConditions] `json:"conditions"`
// An optional description.
Description param.Field[string] `json:"description"`
// The id of the ledger that this account belongs to.
LedgerID param.Field[string] `json:"ledger_id" format:"uuid"`
// Additional data represented as key-value pairs. Both the key and value must be
// strings.
Metadata param.Field[map[string]string] `json:"metadata"`
Variables param.Field[map[string]LedgerEventHandlerVariableParam] `json:"variables"`
}
func (r LedgerEventHandlerNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Deprecated: deprecated
type LedgerEventHandlerNewParamsLedgerTransactionTemplate struct {
// An optional description for internal use.
Description param.Field[string] `json:"description,required"`
// The timestamp (ISO8601 format) at which the ledger transaction happened for
// reporting purposes.
EffectiveAt param.Field[string] `json:"effective_at,required"`
// An array of ledger entry objects.
LedgerEntries param.Field[[]LedgerEventHandlerNewParamsLedgerTransactionTemplateLedgerEntry] `json:"ledger_entries,required"`
// To post a ledger transaction at creation, use `posted`.
Status param.Field[string] `json:"status,required"`
}
func (r LedgerEventHandlerNewParamsLedgerTransactionTemplate) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Deprecated: deprecated
type LedgerEventHandlerNewParamsLedgerTransactionTemplateLedgerEntry struct {
// The LHS of the conditional.
Amount param.Field[string] `json:"amount,required"`
// What the operator between the `field` and `value` is.
Direction param.Field[string] `json:"direction,required"`
// The RHS of the conditional.
LedgerAccountID param.Field[string] `json:"ledger_account_id,required"`
}
func (r LedgerEventHandlerNewParamsLedgerTransactionTemplateLedgerEntry) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Deprecated: deprecated
type LedgerEventHandlerNewParamsConditions struct {
// The LHS of the conditional.
Field param.Field[string] `json:"field,required"`
// What the operator between the `field` and `value` is.
Operator param.Field[string] `json:"operator,required"`
// The RHS of the conditional.
Value param.Field[string] `json:"value,required"`
}
func (r LedgerEventHandlerNewParamsConditions) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type LedgerEventHandlerListParams struct {
AfterCursor param.Field[string] `query:"after_cursor"`
// Use `gt` (>), `gte` (>=), `lt` (<), `lte` (<=), or `eq` (=) to filter by the
// posted at timestamp. For example, for all times after Jan 1 2000 12:00 UTC, use
// created_at%5Bgt%5D=2000-01-01T12:00:00Z.
CreatedAt param.Field[map[string]time.Time] `query:"created_at" format:"date-time"`
// For example, if you want to query for records with metadata key `Type` and value
// `Loan`, the query would be `metadata%5BType%5D=Loan`. This encodes the query
// parameters.
Metadata param.Field[map[string]string] `query:"metadata"`
Name param.Field[string] `query:"name"`
PerPage param.Field[int64] `query:"per_page"`
}
// URLQuery serializes [LedgerEventHandlerListParams]'s query parameters as
// `url.Values`.
func (r LedgerEventHandlerListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}