-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.go
462 lines (408 loc) · 13.5 KB
/
user.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
// 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"
)
// UserService 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 [NewUserService] method instead.
type UserService struct {
Options []option.RequestOption
}
// NewUserService 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 NewUserService(opts ...option.RequestOption) (r *UserService) {
r = &UserService{}
r.Options = opts
return
}
// Gets a user's profile by their id
func (r *UserService) Get(ctx context.Context, id string, opts ...option.RequestOption) (res *UserGetResponse, err error) {
opts = append(r.Options[:], opts...)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("users/%s", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Returns all user profiles
func (r *UserService) List(ctx context.Context, opts ...option.RequestOption) (res *UserListResponse, err error) {
opts = append(r.Options[:], opts...)
path := "users"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Get a user's gaming session details by their id
func (r *UserService) Session(ctx context.Context, id string, opts ...option.RequestOption) (res *UserSessionResponse, err error) {
opts = append(r.Options[:], opts...)
if id == "" {
err = errors.New("missing required id parameter")
return
}
path := fmt.Sprintf("users/%s/session", id)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
type UserGetResponse struct {
// Represents a profile of a user on Nestri
Data UserGetResponseData `json:"data,required"`
JSON userGetResponseJSON `json:"-"`
}
// userGetResponseJSON contains the JSON metadata for the struct [UserGetResponse]
type userGetResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *UserGetResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r userGetResponseJSON) RawJSON() string {
return r.raw
}
// Represents a profile of a user on Nestri
type UserGetResponseData struct {
// Unique object identifier. The format and length of IDs may change over time.
ID string `json:"id,required"`
// The time when this profile was first created
CreatedAt UserGetResponseDataCreatedAtUnion `json:"createdAt,required"`
// The number discriminator for each username
Discriminator UserGetResponseDataDiscriminatorUnion `json:"discriminator,required"`
// Whether the user is active, idle or offline
Status UserGetResponseDataStatus `json:"status,required"`
// The time when this profile was last edited
UpdatedAt UserGetResponseDataUpdatedAtUnion `json:"updatedAt,required"`
// The user's unique username
Username string `json:"username,required"`
// The url to the profile picture.
AvatarURL string `json:"avatarUrl"`
JSON userGetResponseDataJSON `json:"-"`
}
// userGetResponseDataJSON contains the JSON metadata for the struct
// [UserGetResponseData]
type userGetResponseDataJSON struct {
ID apijson.Field
CreatedAt apijson.Field
Discriminator apijson.Field
Status apijson.Field
UpdatedAt apijson.Field
Username apijson.Field
AvatarURL apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *UserGetResponseData) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r userGetResponseDataJSON) RawJSON() string {
return r.raw
}
// The time when this profile was first created
//
// Union satisfied by [shared.UnionString] or [shared.UnionFloat].
type UserGetResponseDataCreatedAtUnion interface {
ImplementsUserGetResponseDataCreatedAtUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*UserGetResponseDataCreatedAtUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
)
}
// The number discriminator for each username
//
// Union satisfied by [shared.UnionString] or [shared.UnionFloat].
type UserGetResponseDataDiscriminatorUnion interface {
ImplementsUserGetResponseDataDiscriminatorUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*UserGetResponseDataDiscriminatorUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
)
}
// Whether the user is active, idle or offline
type UserGetResponseDataStatus string
const (
UserGetResponseDataStatusActive UserGetResponseDataStatus = "active"
UserGetResponseDataStatusIdle UserGetResponseDataStatus = "idle"
UserGetResponseDataStatusOffline UserGetResponseDataStatus = "offline"
)
func (r UserGetResponseDataStatus) IsKnown() bool {
switch r {
case UserGetResponseDataStatusActive, UserGetResponseDataStatusIdle, UserGetResponseDataStatusOffline:
return true
}
return false
}
// The time when this profile was last edited
//
// Union satisfied by [shared.UnionString] or [shared.UnionFloat].
type UserGetResponseDataUpdatedAtUnion interface {
ImplementsUserGetResponseDataUpdatedAtUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*UserGetResponseDataUpdatedAtUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
)
}
type UserListResponse struct {
// Represents a profile of a user on Nestri
Data UserListResponseData `json:"data,required"`
JSON userListResponseJSON `json:"-"`
}
// userListResponseJSON contains the JSON metadata for the struct
// [UserListResponse]
type userListResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *UserListResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r userListResponseJSON) RawJSON() string {
return r.raw
}
// Represents a profile of a user on Nestri
type UserListResponseData struct {
// Unique object identifier. The format and length of IDs may change over time.
ID string `json:"id,required"`
// The time when this profile was first created
CreatedAt UserListResponseDataCreatedAtUnion `json:"createdAt,required"`
// The number discriminator for each username
Discriminator UserListResponseDataDiscriminatorUnion `json:"discriminator,required"`
// Whether the user is active, idle or offline
Status UserListResponseDataStatus `json:"status,required"`
// The time when this profile was last edited
UpdatedAt UserListResponseDataUpdatedAtUnion `json:"updatedAt,required"`
// The user's unique username
Username string `json:"username,required"`
// The url to the profile picture.
AvatarURL string `json:"avatarUrl"`
JSON userListResponseDataJSON `json:"-"`
}
// userListResponseDataJSON contains the JSON metadata for the struct
// [UserListResponseData]
type userListResponseDataJSON struct {
ID apijson.Field
CreatedAt apijson.Field
Discriminator apijson.Field
Status apijson.Field
UpdatedAt apijson.Field
Username apijson.Field
AvatarURL apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *UserListResponseData) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r userListResponseDataJSON) RawJSON() string {
return r.raw
}
// The time when this profile was first created
//
// Union satisfied by [shared.UnionString] or [shared.UnionFloat].
type UserListResponseDataCreatedAtUnion interface {
ImplementsUserListResponseDataCreatedAtUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*UserListResponseDataCreatedAtUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
)
}
// The number discriminator for each username
//
// Union satisfied by [shared.UnionString] or [shared.UnionFloat].
type UserListResponseDataDiscriminatorUnion interface {
ImplementsUserListResponseDataDiscriminatorUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*UserListResponseDataDiscriminatorUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
)
}
// Whether the user is active, idle or offline
type UserListResponseDataStatus string
const (
UserListResponseDataStatusActive UserListResponseDataStatus = "active"
UserListResponseDataStatusIdle UserListResponseDataStatus = "idle"
UserListResponseDataStatusOffline UserListResponseDataStatus = "offline"
)
func (r UserListResponseDataStatus) IsKnown() bool {
switch r {
case UserListResponseDataStatusActive, UserListResponseDataStatusIdle, UserListResponseDataStatusOffline:
return true
}
return false
}
// The time when this profile was last edited
//
// Union satisfied by [shared.UnionString] or [shared.UnionFloat].
type UserListResponseDataUpdatedAtUnion interface {
ImplementsUserListResponseDataUpdatedAtUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*UserListResponseDataUpdatedAtUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
)
}
type UserSessionResponse struct {
// Represents a single game play session, tracking its lifetime and accessibility
// settings.
Data UserSessionResponseData `json:"data,required"`
JSON userSessionResponseJSON `json:"-"`
}
// userSessionResponseJSON contains the JSON metadata for the struct
// [UserSessionResponse]
type userSessionResponseJSON struct {
Data apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *UserSessionResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r userSessionResponseJSON) RawJSON() string {
return r.raw
}
// Represents a single game play session, tracking its lifetime and accessibility
// settings.
type UserSessionResponseData 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 UserSessionResponseDataStartedAtUnion `json:"startedAt,required"`
// The timestamp indicating when this session was completed or terminated. Null if
// session is still active.
EndedAt UserSessionResponseDataEndedAtUnion `json:"endedAt"`
JSON userSessionResponseDataJSON `json:"-"`
}
// userSessionResponseDataJSON contains the JSON metadata for the struct
// [UserSessionResponseData]
type userSessionResponseDataJSON struct {
ID apijson.Field
Public apijson.Field
StartedAt apijson.Field
EndedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *UserSessionResponseData) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r userSessionResponseDataJSON) RawJSON() string {
return r.raw
}
// The timestamp indicating when this session started.
//
// Union satisfied by [shared.UnionString] or [shared.UnionFloat].
type UserSessionResponseDataStartedAtUnion interface {
ImplementsUserSessionResponseDataStartedAtUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*UserSessionResponseDataStartedAtUnion)(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 UserSessionResponseDataEndedAtUnion interface {
ImplementsUserSessionResponseDataEndedAtUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*UserSessionResponseDataEndedAtUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
)
}