Adding tasks to projects
ryanmasondavies opened this issue · 0 comments
ryanmasondavies commented
I needed to add tasks to projects using your code, but found that the FreshBooks API rejects any tasks within project XML that include anything other than 'rate' and 'task_id'. My quick-and-dirty solution was to override Task's to_xml to only include those attributes:
class Task < FreshBooks::Task
def to_xml(elem_name = nil)
# The root element is the class name underscored
elem_name ||= self.class.to_s.split('::').last.underscore
root = REXML::Element.new(elem_name)
# only add rate and id to root elem
element = FreshBooks::XmlSerializer.to_node('rate', self.rate, 'fixnum')
root.add_element(element) if element != nil
# add id
element = FreshBooks::XmlSerializer.to_node('task_id', self.task_id, 'fixnum')
root.add_element(element) if element != nil
root.to_s
end
end
I imagine this needs more thought to solve as the above is a pretty messy solution. Perhaps another attribute when defining the attribute schema that defines whether or not each attribute should be included in upload XML. I noticed readonly
attributes are excluded, but these aren't readonly.