Skip to content

Instantly share code, notes, and snippets.

@sivy
Created October 2, 2009 23:57
Show Gist options
  • Save sivy/200265 to your computer and use it in GitHub Desktop.
Save sivy/200265 to your computer and use it in GitHub Desktop.
"""
URI template handling:
Sample code for how to take a URI Template and turn it into the webhook call to send the activity consumer the activity stream location.
"""
from template_parser import Parser, URITemplate
import urllib2
import md5
def get_hook_uri(uri_template, params):
"""returns a string with the uri params filled in. Will escape feed_uri"""
t = URITemplate(uri_template)
if (params['feed_uri']):
params['feed_uri']=urllib2.quote(params['feed_uri'])
return t.sub(params)
template_str = 'http://localhost:8001/hooks/add_activity?userid=1234&feed_uri={feed_uri}&format={feed_format}&token={token}'
es='http://localhost:8002/activity?user_id=activity_user'
print get_hook_uri(template_str, {
'feed_uri':es,
'feed_format':'atom',
'token':md5.new('magic').hexdigest()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment