Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
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()
})