forked from seamapi/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.go
147 lines (128 loc) · 4.07 KB
/
events.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
// This file was auto-generated by Fern from our API Definition.
package api
import (
json "encoding/json"
fmt "fmt"
core "github.com/seamapi/go/core"
time "time"
)
type EventsGetRequest struct {
EventId *string `json:"event_id,omitempty"`
EventType *string `json:"event_type,omitempty"`
DeviceId *string `json:"device_id,omitempty"`
}
type EventsListRequest struct {
Since *string `json:"since,omitempty"`
Between []*EventsListRequestBetweenItem `json:"between,omitempty"`
DeviceId *string `json:"device_id,omitempty"`
DeviceIds []string `json:"device_ids,omitempty"`
AccessCodeId *string `json:"access_code_id,omitempty"`
AccessCodeIds []string `json:"access_code_ids,omitempty"`
EventType *EventType `json:"event_type,omitempty"`
EventTypes []EventType `json:"event_types,omitempty"`
ConnectedAccountId *string `json:"connected_account_id,omitempty"`
}
type EventsGetResponse struct {
Event *Event `json:"event,omitempty"`
Message *string `json:"message,omitempty"`
Ok bool `json:"ok"`
_rawJSON json.RawMessage
}
func (e *EventsGetResponse) UnmarshalJSON(data []byte) error {
type unmarshaler EventsGetResponse
var value unmarshaler
if err := json.Unmarshal(data, &value); err != nil {
return err
}
*e = EventsGetResponse(value)
e._rawJSON = json.RawMessage(data)
return nil
}
func (e *EventsGetResponse) String() string {
if len(e._rawJSON) > 0 {
if value, err := core.StringifyJSON(e._rawJSON); err == nil {
return value
}
}
if value, err := core.StringifyJSON(e); err == nil {
return value
}
return fmt.Sprintf("%#v", e)
}
type EventsListRequestBetweenItem struct {
typeName string
String string
DateTime time.Time
}
func NewEventsListRequestBetweenItemFromString(value string) *EventsListRequestBetweenItem {
return &EventsListRequestBetweenItem{typeName: "string", String: value}
}
func NewEventsListRequestBetweenItemFromDateTime(value time.Time) *EventsListRequestBetweenItem {
return &EventsListRequestBetweenItem{typeName: "dateTime", DateTime: value}
}
func (e *EventsListRequestBetweenItem) UnmarshalJSON(data []byte) error {
var valueString string
if err := json.Unmarshal(data, &valueString); err == nil {
e.typeName = "string"
e.String = valueString
return nil
}
var valueDateTime time.Time
if err := json.Unmarshal(data, &valueDateTime); err == nil {
e.typeName = "dateTime"
e.DateTime = valueDateTime
return nil
}
return fmt.Errorf("%s cannot be deserialized as a %T", data, e)
}
func (e EventsListRequestBetweenItem) MarshalJSON() ([]byte, error) {
switch e.typeName {
default:
return nil, fmt.Errorf("invalid type %s in %T", e.typeName, e)
case "string":
return json.Marshal(e.String)
case "dateTime":
return json.Marshal(e.DateTime)
}
}
type EventsListRequestBetweenItemVisitor interface {
VisitString(string) error
VisitDateTime(time.Time) error
}
func (e *EventsListRequestBetweenItem) Accept(visitor EventsListRequestBetweenItemVisitor) error {
switch e.typeName {
default:
return fmt.Errorf("invalid type %s in %T", e.typeName, e)
case "string":
return visitor.VisitString(e.String)
case "dateTime":
return visitor.VisitDateTime(e.DateTime)
}
}
type EventsListResponse struct {
Events []*Event `json:"events,omitempty"`
Message *string `json:"message,omitempty"`
Ok bool `json:"ok"`
_rawJSON json.RawMessage
}
func (e *EventsListResponse) UnmarshalJSON(data []byte) error {
type unmarshaler EventsListResponse
var value unmarshaler
if err := json.Unmarshal(data, &value); err != nil {
return err
}
*e = EventsListResponse(value)
e._rawJSON = json.RawMessage(data)
return nil
}
func (e *EventsListResponse) String() string {
if len(e._rawJSON) > 0 {
if value, err := core.StringifyJSON(e._rawJSON); err == nil {
return value
}
}
if value, err := core.StringifyJSON(e); err == nil {
return value
}
return fmt.Sprintf("%#v", e)
}