如果web服务不在正常的“Rails方式”做事情上,我会推荐HTTParty。向网络服务做出Proxy是非常容易的,无论您希望如何回应。
举例来说,这里是他们的访问Twitter的时间表
class Twitter
include HTTParty
base_uri 'twitter.com'
def initialize(u, p)
@auth = {:username => u, :password => p}
end
# which can be :friends, :user or :public
# options[:query] can be things like since, since_id, count, etc.
def timeline(which=:friends, options={})
options.merge!({:basic_auth => @auth})
self.class.get("/statuses/#{which}_timeline.json", options)
end
def post(text)
options = { :query => {:status => text}, :basic_auth => @auth }
self.class.post('/statuses/update.json', options)
end
end
twitter = Twitter.new(config['email'], config['password'])
pp twitter.timeline
谢谢你这么全面的回答。幸运的是,JSON服务是RESTful的,只是它没有以ActiveResource预期的方式做出响应。现在我会避免使用ActiveResource,因为我知道它已经死了,而是读取您链接到的DZone文章。再次感谢! – gjb 2012-08-14 17:01:23
哦,这是个好消息!在这种情况下,任务不应该太困难。即使您没有使用ActiveResource,也可以尝试查看代码以了解其工作原理。 – 2012-08-14 20:46:30
如果您仍在处理此问题,请参阅其他一些可能有用的宝石:https://github.com/filtersquad/api_smith https://github.com/remiprev/her https://github.com/ apotonick/roar – 2012-10-31 13:53:47