Created
January 8, 2012 21:45
-
-
Save bradhe/1579812 to your computer and use it in GitHub Desktop.
Add support for querying for people and adding notifications to messages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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