Created
October 2, 2009 23:57
-
-
Save sivy/200265 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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