I would like to write a Ruby on Rails application that consumes a RESTful web service API performs some logic on the result and then displays that data on my view. For example, let's say I wanted to write a program that did a search on search.twitter.com. Using pure ruby I might create the following method:
def run(search_term='', last_id=0)
@results = []
url = URI.parse("http://search.twitter.com")
res = Net::HTTP.start(url.host, url.port) do |http|
http.get("/search.json?q=#{search_term}&since_id=#{last_id.to_s}")
end
@results = JSON.parse res.body
end
I'm tempted to just drop that method into my Rails controller as a private method, but part of me thinks that there is a better, more "Rails" way to do this. Is there a best practice approach or is this really the best way?