This tutorial about ActiveResource and the YouTube API tells you how to manipulate the URL format. I didn't go nearly as far as they did though. To get ActiveResource to do what I needed it to do, I only needed to override one method:
class FriendFeed::User < FriendFeed::FriendFeedApi
class << self
def element_path(id, prefix_options = {}, query_options = nil)
prefix_option, query_options = split_options(prefix_options) if query_options.nil?
"/api/feed/user/#{id}"
end
end
end
This class wraps the user feed api. It makes a request to http://friendfeed.com/api/feed/user/{id} and converts the response to a ruby object when you make a call to FriendFeed::User.find(id).
The parent class, FriendFeed::FriendFeedApi, inherits from ActiveResource::Base and takes care of setting some defaults used across each of the API categories. For example, it sets the site variable on ActiveResource::Base to "http://friendfeed.com" and the format variable to :json.
No comments:
Post a Comment