Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding tasks to projects #24

Open
ryanmasondavies opened this issue Oct 9, 2014 · 0 comments
Open

Adding tasks to projects #24

ryanmasondavies opened this issue Oct 9, 2014 · 0 comments

Comments

@ryanmasondavies
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant