Skip to content

Instantly share code, notes, and snippets.

@thorncp
Created March 3, 2011 05:42
Show Gist options
  • Save thorncp/852391 to your computer and use it in GitHub Desktop.
Save thorncp/852391 to your computer and use it in GitHub Desktop.
class Derp < Rubot::WebResource
get :chuck, 'http://4q.cc/index.php?pid=fact&person=chuck' do |doc|
if fact = doc.css("#factbox").first
fact.text.strip
else
"fail"
end
end
end
class TestController < Rubot::Controller
command :chuck do
reply Derp.chuck
end
end
module Rubot
class WebResource
def self.get(name, url)
define_singleton_method(name) do
response = Net::HTTP.get(URI.parse(url))
yield Nokogiri::HTML.parse(response)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment