docraptor 1.1.0 → 1.2.0beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +38 -2
- data/.rspec +2 -0
- data/.swagger-codegen-ignore +32 -0
- data/.swagger-codegen/VERSION +1 -0
- data/.swagger-revision +1 -1
- data/CHANGELOG.md +3 -0
- data/Gemfile +5 -1
- data/LICENSE +4 -10
- data/README.md +5 -4
- data/Rakefile +9 -0
- data/docraptor.gemspec +34 -16
- data/docraptor.yaml +5 -1
- data/lib/docraptor.rb +12 -0
- data/lib/docraptor/api/doc_api.rb +40 -56
- data/lib/docraptor/api_client.rb +102 -35
- data/lib/docraptor/api_error.rb +19 -5
- data/lib/docraptor/configuration.rb +40 -1
- data/lib/docraptor/models/async_doc.rb +61 -22
- data/lib/docraptor/models/async_doc_status.rb +66 -32
- data/lib/docraptor/models/doc.rb +122 -54
- data/lib/docraptor/models/prince_options.rb +116 -81
- data/lib/docraptor/version.rb +13 -1
- data/script/fix_gemspec.rb +31 -0
- data/script/post_generate_language +3 -0
- data/spec/api/doc_api_spec.rb +83 -0
- data/spec/api_client_spec.rb +226 -0
- data/spec/configuration_spec.rb +42 -0
- data/spec/models/async_doc_spec.rb +42 -0
- data/spec/models/async_doc_status_spec.rb +72 -0
- data/spec/models/doc_spec.rb +128 -0
- data/spec/models/prince_options_spec.rb +214 -0
- data/spec/spec_helper.rb +111 -0
- data/swagger-config.json +11 -3
- metadata +135 -112
data/lib/docraptor/api_client.rb
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
=begin
|
2
|
+
#DocRaptor v1
|
3
|
+
|
4
|
+
#A native client library for the DocRaptor HTML to PDF/XLS service.
|
5
|
+
|
6
|
+
OpenAPI spec version: 1.0.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
Swagger Codegen version: 2.2.3
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
1
13
|
require 'date'
|
2
14
|
require 'json'
|
3
15
|
require 'logger'
|
@@ -15,6 +27,8 @@ module DocRaptor
|
|
15
27
|
# @return [Hash]
|
16
28
|
attr_accessor :default_headers
|
17
29
|
|
30
|
+
# Initializes the ApiClient
|
31
|
+
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
18
32
|
def initialize(config = Configuration.default)
|
19
33
|
@config = config
|
20
34
|
@user_agent = "ruby-swagger-#{VERSION}"
|
@@ -41,10 +55,18 @@ module DocRaptor
|
|
41
55
|
end
|
42
56
|
|
43
57
|
unless response.success?
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
58
|
+
if response.timed_out?
|
59
|
+
fail ApiError.new('Connection timed out')
|
60
|
+
elsif response.code == 0
|
61
|
+
# Errors from libcurl will be made visible here
|
62
|
+
fail ApiError.new(:code => 0,
|
63
|
+
:message => response.return_message)
|
64
|
+
else
|
65
|
+
fail ApiError.new(:code => response.code,
|
66
|
+
:response_headers => response.headers,
|
67
|
+
:response_body => response.body),
|
68
|
+
response.status_message
|
69
|
+
end
|
48
70
|
end
|
49
71
|
|
50
72
|
if opts[:return_type]
|
@@ -55,6 +77,15 @@ module DocRaptor
|
|
55
77
|
return data, response.code, response.headers
|
56
78
|
end
|
57
79
|
|
80
|
+
# Builds the HTTP request
|
81
|
+
#
|
82
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
83
|
+
# @param [String] path URL path (e.g. /account/new)
|
84
|
+
# @option opts [Hash] :header_params Header parameters
|
85
|
+
# @option opts [Hash] :query_params Query parameters
|
86
|
+
# @option opts [Hash] :form_params Query parameters
|
87
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
88
|
+
# @return [Typhoeus::Request] A Typhoeus Request
|
58
89
|
def build_request(http_method, path, opts = {})
|
59
90
|
url = build_request_url(path)
|
60
91
|
http_method = http_method.to_sym.downcase
|
@@ -63,21 +94,25 @@ module DocRaptor
|
|
63
94
|
query_params = opts[:query_params] || {}
|
64
95
|
form_params = opts[:form_params] || {}
|
65
96
|
|
66
|
-
|
67
97
|
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
68
98
|
|
99
|
+
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
100
|
+
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
69
101
|
|
70
102
|
req_opts = {
|
71
103
|
:method => http_method,
|
72
104
|
:headers => header_params,
|
73
105
|
:params => query_params,
|
106
|
+
:params_encoding => @config.params_encoding,
|
74
107
|
:timeout => @config.timeout,
|
75
108
|
:ssl_verifypeer => @config.verify_ssl,
|
109
|
+
:ssl_verifyhost => _verify_ssl_host,
|
76
110
|
:sslcert => @config.cert_file,
|
77
111
|
:sslkey => @config.key_file,
|
78
112
|
:verbose => @config.debugging
|
79
113
|
}
|
80
114
|
|
115
|
+
# set custom cert, if provided
|
81
116
|
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
82
117
|
|
83
118
|
if [:post, :patch, :put, :delete].include?(http_method)
|
@@ -88,7 +123,9 @@ module DocRaptor
|
|
88
123
|
end
|
89
124
|
end
|
90
125
|
|
91
|
-
Typhoeus::Request.new(url, req_opts)
|
126
|
+
request = Typhoeus::Request.new(url, req_opts)
|
127
|
+
download_file(request) if opts[:return_type] == 'File'
|
128
|
+
request
|
92
129
|
end
|
93
130
|
|
94
131
|
# Check if the given MIME is a JSON MIME.
|
@@ -96,23 +133,29 @@ module DocRaptor
|
|
96
133
|
# application/json
|
97
134
|
# application/json; charset=UTF8
|
98
135
|
# APPLICATION/JSON
|
136
|
+
# */*
|
137
|
+
# @param [String] mime MIME
|
138
|
+
# @return [Boolean] True if the MIME is application/json
|
99
139
|
def json_mime?(mime)
|
100
|
-
|
140
|
+
(mime == "*/*") || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
101
141
|
end
|
102
142
|
|
103
143
|
# Deserialize the response to the given return type.
|
104
144
|
#
|
145
|
+
# @param [Response] response HTTP response
|
105
146
|
# @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
|
106
147
|
def deserialize(response, return_type)
|
107
148
|
body = response.body
|
149
|
+
|
150
|
+
# handle file downloading - return the File instance processed in request callbacks
|
151
|
+
# note that response body is empty when the file is written in chunks in request on_body callback
|
152
|
+
return @tempfile if return_type == 'File'
|
153
|
+
|
108
154
|
return nil if body.nil? || body.empty?
|
109
155
|
|
110
156
|
# return response body directly for String return type
|
111
157
|
return body if return_type == 'String'
|
112
158
|
|
113
|
-
# handle file downloading - save response body into a tmp file and return the File instance
|
114
|
-
return download_file(response) if return_type == 'File'
|
115
|
-
|
116
159
|
# ensuring a default content type
|
117
160
|
content_type = response.headers['Content-Type'] || 'application/json'
|
118
161
|
|
@@ -132,6 +175,9 @@ module DocRaptor
|
|
132
175
|
end
|
133
176
|
|
134
177
|
# Convert data to the given return type.
|
178
|
+
# @param [Object] data Data to be converted
|
179
|
+
# @param [String] return_type Return type
|
180
|
+
# @return [Mixed] Data in a particular type
|
135
181
|
def convert_to_type(data, return_type)
|
136
182
|
return nil if data.nil?
|
137
183
|
case return_type
|
@@ -172,30 +218,38 @@ module DocRaptor
|
|
172
218
|
|
173
219
|
# Save response body into a file in (the defined) temporary folder, using the filename
|
174
220
|
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
221
|
+
# The response body is written to the file in chunks in order to handle files which
|
222
|
+
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
223
|
+
# process can use.
|
175
224
|
#
|
176
225
|
# @see Configuration#temp_folder_path
|
177
|
-
|
178
|
-
def download_file(response)
|
179
|
-
content_disposition = response.headers['Content-Disposition']
|
180
|
-
if content_disposition
|
181
|
-
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
182
|
-
prefix = sanitize_filename(filename)
|
183
|
-
else
|
184
|
-
prefix = 'download-'
|
185
|
-
end
|
186
|
-
prefix = prefix + '-' unless prefix.end_with?('-')
|
187
|
-
|
226
|
+
def download_file(request)
|
188
227
|
tempfile = nil
|
189
|
-
encoding =
|
190
|
-
|
191
|
-
|
192
|
-
|
228
|
+
encoding = nil
|
229
|
+
request.on_headers do |response|
|
230
|
+
content_disposition = response.headers['Content-Disposition']
|
231
|
+
if content_disposition and content_disposition =~ /filename=/i
|
232
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
233
|
+
prefix = sanitize_filename(filename)
|
234
|
+
else
|
235
|
+
prefix = 'download-'
|
236
|
+
end
|
237
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
238
|
+
encoding = response.body.encoding
|
239
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
240
|
+
@tempfile = tempfile
|
241
|
+
end
|
242
|
+
request.on_body do |chunk|
|
243
|
+
chunk.force_encoding(encoding)
|
244
|
+
tempfile.write(chunk)
|
245
|
+
end
|
246
|
+
request.on_complete do |response|
|
247
|
+
tempfile.close
|
248
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
249
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
250
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
251
|
+
"explicitly with `tempfile.delete`"
|
193
252
|
end
|
194
|
-
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
195
|
-
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
196
|
-
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
197
|
-
"explicitly with `tempfile.delete`"
|
198
|
-
tempfile
|
199
253
|
end
|
200
254
|
|
201
255
|
# Sanitize filename by removing path.
|
@@ -204,7 +258,7 @@ module DocRaptor
|
|
204
258
|
# @param [String] filename the filename to be sanitized
|
205
259
|
# @return [String] the sanitized filename
|
206
260
|
def sanitize_filename(filename)
|
207
|
-
filename.gsub
|
261
|
+
filename.gsub(/.*[\/\\]/, '')
|
208
262
|
end
|
209
263
|
|
210
264
|
def build_request_url(path)
|
@@ -213,6 +267,12 @@ module DocRaptor
|
|
213
267
|
URI.encode(@config.base_url + path)
|
214
268
|
end
|
215
269
|
|
270
|
+
# Builds the HTTP request body
|
271
|
+
#
|
272
|
+
# @param [Hash] header_params Header parameters
|
273
|
+
# @param [Hash] form_params Query parameters
|
274
|
+
# @param [Object] body HTTP body (JSON/XML)
|
275
|
+
# @return [String] HTTP body data in the form of string
|
216
276
|
def build_request_body(header_params, form_params, body)
|
217
277
|
# http form
|
218
278
|
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
@@ -236,6 +296,10 @@ module DocRaptor
|
|
236
296
|
end
|
237
297
|
|
238
298
|
# Update hearder and query params based on authentication settings.
|
299
|
+
#
|
300
|
+
# @param [Hash] header_params Header parameters
|
301
|
+
# @param [Hash] query_params Query parameters
|
302
|
+
# @param [String] auth_names Authentication scheme name
|
239
303
|
def update_params_for_auth!(header_params, query_params, auth_names)
|
240
304
|
Array(auth_names).each do |auth_name|
|
241
305
|
auth_setting = @config.auth_settings[auth_name]
|
@@ -248,6 +312,9 @@ module DocRaptor
|
|
248
312
|
end
|
249
313
|
end
|
250
314
|
|
315
|
+
# Sets user agent in HTTP header
|
316
|
+
#
|
317
|
+
# @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
|
251
318
|
def user_agent=(user_agent)
|
252
319
|
@user_agent = user_agent
|
253
320
|
@default_headers['User-Agent'] = @user_agent
|
@@ -279,13 +346,13 @@ module DocRaptor
|
|
279
346
|
# @return [String] JSON string representation of the object
|
280
347
|
def object_to_http_body(model)
|
281
348
|
return model if model.nil? || model.is_a?(String)
|
282
|
-
|
349
|
+
local_body = nil
|
283
350
|
if model.is_a?(Array)
|
284
|
-
|
351
|
+
local_body = model.map{|m| object_to_hash(m) }
|
285
352
|
else
|
286
|
-
|
353
|
+
local_body = object_to_hash(model)
|
287
354
|
end
|
288
|
-
|
355
|
+
local_body.to_json
|
289
356
|
end
|
290
357
|
|
291
358
|
# Convert object(non-array) to hash.
|
data/lib/docraptor/api_error.rb
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
=begin
|
2
|
+
#DocRaptor v1
|
3
|
+
|
4
|
+
#A native client library for the DocRaptor HTML to PDF/XLS service.
|
5
|
+
|
6
|
+
OpenAPI spec version: 1.0.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
Swagger Codegen version: 2.2.3
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
1
13
|
module DocRaptor
|
2
14
|
class ApiError < StandardError
|
3
15
|
attr_reader :code, :response_headers, :response_body
|
@@ -9,12 +21,14 @@ module DocRaptor
|
|
9
21
|
# ApiError.new(:code => 404, :message => "Not Found")
|
10
22
|
def initialize(arg = nil)
|
11
23
|
if arg.is_a? Hash
|
24
|
+
if arg.key?(:message) || arg.key?('message')
|
25
|
+
super(arg[:message] || arg['message'])
|
26
|
+
else
|
27
|
+
super arg
|
28
|
+
end
|
29
|
+
|
12
30
|
arg.each do |k, v|
|
13
|
-
|
14
|
-
super v
|
15
|
-
else
|
16
|
-
instance_variable_set "@#{k}", v
|
17
|
-
end
|
31
|
+
instance_variable_set "@#{k}", v
|
18
32
|
end
|
19
33
|
else
|
20
34
|
super arg
|
@@ -1,3 +1,15 @@
|
|
1
|
+
=begin
|
2
|
+
#DocRaptor v1
|
3
|
+
|
4
|
+
#A native client library for the DocRaptor HTML to PDF/XLS service.
|
5
|
+
|
6
|
+
OpenAPI spec version: 1.0.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
Swagger Codegen version: 2.2.3
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
1
13
|
require 'uri'
|
2
14
|
|
3
15
|
module DocRaptor
|
@@ -64,7 +76,12 @@ module DocRaptor
|
|
64
76
|
# Default to 0 (never times out).
|
65
77
|
attr_accessor :timeout
|
66
78
|
|
67
|
-
|
79
|
+
# Set this to false to skip client side validation in the operation.
|
80
|
+
# Default to true.
|
81
|
+
# @return [true, false]
|
82
|
+
attr_accessor :client_side_validation
|
83
|
+
|
84
|
+
### TLS/SSL setting
|
68
85
|
# Set this to false to skip verifying SSL certificate when calling API from https server.
|
69
86
|
# Default to true.
|
70
87
|
#
|
@@ -73,6 +90,16 @@ module DocRaptor
|
|
73
90
|
# @return [true, false]
|
74
91
|
attr_accessor :verify_ssl
|
75
92
|
|
93
|
+
### TLS/SSL setting
|
94
|
+
# Set this to false to skip verifying SSL host name
|
95
|
+
# Default to true.
|
96
|
+
#
|
97
|
+
# @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
|
98
|
+
#
|
99
|
+
# @return [true, false]
|
100
|
+
attr_accessor :verify_ssl_host
|
101
|
+
|
102
|
+
### TLS/SSL setting
|
76
103
|
# Set this to customize the certificate file to verify the peer.
|
77
104
|
#
|
78
105
|
# @return [String] the path to the certificate file
|
@@ -81,12 +108,21 @@ module DocRaptor
|
|
81
108
|
# https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
|
82
109
|
attr_accessor :ssl_ca_cert
|
83
110
|
|
111
|
+
### TLS/SSL setting
|
84
112
|
# Client certificate file (for client certificate)
|
85
113
|
attr_accessor :cert_file
|
86
114
|
|
115
|
+
### TLS/SSL setting
|
87
116
|
# Client private key file (for client certificate)
|
88
117
|
attr_accessor :key_file
|
89
118
|
|
119
|
+
# Set this to customize parameters encoding of array parameter with multi collectionFormat.
|
120
|
+
# Default to nil.
|
121
|
+
#
|
122
|
+
# @see The params_encoding option of Ethon. Related source code:
|
123
|
+
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
|
124
|
+
attr_accessor :params_encoding
|
125
|
+
|
90
126
|
attr_accessor :inject_format
|
91
127
|
|
92
128
|
attr_accessor :force_ending_format
|
@@ -98,7 +134,10 @@ module DocRaptor
|
|
98
134
|
@api_key = {}
|
99
135
|
@api_key_prefix = {}
|
100
136
|
@timeout = 0
|
137
|
+
@client_side_validation = true
|
101
138
|
@verify_ssl = true
|
139
|
+
@verify_ssl_host = true
|
140
|
+
@params_encoding = nil
|
102
141
|
@cert_file = nil
|
103
142
|
@key_file = nil
|
104
143
|
@debugging = false
|
@@ -1,16 +1,28 @@
|
|
1
|
+
=begin
|
2
|
+
#DocRaptor v1
|
3
|
+
|
4
|
+
#A native client library for the DocRaptor HTML to PDF/XLS service.
|
5
|
+
|
6
|
+
OpenAPI spec version: 1.0.0
|
7
|
+
|
8
|
+
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
9
|
+
Swagger Codegen version: 2.2.3
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
1
13
|
require 'date'
|
2
14
|
|
3
15
|
module DocRaptor
|
16
|
+
|
4
17
|
class AsyncDoc
|
5
18
|
# The identifier used to get the status of the document using the status api.
|
6
19
|
attr_accessor :status_id
|
7
20
|
|
21
|
+
|
8
22
|
# Attribute mapping from ruby-style variable name to JSON key.
|
9
23
|
def self.attribute_map
|
10
24
|
{
|
11
|
-
|
12
25
|
:'status_id' => :'status_id'
|
13
|
-
|
14
26
|
}
|
15
27
|
end
|
16
28
|
|
@@ -18,24 +30,38 @@ module DocRaptor
|
|
18
30
|
def self.swagger_types
|
19
31
|
{
|
20
32
|
:'status_id' => :'String'
|
21
|
-
|
22
33
|
}
|
23
34
|
end
|
24
35
|
|
36
|
+
# Initializes the object
|
37
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
25
38
|
def initialize(attributes = {})
|
26
39
|
return unless attributes.is_a?(Hash)
|
27
40
|
|
28
41
|
# convert string to symbol for hash key
|
29
|
-
attributes = attributes.
|
30
|
-
|
42
|
+
attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
|
31
43
|
|
32
|
-
if attributes
|
44
|
+
if attributes.has_key?(:'status_id')
|
33
45
|
self.status_id = attributes[:'status_id']
|
34
46
|
end
|
35
47
|
|
36
48
|
end
|
37
49
|
|
38
|
-
#
|
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
|
+
return invalid_properties
|
55
|
+
end
|
56
|
+
|
57
|
+
# Check to see if the all the properties in the model are valid
|
58
|
+
# @return true if the model is valid
|
59
|
+
def valid?
|
60
|
+
return true
|
61
|
+
end
|
62
|
+
|
63
|
+
# Checks equality by comparing each attribute.
|
64
|
+
# @param [Object] Object to be compared
|
39
65
|
def ==(o)
|
40
66
|
return true if self.equal?(o)
|
41
67
|
self.class == o.class &&
|
@@ -43,35 +69,41 @@ module DocRaptor
|
|
43
69
|
end
|
44
70
|
|
45
71
|
# @see the `==` method
|
72
|
+
# @param [Object] Object to be compared
|
46
73
|
def eql?(o)
|
47
74
|
self == o
|
48
75
|
end
|
49
76
|
|
50
|
-
#
|
77
|
+
# Calculates hash code according to all attributes.
|
78
|
+
# @return [Fixnum] Hash code
|
51
79
|
def hash
|
52
80
|
[status_id].hash
|
53
81
|
end
|
54
82
|
|
55
|
-
#
|
83
|
+
# Builds the object from hash
|
84
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
85
|
+
# @return [Object] Returns the model itself
|
56
86
|
def build_from_hash(attributes)
|
57
87
|
return nil unless attributes.is_a?(Hash)
|
58
88
|
self.class.swagger_types.each_pair do |key, type|
|
59
|
-
if type =~
|
89
|
+
if type =~ /\AArray<(.*)>/i
|
90
|
+
# check to ensure the input is an array given that the the attribute
|
91
|
+
# is documented as an array but the input is not
|
60
92
|
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
61
93
|
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
62
|
-
else
|
63
|
-
#TODO show warning in debug mode
|
64
94
|
end
|
65
95
|
elsif !attributes[self.class.attribute_map[key]].nil?
|
66
96
|
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
67
|
-
else
|
68
|
-
# data not found in attributes(hash), not an issue as the data can be optional
|
69
|
-
end
|
97
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
70
98
|
end
|
71
99
|
|
72
100
|
self
|
73
101
|
end
|
74
102
|
|
103
|
+
# Deserializes the data based on type
|
104
|
+
# @param string type Data type
|
105
|
+
# @param string value Value to be deserialized
|
106
|
+
# @return [Object] Deserialized data
|
75
107
|
def _deserialize(type, value)
|
76
108
|
case type.to_sym
|
77
109
|
when :DateTime
|
@@ -85,7 +117,7 @@ module DocRaptor
|
|
85
117
|
when :Float
|
86
118
|
value.to_f
|
87
119
|
when :BOOLEAN
|
88
|
-
if value.to_s =~
|
120
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
89
121
|
true
|
90
122
|
else
|
91
123
|
false
|
@@ -96,7 +128,7 @@ module DocRaptor
|
|
96
128
|
when /\AArray<(?<inner_type>.+)>\z/
|
97
129
|
inner_type = Regexp.last_match[:inner_type]
|
98
130
|
value.map { |v| _deserialize(inner_type, v) }
|
99
|
-
when /\AHash<(?<k_type
|
131
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
100
132
|
k_type = Regexp.last_match[:k_type]
|
101
133
|
v_type = Regexp.last_match[:v_type]
|
102
134
|
{}.tap do |hash|
|
@@ -105,21 +137,25 @@ module DocRaptor
|
|
105
137
|
end
|
106
138
|
end
|
107
139
|
else # model
|
108
|
-
|
109
|
-
|
140
|
+
temp_model = DocRaptor.const_get(type).new
|
141
|
+
temp_model.build_from_hash(value)
|
110
142
|
end
|
111
143
|
end
|
112
144
|
|
145
|
+
# Returns the string representation of the object
|
146
|
+
# @return [String] String presentation of the object
|
113
147
|
def to_s
|
114
148
|
to_hash.to_s
|
115
149
|
end
|
116
150
|
|
117
|
-
# to_body is an alias to
|
151
|
+
# to_body is an alias to to_hash (backward compatibility)
|
152
|
+
# @return [Hash] Returns the object in the form of hash
|
118
153
|
def to_body
|
119
154
|
to_hash
|
120
155
|
end
|
121
156
|
|
122
|
-
#
|
157
|
+
# Returns the object in the form of hash
|
158
|
+
# @return [Hash] Returns the object in the form of hash
|
123
159
|
def to_hash
|
124
160
|
hash = {}
|
125
161
|
self.class.attribute_map.each_pair do |attr, param|
|
@@ -130,8 +166,10 @@ module DocRaptor
|
|
130
166
|
hash
|
131
167
|
end
|
132
168
|
|
133
|
-
#
|
169
|
+
# Outputs non-array value in the form of hash
|
134
170
|
# For object, use to_hash. Otherwise, just return the value
|
171
|
+
# @param [Object] value Any valid value
|
172
|
+
# @return [Hash] Returns the value in the form of hash
|
135
173
|
def _to_hash(value)
|
136
174
|
if value.is_a?(Array)
|
137
175
|
value.compact.map{ |v| _to_hash(v) }
|
@@ -147,4 +185,5 @@ module DocRaptor
|
|
147
185
|
end
|
148
186
|
|
149
187
|
end
|
188
|
+
|
150
189
|
end
|