-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.go
353 lines (323 loc) · 15 KB
/
file.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
// File generated from our OpenAPI spec by Stainless.
package acme
import (
"bytes"
"context"
"fmt"
"io"
"mime/multipart"
"net/http"
"net/url"
"time"
"github.com/acme/acme-go/internal/apiform"
"github.com/acme/acme-go/internal/apijson"
"github.com/acme/acme-go/internal/apiquery"
"github.com/acme/acme-go/internal/param"
"github.com/acme/acme-go/internal/requestconfig"
"github.com/acme/acme-go/internal/shared"
"github.com/acme/acme-go/option"
)
// FileService contains methods and other services that help with interacting with
// the acme 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 [NewFileService] method instead.
type FileService struct {
Options []option.RequestOption
}
// NewFileService 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 NewFileService(opts ...option.RequestOption) (r *FileService) {
r = &FileService{}
r.Options = opts
return
}
// To upload a file to Acme, you'll need to send a request of Content-Type
// `multipart/form-data`. The request should contain the file you would like to
// upload, as well as the parameters for creating a file.
func (r *FileService) New(ctx context.Context, body FileNewParams, opts ...option.RequestOption) (res *File, err error) {
opts = append(r.Options[:], opts...)
path := "files"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Retrieve a File
func (r *FileService) Get(ctx context.Context, fileID string, opts ...option.RequestOption) (res *File, err error) {
opts = append(r.Options[:], opts...)
path := fmt.Sprintf("files/%s", fileID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// List Files
func (r *FileService) List(ctx context.Context, query FileListParams, opts ...option.RequestOption) (res *shared.Page[File], err error) {
var raw *http.Response
opts = append(r.Options, opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "files"
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 Files
func (r *FileService) ListAutoPaging(ctx context.Context, query FileListParams, opts ...option.RequestOption) *shared.PageAutoPager[File] {
return shared.NewPageAutoPager(r.List(ctx, query, opts...))
}
// Files are objects that represent a file hosted on Acme's servers. The file
// may have been uploaded by you (for example, when uploading a check image) or it
// may have been created by Acme (for example, an autogenerated statement PDF).
type File struct {
// The File's identifier.
ID string `json:"id,required"`
// The time the File was created.
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// A description of the File.
Description string `json:"description,required,nullable"`
// Whether the File was generated by Acme or by you and sent to Acme.
Direction FileDirection `json:"direction,required"`
// A URL from where the File can be downloaded at this point in time. The location
// of this URL may change over time.
DownloadURL string `json:"download_url,required,nullable"`
// The filename that was provided upon upload or generated by Acme.
Filename string `json:"filename,required,nullable"`
// The MIME type of the file.
MimeType string `json:"mime_type,required"`
// What the File will be used for. We may add additional possible values for this
// enum over time; your application should be able to handle such additions
// gracefully.
Purpose FilePurpose `json:"purpose,required"`
// A constant representing the object's type. For this resource it will always be
// `file`.
Type FileType `json:"type,required"`
JSON fileJSON `json:"-"`
}
// fileJSON contains the JSON metadata for the struct [File]
type fileJSON struct {
ID apijson.Field
CreatedAt apijson.Field
Description apijson.Field
Direction apijson.Field
DownloadURL apijson.Field
Filename apijson.Field
MimeType apijson.Field
Purpose apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *File) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
// Whether the File was generated by Acme or by you and sent to Acme.
type FileDirection string
const (
// This File was sent by you to Acme.
FileDirectionToAcme FileDirection = "to_acme"
// This File was generated by Acme.
FileDirectionFromAcme FileDirection = "from_acme"
)
// What the File will be used for. We may add additional possible values for this
// enum over time; your application should be able to handle such additions
// gracefully.
type FilePurpose string
const (
// An image of the front of a check, used for check deposits.
FilePurposeCheckImageFront FilePurpose = "check_image_front"
// An image of the back of a check, used for check deposits.
FilePurposeCheckImageBack FilePurpose = "check_image_back"
// An image of a check that was mailed to a recipient.
FilePurposeMailedCheckImage FilePurpose = "mailed_check_image"
// IRS Form 1099-INT.
FilePurposeForm1099Int FilePurpose = "form_1099_int"
// IRS Form SS-4.
FilePurposeFormSS4 FilePurpose = "form_ss_4"
// An image of a government-issued ID.
FilePurposeIdentityDocument FilePurpose = "identity_document"
// A statement generated by Acme.
FilePurposeAcmeStatement FilePurpose = "acme_statement"
// A file purpose not covered by any of the other cases.
FilePurposeOther FilePurpose = "other"
// A legal document forming a trust.
FilePurposeTrustFormationDocument FilePurpose = "trust_formation_document"
// A card image to be rendered inside digital wallet apps. This must be a 1536x969
// pixel PNG.
FilePurposeDigitalWalletArtwork FilePurpose = "digital_wallet_artwork"
// An icon for you app to be rendered inside digital wallet apps. This must be a
// 100x100 pixel PNG.
FilePurposeDigitalWalletAppIcon FilePurpose = "digital_wallet_app_icon"
// A card image to be printed on the front of a physical card. This must be a
// 2100x1340 pixel PNG with no other color but black.
FilePurposePhysicalCardFront FilePurpose = "physical_card_front"
// The image to be printed on the back of a physical card.
FilePurposePhysicalCardBack FilePurpose = "physical_card_back"
// An image representing the entirety of the carrier used for a physical card. This
// must be a 2550x3300 pixel PNG with no other color but black.
FilePurposePhysicalCardCarrier FilePurpose = "physical_card_carrier"
// A document requested by Acme.
FilePurposeDocumentRequest FilePurpose = "document_request"
// A supplemental document associated an an Entity.
FilePurposeEntitySupplementalDocument FilePurpose = "entity_supplemental_document"
// The results of an Export you requested via the dashboard or API.
FilePurposeExport FilePurpose = "export"
)
// A constant representing the object's type. For this resource it will always be
// `file`.
type FileType string
const (
FileTypeFile FileType = "file"
)
type FileNewParams struct {
// The file contents. This should follow the specifications of
// [RFC 7578](https://datatracker.ietf.org/doc/html/rfc7578) which defines file
// transfers for the multipart/form-data protocol.
File param.Field[io.Reader] `json:"file,required" format:"binary"`
// What the File will be used for in Acme's systems.
Purpose param.Field[FileNewParamsPurpose] `json:"purpose,required"`
// The description you choose to give the File.
Description param.Field[string] `json:"description"`
}
func (r FileNewParams) MarshalMultipart() (data []byte, contentType string, err error) {
buf := bytes.NewBuffer(nil)
writer := multipart.NewWriter(buf)
err = apiform.MarshalRoot(r, writer)
if err != nil {
writer.Close()
return nil, "", err
}
err = writer.Close()
if err != nil {
return nil, "", err
}
return buf.Bytes(), writer.FormDataContentType(), nil
}
// What the File will be used for in Acme's systems.
type FileNewParamsPurpose string
const (
// An image of the front of a check, used for check deposits.
FileNewParamsPurposeCheckImageFront FileNewParamsPurpose = "check_image_front"
// An image of the back of a check, used for check deposits.
FileNewParamsPurposeCheckImageBack FileNewParamsPurpose = "check_image_back"
// An image of a check that was mailed to a recipient.
FileNewParamsPurposeMailedCheckImage FileNewParamsPurpose = "mailed_check_image"
// IRS Form SS-4.
FileNewParamsPurposeFormSS4 FileNewParamsPurpose = "form_ss_4"
// An image of a government-issued ID.
FileNewParamsPurposeIdentityDocument FileNewParamsPurpose = "identity_document"
// A file purpose not covered by any of the other cases.
FileNewParamsPurposeOther FileNewParamsPurpose = "other"
// A legal document forming a trust.
FileNewParamsPurposeTrustFormationDocument FileNewParamsPurpose = "trust_formation_document"
// A card image to be rendered inside digital wallet apps. This must be a 1536x969
// pixel PNG.
FileNewParamsPurposeDigitalWalletArtwork FileNewParamsPurpose = "digital_wallet_artwork"
// An icon for you app to be rendered inside digital wallet apps. This must be a
// 100x100 pixel PNG.
FileNewParamsPurposeDigitalWalletAppIcon FileNewParamsPurpose = "digital_wallet_app_icon"
// A card image to be printed on the front of a physical card. This must be a
// 2100x1340 pixel PNG with no other color but black.
FileNewParamsPurposePhysicalCardFront FileNewParamsPurpose = "physical_card_front"
// An image representing the entirety of the carrier used for a physical card. This
// must be a 2550x3300 pixel PNG with no other color but black.
FileNewParamsPurposePhysicalCardCarrier FileNewParamsPurpose = "physical_card_carrier"
// A document requested by Acme.
FileNewParamsPurposeDocumentRequest FileNewParamsPurpose = "document_request"
// A supplemental document associated an an Entity.
FileNewParamsPurposeEntitySupplementalDocument FileNewParamsPurpose = "entity_supplemental_document"
)
type FileListParams struct {
CreatedAt param.Field[FileListParamsCreatedAt] `query:"created_at"`
// Return the page of entries after this one.
Cursor param.Field[string] `query:"cursor"`
// Limit the size of the list that is returned. The default (and maximum) is 100
// objects.
Limit param.Field[int64] `query:"limit"`
Purpose param.Field[FileListParamsPurpose] `query:"purpose"`
}
// URLQuery serializes [FileListParams]'s query parameters as `url.Values`.
func (r FileListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatDots,
})
}
type FileListParamsCreatedAt 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 [FileListParamsCreatedAt]'s query parameters as
// `url.Values`.
func (r FileListParamsCreatedAt) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatDots,
})
}
type FileListParamsPurpose struct {
// Filter Files for those with the specified purpose or purposes. For GET requests,
// this should be encoded as a comma-delimited string, such as `?in=one,two,three`.
In param.Field[[]FileListParamsPurposeIn] `query:"in"`
}
// URLQuery serializes [FileListParamsPurpose]'s query parameters as `url.Values`.
func (r FileListParamsPurpose) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatDots,
})
}
type FileListParamsPurposeIn string
const (
// An image of the front of a check, used for check deposits.
FileListParamsPurposeInCheckImageFront FileListParamsPurposeIn = "check_image_front"
// An image of the back of a check, used for check deposits.
FileListParamsPurposeInCheckImageBack FileListParamsPurposeIn = "check_image_back"
// An image of a check that was mailed to a recipient.
FileListParamsPurposeInMailedCheckImage FileListParamsPurposeIn = "mailed_check_image"
// IRS Form 1099-INT.
FileListParamsPurposeInForm1099Int FileListParamsPurposeIn = "form_1099_int"
// IRS Form SS-4.
FileListParamsPurposeInFormSS4 FileListParamsPurposeIn = "form_ss_4"
// An image of a government-issued ID.
FileListParamsPurposeInIdentityDocument FileListParamsPurposeIn = "identity_document"
// A statement generated by Acme.
FileListParamsPurposeInAcmeStatement FileListParamsPurposeIn = "acme_statement"
// A file purpose not covered by any of the other cases.
FileListParamsPurposeInOther FileListParamsPurposeIn = "other"
// A legal document forming a trust.
FileListParamsPurposeInTrustFormationDocument FileListParamsPurposeIn = "trust_formation_document"
// A card image to be rendered inside digital wallet apps. This must be a 1536x969
// pixel PNG.
FileListParamsPurposeInDigitalWalletArtwork FileListParamsPurposeIn = "digital_wallet_artwork"
// An icon for you app to be rendered inside digital wallet apps. This must be a
// 100x100 pixel PNG.
FileListParamsPurposeInDigitalWalletAppIcon FileListParamsPurposeIn = "digital_wallet_app_icon"
// A card image to be printed on the front of a physical card. This must be a
// 2100x1340 pixel PNG with no other color but black.
FileListParamsPurposeInPhysicalCardFront FileListParamsPurposeIn = "physical_card_front"
// The image to be printed on the back of a physical card.
FileListParamsPurposeInPhysicalCardBack FileListParamsPurposeIn = "physical_card_back"
// An image representing the entirety of the carrier used for a physical card. This
// must be a 2550x3300 pixel PNG with no other color but black.
FileListParamsPurposeInPhysicalCardCarrier FileListParamsPurposeIn = "physical_card_carrier"
// A document requested by Acme.
FileListParamsPurposeInDocumentRequest FileListParamsPurposeIn = "document_request"
// A supplemental document associated an an Entity.
FileListParamsPurposeInEntitySupplementalDocument FileListParamsPurposeIn = "entity_supplemental_document"
// The results of an Export you requested via the dashboard or API.
FileListParamsPurposeInExport FileListParamsPurposeIn = "export"
)