class Cheminee::ApiClient
def deserialize(response, return_type)
-
return_type
(String
) -- some examples: "User", "Array", "Hash " -
response
(Response
) -- HTTP response
def deserialize(response, return_type) body = response.body return nil if body.nil? || body.empty? # return response body directly for String return type return body.to_s if return_type == 'String' # ensuring a default content type content_type = response.headers['Content-Type'] || 'application/json' fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type) begin data = JSON.parse("[#{body}]", :symbolize_names => true)[0] rescue JSON::ParserError => e if %w(String Date Time).include?(return_type) data = body else raise e end end convert_to_type data, return_type end