activitysmith 1.13.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +27 -5
- data/generated/activitysmith_openapi/api/push_notifications_api.rb +80 -2
- data/generated/activitysmith_openapi/models/app_icon_badge_count_update_response.rb +34 -4
- data/generated/activitysmith_openapi/models/live_activity_end_response.rb +64 -4
- data/generated/activitysmith_openapi/models/live_activity_start_response.rb +35 -4
- data/generated/activitysmith_openapi/models/live_activity_stream_delete_response.rb +53 -4
- data/generated/activitysmith_openapi/models/live_activity_stream_put_response.rb +54 -4
- data/generated/activitysmith_openapi/models/live_activity_update_response.rb +76 -4
- data/generated/activitysmith_openapi/models/push_notification_replace_request.rb +434 -0
- data/generated/activitysmith_openapi/models/push_notification_replace_response.rb +298 -0
- data/generated/activitysmith_openapi/models/push_notification_response.rb +63 -4
- data/generated/activitysmith_openapi.rb +2 -0
- data/generated/openapi-source.json +2 -2
- data/lib/activitysmith/notifications.rb +12 -0
- data/lib/activitysmith/version.rb +1 -1
- metadata +4 -2
|
@@ -26,6 +26,23 @@ module OpenapiClient
|
|
|
26
26
|
|
|
27
27
|
attr_accessor :timestamp
|
|
28
28
|
|
|
29
|
+
attr_accessor :users_notified
|
|
30
|
+
|
|
31
|
+
attr_accessor :effective_channel_slugs
|
|
32
|
+
|
|
33
|
+
# Optional tags to organize and filter notification history.
|
|
34
|
+
attr_accessor :tags
|
|
35
|
+
|
|
36
|
+
# Present when the update started a new Live Activity for a managed stream.
|
|
37
|
+
attr_accessor :operation
|
|
38
|
+
|
|
39
|
+
attr_accessor :stream_key
|
|
40
|
+
|
|
41
|
+
attr_accessor :previous_activity_id
|
|
42
|
+
|
|
43
|
+
# Per-device delivery errors when some devices could not be reached.
|
|
44
|
+
attr_accessor :errors
|
|
45
|
+
|
|
29
46
|
# Attribute mapping from ruby-style variable name to JSON key.
|
|
30
47
|
def self.attribute_map
|
|
31
48
|
{
|
|
@@ -33,7 +50,14 @@ module OpenapiClient
|
|
|
33
50
|
:'activity_id' => :'activity_id',
|
|
34
51
|
:'devices_queued' => :'devices_queued',
|
|
35
52
|
:'devices_notified' => :'devices_notified',
|
|
36
|
-
:'timestamp' => :'timestamp'
|
|
53
|
+
:'timestamp' => :'timestamp',
|
|
54
|
+
:'users_notified' => :'users_notified',
|
|
55
|
+
:'effective_channel_slugs' => :'effective_channel_slugs',
|
|
56
|
+
:'tags' => :'tags',
|
|
57
|
+
:'operation' => :'operation',
|
|
58
|
+
:'stream_key' => :'stream_key',
|
|
59
|
+
:'previous_activity_id' => :'previous_activity_id',
|
|
60
|
+
:'errors' => :'errors'
|
|
37
61
|
}
|
|
38
62
|
end
|
|
39
63
|
|
|
@@ -49,7 +73,14 @@ module OpenapiClient
|
|
|
49
73
|
:'activity_id' => :'String',
|
|
50
74
|
:'devices_queued' => :'Integer',
|
|
51
75
|
:'devices_notified' => :'Integer',
|
|
52
|
-
:'timestamp' => :'Time'
|
|
76
|
+
:'timestamp' => :'Time',
|
|
77
|
+
:'users_notified' => :'Integer',
|
|
78
|
+
:'effective_channel_slugs' => :'Array<String>',
|
|
79
|
+
:'tags' => :'Array<String>',
|
|
80
|
+
:'operation' => :'String',
|
|
81
|
+
:'stream_key' => :'String',
|
|
82
|
+
:'previous_activity_id' => :'String',
|
|
83
|
+
:'errors' => :'Array<String>'
|
|
53
84
|
}
|
|
54
85
|
end
|
|
55
86
|
|
|
@@ -99,6 +130,40 @@ module OpenapiClient
|
|
|
99
130
|
else
|
|
100
131
|
self.timestamp = nil
|
|
101
132
|
end
|
|
133
|
+
|
|
134
|
+
if attributes.key?(:'users_notified')
|
|
135
|
+
self.users_notified = attributes[:'users_notified']
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
if attributes.key?(:'effective_channel_slugs')
|
|
139
|
+
if (value = attributes[:'effective_channel_slugs']).is_a?(Array)
|
|
140
|
+
self.effective_channel_slugs = value
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
if attributes.key?(:'tags')
|
|
145
|
+
if (value = attributes[:'tags']).is_a?(Array)
|
|
146
|
+
self.tags = value
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
if attributes.key?(:'operation')
|
|
151
|
+
self.operation = attributes[:'operation']
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
if attributes.key?(:'stream_key')
|
|
155
|
+
self.stream_key = attributes[:'stream_key']
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
if attributes.key?(:'previous_activity_id')
|
|
159
|
+
self.previous_activity_id = attributes[:'previous_activity_id']
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
if attributes.key?(:'errors')
|
|
163
|
+
if (value = attributes[:'errors']).is_a?(Array)
|
|
164
|
+
self.errors = value
|
|
165
|
+
end
|
|
166
|
+
end
|
|
102
167
|
end
|
|
103
168
|
|
|
104
169
|
# Show invalid properties with the reasons. Usually used together with valid?
|
|
@@ -140,7 +205,14 @@ module OpenapiClient
|
|
|
140
205
|
activity_id == o.activity_id &&
|
|
141
206
|
devices_queued == o.devices_queued &&
|
|
142
207
|
devices_notified == o.devices_notified &&
|
|
143
|
-
timestamp == o.timestamp
|
|
208
|
+
timestamp == o.timestamp &&
|
|
209
|
+
users_notified == o.users_notified &&
|
|
210
|
+
effective_channel_slugs == o.effective_channel_slugs &&
|
|
211
|
+
tags == o.tags &&
|
|
212
|
+
operation == o.operation &&
|
|
213
|
+
stream_key == o.stream_key &&
|
|
214
|
+
previous_activity_id == o.previous_activity_id &&
|
|
215
|
+
errors == o.errors
|
|
144
216
|
end
|
|
145
217
|
|
|
146
218
|
# @see the `==` method
|
|
@@ -152,7 +224,7 @@ module OpenapiClient
|
|
|
152
224
|
# Calculates hash code according to all attributes.
|
|
153
225
|
# @return [Integer] Hash code
|
|
154
226
|
def hash
|
|
155
|
-
[success, activity_id, devices_queued, devices_notified, timestamp].hash
|
|
227
|
+
[success, activity_id, devices_queued, devices_notified, timestamp, users_notified, effective_channel_slugs, tags, operation, stream_key, previous_activity_id, errors].hash
|
|
156
228
|
end
|
|
157
229
|
|
|
158
230
|
# Builds the object from hash
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
#ActivitySmith API
|
|
3
|
+
|
|
4
|
+
#Send push notifications and Live Activities to your own devices via a single API key.
|
|
5
|
+
|
|
6
|
+
The version of the OpenAPI document: 1.0.0
|
|
7
|
+
|
|
8
|
+
Generated by: https://openapi-generator.tech
|
|
9
|
+
Generator version: 7.7.0
|
|
10
|
+
|
|
11
|
+
=end
|
|
12
|
+
|
|
13
|
+
require 'date'
|
|
14
|
+
require 'time'
|
|
15
|
+
|
|
16
|
+
module OpenapiClient
|
|
17
|
+
# Replacement content. title, subtitle, message, redirection, media, icon, actions, and payload fully replace the original values. Omit metadata or tags to keep the stored values; send {} or [] to clear them.
|
|
18
|
+
class PushNotificationReplaceRequest
|
|
19
|
+
# Additional information shown in notification and Live Activity details in ActivitySmith. Not displayed in the Push Notification or Live Activity on the device. Values must be strings, finite numbers, or booleans. At most 50 entries and 16 KB of serialized UTF-8 JSON. Omit on updates to preserve existing Metadata; send {} to clear it.
|
|
20
|
+
attr_accessor :metadata
|
|
21
|
+
|
|
22
|
+
attr_accessor :title
|
|
23
|
+
|
|
24
|
+
attr_accessor :message
|
|
25
|
+
|
|
26
|
+
attr_accessor :subtitle
|
|
27
|
+
|
|
28
|
+
# Optional HTTPS image URL without credentials for a custom notification icon. If the image cannot be loaded, the app icon is used. iOS may omit subtitle when displaying a custom icon.
|
|
29
|
+
attr_accessor :icon
|
|
30
|
+
|
|
31
|
+
# Optional HTTPS URL for an image, audio file, or video that users can preview or play when they expand the notification. If `redirection` is omitted, tapping the notification opens this URL. Cannot be combined with `actions`.
|
|
32
|
+
attr_accessor :media
|
|
33
|
+
|
|
34
|
+
# Optional HTTP, HTTPS, Shortcuts, or installed app URL opened when the user taps the notification body. Custom schemes such as spotify:// and spotify:track:123 require iOS 1.13.4 build 2 or later and an installed handler; no web fallback is provided. Internal and executable schemes are blocked. Overrides the default tap target from media.
|
|
35
|
+
attr_accessor :redirection
|
|
36
|
+
|
|
37
|
+
# Optional interactive actions shown when users expand the notification. Cannot be combined with `media`.
|
|
38
|
+
attr_accessor :actions
|
|
39
|
+
|
|
40
|
+
attr_accessor :payload
|
|
41
|
+
|
|
42
|
+
attr_accessor :badge
|
|
43
|
+
|
|
44
|
+
# Optional tags to organize and filter notification history.
|
|
45
|
+
attr_accessor :tags
|
|
46
|
+
|
|
47
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
|
48
|
+
def self.attribute_map
|
|
49
|
+
{
|
|
50
|
+
:'metadata' => :'metadata',
|
|
51
|
+
:'title' => :'title',
|
|
52
|
+
:'message' => :'message',
|
|
53
|
+
:'subtitle' => :'subtitle',
|
|
54
|
+
:'icon' => :'icon',
|
|
55
|
+
:'media' => :'media',
|
|
56
|
+
:'redirection' => :'redirection',
|
|
57
|
+
:'actions' => :'actions',
|
|
58
|
+
:'payload' => :'payload',
|
|
59
|
+
:'badge' => :'badge',
|
|
60
|
+
:'tags' => :'tags'
|
|
61
|
+
}
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Returns all the JSON keys this model knows about
|
|
65
|
+
def self.acceptable_attributes
|
|
66
|
+
attribute_map.values
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Attribute type mapping.
|
|
70
|
+
def self.openapi_types
|
|
71
|
+
{
|
|
72
|
+
:'metadata' => :'Hash<String, MetadataValue>',
|
|
73
|
+
:'title' => :'String',
|
|
74
|
+
:'message' => :'String',
|
|
75
|
+
:'subtitle' => :'String',
|
|
76
|
+
:'icon' => :'String',
|
|
77
|
+
:'media' => :'String',
|
|
78
|
+
:'redirection' => :'String',
|
|
79
|
+
:'actions' => :'Array<PushNotificationAction>',
|
|
80
|
+
:'payload' => :'Object',
|
|
81
|
+
:'badge' => :'Integer',
|
|
82
|
+
:'tags' => :'Array<String>'
|
|
83
|
+
}
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# List of attributes with nullable: true
|
|
87
|
+
def self.openapi_nullable
|
|
88
|
+
Set.new([
|
|
89
|
+
])
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Initializes the object
|
|
93
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
|
94
|
+
def initialize(attributes = {})
|
|
95
|
+
if (!attributes.is_a?(Hash))
|
|
96
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `OpenapiClient::PushNotificationReplaceRequest` initialize method"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
|
100
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
|
101
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
|
102
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::PushNotificationReplaceRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
|
103
|
+
end
|
|
104
|
+
h[k.to_sym] = v
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if attributes.key?(:'metadata')
|
|
108
|
+
if (value = attributes[:'metadata']).is_a?(Hash)
|
|
109
|
+
self.metadata = value
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
if attributes.key?(:'title')
|
|
114
|
+
self.title = attributes[:'title']
|
|
115
|
+
else
|
|
116
|
+
self.title = nil
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
if attributes.key?(:'message')
|
|
120
|
+
self.message = attributes[:'message']
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
if attributes.key?(:'subtitle')
|
|
124
|
+
self.subtitle = attributes[:'subtitle']
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
if attributes.key?(:'icon')
|
|
128
|
+
self.icon = attributes[:'icon']
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
if attributes.key?(:'media')
|
|
132
|
+
self.media = attributes[:'media']
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
if attributes.key?(:'redirection')
|
|
136
|
+
self.redirection = attributes[:'redirection']
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
if attributes.key?(:'actions')
|
|
140
|
+
if (value = attributes[:'actions']).is_a?(Array)
|
|
141
|
+
self.actions = value
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
if attributes.key?(:'payload')
|
|
146
|
+
self.payload = attributes[:'payload']
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
if attributes.key?(:'badge')
|
|
150
|
+
self.badge = attributes[:'badge']
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
if attributes.key?(:'tags')
|
|
154
|
+
if (value = attributes[:'tags']).is_a?(Array)
|
|
155
|
+
self.tags = value
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
|
161
|
+
# @return Array for valid properties with the reasons
|
|
162
|
+
def list_invalid_properties
|
|
163
|
+
warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
|
|
164
|
+
invalid_properties = Array.new
|
|
165
|
+
if !@metadata.nil? && @metadata.length > 50
|
|
166
|
+
invalid_properties.push('invalid value for "metadata", number of items must be less than or equal to 50.')
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
if @title.nil?
|
|
170
|
+
invalid_properties.push('invalid value for "title", title cannot be nil.')
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
pattern = Regexp.new(/^https:\/\//)
|
|
174
|
+
if !@icon.nil? && @icon !~ pattern
|
|
175
|
+
invalid_properties.push("invalid value for \"icon\", must conform to the pattern #{pattern}.")
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
pattern = Regexp.new(/^https:\/\//)
|
|
179
|
+
if !@media.nil? && @media !~ pattern
|
|
180
|
+
invalid_properties.push("invalid value for \"media\", must conform to the pattern #{pattern}.")
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
if !@redirection.nil? && @redirection.to_s.length > 2048
|
|
184
|
+
invalid_properties.push('invalid value for "redirection", the character length must be smaller than or equal to 2048.')
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
pattern = Regexp.new(/^[A-Za-z][A-Za-z0-9+.-]*:/)
|
|
188
|
+
if !@redirection.nil? && @redirection !~ pattern
|
|
189
|
+
invalid_properties.push("invalid value for \"redirection\", must conform to the pattern #{pattern}.")
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
if !@actions.nil? && @actions.length > 4
|
|
193
|
+
invalid_properties.push('invalid value for "actions", number of items must be less than or equal to 4.')
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
invalid_properties
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# Check to see if the all the properties in the model are valid
|
|
200
|
+
# @return true if the model is valid
|
|
201
|
+
def valid?
|
|
202
|
+
warn '[DEPRECATED] the `valid?` method is obsolete'
|
|
203
|
+
return false if !@metadata.nil? && @metadata.length > 50
|
|
204
|
+
return false if @title.nil?
|
|
205
|
+
return false if !@icon.nil? && @icon !~ Regexp.new(/^https:\/\//)
|
|
206
|
+
return false if !@media.nil? && @media !~ Regexp.new(/^https:\/\//)
|
|
207
|
+
return false if !@redirection.nil? && @redirection.to_s.length > 2048
|
|
208
|
+
return false if !@redirection.nil? && @redirection !~ Regexp.new(/^[A-Za-z][A-Za-z0-9+.-]*:/)
|
|
209
|
+
return false if !@actions.nil? && @actions.length > 4
|
|
210
|
+
true
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# Custom attribute writer method with validation
|
|
214
|
+
# @param [Object] metadata Value to be assigned
|
|
215
|
+
def metadata=(metadata)
|
|
216
|
+
if metadata.nil?
|
|
217
|
+
fail ArgumentError, 'metadata cannot be nil'
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
if metadata.length > 50
|
|
221
|
+
fail ArgumentError, 'invalid value for "metadata", number of items must be less than or equal to 50.'
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
@metadata = metadata
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
# Custom attribute writer method with validation
|
|
228
|
+
# @param [Object] icon Value to be assigned
|
|
229
|
+
def icon=(icon)
|
|
230
|
+
if icon.nil?
|
|
231
|
+
fail ArgumentError, 'icon cannot be nil'
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
pattern = Regexp.new(/^https:\/\//)
|
|
235
|
+
if icon !~ pattern
|
|
236
|
+
fail ArgumentError, "invalid value for \"icon\", must conform to the pattern #{pattern}."
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
@icon = icon
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
# Custom attribute writer method with validation
|
|
243
|
+
# @param [Object] media Value to be assigned
|
|
244
|
+
def media=(media)
|
|
245
|
+
if media.nil?
|
|
246
|
+
fail ArgumentError, 'media cannot be nil'
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
pattern = Regexp.new(/^https:\/\//)
|
|
250
|
+
if media !~ pattern
|
|
251
|
+
fail ArgumentError, "invalid value for \"media\", must conform to the pattern #{pattern}."
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
@media = media
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
# Custom attribute writer method with validation
|
|
258
|
+
# @param [Object] redirection Value to be assigned
|
|
259
|
+
def redirection=(redirection)
|
|
260
|
+
if redirection.nil?
|
|
261
|
+
fail ArgumentError, 'redirection cannot be nil'
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
if redirection.to_s.length > 2048
|
|
265
|
+
fail ArgumentError, 'invalid value for "redirection", the character length must be smaller than or equal to 2048.'
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
pattern = Regexp.new(/^[A-Za-z][A-Za-z0-9+.-]*:/)
|
|
269
|
+
if redirection !~ pattern
|
|
270
|
+
fail ArgumentError, "invalid value for \"redirection\", must conform to the pattern #{pattern}."
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
@redirection = redirection
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
# Custom attribute writer method with validation
|
|
277
|
+
# @param [Object] actions Value to be assigned
|
|
278
|
+
def actions=(actions)
|
|
279
|
+
if actions.nil?
|
|
280
|
+
fail ArgumentError, 'actions cannot be nil'
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
if actions.length > 4
|
|
284
|
+
fail ArgumentError, 'invalid value for "actions", number of items must be less than or equal to 4.'
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
@actions = actions
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
# Checks equality by comparing each attribute.
|
|
291
|
+
# @param [Object] Object to be compared
|
|
292
|
+
def ==(o)
|
|
293
|
+
return true if self.equal?(o)
|
|
294
|
+
self.class == o.class &&
|
|
295
|
+
metadata == o.metadata &&
|
|
296
|
+
title == o.title &&
|
|
297
|
+
message == o.message &&
|
|
298
|
+
subtitle == o.subtitle &&
|
|
299
|
+
icon == o.icon &&
|
|
300
|
+
media == o.media &&
|
|
301
|
+
redirection == o.redirection &&
|
|
302
|
+
actions == o.actions &&
|
|
303
|
+
payload == o.payload &&
|
|
304
|
+
badge == o.badge &&
|
|
305
|
+
tags == o.tags
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
# @see the `==` method
|
|
309
|
+
# @param [Object] Object to be compared
|
|
310
|
+
def eql?(o)
|
|
311
|
+
self == o
|
|
312
|
+
end
|
|
313
|
+
|
|
314
|
+
# Calculates hash code according to all attributes.
|
|
315
|
+
# @return [Integer] Hash code
|
|
316
|
+
def hash
|
|
317
|
+
[metadata, title, message, subtitle, icon, media, redirection, actions, payload, badge, tags].hash
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
# Builds the object from hash
|
|
321
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
|
322
|
+
# @return [Object] Returns the model itself
|
|
323
|
+
def self.build_from_hash(attributes)
|
|
324
|
+
return nil unless attributes.is_a?(Hash)
|
|
325
|
+
attributes = attributes.transform_keys(&:to_sym)
|
|
326
|
+
transformed_hash = {}
|
|
327
|
+
openapi_types.each_pair do |key, type|
|
|
328
|
+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
|
329
|
+
transformed_hash["#{key}"] = nil
|
|
330
|
+
elsif type =~ /\AArray<(.*)>/i
|
|
331
|
+
# check to ensure the input is an array given that the attribute
|
|
332
|
+
# is documented as an array but the input is not
|
|
333
|
+
if attributes[attribute_map[key]].is_a?(Array)
|
|
334
|
+
transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
|
|
335
|
+
end
|
|
336
|
+
elsif !attributes[attribute_map[key]].nil?
|
|
337
|
+
transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
|
|
338
|
+
end
|
|
339
|
+
end
|
|
340
|
+
new(transformed_hash)
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
# Deserializes the data based on type
|
|
344
|
+
# @param string type Data type
|
|
345
|
+
# @param string value Value to be deserialized
|
|
346
|
+
# @return [Object] Deserialized data
|
|
347
|
+
def self._deserialize(type, value)
|
|
348
|
+
case type.to_sym
|
|
349
|
+
when :Time
|
|
350
|
+
Time.parse(value)
|
|
351
|
+
when :Date
|
|
352
|
+
Date.parse(value)
|
|
353
|
+
when :String
|
|
354
|
+
value.to_s
|
|
355
|
+
when :Integer
|
|
356
|
+
value.to_i
|
|
357
|
+
when :Float
|
|
358
|
+
value.to_f
|
|
359
|
+
when :Boolean
|
|
360
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
|
361
|
+
true
|
|
362
|
+
else
|
|
363
|
+
false
|
|
364
|
+
end
|
|
365
|
+
when :Object
|
|
366
|
+
# generic object (usually a Hash), return directly
|
|
367
|
+
value
|
|
368
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
|
369
|
+
inner_type = Regexp.last_match[:inner_type]
|
|
370
|
+
value.map { |v| _deserialize(inner_type, v) }
|
|
371
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
|
372
|
+
k_type = Regexp.last_match[:k_type]
|
|
373
|
+
v_type = Regexp.last_match[:v_type]
|
|
374
|
+
{}.tap do |hash|
|
|
375
|
+
value.each do |k, v|
|
|
376
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
|
377
|
+
end
|
|
378
|
+
end
|
|
379
|
+
else # model
|
|
380
|
+
# models (e.g. Pet) or oneOf
|
|
381
|
+
klass = OpenapiClient.const_get(type)
|
|
382
|
+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
|
383
|
+
end
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
# Returns the string representation of the object
|
|
387
|
+
# @return [String] String presentation of the object
|
|
388
|
+
def to_s
|
|
389
|
+
to_hash.to_s
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
# to_body is an alias to to_hash (backward compatibility)
|
|
393
|
+
# @return [Hash] Returns the object in the form of hash
|
|
394
|
+
def to_body
|
|
395
|
+
to_hash
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
# Returns the object in the form of hash
|
|
399
|
+
# @return [Hash] Returns the object in the form of hash
|
|
400
|
+
def to_hash
|
|
401
|
+
hash = {}
|
|
402
|
+
self.class.attribute_map.each_pair do |attr, param|
|
|
403
|
+
value = self.send(attr)
|
|
404
|
+
if value.nil?
|
|
405
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
|
406
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
hash[param] = _to_hash(value)
|
|
410
|
+
end
|
|
411
|
+
hash
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
# Outputs non-array value in the form of hash
|
|
415
|
+
# For object, use to_hash. Otherwise, just return the value
|
|
416
|
+
# @param [Object] value Any valid value
|
|
417
|
+
# @return [Hash] Returns the value in the form of hash
|
|
418
|
+
def _to_hash(value)
|
|
419
|
+
if value.is_a?(Array)
|
|
420
|
+
value.compact.map { |v| _to_hash(v) }
|
|
421
|
+
elsif value.is_a?(Hash)
|
|
422
|
+
{}.tap do |hash|
|
|
423
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
|
424
|
+
end
|
|
425
|
+
elsif value.respond_to? :to_hash
|
|
426
|
+
value.to_hash
|
|
427
|
+
else
|
|
428
|
+
value
|
|
429
|
+
end
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
end
|