class CybridApiId::ApiClient

def deserialize(response, return_type)

Parameters:
  • return_type (String) -- some examples: "User", "Array", "Hash"
  • response (Response) -- HTTP response
def deserialize(response, return_type)
  body = response.body
  # handle file downloading - return the File instance processed in request callbacks
  # note that response body is empty when the file is written in chunks in request on_body callback
  return @tempfile if return_type == 'File'
  return nil if body.nil? || body.empty?
  # return response body directly for String return type
  return body 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