| Creating an extension with Google App Engine is incredibly simple:
|
|
Creating your own extension only takes a few lines of code:
#!/usr/bin/env python
import cgi
import wsgiref.handlers
from google.appengine.api import users
from google.appengine.ext import webapp
from dekiext import *
class MyExtension(DekiExt):
# this method is required
def title(self): return "My Extension"
# the following methods are optional
def description(self): return "My Description"
def namespace(self): return "my"
def copyright(self): return "My Copyright"
def label(self): return "MyExt"
# function to export
@function("str", "return user greeting")
@param("str", "name of user (default: \"stranger\")", True)
def hello(self, name):
return "Hi " + (name or "stranger!")
def main():
application = webapp.WSGIApplication([('/', MyExtension)], debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == "__main__":
main()
Upload it to your account. Now try it out by going to your application's URI. (e.g. http://dekiext.appspot.com)
<extension>
<title>My Extension</title>
<copyright>My Copyright</copyright>
<description>My Description</description>
<namespace>my</namespace>
<function>
<name>hello</name>
<description>return user gretting</description>
<uri protocol="xmlrpc">http://dekiext.appspot.com/hello.rpc</uri>
<param name="name" type="str" optional="true">name of user (default: "stranger")</param>
<return type="str" />
</function>
</extension>
To add your newly created extension to Deki Wiki, follow these steps:
Your users can now invoke extension functions directly from your Google App Engine application.
The DekExt module relies on one class (DekiExt) and two decorator methods (@function and @param).
Your class MUST derive from the DekiExt class. You can then decorate methods you want to export with @function.
Your class MUST implement the title() method. The title() method returns the full name for your extension.
Your class MAY implement the description() method. The description() method returns a description of the functions in your extension.
Your class MAY implement the namespace() method. The namespace() method returns the namespace (i.e. prefix) for your extension.
Your class MAY implement the copyright() method. The copyright() method returns the copyright notice for your extension.
Your class MAY implement the label() method. The label() method returns the short name for your extension.
return_type must be one of "bool", "num", "str", "list", "map" or "any". It describes the return type for your extension function.
description is optional. If provided, it is be visible in the Extension Dialog when the function is selected.
transform is not used yet.
All parameters, except self, MUST be described with @param. Parameter description must be listed in order from left-to-right.
param_type be one of "bool", "num", "str", "list", "map" or "any". It describes the parameter type for your extension function.
description is optional. If provided, it is visible in the Extension Dialog when the function is selected.
optional is optional. It indicates if this parameter is mandatory or if it can be left out.
| File | Size | Date | Attached by | |||
|---|---|---|---|---|---|---|
| google-app-engine.png No description | 35.21 kB | 18:16, 29 May 2008 | SteveB | Actions | ||
Concurrent editing is a dream...or no more?
Please, take a look!