SipXCAPApi
Version 5 (Adrian Georgescu, 04/13/2010 10:14 am)
1 | 1 | Adrian Georgescu | = XCAP API = |
---|---|---|---|
2 | 1 | Adrian Georgescu | |
3 | 1 | Adrian Georgescu | [[TOC(WikiStart, Sip*, depth=3)]] |
4 | 1 | Adrian Georgescu | 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. |
5 | 2 | Oliver Bril | |
6 | 2 | Oliver Bril | XCAP client is implemented by [http://devel.ag-projects.com/cgi-bin/darcsweb.cgi?r=python-xcaplib;a=summary python-xcaplib]. The library provides {{{xcaplib.client.XCAPClient}}} class which is an HTTP client with an interface better suited for XCAP servers. The library also provides |
7 | 2 | Oliver Bril | a version of XCAPClient ({{{xcaplib.green.XCAPClient}}}) built on top of eventlet, which may be used in twisted reactor. |
8 | 2 | Oliver Bril | |
9 | 5 | Adrian Georgescu | == Components == |
10 | 5 | Adrian Georgescu | |
11 | 5 | Adrian Georgescu | '''get'''(''self'', ''application'', ''node''={{{None}}}, ''etag''={{{None}}}, ''headers''={{{None}}}):: |
12 | 5 | Adrian Georgescu | Make an HTTP GET request to the resource identified by ''application'' and ''node''. Return a Resource instance on success. |
13 | 5 | Adrian Georgescu | Raise HTTPError if the operation was unsuccessful. |
14 | 5 | Adrian Georgescu | |
15 | 5 | Adrian Georgescu | '''put'''(''self'', ''application'', ''resource'', ''node''={{{None}}}, ''etag''={{{None}}}, ''headers''={{{None}}}):: |
16 | 5 | Adrian Georgescu | Make an HTTP PUT request to the resource identified by ''application'' and ''node''. Use ''resource'' as a request body. |
17 | 5 | Adrian Georgescu | Raise HTTPError is the operation was unsuccessful. |
18 | 5 | Adrian Georgescu | |
19 | 5 | Adrian Georgescu | '''delete'''(''self'', ''application'', ''node''={{{None}}}, ''etag''={{{None}}}, ''headers''={{{None}}}):: |
20 | 5 | Adrian Georgescu | Make an HTTP DELETE request to the resource identified by ''application'' and ''node''. |
21 | 5 | Adrian Georgescu | Raise HTTPError if the operation was unsuccessful. |
22 | 5 | Adrian Georgescu | |
23 | 5 | Adrian Georgescu | == Usage== |
24 | 5 | Adrian Georgescu | |
25 | 2 | Oliver Bril | {{{ |
26 | 2 | Oliver Bril | client = XCAPClient(xcap_root, xcap_user_id, password=password) |
27 | 2 | Oliver Bril | document = file('examples/resource-lists.xml').read() |
28 | 2 | Oliver Bril | |
29 | 2 | Oliver Bril | # put the document on the server |
30 | 2 | Oliver Bril | client.put('resource-lists', document) |
31 | 2 | Oliver Bril | |
32 | 1 | Adrian Georgescu | # read the document from the server |
33 | 3 | Oliver Bril | got = client.get('resource-lists') |
34 | 3 | Oliver Bril | |
35 | 4 | Oliver Bril | # get a specific element within a document |
36 | 3 | Oliver Bril | element = client.get('resource-lists', '/resource-lists/list/entry/display-name') |
37 | 3 | Oliver Bril | |
38 | 3 | Oliver Bril | # get an attribute: |
39 | 3 | Oliver Bril | res = client.get('resource-lists', '/resource-lists/list/entry/@uri') |
40 | 3 | Oliver Bril | |
41 | 3 | Oliver Bril | # replace an element conditionally, based on the etag |
42 | 3 | Oliver Bril | client.put('resource-lists', '<entry uri="sip:bob@example.com"><display-name>The Bob</display-name></entry>', |
43 | 3 | Oliver Bril | '/resource-lists/list/entry[@uri="sip:bob@example.com"]', etag=stored_etag) |
44 | 3 | Oliver Bril | |
45 | 3 | Oliver Bril | # delete an element |
46 | 3 | Oliver Bril | client.delete('resource-lists', node_selector, etag=res.etag) |
47 | 3 | Oliver Bril | }}} |