Skip to content

Instantly share code, notes, and snippets.

@stefanpenner
Forked from mislav/template-uri.rb
Created November 10, 2009 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanpenner/230481 to your computer and use it in GitHub Desktop.
Save stefanpenner/230481 to your computer and use it in GitHub Desktop.
# previously required http://github.com/mislav/addressable
# with changes merged upstream, main repo should work too:
# http://github.com/sporkmonger/addressable/
require 'addressable/template'
# http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses%C2%A0followers
template = Addressable::Template.new 'http://{host=twitter.com}' +
'/statuses/followers{-prefix|/|id}.{format=json}' +
'?{-join|&|user_id,screen_name,cursor}'
template.expand(:id => 'mislav')
# => http://twitter.com/statuses/followers/mislav.json?
template.expand(:id => 'mislav', :format => 'xml')
# => http://twitter.com/statuses/followers/mislav.xml?
template.expand(:user_id => 7516242)
# => http://twitter.com/statuses/followers.json?user_id=7516242
template.expand(:screen_name => 'mislav', :cursor => -1)
# => http://twitter.com/statuses/followers.json?screen_name=mislav&cursor=-1
template.expand(:host => 'api.tweetmuffler.com', :id => 'mislav')
# => http://api.tweetmuffler.com/statuses/followers/mislav.json?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment