Skip to content

Instantly share code, notes, and snippets.

@bradhe
Created December 29, 2011 08:08
Show Gist options
  • Save bradhe/1532844 to your computer and use it in GitHub Desktop.
Save bradhe/1532844 to your computer and use it in GitHub Desktop.
Monkey patch for adding the ability to deliver notifications with messages in from basecamp-wrapper
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
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment