object_interface.py 1.42 KB
Newer Older
jens.kleineheismann's avatar
jens.kleineheismann committed
1
2
"""This module contain the ObjectInterface class."""

3
4
5
6
7
from .clients import RestClient
from .models import Group, Oe, User


class ObjectInterface(object):
jens.kleineheismann's avatar
jens.kleineheismann committed
8
9
    """Object oriented interface to the KIT Gruppenverwaltung API"""

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    class Config(object):
        def __init__(self, provider):
            self.provider = provider

        def auth(self, username, password):
            self.provider.client.config.username = username
            self.provider.client.config.password = password

        def enable_post(self):
            self.provider.client.config.enable_post = True

        def disable_post(self):
            self.provider.client.config.enable_post = False

        def enable_delete(self):
            self.provider.client.config.enable_delete = True

        def disable_delete(self):
            self.provider.client.config.enable_delete = False

    def __init__(self, client=None, client_config=None):
        self.config = self.Config(self)
jens.kleineheismann's avatar
jens.kleineheismann committed
32

33
34
35
36
37
38
39
        if client is None:
            self.client = RestClient(config=client_config)
        else:
            self.client = client

    def getOe(self, pk):
        return Oe(client=self.client, pk=pk)
jens.kleineheismann's avatar
jens.kleineheismann committed
40

41
42
    def getGroup(self, pk):
        return Group(client=self.client, pk=pk)
jens.kleineheismann's avatar
jens.kleineheismann committed
43

44
45
    def newGroup(self, name, description):
        raise NotImplementedError("Use kitgvapi.models.Oe.create_group() instead.")
jens.kleineheismann's avatar
jens.kleineheismann committed
46

47
48
    def getUser(self, pk):
        return User(client=self.client, pk=pk)