Changes between Version 4 and Version 5 of DeveloperGuidelines/WebServices


Ignore:
Timestamp:
02/08/09 21:19:50 (13 years ago)
Author:
Fran Boon
Comment:

Options using Pyjamas & T3-style decorators

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/WebServices

    v4 v5  
    2323
    2424----
     25Another approach (from T3: http://groups.google.com/group/web2py/browse_thread/thread/9ec8b06b158adb75):
     26Model:
     27{{{
     28from gluon.storage import Storage
     29settings=Storage()
     30settings.rss_procedures=[]
     31settings.exposed_procedures=[]
     32settings.xmlrpc_procedures=[]
     33settings.json_procedures=[]
     34def rss(f):
     35    settings.rss_procedures.append(f.__name__)
     36    return f
     37def expose(f):
     38    settings.exposed_procedures.append(f.__name__)
     39    return f
     40def json(f):
     41    settings.json_procedures.append(f.__name__)
     42    return f
     43def xmlrpc(f):
     44    settings.xmlrpc_procedures.append(f.__name__)
     45}}}
     46Controller:
     47{{{
     48def rss():
     49    if request.args and request.args[0] in settings.rss_procedures:
     50       feed=eval('%s(*request.args[1:],**dict
     51(request.vars))'%request.args[0])
     52    else:
     53       t2._error()
     54    import gluon.contrib.rss2 as rss2
     55    rss = rss2.RSS2(
     56       title=feed['title'],
     57       link = feed['link'],
     58       description = feed['description'],
     59       lastBuildDate = feed['created_on'],
     60       items = [
     61          rss2.RSSItem(
     62            title = entry['title'],
     63            link = entry['link'],
     64            description = entry['description'],
     65            pubDate = entry['created_on']) for entry in feed
     66['entries']]
     67       )
     68    response.headers['Content-Type']='application/rss+xml'
     69    return rss2.dumps(rss)
     70
     71def run():
     72    if request.args and request.args[0] in
     73settings.exposed_procedures:
     74       return eval('%s(*request.args[1:],**dict
     75(request.vars))'%request.args[0])
     76    return 'Not Authorized'
     77
     78def xmlrpc():
     79    methods=[eval(x) for x in settings.xmlrpc_procedures]
     80    return response.xmlrpc(request,methods)
     81
     82def json():
     83    if request.args and request.args[0] in settings.json_procedures:
     84       import gluon.contrib.simplejson as sj
     85       return sj.dumps(eval('%s(*request.args[1:],**dict
     86(request.vars))'%request.args[0]))
     87    return 'Not Authorized'
     88}}}
     89----
     90Another approach (using [http://pyjs.org Pyjamas]):
     91
     92* http://mdp.cti.depaul.edu/AlterEgo/default/show/203
     93
     94----
    2595DeveloperGuidelines