-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers.go
440 lines (387 loc) · 10.4 KB
/
users.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
// This file was auto-generated by Fern from our API Definition.
package api
import (
json "encoding/json"
fmt "fmt"
internal "github.com/trophyso/trophy-go/internal"
time "time"
)
type UsersStreakRequest struct {
// The number of past streak periods to include in the streakHistory field of the response.
HistoryPeriods *int `json:"-" url:"historyPeriods,omitempty"`
}
type MetricResponse struct {
// The unique ID of the metric.
Id string `json:"id" url:"id"`
// The unique key of the metric.
Key string `json:"key" url:"key"`
// The name of the metric.
Name string `json:"name" url:"name"`
// The emoji to represent the metric.
Emoji string `json:"emoji" url:"emoji"`
// The status of the metric.
Status MetricStatus `json:"status" url:"status"`
// The user's current total for the metric.
Current float64 `json:"current" url:"current"`
// A list of the metric's achievements and the user's progress towards each.
Achievements []*MultiStageAchievementResponse `json:"achievements,omitempty" url:"achievements,omitempty"`
extraProperties map[string]interface{}
rawJSON json.RawMessage
}
func (m *MetricResponse) GetId() string {
if m == nil {
return ""
}
return m.Id
}
func (m *MetricResponse) GetKey() string {
if m == nil {
return ""
}
return m.Key
}
func (m *MetricResponse) GetName() string {
if m == nil {
return ""
}
return m.Name
}
func (m *MetricResponse) GetEmoji() string {
if m == nil {
return ""
}
return m.Emoji
}
func (m *MetricResponse) GetStatus() MetricStatus {
if m == nil {
return ""
}
return m.Status
}
func (m *MetricResponse) GetCurrent() float64 {
if m == nil {
return 0
}
return m.Current
}
func (m *MetricResponse) GetAchievements() []*MultiStageAchievementResponse {
if m == nil {
return nil
}
return m.Achievements
}
func (m *MetricResponse) GetExtraProperties() map[string]interface{} {
return m.extraProperties
}
func (m *MetricResponse) UnmarshalJSON(data []byte) error {
type unmarshaler MetricResponse
var value unmarshaler
if err := json.Unmarshal(data, &value); err != nil {
return err
}
*m = MetricResponse(value)
extraProperties, err := internal.ExtractExtraProperties(data, *m)
if err != nil {
return err
}
m.extraProperties = extraProperties
m.rawJSON = json.RawMessage(data)
return nil
}
func (m *MetricResponse) String() string {
if len(m.rawJSON) > 0 {
if value, err := internal.StringifyJSON(m.rawJSON); err == nil {
return value
}
}
if value, err := internal.StringifyJSON(m); err == nil {
return value
}
return fmt.Sprintf("%#v", m)
}
// The status of the achievement.
type MetricStatus string
const (
MetricStatusArchived MetricStatus = "archived"
MetricStatusActive MetricStatus = "active"
)
func NewMetricStatusFromString(s string) (MetricStatus, error) {
switch s {
case "archived":
return MetricStatusArchived, nil
case "active":
return MetricStatusActive, nil
}
var t MetricStatus
return "", fmt.Errorf("%s is not a valid %T", s, t)
}
func (m MetricStatus) Ptr() *MetricStatus {
return &m
}
// An object representing the user's streak.
type StreakResponse struct {
// The length of the user's current streak.
Length int `json:"length" url:"length"`
// The frequency of the streak.
Frequency StreakFrequency `json:"frequency" url:"frequency"`
// The date the streak started.
Started *string `json:"started,omitempty" url:"started,omitempty"`
// The start date of the current streak period.
PeriodStart *string `json:"periodStart,omitempty" url:"periodStart,omitempty"`
// The end date of the current streak period.
PeriodEnd *string `json:"periodEnd,omitempty" url:"periodEnd,omitempty"`
// The date the streak will expire if the user does not increment a metric.
Expires *string `json:"expires,omitempty" url:"expires,omitempty"`
// A list of the user's past streak periods up through the current period. Each period includes the start and end dates and the length of the streak.
StreakHistory []*StreakResponseStreakHistoryItem `json:"streakHistory,omitempty" url:"streakHistory,omitempty"`
extraProperties map[string]interface{}
rawJSON json.RawMessage
}
func (s *StreakResponse) GetLength() int {
if s == nil {
return 0
}
return s.Length
}
func (s *StreakResponse) GetFrequency() StreakFrequency {
if s == nil {
return ""
}
return s.Frequency
}
func (s *StreakResponse) GetStarted() *string {
if s == nil {
return nil
}
return s.Started
}
func (s *StreakResponse) GetPeriodStart() *string {
if s == nil {
return nil
}
return s.PeriodStart
}
func (s *StreakResponse) GetPeriodEnd() *string {
if s == nil {
return nil
}
return s.PeriodEnd
}
func (s *StreakResponse) GetExpires() *string {
if s == nil {
return nil
}
return s.Expires
}
func (s *StreakResponse) GetStreakHistory() []*StreakResponseStreakHistoryItem {
if s == nil {
return nil
}
return s.StreakHistory
}
func (s *StreakResponse) GetExtraProperties() map[string]interface{} {
return s.extraProperties
}
func (s *StreakResponse) UnmarshalJSON(data []byte) error {
type unmarshaler StreakResponse
var value unmarshaler
if err := json.Unmarshal(data, &value); err != nil {
return err
}
*s = StreakResponse(value)
extraProperties, err := internal.ExtractExtraProperties(data, *s)
if err != nil {
return err
}
s.extraProperties = extraProperties
s.rawJSON = json.RawMessage(data)
return nil
}
func (s *StreakResponse) String() string {
if len(s.rawJSON) > 0 {
if value, err := internal.StringifyJSON(s.rawJSON); err == nil {
return value
}
}
if value, err := internal.StringifyJSON(s); err == nil {
return value
}
return fmt.Sprintf("%#v", s)
}
// An object representing a past streak period.
type StreakResponseStreakHistoryItem struct {
// The date this streak period started.
PeriodStart string `json:"periodStart" url:"periodStart"`
// The date this streak period ended.
PeriodEnd string `json:"periodEnd" url:"periodEnd"`
// The length of the user's streak during this period.
Length int `json:"length" url:"length"`
extraProperties map[string]interface{}
rawJSON json.RawMessage
}
func (s *StreakResponseStreakHistoryItem) GetPeriodStart() string {
if s == nil {
return ""
}
return s.PeriodStart
}
func (s *StreakResponseStreakHistoryItem) GetPeriodEnd() string {
if s == nil {
return ""
}
return s.PeriodEnd
}
func (s *StreakResponseStreakHistoryItem) GetLength() int {
if s == nil {
return 0
}
return s.Length
}
func (s *StreakResponseStreakHistoryItem) GetExtraProperties() map[string]interface{} {
return s.extraProperties
}
func (s *StreakResponseStreakHistoryItem) UnmarshalJSON(data []byte) error {
type unmarshaler StreakResponseStreakHistoryItem
var value unmarshaler
if err := json.Unmarshal(data, &value); err != nil {
return err
}
*s = StreakResponseStreakHistoryItem(value)
extraProperties, err := internal.ExtractExtraProperties(data, *s)
if err != nil {
return err
}
s.extraProperties = extraProperties
s.rawJSON = json.RawMessage(data)
return nil
}
func (s *StreakResponseStreakHistoryItem) String() string {
if len(s.rawJSON) > 0 {
if value, err := internal.StringifyJSON(s.rawJSON); err == nil {
return value
}
}
if value, err := internal.StringifyJSON(s); err == nil {
return value
}
return fmt.Sprintf("%#v", s)
}
// A user of your application.
type User struct {
// The user's email address. Required if subscribeToEmails is true.
Email *string `json:"email,omitempty" url:"email,omitempty"`
// The name to refer to the user by in emails.
Name *string `json:"name,omitempty" url:"name,omitempty"`
// The user's timezone (used for email scheduling).
Tz *string `json:"tz,omitempty" url:"tz,omitempty"`
// Whether the user should receive Trophy-powered emails. Cannot be false if an email is provided.
SubscribeToEmails *bool `json:"subscribeToEmails,omitempty" url:"subscribeToEmails,omitempty"`
// The ID of the user in your database. Must be a string.
Id string `json:"id" url:"id"`
// Whether the user is in the control group, meaning they do not receive emails or other communications from Trophy.
Control *bool `json:"control,omitempty" url:"control,omitempty"`
// The date and time the user was created, in ISO 8601 format.
Created *time.Time `json:"created,omitempty" url:"created,omitempty"`
// The date and time the user was last updated, in ISO 8601 format.
Updated *time.Time `json:"updated,omitempty" url:"updated,omitempty"`
extraProperties map[string]interface{}
rawJSON json.RawMessage
}
func (u *User) GetEmail() *string {
if u == nil {
return nil
}
return u.Email
}
func (u *User) GetName() *string {
if u == nil {
return nil
}
return u.Name
}
func (u *User) GetTz() *string {
if u == nil {
return nil
}
return u.Tz
}
func (u *User) GetSubscribeToEmails() *bool {
if u == nil {
return nil
}
return u.SubscribeToEmails
}
func (u *User) GetId() string {
if u == nil {
return ""
}
return u.Id
}
func (u *User) GetControl() *bool {
if u == nil {
return nil
}
return u.Control
}
func (u *User) GetCreated() *time.Time {
if u == nil {
return nil
}
return u.Created
}
func (u *User) GetUpdated() *time.Time {
if u == nil {
return nil
}
return u.Updated
}
func (u *User) GetExtraProperties() map[string]interface{} {
return u.extraProperties
}
func (u *User) UnmarshalJSON(data []byte) error {
type embed User
var unmarshaler = struct {
embed
Created *internal.DateTime `json:"created,omitempty"`
Updated *internal.DateTime `json:"updated,omitempty"`
}{
embed: embed(*u),
}
if err := json.Unmarshal(data, &unmarshaler); err != nil {
return err
}
*u = User(unmarshaler.embed)
u.Created = unmarshaler.Created.TimePtr()
u.Updated = unmarshaler.Updated.TimePtr()
extraProperties, err := internal.ExtractExtraProperties(data, *u)
if err != nil {
return err
}
u.extraProperties = extraProperties
u.rawJSON = json.RawMessage(data)
return nil
}
func (u *User) MarshalJSON() ([]byte, error) {
type embed User
var marshaler = struct {
embed
Created *internal.DateTime `json:"created,omitempty"`
Updated *internal.DateTime `json:"updated,omitempty"`
}{
embed: embed(*u),
Created: internal.NewOptionalDateTime(u.Created),
Updated: internal.NewOptionalDateTime(u.Updated),
}
return json.Marshal(marshaler)
}
func (u *User) String() string {
if len(u.rawJSON) > 0 {
if value, err := internal.StringifyJSON(u.rawJSON); err == nil {
return value
}
}
if value, err := internal.StringifyJSON(u); err == nil {
return value
}
return fmt.Sprintf("%#v", u)
}