-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.go
477 lines (413 loc) · 13.4 KB
/
task.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package nestri
import (
"context"
"errors"
"fmt"
"net/http"
"reflect"
"github.com/nestrilabs/nestri-go-sdk/internal/apijson"
"github.com/nestrilabs/nestri-go-sdk/internal/requestconfig"
"github.com/nestrilabs/nestri-go-sdk/option"
"github.com/nestrilabs/nestri-go-sdk/shared"
"github.com/tidwall/gjson"
)
// TaskService contains methods and other services that help with interacting with
// the nestri 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 [NewTaskService] method instead.
type TaskService struct {
Options []option.RequestOption
}
// NewTaskService 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 NewTaskService(opts ...option.RequestOption) (r *TaskService) {
r = &TaskService{}
r.Options = opts
return
}
// Create a task
func (r *TaskService) New(ctx context.Context, opts ...option.RequestOption) (res *TaskNewResponse, err error) {
opts = append(r.Options[:], opts...)
path := "tasks"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return
}
// Get a task by its id
func (r *TaskService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *TaskGetResponse, err error) {
opts = append(r.Options[:], opts...)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("tasks/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Updates the metadata about a task by querying remote task
func (r *TaskService) Update(ctx context.Context, id string, opts ...option.RequestOption) (res *TaskUpdateResponse, err error) {
opts = append(r.Options[:], opts...)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("tasks/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, nil, &res, opts...)
return
}
// List all tasks by this user
func (r *TaskService) List(ctx context.Context, opts ...option.RequestOption) (res *TaskListResponse, err error) {
opts = append(r.Options[:], opts...)
path := "tasks"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Stop a running task by its id
func (r *TaskService) Delete(ctx context.Context, id string, opts ...option.RequestOption) (res *TaskDeleteResponse, err error) {
opts = append(r.Options[:], opts...)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("tasks/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return
}
// Get a task by its id
func (r *TaskService) Session(ctx context.Context, id string, opts ...option.RequestOption) (res *TaskSessionResponse, err error) {
opts = append(r.Options[:], opts...)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("tasks/%s/session", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
type TaskNewResponse struct {
// The id of the task created
Data string `json:"data,required"`
JSON taskNewResponseJSON `json:"-"`
}
// taskNewResponseJSON contains the JSON metadata for the struct [TaskNewResponse]
type taskNewResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TaskNewResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r taskNewResponseJSON) RawJSON() string {
return r.raw
}
type TaskGetResponse struct {
// Subscription to a Nestri product.
Data TaskGetResponseData `json:"data,required"`
JSON taskGetResponseJSON `json:"-"`
}
// taskGetResponseJSON contains the JSON metadata for the struct [TaskGetResponse]
type taskGetResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TaskGetResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r taskGetResponseJSON) RawJSON() string {
return r.raw
}
// Subscription to a Nestri product.
type TaskGetResponseData struct {
// Unique object identifier. The format and length of IDs may change over time.
ID string `json:"id,required"`
// The polar.sh checkout id
CheckoutID string `json:"checkoutID,required"`
// Cancelled date for the subscription.
CanceledAt TaskGetResponseDataCanceledAtUnion `json:"canceledAt"`
JSON taskGetResponseDataJSON `json:"-"`
}
// taskGetResponseDataJSON contains the JSON metadata for the struct
// [TaskGetResponseData]
type taskGetResponseDataJSON struct {
ID apijson.Field
CheckoutID apijson.Field
CanceledAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TaskGetResponseData) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r taskGetResponseDataJSON) RawJSON() string {
return r.raw
}
// Cancelled date for the subscription.
//
// Union satisfied by [shared.UnionString] or [shared.UnionFloat].
type TaskGetResponseDataCanceledAtUnion interface {
ImplementsTaskGetResponseDataCanceledAtUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*TaskGetResponseDataCanceledAtUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
)
}
type TaskUpdateResponse struct {
// Subscription to a Nestri product.
Data TaskUpdateResponseData `json:"data,required"`
JSON taskUpdateResponseJSON `json:"-"`
}
// taskUpdateResponseJSON contains the JSON metadata for the struct
// [TaskUpdateResponse]
type taskUpdateResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TaskUpdateResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r taskUpdateResponseJSON) RawJSON() string {
return r.raw
}
// Subscription to a Nestri product.
type TaskUpdateResponseData struct {
// Unique object identifier. The format and length of IDs may change over time.
ID string `json:"id,required"`
// The polar.sh checkout id
CheckoutID string `json:"checkoutID,required"`
// Cancelled date for the subscription.
CanceledAt TaskUpdateResponseDataCanceledAtUnion `json:"canceledAt"`
JSON taskUpdateResponseDataJSON `json:"-"`
}
// taskUpdateResponseDataJSON contains the JSON metadata for the struct
// [TaskUpdateResponseData]
type taskUpdateResponseDataJSON struct {
ID apijson.Field
CheckoutID apijson.Field
CanceledAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TaskUpdateResponseData) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r taskUpdateResponseDataJSON) RawJSON() string {
return r.raw
}
// Cancelled date for the subscription.
//
// Union satisfied by [shared.UnionString] or [shared.UnionFloat].
type TaskUpdateResponseDataCanceledAtUnion interface {
ImplementsTaskUpdateResponseDataCanceledAtUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*TaskUpdateResponseDataCanceledAtUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
)
}
type TaskListResponse struct {
// Subscription to a Nestri product.
Data TaskListResponseData `json:"data,required"`
JSON taskListResponseJSON `json:"-"`
}
// taskListResponseJSON contains the JSON metadata for the struct
// [TaskListResponse]
type taskListResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TaskListResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r taskListResponseJSON) RawJSON() string {
return r.raw
}
// Subscription to a Nestri product.
type TaskListResponseData struct {
// Unique object identifier. The format and length of IDs may change over time.
ID string `json:"id,required"`
// The polar.sh checkout id
CheckoutID string `json:"checkoutID,required"`
// Cancelled date for the subscription.
CanceledAt TaskListResponseDataCanceledAtUnion `json:"canceledAt"`
JSON taskListResponseDataJSON `json:"-"`
}
// taskListResponseDataJSON contains the JSON metadata for the struct
// [TaskListResponseData]
type taskListResponseDataJSON struct {
ID apijson.Field
CheckoutID apijson.Field
CanceledAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TaskListResponseData) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r taskListResponseDataJSON) RawJSON() string {
return r.raw
}
// Cancelled date for the subscription.
//
// Union satisfied by [shared.UnionString] or [shared.UnionFloat].
type TaskListResponseDataCanceledAtUnion interface {
ImplementsTaskListResponseDataCanceledAtUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*TaskListResponseDataCanceledAtUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
)
}
type TaskDeleteResponse struct {
Data TaskDeleteResponseData `json:"data,required"`
JSON taskDeleteResponseJSON `json:"-"`
}
// taskDeleteResponseJSON contains the JSON metadata for the struct
// [TaskDeleteResponse]
type taskDeleteResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TaskDeleteResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r taskDeleteResponseJSON) RawJSON() string {
return r.raw
}
type TaskDeleteResponseData string
const (
TaskDeleteResponseDataOk TaskDeleteResponseData = "ok"
)
func (r TaskDeleteResponseData) IsKnown() bool {
switch r {
case TaskDeleteResponseDataOk:
return true
}
return false
}
type TaskSessionResponse struct {
// Represents a single game play session, tracking its lifetime and accessibility
// settings.
Data TaskSessionResponseData `json:"data,required"`
JSON taskSessionResponseJSON `json:"-"`
}
// taskSessionResponseJSON contains the JSON metadata for the struct
// [TaskSessionResponse]
type taskSessionResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TaskSessionResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r taskSessionResponseJSON) RawJSON() string {
return r.raw
}
// Represents a single game play session, tracking its lifetime and accessibility
// settings.
type TaskSessionResponseData struct {
// Unique object identifier. The format and length of IDs may change over time.
ID string `json:"id,required"`
// If true, the session is publicly viewable by all users. If false, only
// authorized users can access it
Public bool `json:"public,required"`
// The timestamp indicating when this session started.
StartedAt TaskSessionResponseDataStartedAtUnion `json:"startedAt,required"`
// The timestamp indicating when this session was completed or terminated. Null if
// session is still active.
EndedAt TaskSessionResponseDataEndedAtUnion `json:"endedAt"`
JSON taskSessionResponseDataJSON `json:"-"`
}
// taskSessionResponseDataJSON contains the JSON metadata for the struct
// [TaskSessionResponseData]
type taskSessionResponseDataJSON struct {
ID apijson.Field
Public apijson.Field
StartedAt apijson.Field
EndedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TaskSessionResponseData) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r taskSessionResponseDataJSON) RawJSON() string {
return r.raw
}
// The timestamp indicating when this session started.
//
// Union satisfied by [shared.UnionString] or [shared.UnionFloat].
type TaskSessionResponseDataStartedAtUnion interface {
ImplementsTaskSessionResponseDataStartedAtUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*TaskSessionResponseDataStartedAtUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
)
}
// The timestamp indicating when this session was completed or terminated. Null if
// session is still active.
//
// Union satisfied by [shared.UnionString] or [shared.UnionFloat].
type TaskSessionResponseDataEndedAtUnion interface {
ImplementsTaskSessionResponseDataEndedAtUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*TaskSessionResponseDataEndedAtUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
)
}