Skip to content

Instantly share code, notes, and snippets.

@superfeedr
Created September 21, 2009 05:10
Show Gist options
  • Save superfeedr/190082 to your computer and use it in GitHub Desktop.
Save superfeedr/190082 to your computer and use it in GitHub Desktop.
require "rubygems"
require "eventmachine"
require "em-http"
require "activesupport"
require "nokogiri"
url = "http://www.scriptlets.org/run/1218j9o"
# url = "http://0.0.0.0:4567/"
EM.run {
body = Nokogiri::XML::Builder.new do |xml|
xml.feed(:xmlns => "http://www.w3.org/2005/Atom") do |feed_|
feed_.updated(Time.now.iso8601)
feed_.id_("azertyu")
feed_.link(:href => "http://domain.com", :rel => "self")
feed_.entry do |entry|
entry.title("Title")
entry.id_("12456")
entry.published(1.day.ago) # Should be a string of the right format already (as it's extracted directly from the publish stanza)
entry.summary("summary")
entry.link(:rel => "self", :type => "text/html", :href => "http://thing", :title => "title")
entry.category(:term => "tag1")
entry.category(:term => "tag2")
entry.author do |author|
author.name("julien")
author.uri("http://twitter.com/julien51")
author.email("[email protected]")
end
end
end
end.to_xml
# And now, let's send that body to all subscribers.
multi = EventMachine::MultiRequest.new
# add multiple requests to the multi-handler
uri = URI.parse(url)
multi.add(EventMachine::HttpRequest.new(uri).post :body => body, :head => {"User-Agent" => "Superfeedr Hubbub : http://superfeedr.com/hubbub", "Content-Length" => body.size, "Content-Type" => "application/atom+xml"})
multi.callback {
multi.responses[:succeeded].each do |resp|
puts("Notification succeeded : #{resp.response_header.status} (#{resp.response_header.inspect})")
puts resp.response
EM.stop_event_loop
end
multi.responses[:failed].each do |resp|
puts("Notification failed (#{resp.inspect}): #{resp.response_header.status} (#{resp.response_header.inspect})")
end
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment