fn_ruby 0.1.32 → 0.2.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 +19 -12
- data/VERSION +1 -1
- data/docs/Call.md +14 -0
- data/docs/CallApi.md +212 -0
- data/docs/CallWrapper.md +8 -0
- data/docs/CallsWrapper.md +9 -0
- data/docs/Log.md +9 -0
- data/docs/LogApi.md +109 -0
- data/docs/LogWrapper.md +8 -0
- data/docs/Route.md +2 -3
- data/docs/RoutesApi.md +58 -4
- data/fn_ruby-0.1.32.gem +0 -0
- data/fn_ruby.gemspec +2 -2
- data/lib/fn_ruby.rb +9 -7
- data/lib/fn_ruby/api/apps_api.rb +2 -2
- data/lib/fn_ruby/api/call_api.rb +263 -0
- data/lib/fn_ruby/api/log_api.rb +144 -0
- data/lib/fn_ruby/api/routes_api.rb +73 -6
- data/lib/fn_ruby/api_client.rb +2 -2
- data/lib/fn_ruby/api_error.rb +2 -2
- data/lib/fn_ruby/configuration.rb +2 -2
- data/lib/fn_ruby/models/app.rb +2 -2
- data/lib/fn_ruby/models/app_wrapper.rb +2 -2
- data/lib/fn_ruby/models/apps_wrapper.rb +2 -2
- data/lib/fn_ruby/models/call.rb +249 -0
- data/lib/fn_ruby/models/call_wrapper.rb +194 -0
- data/lib/fn_ruby/models/calls_wrapper.rb +204 -0
- data/lib/fn_ruby/models/error.rb +2 -2
- data/lib/fn_ruby/models/error_body.rb +2 -2
- data/lib/fn_ruby/models/log.rb +198 -0
- data/lib/fn_ruby/models/log_wrapper.rb +194 -0
- data/lib/fn_ruby/models/route.rb +7 -13
- data/lib/fn_ruby/models/route_wrapper.rb +2 -2
- data/lib/fn_ruby/models/routes_wrapper.rb +2 -2
- data/lib/fn_ruby/models/version.rb +2 -2
- data/lib/fn_ruby/version.rb +3 -3
- data/spec/api/apps_api_spec.rb +2 -2
- data/spec/api/call_api_spec.rb +87 -0
- data/spec/api/log_api_spec.rb +61 -0
- data/spec/api/routes_api_spec.rb +18 -4
- data/spec/api_client_spec.rb +2 -2
- data/spec/configuration_spec.rb +2 -2
- data/spec/models/app_spec.rb +2 -2
- data/spec/models/app_wrapper_spec.rb +2 -2
- data/spec/models/apps_wrapper_spec.rb +2 -2
- data/spec/models/call_spec.rb +78 -0
- data/spec/models/call_wrapper_spec.rb +42 -0
- data/spec/models/calls_wrapper_spec.rb +48 -0
- data/spec/models/error_body_spec.rb +2 -2
- data/spec/models/error_spec.rb +2 -2
- data/spec/models/log_spec.rb +48 -0
- data/spec/models/log_wrapper_spec.rb +42 -0
- data/spec/models/route_spec.rb +2 -8
- data/spec/models/route_wrapper_spec.rb +2 -2
- data/spec/models/routes_wrapper_spec.rb +2 -2
- data/spec/models/version_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -2
- metadata +31 -2
@@ -1,9 +1,9 @@
|
|
1
1
|
=begin
|
2
|
-
#
|
2
|
+
#fn
|
3
3
|
|
4
4
|
#The open source serverless platform.
|
5
5
|
|
6
|
-
OpenAPI spec version: 0.
|
6
|
+
OpenAPI spec version: 0.2.0
|
7
7
|
|
8
8
|
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
9
|
Swagger Codegen version: 2.2.3
|
@@ -76,7 +76,7 @@ module Fn
|
|
76
76
|
end
|
77
77
|
|
78
78
|
# Create new Route
|
79
|
-
# Create a new route in an app, if app doesn't exists, it creates the app
|
79
|
+
# Create a new route in an app, if app doesn't exists, it creates the app. Post does not skip validation of zero values.
|
80
80
|
# @param app name of the app.
|
81
81
|
# @param body One route to post.
|
82
82
|
# @param [Hash] opts the optional parameters
|
@@ -87,7 +87,7 @@ module Fn
|
|
87
87
|
end
|
88
88
|
|
89
89
|
# Create new Route
|
90
|
-
# Create a new route in an app, if app doesn't exists, it creates the app
|
90
|
+
# Create a new route in an app, if app doesn't exists, it creates the app. Post does not skip validation of zero values.
|
91
91
|
# @param app name of the app.
|
92
92
|
# @param body One route to post.
|
93
93
|
# @param [Hash] opts the optional parameters
|
@@ -257,7 +257,7 @@ module Fn
|
|
257
257
|
return data, status_code, headers
|
258
258
|
end
|
259
259
|
|
260
|
-
# Update a Route
|
260
|
+
# Update a Route, Fails if the route or app does not exist. Accepts partial updates / skips validation of zero values.
|
261
261
|
# Update a route
|
262
262
|
# @param app name of the app.
|
263
263
|
# @param route route path.
|
@@ -269,7 +269,7 @@ module Fn
|
|
269
269
|
return data
|
270
270
|
end
|
271
271
|
|
272
|
-
# Update a Route
|
272
|
+
# Update a Route, Fails if the route or app does not exist. Accepts partial updates / skips validation of zero values.
|
273
273
|
# Update a route
|
274
274
|
# @param app name of the app.
|
275
275
|
# @param route route path.
|
@@ -323,5 +323,72 @@ module Fn
|
|
323
323
|
end
|
324
324
|
return data, status_code, headers
|
325
325
|
end
|
326
|
+
|
327
|
+
# Create a Route if it does not exist. Update if it does. Will also create app if it does not exist. Put does not skip validation of zero values
|
328
|
+
# Update or Create a route
|
329
|
+
# @param app name of the app.
|
330
|
+
# @param route route path.
|
331
|
+
# @param body One route to post.
|
332
|
+
# @param [Hash] opts the optional parameters
|
333
|
+
# @return [RouteWrapper]
|
334
|
+
def apps_app_routes_route_put(app, route, body, opts = {})
|
335
|
+
data, _status_code, _headers = apps_app_routes_route_put_with_http_info(app, route, body, opts)
|
336
|
+
return data
|
337
|
+
end
|
338
|
+
|
339
|
+
# Create a Route if it does not exist. Update if it does. Will also create app if it does not exist. Put does not skip validation of zero values
|
340
|
+
# Update or Create a route
|
341
|
+
# @param app name of the app.
|
342
|
+
# @param route route path.
|
343
|
+
# @param body One route to post.
|
344
|
+
# @param [Hash] opts the optional parameters
|
345
|
+
# @return [Array<(RouteWrapper, Fixnum, Hash)>] RouteWrapper data, response status code and response headers
|
346
|
+
def apps_app_routes_route_put_with_http_info(app, route, body, opts = {})
|
347
|
+
if @api_client.config.debugging
|
348
|
+
@api_client.config.logger.debug "Calling API: RoutesApi.apps_app_routes_route_put ..."
|
349
|
+
end
|
350
|
+
# verify the required parameter 'app' is set
|
351
|
+
if @api_client.config.client_side_validation && app.nil?
|
352
|
+
fail ArgumentError, "Missing the required parameter 'app' when calling RoutesApi.apps_app_routes_route_put"
|
353
|
+
end
|
354
|
+
# verify the required parameter 'route' is set
|
355
|
+
if @api_client.config.client_side_validation && route.nil?
|
356
|
+
fail ArgumentError, "Missing the required parameter 'route' when calling RoutesApi.apps_app_routes_route_put"
|
357
|
+
end
|
358
|
+
# verify the required parameter 'body' is set
|
359
|
+
if @api_client.config.client_side_validation && body.nil?
|
360
|
+
fail ArgumentError, "Missing the required parameter 'body' when calling RoutesApi.apps_app_routes_route_put"
|
361
|
+
end
|
362
|
+
# resource path
|
363
|
+
local_var_path = "/apps/{app}/routes/{route}".sub('{' + 'app' + '}', app.to_s).sub('{' + 'route' + '}', route.to_s)
|
364
|
+
|
365
|
+
# query parameters
|
366
|
+
query_params = {}
|
367
|
+
|
368
|
+
# header parameters
|
369
|
+
header_params = {}
|
370
|
+
# HTTP header 'Accept' (if needed)
|
371
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
372
|
+
# HTTP header 'Content-Type'
|
373
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
|
374
|
+
|
375
|
+
# form parameters
|
376
|
+
form_params = {}
|
377
|
+
|
378
|
+
# http body (model)
|
379
|
+
post_body = @api_client.object_to_http_body(body)
|
380
|
+
auth_names = []
|
381
|
+
data, status_code, headers = @api_client.call_api(:PUT, local_var_path,
|
382
|
+
:header_params => header_params,
|
383
|
+
:query_params => query_params,
|
384
|
+
:form_params => form_params,
|
385
|
+
:body => post_body,
|
386
|
+
:auth_names => auth_names,
|
387
|
+
:return_type => 'RouteWrapper')
|
388
|
+
if @api_client.config.debugging
|
389
|
+
@api_client.config.logger.debug "API called: RoutesApi#apps_app_routes_route_put\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
390
|
+
end
|
391
|
+
return data, status_code, headers
|
392
|
+
end
|
326
393
|
end
|
327
394
|
end
|
data/lib/fn_ruby/api_client.rb
CHANGED
data/lib/fn_ruby/api_error.rb
CHANGED
data/lib/fn_ruby/models/app.rb
CHANGED
@@ -0,0 +1,249 @@
|
|
1
|
+
=begin
|
2
|
+
#fn
|
3
|
+
|
4
|
+
#The open source serverless platform.
|
5
|
+
|
6
|
+
OpenAPI spec version: 0.2.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
Swagger Codegen version: 2.2.3
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'date'
|
14
|
+
|
15
|
+
module Fn
|
16
|
+
|
17
|
+
class Call
|
18
|
+
# Call UUID ID.
|
19
|
+
attr_accessor :id
|
20
|
+
|
21
|
+
# Call execution status.
|
22
|
+
attr_accessor :status
|
23
|
+
|
24
|
+
# App name that is assigned to a route that is being executed.
|
25
|
+
attr_accessor :app_name
|
26
|
+
|
27
|
+
# App route that is being executed.
|
28
|
+
attr_accessor :path
|
29
|
+
|
30
|
+
# Time when call was submitted. Always in UTC.
|
31
|
+
attr_accessor :created_at
|
32
|
+
|
33
|
+
# Time when call started execution. Always in UTC.
|
34
|
+
attr_accessor :started_at
|
35
|
+
|
36
|
+
# Time when call completed, whether it was successul or failed. Always in UTC.
|
37
|
+
attr_accessor :completed_at
|
38
|
+
|
39
|
+
|
40
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
41
|
+
def self.attribute_map
|
42
|
+
{
|
43
|
+
:'id' => :'id',
|
44
|
+
:'status' => :'status',
|
45
|
+
:'app_name' => :'app_name',
|
46
|
+
:'path' => :'path',
|
47
|
+
:'created_at' => :'created_at',
|
48
|
+
:'started_at' => :'started_at',
|
49
|
+
:'completed_at' => :'completed_at'
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
# Attribute type mapping.
|
54
|
+
def self.swagger_types
|
55
|
+
{
|
56
|
+
:'id' => :'String',
|
57
|
+
:'status' => :'String',
|
58
|
+
:'app_name' => :'String',
|
59
|
+
:'path' => :'String',
|
60
|
+
:'created_at' => :'DateTime',
|
61
|
+
:'started_at' => :'DateTime',
|
62
|
+
:'completed_at' => :'DateTime'
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
# Initializes the object
|
67
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
68
|
+
def initialize(attributes = {})
|
69
|
+
return unless attributes.is_a?(Hash)
|
70
|
+
|
71
|
+
# convert string to symbol for hash key
|
72
|
+
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
73
|
+
|
74
|
+
if attributes.has_key?(:'id')
|
75
|
+
self.id = attributes[:'id']
|
76
|
+
end
|
77
|
+
|
78
|
+
if attributes.has_key?(:'status')
|
79
|
+
self.status = attributes[:'status']
|
80
|
+
end
|
81
|
+
|
82
|
+
if attributes.has_key?(:'app_name')
|
83
|
+
self.app_name = attributes[:'app_name']
|
84
|
+
end
|
85
|
+
|
86
|
+
if attributes.has_key?(:'path')
|
87
|
+
self.path = attributes[:'path']
|
88
|
+
end
|
89
|
+
|
90
|
+
if attributes.has_key?(:'created_at')
|
91
|
+
self.created_at = attributes[:'created_at']
|
92
|
+
end
|
93
|
+
|
94
|
+
if attributes.has_key?(:'started_at')
|
95
|
+
self.started_at = attributes[:'started_at']
|
96
|
+
end
|
97
|
+
|
98
|
+
if attributes.has_key?(:'completed_at')
|
99
|
+
self.completed_at = attributes[:'completed_at']
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
105
|
+
# @return Array for valid properies with the reasons
|
106
|
+
def list_invalid_properties
|
107
|
+
invalid_properties = Array.new
|
108
|
+
return invalid_properties
|
109
|
+
end
|
110
|
+
|
111
|
+
# Check to see if the all the properties in the model are valid
|
112
|
+
# @return true if the model is valid
|
113
|
+
def valid?
|
114
|
+
return true
|
115
|
+
end
|
116
|
+
|
117
|
+
# Checks equality by comparing each attribute.
|
118
|
+
# @param [Object] Object to be compared
|
119
|
+
def ==(o)
|
120
|
+
return true if self.equal?(o)
|
121
|
+
self.class == o.class &&
|
122
|
+
id == o.id &&
|
123
|
+
status == o.status &&
|
124
|
+
app_name == o.app_name &&
|
125
|
+
path == o.path &&
|
126
|
+
created_at == o.created_at &&
|
127
|
+
started_at == o.started_at &&
|
128
|
+
completed_at == o.completed_at
|
129
|
+
end
|
130
|
+
|
131
|
+
# @see the `==` method
|
132
|
+
# @param [Object] Object to be compared
|
133
|
+
def eql?(o)
|
134
|
+
self == o
|
135
|
+
end
|
136
|
+
|
137
|
+
# Calculates hash code according to all attributes.
|
138
|
+
# @return [Fixnum] Hash code
|
139
|
+
def hash
|
140
|
+
[id, status, app_name, path, created_at, started_at, completed_at].hash
|
141
|
+
end
|
142
|
+
|
143
|
+
# Builds the object from hash
|
144
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
145
|
+
# @return [Object] Returns the model itself
|
146
|
+
def build_from_hash(attributes)
|
147
|
+
return nil unless attributes.is_a?(Hash)
|
148
|
+
self.class.swagger_types.each_pair do |key, type|
|
149
|
+
if type =~ /\AArray<(.*)>/i
|
150
|
+
# check to ensure the input is an array given that the the attribute
|
151
|
+
# is documented as an array but the input is not
|
152
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
153
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
154
|
+
end
|
155
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
156
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
157
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
158
|
+
end
|
159
|
+
|
160
|
+
self
|
161
|
+
end
|
162
|
+
|
163
|
+
# Deserializes the data based on type
|
164
|
+
# @param string type Data type
|
165
|
+
# @param string value Value to be deserialized
|
166
|
+
# @return [Object] Deserialized data
|
167
|
+
def _deserialize(type, value)
|
168
|
+
case type.to_sym
|
169
|
+
when :DateTime
|
170
|
+
DateTime.parse(value)
|
171
|
+
when :Date
|
172
|
+
Date.parse(value)
|
173
|
+
when :String
|
174
|
+
value.to_s
|
175
|
+
when :Integer
|
176
|
+
value.to_i
|
177
|
+
when :Float
|
178
|
+
value.to_f
|
179
|
+
when :BOOLEAN
|
180
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
181
|
+
true
|
182
|
+
else
|
183
|
+
false
|
184
|
+
end
|
185
|
+
when :Object
|
186
|
+
# generic object (usually a Hash), return directly
|
187
|
+
value
|
188
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
189
|
+
inner_type = Regexp.last_match[:inner_type]
|
190
|
+
value.map { |v| _deserialize(inner_type, v) }
|
191
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
192
|
+
k_type = Regexp.last_match[:k_type]
|
193
|
+
v_type = Regexp.last_match[:v_type]
|
194
|
+
{}.tap do |hash|
|
195
|
+
value.each do |k, v|
|
196
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
else # model
|
200
|
+
temp_model = Fn.const_get(type).new
|
201
|
+
temp_model.build_from_hash(value)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
# Returns the string representation of the object
|
206
|
+
# @return [String] String presentation of the object
|
207
|
+
def to_s
|
208
|
+
to_hash.to_s
|
209
|
+
end
|
210
|
+
|
211
|
+
# to_body is an alias to to_hash (backward compatibility)
|
212
|
+
# @return [Hash] Returns the object in the form of hash
|
213
|
+
def to_body
|
214
|
+
to_hash
|
215
|
+
end
|
216
|
+
|
217
|
+
# Returns the object in the form of hash
|
218
|
+
# @return [Hash] Returns the object in the form of hash
|
219
|
+
def to_hash
|
220
|
+
hash = {}
|
221
|
+
self.class.attribute_map.each_pair do |attr, param|
|
222
|
+
value = self.send(attr)
|
223
|
+
next if value.nil?
|
224
|
+
hash[param] = _to_hash(value)
|
225
|
+
end
|
226
|
+
hash
|
227
|
+
end
|
228
|
+
|
229
|
+
# Outputs non-array value in the form of hash
|
230
|
+
# For object, use to_hash. Otherwise, just return the value
|
231
|
+
# @param [Object] value Any valid value
|
232
|
+
# @return [Hash] Returns the value in the form of hash
|
233
|
+
def _to_hash(value)
|
234
|
+
if value.is_a?(Array)
|
235
|
+
value.compact.map{ |v| _to_hash(v) }
|
236
|
+
elsif value.is_a?(Hash)
|
237
|
+
{}.tap do |hash|
|
238
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
239
|
+
end
|
240
|
+
elsif value.respond_to? :to_hash
|
241
|
+
value.to_hash
|
242
|
+
else
|
243
|
+
value
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
=begin
|
2
|
+
#fn
|
3
|
+
|
4
|
+
#The open source serverless platform.
|
5
|
+
|
6
|
+
OpenAPI spec version: 0.2.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
Swagger Codegen version: 2.2.3
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'date'
|
14
|
+
|
15
|
+
module Fn
|
16
|
+
|
17
|
+
class CallWrapper
|
18
|
+
# Call object.
|
19
|
+
attr_accessor :call
|
20
|
+
|
21
|
+
|
22
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
23
|
+
def self.attribute_map
|
24
|
+
{
|
25
|
+
:'call' => :'call'
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
# Attribute type mapping.
|
30
|
+
def self.swagger_types
|
31
|
+
{
|
32
|
+
:'call' => :'Call'
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
# Initializes the object
|
37
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
38
|
+
def initialize(attributes = {})
|
39
|
+
return unless attributes.is_a?(Hash)
|
40
|
+
|
41
|
+
# convert string to symbol for hash key
|
42
|
+
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
43
|
+
|
44
|
+
if attributes.has_key?(:'call')
|
45
|
+
self.call = attributes[:'call']
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
51
|
+
# @return Array for valid properies with the reasons
|
52
|
+
def list_invalid_properties
|
53
|
+
invalid_properties = Array.new
|
54
|
+
if @call.nil?
|
55
|
+
invalid_properties.push("invalid value for 'call', call cannot be nil.")
|
56
|
+
end
|
57
|
+
|
58
|
+
return invalid_properties
|
59
|
+
end
|
60
|
+
|
61
|
+
# Check to see if the all the properties in the model are valid
|
62
|
+
# @return true if the model is valid
|
63
|
+
def valid?
|
64
|
+
return false if @call.nil?
|
65
|
+
return true
|
66
|
+
end
|
67
|
+
|
68
|
+
# Checks equality by comparing each attribute.
|
69
|
+
# @param [Object] Object to be compared
|
70
|
+
def ==(o)
|
71
|
+
return true if self.equal?(o)
|
72
|
+
self.class == o.class &&
|
73
|
+
call == o.call
|
74
|
+
end
|
75
|
+
|
76
|
+
# @see the `==` method
|
77
|
+
# @param [Object] Object to be compared
|
78
|
+
def eql?(o)
|
79
|
+
self == o
|
80
|
+
end
|
81
|
+
|
82
|
+
# Calculates hash code according to all attributes.
|
83
|
+
# @return [Fixnum] Hash code
|
84
|
+
def hash
|
85
|
+
[call].hash
|
86
|
+
end
|
87
|
+
|
88
|
+
# Builds the object from hash
|
89
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
90
|
+
# @return [Object] Returns the model itself
|
91
|
+
def build_from_hash(attributes)
|
92
|
+
return nil unless attributes.is_a?(Hash)
|
93
|
+
self.class.swagger_types.each_pair do |key, type|
|
94
|
+
if type =~ /\AArray<(.*)>/i
|
95
|
+
# check to ensure the input is an array given that the the attribute
|
96
|
+
# is documented as an array but the input is not
|
97
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
98
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
99
|
+
end
|
100
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
101
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
102
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
103
|
+
end
|
104
|
+
|
105
|
+
self
|
106
|
+
end
|
107
|
+
|
108
|
+
# Deserializes the data based on type
|
109
|
+
# @param string type Data type
|
110
|
+
# @param string value Value to be deserialized
|
111
|
+
# @return [Object] Deserialized data
|
112
|
+
def _deserialize(type, value)
|
113
|
+
case type.to_sym
|
114
|
+
when :DateTime
|
115
|
+
DateTime.parse(value)
|
116
|
+
when :Date
|
117
|
+
Date.parse(value)
|
118
|
+
when :String
|
119
|
+
value.to_s
|
120
|
+
when :Integer
|
121
|
+
value.to_i
|
122
|
+
when :Float
|
123
|
+
value.to_f
|
124
|
+
when :BOOLEAN
|
125
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
126
|
+
true
|
127
|
+
else
|
128
|
+
false
|
129
|
+
end
|
130
|
+
when :Object
|
131
|
+
# generic object (usually a Hash), return directly
|
132
|
+
value
|
133
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
134
|
+
inner_type = Regexp.last_match[:inner_type]
|
135
|
+
value.map { |v| _deserialize(inner_type, v) }
|
136
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
137
|
+
k_type = Regexp.last_match[:k_type]
|
138
|
+
v_type = Regexp.last_match[:v_type]
|
139
|
+
{}.tap do |hash|
|
140
|
+
value.each do |k, v|
|
141
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
else # model
|
145
|
+
temp_model = Fn.const_get(type).new
|
146
|
+
temp_model.build_from_hash(value)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# Returns the string representation of the object
|
151
|
+
# @return [String] String presentation of the object
|
152
|
+
def to_s
|
153
|
+
to_hash.to_s
|
154
|
+
end
|
155
|
+
|
156
|
+
# to_body is an alias to to_hash (backward compatibility)
|
157
|
+
# @return [Hash] Returns the object in the form of hash
|
158
|
+
def to_body
|
159
|
+
to_hash
|
160
|
+
end
|
161
|
+
|
162
|
+
# Returns the object in the form of hash
|
163
|
+
# @return [Hash] Returns the object in the form of hash
|
164
|
+
def to_hash
|
165
|
+
hash = {}
|
166
|
+
self.class.attribute_map.each_pair do |attr, param|
|
167
|
+
value = self.send(attr)
|
168
|
+
next if value.nil?
|
169
|
+
hash[param] = _to_hash(value)
|
170
|
+
end
|
171
|
+
hash
|
172
|
+
end
|
173
|
+
|
174
|
+
# Outputs non-array value in the form of hash
|
175
|
+
# For object, use to_hash. Otherwise, just return the value
|
176
|
+
# @param [Object] value Any valid value
|
177
|
+
# @return [Hash] Returns the value in the form of hash
|
178
|
+
def _to_hash(value)
|
179
|
+
if value.is_a?(Array)
|
180
|
+
value.compact.map{ |v| _to_hash(v) }
|
181
|
+
elsif value.is_a?(Hash)
|
182
|
+
{}.tap do |hash|
|
183
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
184
|
+
end
|
185
|
+
elsif value.respond_to? :to_hash
|
186
|
+
value.to_hash
|
187
|
+
else
|
188
|
+
value
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|