-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathprotocolv2.rb
More file actions
264 lines (229 loc) · 7.72 KB
/
protocolv2.rb
File metadata and controls
264 lines (229 loc) · 7.72 KB
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
require 'json'
module LaunchDarkly
module Impl
module DataSystem
module ProtocolV2
#
# This module contains the protocol definitions and data types for the
# LaunchDarkly data system version 2 (FDv2).
#
#
# DeleteObject specifies the deletion of a particular object.
#
# This type is not stable, and not subject to any backwards
# compatibility guarantees or semantic versioning. It is not suitable for production usage.
#
class DeleteObject
# @return [Integer] The version
attr_reader :version
# @return [String] The object kind ({LaunchDarkly::Interfaces::DataSystem::ObjectKind})
attr_reader :kind
# @return [String] The key
attr_reader :key
#
# @param version [Integer] The version
# @param kind [String] The object kind ({LaunchDarkly::Interfaces::DataSystem::ObjectKind})
# @param key [String] The key
#
def initialize(version:, kind:, key:)
@version = version
@kind = kind
@key = key
end
#
# Returns the event name.
#
# @return [Symbol]
#
def name
LaunchDarkly::Interfaces::DataSystem::EventName::DELETE_OBJECT
end
#
# Serializes the DeleteObject to a JSON-compatible hash.
#
# @return [Hash]
#
def to_h
{
version: @version,
kind: @kind,
key: @key,
}
end
#
# Deserializes a DeleteObject from a JSON-compatible hash.
#
# @param data [Hash] The hash representation
# @return [DeleteObject]
# @raise [ArgumentError] if required fields are missing
#
def self.from_h(data)
version = data[:version]
kind = data[:kind]
key = data[:key]
raise ArgumentError, "Missing required fields in DeleteObject" if version.nil? || kind.nil? || key.nil?
new(version: version, kind: kind, key: key)
end
end
#
# PutObject specifies the addition of a particular object with upsert semantics.
#
# This type is not stable, and not subject to any backwards
# compatibility guarantees or semantic versioning. It is not suitable for production usage.
#
class PutObject
# @return [Integer] The version
attr_reader :version
# @return [String] The object kind ({LaunchDarkly::Interfaces::DataSystem::ObjectKind})
attr_reader :kind
# @return [String] The key
attr_reader :key
# @return [Hash] The object data
attr_reader :object
#
# @param version [Integer] The version
# @param kind [String] The object kind ({LaunchDarkly::Interfaces::DataSystem::ObjectKind})
# @param key [String] The key
# @param object [Hash] The object data
#
def initialize(version:, kind:, key:, object:)
@version = version
@kind = kind
@key = key
@object = object
end
#
# Returns the event name.
#
# @return [Symbol]
#
def name
LaunchDarkly::Interfaces::DataSystem::EventName::PUT_OBJECT
end
#
# Serializes the PutObject to a JSON-compatible hash.
#
# @return [Hash]
#
def to_h
{
version: @version,
kind: @kind,
key: @key,
object: @object,
}
end
#
# Deserializes a PutObject from a JSON-compatible hash.
#
# @param data [Hash] The hash representation
# @return [PutObject]
# @raise [ArgumentError] if required fields are missing
#
def self.from_h(data)
version = data[:version]
kind = data[:kind]
key = data[:key]
object_data = data[:object]
raise ArgumentError, "Missing required fields in PutObject" if version.nil? || kind.nil? || key.nil? || object_data.nil?
new(version: version, kind: kind, key: key, object: object_data)
end
end
#
# Goodbye represents a goodbye event.
#
# This type is not stable, and not subject to any backwards
# compatibility guarantees or semantic versioning. It is not suitable for production usage.
#
class Goodbye
# @return [String] The reason for goodbye
attr_reader :reason
# @return [Boolean] Whether the goodbye is silent
attr_reader :silent
# @return [Boolean] Whether this represents a catastrophic failure
attr_reader :catastrophe
#
# @param reason [String] The reason for goodbye
# @param silent [Boolean] Whether the goodbye is silent
# @param catastrophe [Boolean] Whether this represents a catastrophic failure
#
def initialize(reason:, silent:, catastrophe:)
@reason = reason
@silent = silent
@catastrophe = catastrophe
end
#
# Serializes the Goodbye to a JSON-compatible hash.
#
# @return [Hash]
#
def to_h
{
reason: @reason,
silent: @silent,
catastrophe: @catastrophe,
}
end
#
# Deserializes a Goodbye event from a JSON-compatible hash.
#
# @param data [Hash] The hash representation
# @return [Goodbye]
# @raise [ArgumentError] if required fields are missing
#
def self.from_h(data)
reason = data[:reason]
silent = data[:silent]
catastrophe = data[:catastrophe]
raise ArgumentError, "Missing required fields in Goodbye" if reason.nil? || silent.nil? || catastrophe.nil?
new(reason: reason, silent: silent, catastrophe: catastrophe)
end
end
#
# Error represents an error event.
#
# This type is not stable, and not subject to any backwards
# compatibility guarantees or semantic versioning. It is not suitable for production usage.
#
class Error
# @return [String] The payload ID
attr_reader :payload_id
# @return [String] The reason for the error
attr_reader :reason
#
# @param payload_id [String] The payload ID
# @param reason [String] The reason for the error
#
def initialize(payload_id:, reason:)
@payload_id = payload_id
@reason = reason
end
#
# Serializes the Error to a JSON-compatible hash.
#
# @return [Hash]
#
def to_h
{
payloadId: @payload_id,
reason: @reason,
}
end
#
# Deserializes an Error from a JSON-compatible hash.
#
# @param data [Hash] The hash representation
# @return [Error]
# @raise [ArgumentError] if required fields are missing
#
def self.from_h(data)
payload_id = data[:payloadId]
reason = data[:reason]
raise ArgumentError, "Missing required fields in Error" if payload_id.nil? || reason.nil?
new(payload_id: payload_id, reason: reason)
end
end
end
end
end
end