public
Last active

URI templates are, like, super-useful

  • Download Gist
template-uri.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# https://github.com/sporkmonger/addressable/
require 'addressable/template'
 
# http://dev.twitter.com/doc/get/statuses/followers
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?

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.