Skip to content

Instantly share code, notes, and snippets.

@bradhe
Created January 8, 2012 21:45
Show Gist options
  • Save bradhe/1579812 to your computer and use it in GitHub Desktop.
Save bradhe/1579812 to your computer and use it in GitHub Desktop.
Add support for querying for people and adding notifications to messages.
module Basecamp
class Message
attr_accessor :notify
def to_xml(arg={})
# Little heavy handed but...it does the trick.
doc = Nokogiri::XML(super(arg))
# This doesn't create a "request" element by default, so lets
# create one.
request = doc.create_element('request')
# Move the <post/> element in to the request element...
request.add_child(doc.children.find { |n| n.name.eql?('post') })
# Add all the notification thingers...
notify.each do |n|
if n.is_a? Basecamp::Person
id = n.id
else
id = n
end
request.add_child(doc.create_element('notify', id.to_s))
end
# Stick it back in the doc...and thunk back to a string.
doc.add_child(request)
doc.to_s
end
def notify
@notify ||= []
end
end
class Project
def people
get(:people).map { |h| Basecamp::Person.new(h) }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment