module RailsConnector class CmsRestApi module AttributeSerializer class << self def convert(attributes) Hash[ attributes.map do |attribute_name, value| converted_value = if link_array?(value) convert_links(value) elsif value.is_a?(BasicObj) value.id elsif obj_array?(value) value.map(&:id) elsif value.is_a?(Time) || value.is_a?(Date) convert_time(value) elsif value.is_a?(Array) value.map(&:to_s) elsif value.is_a?(File) RailsConnector::CmsRestApi::BlobUploader.upload_file(value) else value.to_s end [attribute_name.to_s, converted_value] end ] end private def link_array?(value) value.is_a?(Array) && value.all? do |element| element.is_a?(Link) end end def obj_array?(value) value.is_a?(Array) && value.all? do |element| element.is_a?(BasicObj) end end def convert_links(links) links.map do |link| link.to_cms_api_linklist_params end end def convert_time(point_in_time) time_object = if point_in_time.instance_of?(Date) point_in_time.to_time else point_in_time.to_time.utc end time_object.strftime("%Y%m%d%H%M%S") end end end end end