XCAPapi

Version 1 (Tijmen de Mes, 05/10/2012 05:17 pm)

1 1 Tijmen de Mes
h1. XCAP API
2 1 Tijmen de Mes
3 1 Tijmen de Mes
4 1 Tijmen de Mes
5 1 Tijmen de Mes
XCAP protocol allows a client to read, write, and modify application configuration data stored in XML format on a server. XCAP maps XML document sub-trees and element attributes to HTTP URIs, so that these components can be directly accessed by clients using HTTP protocol. An XCAP server is used by XCAP clients to store data like buddy lists and presence policy in combination with a SIP Presence server that supports PUBLISH, SUBSCRIBE and NOTIFY methods to provide a complete SIP SIMPLE solution.
6 1 Tijmen de Mes
7 1 Tijmen de Mes
XCAP client is implemented by "python-xcaplib":http://devel.ag-projects.com/cgi-bin/darcsweb.cgi?r=python-xcaplib;a=summary. The library provides @xcaplib.client.XCAPClient@ class which is an HTTP client with an interface better suited for XCAP servers. The library also provides
8 1 Tijmen de Mes
a version of XCAPClient (@xcaplib.green.XCAPClient@) built on top of eventlet, which may be used in twisted reactor.
9 1 Tijmen de Mes
10 1 Tijmen de Mes
11 1 Tijmen de Mes
h2. Components
12 1 Tijmen de Mes
13 1 Tijmen de Mes
14 1 Tijmen de Mes
*get*(_self_, _application_, _node_=@None@, _etag_=@None@, _headers_=@None@)
15 1 Tijmen de Mes
 Make an HTTP GET request to the resource identified by _application_ and _node_. Return a Resource instance on success.
16 1 Tijmen de Mes
 Raise HTTPError if the operation was unsuccessful.
17 1 Tijmen de Mes
18 1 Tijmen de Mes
*put*(_self_, _application_, _resource_, _node_=@None@, _etag_=@None@, _headers_=@None@)
19 1 Tijmen de Mes
 Make an HTTP PUT request to the resource identified by _application_ and _node_. Use _resource_ as a request body.
20 1 Tijmen de Mes
 Raise HTTPError is the operation was unsuccessful.
21 1 Tijmen de Mes
22 1 Tijmen de Mes
*delete*(_self_, _application_, _node_=@None@, _etag_=@None@, _headers_=@None@)
23 1 Tijmen de Mes
 Make an HTTP DELETE request to the resource identified by _application_ and _node_.
24 1 Tijmen de Mes
 Raise HTTPError if the operation was unsuccessful.
25 1 Tijmen de Mes
26 1 Tijmen de Mes
27 1 Tijmen de Mes
h2. Usage
28 1 Tijmen de Mes
29 1 Tijmen de Mes
30 1 Tijmen de Mes
<pre>
31 1 Tijmen de Mes
client = XCAPClient(xcap_root, xcap_user_id, password=password)
32 1 Tijmen de Mes
document = file('examples/resource-lists.xml').read()
33 1 Tijmen de Mes
34 1 Tijmen de Mes
# put the document on the server
35 1 Tijmen de Mes
client.put('resource-lists', document)
36 1 Tijmen de Mes
37 1 Tijmen de Mes
# read the document from the server
38 1 Tijmen de Mes
got = client.get('resource-lists')
39 1 Tijmen de Mes
40 1 Tijmen de Mes
# get a specific element within a document
41 1 Tijmen de Mes
element = client.get('resource-lists', '/resource-lists/list/entry/display-name')
42 1 Tijmen de Mes
43 1 Tijmen de Mes
# get an attribute:
44 1 Tijmen de Mes
res = client.get('resource-lists', '/resource-lists/list/entry/@uri')
45 1 Tijmen de Mes
46 1 Tijmen de Mes
# replace an element conditionally, based on the etag
47 1 Tijmen de Mes
client.put('resource-lists', '<entry uri="sip:bob@example.com"><display-name>The Bob</display-name></entry>',
48 1 Tijmen de Mes
           '/resource-lists/list/entry[@uri="sip:bob@example.com"]', etag=stored_etag)
49 1 Tijmen de Mes
50 1 Tijmen de Mes
# delete an element
51 1 Tijmen de Mes
client.delete('resource-lists', node_selector, etag=res.etag)
52 1 Tijmen de Mes
</pre>