Introducing AutoApi - Part 2
posted
Sunday, August 03 at 06:07PM
Just a few more refinements.
require 'lib/auto_api'
require 'json'
class TwitterClient < AutoApi::Base
authenticate "username", "password"
service_url "http://twitter.com/statuses/{remote_method}.{format}"
remote_method :friends_timeline, :default_parameters => {:format => "json", :remote_method => "friends_timeline"} do |json_response|
JSON.parse(json_response)
end
end
twitter_client = TwitterClient.new
twitter_client.friends_timeline(:count => 2) # => returns parsed JSON object, e.g., an Array of post Hashes
The next logical steps are to let the service_url statement accept default parameters, and allow the remote_method statement to force overrides. That way if a person calls twitter_client.friends_timeline(:format => "rss"), I could have it force json, since the callback block expects it.