~openerp-community/openobject-server/training

« back to all changes in this revision

Viewing changes to presentation.en/src/xml_rpc.rst

  • Committer: Fabien Pinckaers
  • Date: 2009-08-04 16:14:19 UTC
  • Revision ID: fp@tinyerp.com-20090804161419-vwan9tdtjheeua87
add

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
Web-Services !
 
3
--------------
 
4
 
 
5
.. class:: section-title
 
6
 
 
7
    Can we communicate ?
 
8
 
 
9
Web-Services - Python
 
10
---------------------
 
11
 
 
12
Using the xmlrpclib library
 
13
 
 
14
.. sourcecode:: python
 
15
 
 
16
    import xmlrpclib
 
17
 
 
18
.. warning::
 
19
 
 
20
    For each exchange with the server, don't forget to supply the user ID, the PWD and the database name
 
21
 
 
22
Web-Services - Python - Login
 
23
-----------------------------
 
24
 
 
25
.. sourcecode:: python
 
26
 
 
27
    import xmlrpclib
 
28
 
 
29
    database = "terp"
 
30
    username = "admin"
 
31
    password = "admin"
 
32
 
 
33
    socket = xmlrpclib.ServerProxy( "http://localhost:8069/xmlrpc/common" )
 
34
    user_id = socket.login( database, username, password )
 
35
 
 
36
Web-Services - Python - Search
 
37
------------------------------
 
38
 
 
39
.. sourcecode:: python
 
40
 
 
41
    socket = xmlrpclib.ServerProxy( "http://localhost:8069/xmlrpc/object" )
 
42
    ids = socket.execute(
 
43
        database, user_id, password,
 
44
        "openacademy.lecturer", "search", []
 
45
    )
 
46
    lecturers = socket.execute(
 
47
        database, user_id, password,
 
48
        "openacademy.lecturer", "read", ids, ['name', 'email']
 
49
    )
 
50
 
 
51
    for lecturer in lecturers:
 
52
        print "lecturer: %20s - %s" % ( lecturer['name'], lecturer['email'] )
 
53
 
 
54
Web-Services - Ruby
 
55
-------------------
 
56
 
 
57
Using the **xmlrpc/client** library
 
58
 
 
59
.. sourcecode:: ruby
 
60
 
 
61
    require 'xmlrpc/client'
 
62
 
 
63
.. warning::
 
64
 
 
65
    For each exchange with the server, don't forget to supply the user ID, the PWD and the database name
 
66
 
 
67
Web-Services - Ruby - Login
 
68
---------------------------
 
69
 
 
70
.. sourcecode:: ruby
 
71
 
 
72
    require 'xmlrpc/client'
 
73
 
 
74
    database = "terp"
 
75
    username = "admin"
 
76
    password = "admin"
 
77
 
 
78
    socket = XMLRPC::Client.new( 'http://localhost', '/xmlrpc/common', 8069 )
 
79
    user_id = socket.login( database, username, password )
 
80
 
 
81
Web-Services - Ruby - Search
 
82
----------------------------
 
83
 
 
84
.. sourcecode:: ruby
 
85
 
 
86
    socket = XMLRPC::Client.new( 'http://localhost', '/xmlrpc/object', 8069 )
 
87
    ids = socket.execute(
 
88
        database, user_id, password,
 
89
        'openacademy.lecturer', 'search', []
 
90
    )
 
91
    lecturers = socket.execute(
 
92
        database, user_id, password,
 
93
        'openacademy.lecturer', 'read', ['name', 'email']
 
94
    )
 
95
 
 
96
    for lecturer in lecturers:
 
97
        print "lecturer: %20s - %s" % [ lecturer['name'], lecturer['email'] ]
 
98