Skip to content

Commit 15de8fc

Browse files
committed
init authenticate
1 parent 9841c86 commit 15de8fc

File tree

7 files changed

+57
-0
lines changed

7 files changed

+57
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ instance/
6868
# Scrapy stuff:
6969
.scrapy
7070

71+
#vscode
72+
.vscode
73+
7174
# Sphinx documentation
7275
docs/_build/
7376

odooapiclient/__init__.py

Whitespace-only changes.

odooapiclient/auth.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
import logging
3+
import xmlrpc.client
4+
5+
_logger = logging.getLogger(__name__)
6+
7+
8+
class Connection(object):
9+
10+
def __init__(self, url):
11+
self._url = url
12+
self._common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(self._url))
13+
14+
def trasmit(self, method, *args, **kwargs):
15+
try:
16+
response = getattr(self._common, method)(*args)
17+
_logger.info("Response of method '{}' ⭢ {}".format(method, response))
18+
return response
19+
except xmlrpc.client.ProtocolError as err:
20+
_logger.error(err)
21+
22+
def authenticate(self, db, user, password, session={}):
23+
response = self.trasmit('authenticate', db, user, password, session)
24+
return response

odooapiclient/client.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import auth
2+
3+
4+
class Client(object):
5+
6+
def __init__(self, protocol='http', host='localhost', port=8069, dbname=None, ssl=False):
7+
if ssl:
8+
protocol, port = 'https', 443
9+
10+
self._host = host
11+
self._port = port
12+
self._db = dbname
13+
self._protocol = protocol
14+
15+
self._url = "{protocol}://{host}:{port}".format(
16+
protocol=self._protocol,
17+
host=self._host,
18+
port=self._port
19+
)
20+
21+
def authenticate(self, login, pwd):
22+
self._login, self._password = login, pwd
23+
service = auth.Connection(self._url)
24+
self._uid = service.authenticate(self._db, login, pwd, {})
25+
return self._uid

samples/README.md

Whitespace-only changes.

samples/__init__.py

Whitespace-only changes.

samples/example.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from odooapiclient.client import Client
2+
3+
4+
client = Client(host='andriisem.odoo.com', dbname='andriisem', saas=True)
5+
client.authenticate(login='semko.andrey.i@gmail.com', pwd='audi100')

0 commit comments

Comments
 (0)