jsonrpc
Provides an JSON-RPC implementation. It is very similar to the xmlrpc module and shares almost the same interface.
module exceptions
- InvalidServerResponse - Exception thrown if a server did not respond with response status 200 (OK).
- MalformedJSONRpc - Exception thrown if an XML-RPC response is not well formed.
- JSONRPCError - Exception thrown if the RPC response is a Fault.
- JSONRPCError::error The error object returned by the RPC call.
module methods
- marshall(obj) - Marshalls an object to JSON.(see http://json.org). It just calls the toJSON function of the object if it has such method. So, to customize serialization of objects one just needs to specify/override the toJSON method which should return a string conforming with the JSON specification.
- obj - The object to marshall
- returns An JSON representation of the object.
- unmarshall(json) - Unmarshalls a JSON document to a JavaScript? object. It parses the JSON source and creates a JavaScript? object.
- json - The source to unmarshall.
- returns The JavaScript? object created.
module classes
ServiceProxy(url, methodNames, user, pass) - Class for creating proxy objects which resemble the remote service. Method calls to this proxy will result in calls to the remote service.
- url - The URL of the service.
- methodNames - Array of names of methods that can be called on the server.
- user=null - The user name to use for HTTP authentication.
- pass=null - The password to use for HTTP authentication.
The arguments are interpreted as shown in the examples:
ServerProxy("url", ["methodName1",...], "user", "pass")
ServerProxy("url", "user", "pass")
The ServiceProxy objects expose all the methods of the remote service as JSONRPCMethod objects. In addition the object also has the following methods and properties.
- ServiceProxy::_addMethodNames(methodNames) - Adds new JSONRPCMethods to the proxy server which can then be invoked.
- methodNames - Array of names of methods that can be called on the server.
- ServiceProxy::_setAuthentication(user, pass) - Sets username and password for HTTP Authentication for all methods of this service.
- user - The user name.
- pass The password.
- ServiceProxy::_url - The URL of the service to resemble.
- ServiceProxy::_user - The user used for HTTP authentication.
- ServiceProxy::_password- The password used for HTTP authentication.
- ServiceProxy::_methods - All JSONRPCMethod objects the proxy can call.
JSONRPCMethod(url, name, user, pass) - Class for creating JSON-RPC methods. Calling the created method will result in an JSON-RPC call to the service. The return value of this call will be the return value of the RPC call. JSON-RPC errors will be raised as Exceptions.
- url - The URL of the service providing the method.
- name - The name of the method to invoke.
- user=null - The user name to use for HTTP authentication.
- pass=null - The password to use for HTTP authentication.
Asynchronous operation: If the last parameter passed to the method is an JSONRPCAsyncCallback object, then the remote method will be called asynchronously. The results and errors are passed to the callback.
- JSONRPCMethod::notify(...) - Calls the remote method using asynchronous notification. This method will never be replied to by the remote service, so no callback is needed.
- JSONRPCMethod::setAuthentication(user, pass) - Sets username and password for HTTP Authentication.
- user - The user name.
- pass - The password.
- JSONRPCMethod::methodName - The name of the remote method.
- JSONRPCMethod::url - The URL of the remote service containing the method.
- JSONRPCMethod::user - The user name used for HTTP authorization.
- JSONRPCMethod::password - The password used for HTTP authorization.
JSONRPCAsyncCallback(result, err) - The interface of a callback for asynchronous JSON-RPC.
- result - The result of the call (null if error).
- err - A JSONRPCError if there was one returned otherwise null.
dependencies
documentation/urllib is required for making the HTTP request to the remote service.
