XCAPapi » History » Version 1
Tijmen de Mes, 05/10/2012 05:17 PM
1 | 1 | Tijmen de Mes | h1. XCAP API |
---|---|---|---|
2 | |||
3 | |||
4 | |||
5 | 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 | |||
7 | 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 | a version of XCAPClient (@xcaplib.green.XCAPClient@) built on top of eventlet, which may be used in twisted reactor. |
||
9 | |||
10 | |||
11 | h2. Components |
||
12 | |||
13 | |||
14 | *get*(_self_, _application_, _node_=@None@, _etag_=@None@, _headers_=@None@) |
||
15 | Make an HTTP GET request to the resource identified by _application_ and _node_. Return a Resource instance on success. |
||
16 | Raise HTTPError if the operation was unsuccessful. |
||
17 | |||
18 | *put*(_self_, _application_, _resource_, _node_=@None@, _etag_=@None@, _headers_=@None@) |
||
19 | Make an HTTP PUT request to the resource identified by _application_ and _node_. Use _resource_ as a request body. |
||
20 | Raise HTTPError is the operation was unsuccessful. |
||
21 | |||
22 | *delete*(_self_, _application_, _node_=@None@, _etag_=@None@, _headers_=@None@) |
||
23 | Make an HTTP DELETE request to the resource identified by _application_ and _node_. |
||
24 | Raise HTTPError if the operation was unsuccessful. |
||
25 | |||
26 | |||
27 | h2. Usage |
||
28 | |||
29 | |||
30 | <pre> |
||
31 | client = XCAPClient(xcap_root, xcap_user_id, password=password) |
||
32 | document = file('examples/resource-lists.xml').read() |
||
33 | |||
34 | # put the document on the server |
||
35 | client.put('resource-lists', document) |
||
36 | |||
37 | # read the document from the server |
||
38 | got = client.get('resource-lists') |
||
39 | |||
40 | # get a specific element within a document |
||
41 | element = client.get('resource-lists', '/resource-lists/list/entry/display-name') |
||
42 | |||
43 | # get an attribute: |
||
44 | res = client.get('resource-lists', '/resource-lists/list/entry/@uri') |
||
45 | |||
46 | # replace an element conditionally, based on the etag |
||
47 | client.put('resource-lists', '<entry uri="sip:bob@example.com"><display-name>The Bob</display-name></entry>', |
||
48 | '/resource-lists/list/entry[@uri="sip:bob@example.com"]', etag=stored_etag) |
||
49 | |||
50 | # delete an element |
||
51 | client.delete('resource-lists', node_selector, etag=res.etag) |
||
52 | </pre> |