-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.go
522 lines (458 loc) · 20.8 KB
/
export.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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package increase
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"time"
"github.com/Increase/increase-go/internal/apijson"
"github.com/Increase/increase-go/internal/apiquery"
"github.com/Increase/increase-go/internal/param"
"github.com/Increase/increase-go/internal/requestconfig"
"github.com/Increase/increase-go/option"
"github.com/Increase/increase-go/packages/pagination"
)
// ExportService contains methods and other services that help with interacting
// with the increase 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 [NewExportService] method instead.
type ExportService struct {
Options []option.RequestOption
}
// NewExportService 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 NewExportService(opts ...option.RequestOption) (r *ExportService) {
r = &ExportService{}
r.Options = opts
return
}
// Create an Export
func (r *ExportService) New(ctx context.Context, body ExportNewParams, opts ...option.RequestOption) (res *Export, err error) {
opts = append(r.Options[:], opts...)
path := "exports"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Retrieve an Export
func (r *ExportService) Get(ctx context.Context, exportID string, opts ...option.RequestOption) (res *Export, err error) {
opts = append(r.Options[:], opts...)
if exportID == "" {
err = errors.New("missing required export_id parameter")
return
}
path := fmt.Sprintf("exports/%s", exportID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// List Exports
func (r *ExportService) List(ctx context.Context, query ExportListParams, opts ...option.RequestOption) (res *pagination.Page[Export], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "exports"
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 Exports
func (r *ExportService) ListAutoPaging(ctx context.Context, query ExportListParams, opts ...option.RequestOption) *pagination.PageAutoPager[Export] {
return pagination.NewPageAutoPager(r.List(ctx, query, opts...))
}
// Exports are batch summaries of your Increase data. You can make them from the
// API or dashboard. Since they can take a while, they are generated
// asynchronously. We send a webhook when they are ready. For more information,
// please read our
// [Exports documentation](https://increase.com/documentation/exports).
type Export struct {
// The Export identifier.
ID string `json:"id,required"`
// The category of the Export. We may add additional possible values for this enum
// over time; your application should be able to handle that gracefully.
Category ExportCategory `json:"category,required"`
// The time the Export was created.
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// A URL at which the Export's file can be downloaded. This will be present when
// the Export's status transitions to `complete`.
FileDownloadURL string `json:"file_download_url,required,nullable"`
// The File containing the contents of the Export. This will be present when the
// Export's status transitions to `complete`.
FileID string `json:"file_id,required,nullable"`
// The idempotency key you chose for this object. This value is unique across
// Increase and is used to ensure that a request is only processed once. Learn more
// about [idempotency](https://increase.com/documentation/idempotency-keys).
IdempotencyKey string `json:"idempotency_key,required,nullable"`
// The status of the Export.
Status ExportStatus `json:"status,required"`
// A constant representing the object's type. For this resource it will always be
// `export`.
Type ExportType `json:"type,required"`
JSON exportJSON `json:"-"`
}
// exportJSON contains the JSON metadata for the struct [Export]
type exportJSON struct {
ID apijson.Field
Category apijson.Field
CreatedAt apijson.Field
FileDownloadURL apijson.Field
FileID apijson.Field
IdempotencyKey apijson.Field
Status apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Export) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r exportJSON) RawJSON() string {
return r.raw
}
// The category of the Export. We may add additional possible values for this enum
// over time; your application should be able to handle that gracefully.
type ExportCategory string
const (
ExportCategoryAccountStatementOfx ExportCategory = "account_statement_ofx"
ExportCategoryTransactionCsv ExportCategory = "transaction_csv"
ExportCategoryBalanceCsv ExportCategory = "balance_csv"
ExportCategoryBookkeepingAccountBalanceCsv ExportCategory = "bookkeeping_account_balance_csv"
ExportCategoryEntityCsv ExportCategory = "entity_csv"
ExportCategoryVendorCsv ExportCategory = "vendor_csv"
ExportCategoryDashboardTableCsv ExportCategory = "dashboard_table_csv"
)
func (r ExportCategory) IsKnown() bool {
switch r {
case ExportCategoryAccountStatementOfx, ExportCategoryTransactionCsv, ExportCategoryBalanceCsv, ExportCategoryBookkeepingAccountBalanceCsv, ExportCategoryEntityCsv, ExportCategoryVendorCsv, ExportCategoryDashboardTableCsv:
return true
}
return false
}
// The status of the Export.
type ExportStatus string
const (
ExportStatusPending ExportStatus = "pending"
ExportStatusComplete ExportStatus = "complete"
ExportStatusFailed ExportStatus = "failed"
)
func (r ExportStatus) IsKnown() bool {
switch r {
case ExportStatusPending, ExportStatusComplete, ExportStatusFailed:
return true
}
return false
}
// A constant representing the object's type. For this resource it will always be
// `export`.
type ExportType string
const (
ExportTypeExport ExportType = "export"
)
func (r ExportType) IsKnown() bool {
switch r {
case ExportTypeExport:
return true
}
return false
}
type ExportNewParams struct {
// The type of Export to create.
Category param.Field[ExportNewParamsCategory] `json:"category,required"`
// Options for the created export. Required if `category` is equal to
// `account_statement_ofx`.
AccountStatementOfx param.Field[ExportNewParamsAccountStatementOfx] `json:"account_statement_ofx"`
// Options for the created export. Required if `category` is equal to
// `balance_csv`.
BalanceCsv param.Field[ExportNewParamsBalanceCsv] `json:"balance_csv"`
// Options for the created export. Required if `category` is equal to
// `bookkeeping_account_balance_csv`.
BookkeepingAccountBalanceCsv param.Field[ExportNewParamsBookkeepingAccountBalanceCsv] `json:"bookkeeping_account_balance_csv"`
// Options for the created export. Required if `category` is equal to `entity_csv`.
EntityCsv param.Field[ExportNewParamsEntityCsv] `json:"entity_csv"`
// Options for the created export. Required if `category` is equal to
// `transaction_csv`.
TransactionCsv param.Field[ExportNewParamsTransactionCsv] `json:"transaction_csv"`
// Options for the created export. Required if `category` is equal to `vendor_csv`.
VendorCsv param.Field[interface{}] `json:"vendor_csv"`
}
func (r ExportNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// The type of Export to create.
type ExportNewParamsCategory string
const (
ExportNewParamsCategoryAccountStatementOfx ExportNewParamsCategory = "account_statement_ofx"
ExportNewParamsCategoryTransactionCsv ExportNewParamsCategory = "transaction_csv"
ExportNewParamsCategoryBalanceCsv ExportNewParamsCategory = "balance_csv"
ExportNewParamsCategoryBookkeepingAccountBalanceCsv ExportNewParamsCategory = "bookkeeping_account_balance_csv"
ExportNewParamsCategoryEntityCsv ExportNewParamsCategory = "entity_csv"
ExportNewParamsCategoryVendorCsv ExportNewParamsCategory = "vendor_csv"
)
func (r ExportNewParamsCategory) IsKnown() bool {
switch r {
case ExportNewParamsCategoryAccountStatementOfx, ExportNewParamsCategoryTransactionCsv, ExportNewParamsCategoryBalanceCsv, ExportNewParamsCategoryBookkeepingAccountBalanceCsv, ExportNewParamsCategoryEntityCsv, ExportNewParamsCategoryVendorCsv:
return true
}
return false
}
// Options for the created export. Required if `category` is equal to
// `account_statement_ofx`.
type ExportNewParamsAccountStatementOfx struct {
// The Account to create a statement for.
AccountID param.Field[string] `json:"account_id,required"`
// Filter results by time range on the `created_at` attribute.
CreatedAt param.Field[ExportNewParamsAccountStatementOfxCreatedAt] `json:"created_at"`
}
func (r ExportNewParamsAccountStatementOfx) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Filter results by time range on the `created_at` attribute.
type ExportNewParamsAccountStatementOfxCreatedAt struct {
// Return results after this [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)
// timestamp.
After param.Field[time.Time] `json:"after" format:"date-time"`
// Return results before this [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)
// timestamp.
Before param.Field[time.Time] `json:"before" format:"date-time"`
// Return results on or after this
// [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp.
OnOrAfter param.Field[time.Time] `json:"on_or_after" format:"date-time"`
// Return results on or before this
// [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp.
OnOrBefore param.Field[time.Time] `json:"on_or_before" format:"date-time"`
}
func (r ExportNewParamsAccountStatementOfxCreatedAt) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Options for the created export. Required if `category` is equal to
// `balance_csv`.
type ExportNewParamsBalanceCsv struct {
// Filter exported Transactions to the specified Account.
AccountID param.Field[string] `json:"account_id"`
// Filter results by time range on the `created_at` attribute.
CreatedAt param.Field[ExportNewParamsBalanceCsvCreatedAt] `json:"created_at"`
// Filter exported Transactions to the specified Program.
ProgramID param.Field[string] `json:"program_id"`
}
func (r ExportNewParamsBalanceCsv) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Filter results by time range on the `created_at` attribute.
type ExportNewParamsBalanceCsvCreatedAt struct {
// Return results after this [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)
// timestamp.
After param.Field[time.Time] `json:"after" format:"date-time"`
// Return results before this [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)
// timestamp.
Before param.Field[time.Time] `json:"before" format:"date-time"`
// Return results on or after this
// [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp.
OnOrAfter param.Field[time.Time] `json:"on_or_after" format:"date-time"`
// Return results on or before this
// [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp.
OnOrBefore param.Field[time.Time] `json:"on_or_before" format:"date-time"`
}
func (r ExportNewParamsBalanceCsvCreatedAt) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Options for the created export. Required if `category` is equal to
// `bookkeeping_account_balance_csv`.
type ExportNewParamsBookkeepingAccountBalanceCsv struct {
// Filter exported Transactions to the specified Bookkeeping Account.
BookkeepingAccountID param.Field[string] `json:"bookkeeping_account_id"`
// Filter results by time range on the `created_at` attribute.
CreatedAt param.Field[ExportNewParamsBookkeepingAccountBalanceCsvCreatedAt] `json:"created_at"`
}
func (r ExportNewParamsBookkeepingAccountBalanceCsv) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Filter results by time range on the `created_at` attribute.
type ExportNewParamsBookkeepingAccountBalanceCsvCreatedAt struct {
// Return results after this [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)
// timestamp.
After param.Field[time.Time] `json:"after" format:"date-time"`
// Return results before this [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)
// timestamp.
Before param.Field[time.Time] `json:"before" format:"date-time"`
// Return results on or after this
// [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp.
OnOrAfter param.Field[time.Time] `json:"on_or_after" format:"date-time"`
// Return results on or before this
// [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp.
OnOrBefore param.Field[time.Time] `json:"on_or_before" format:"date-time"`
}
func (r ExportNewParamsBookkeepingAccountBalanceCsvCreatedAt) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Options for the created export. Required if `category` is equal to `entity_csv`.
type ExportNewParamsEntityCsv struct {
// Entity statuses to filter by.
Status param.Field[ExportNewParamsEntityCsvStatus] `json:"status"`
}
func (r ExportNewParamsEntityCsv) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Entity statuses to filter by.
type ExportNewParamsEntityCsvStatus struct {
// Entity statuses to filter by. For GET requests, this should be encoded as a
// comma-delimited string, such as `?in=one,two,three`.
In param.Field[[]ExportNewParamsEntityCsvStatusIn] `json:"in,required"`
}
func (r ExportNewParamsEntityCsvStatus) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type ExportNewParamsEntityCsvStatusIn string
const (
ExportNewParamsEntityCsvStatusInActive ExportNewParamsEntityCsvStatusIn = "active"
ExportNewParamsEntityCsvStatusInArchived ExportNewParamsEntityCsvStatusIn = "archived"
ExportNewParamsEntityCsvStatusInDisabled ExportNewParamsEntityCsvStatusIn = "disabled"
)
func (r ExportNewParamsEntityCsvStatusIn) IsKnown() bool {
switch r {
case ExportNewParamsEntityCsvStatusInActive, ExportNewParamsEntityCsvStatusInArchived, ExportNewParamsEntityCsvStatusInDisabled:
return true
}
return false
}
// Options for the created export. Required if `category` is equal to
// `transaction_csv`.
type ExportNewParamsTransactionCsv struct {
// Filter exported Transactions to the specified Account.
AccountID param.Field[string] `json:"account_id"`
// Filter results by time range on the `created_at` attribute.
CreatedAt param.Field[ExportNewParamsTransactionCsvCreatedAt] `json:"created_at"`
// Filter exported Transactions to the specified Program.
ProgramID param.Field[string] `json:"program_id"`
}
func (r ExportNewParamsTransactionCsv) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Filter results by time range on the `created_at` attribute.
type ExportNewParamsTransactionCsvCreatedAt struct {
// Return results after this [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)
// timestamp.
After param.Field[time.Time] `json:"after" format:"date-time"`
// Return results before this [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)
// timestamp.
Before param.Field[time.Time] `json:"before" format:"date-time"`
// Return results on or after this
// [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp.
OnOrAfter param.Field[time.Time] `json:"on_or_after" format:"date-time"`
// Return results on or before this
// [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp.
OnOrBefore param.Field[time.Time] `json:"on_or_before" format:"date-time"`
}
func (r ExportNewParamsTransactionCsvCreatedAt) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type ExportListParams struct {
Category param.Field[ExportListParamsCategory] `query:"category"`
CreatedAt param.Field[ExportListParamsCreatedAt] `query:"created_at"`
// Return the page of entries after this one.
Cursor param.Field[string] `query:"cursor"`
// Filter records to the one with the specified `idempotency_key` you chose for
// that object. This value is unique across Increase and is used to ensure that a
// request is only processed once. Learn more about
// [idempotency](https://increase.com/documentation/idempotency-keys).
IdempotencyKey param.Field[string] `query:"idempotency_key"`
// Limit the size of the list that is returned. The default (and maximum) is 100
// objects.
Limit param.Field[int64] `query:"limit"`
Status param.Field[ExportListParamsStatus] `query:"status"`
}
// URLQuery serializes [ExportListParams]'s query parameters as `url.Values`.
func (r ExportListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatDots,
})
}
type ExportListParamsCategory struct {
// Filter Exports for those with the specified category or categories. For GET
// requests, this should be encoded as a comma-delimited string, such as
// `?in=one,two,three`.
In param.Field[[]ExportListParamsCategoryIn] `query:"in"`
}
// URLQuery serializes [ExportListParamsCategory]'s query parameters as
// `url.Values`.
func (r ExportListParamsCategory) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatDots,
})
}
type ExportListParamsCategoryIn string
const (
ExportListParamsCategoryInAccountStatementOfx ExportListParamsCategoryIn = "account_statement_ofx"
ExportListParamsCategoryInTransactionCsv ExportListParamsCategoryIn = "transaction_csv"
ExportListParamsCategoryInBalanceCsv ExportListParamsCategoryIn = "balance_csv"
ExportListParamsCategoryInBookkeepingAccountBalanceCsv ExportListParamsCategoryIn = "bookkeeping_account_balance_csv"
ExportListParamsCategoryInEntityCsv ExportListParamsCategoryIn = "entity_csv"
ExportListParamsCategoryInVendorCsv ExportListParamsCategoryIn = "vendor_csv"
ExportListParamsCategoryInDashboardTableCsv ExportListParamsCategoryIn = "dashboard_table_csv"
)
func (r ExportListParamsCategoryIn) IsKnown() bool {
switch r {
case ExportListParamsCategoryInAccountStatementOfx, ExportListParamsCategoryInTransactionCsv, ExportListParamsCategoryInBalanceCsv, ExportListParamsCategoryInBookkeepingAccountBalanceCsv, ExportListParamsCategoryInEntityCsv, ExportListParamsCategoryInVendorCsv, ExportListParamsCategoryInDashboardTableCsv:
return true
}
return false
}
type ExportListParamsCreatedAt struct {
// Return results after this [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)
// timestamp.
After param.Field[time.Time] `query:"after" format:"date-time"`
// Return results before this [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)
// timestamp.
Before param.Field[time.Time] `query:"before" format:"date-time"`
// Return results on or after this
// [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp.
OnOrAfter param.Field[time.Time] `query:"on_or_after" format:"date-time"`
// Return results on or before this
// [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) timestamp.
OnOrBefore param.Field[time.Time] `query:"on_or_before" format:"date-time"`
}
// URLQuery serializes [ExportListParamsCreatedAt]'s query parameters as
// `url.Values`.
func (r ExportListParamsCreatedAt) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatDots,
})
}
type ExportListParamsStatus struct {
// Filter Exports for those with the specified status or statuses. For GET
// requests, this should be encoded as a comma-delimited string, such as
// `?in=one,two,three`.
In param.Field[[]ExportListParamsStatusIn] `query:"in"`
}
// URLQuery serializes [ExportListParamsStatus]'s query parameters as `url.Values`.
func (r ExportListParamsStatus) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatDots,
})
}
type ExportListParamsStatusIn string
const (
ExportListParamsStatusInPending ExportListParamsStatusIn = "pending"
ExportListParamsStatusInComplete ExportListParamsStatusIn = "complete"
ExportListParamsStatusInFailed ExportListParamsStatusIn = "failed"
)
func (r ExportListParamsStatusIn) IsKnown() bool {
switch r {
case ExportListParamsStatusInPending, ExportListParamsStatusInComplete, ExportListParamsStatusInFailed:
return true
}
return false
}