NextCloud.get_connection_issues()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 3
nop 1
1
# -*- coding: utf-8 -*-
2
from .requester import OCSRequester, WebDAVRequester
3
from .api_wrappers import OCS_API_CLASSES, WEBDAV_CLASS
4
5
6
class NextCloud(object):
7
8
    def __init__(self, endpoint, user, password, json_output=True):
9
        self.user = user
10
        self.query_components = []
11
12
        ocs_requester = OCSRequester(endpoint, user, password, json_output)
13
        webdav_requester = WebDAVRequester(endpoint, user, password)
14
15
        self.functionality_classes = [api_class(ocs_requester) for api_class in OCS_API_CLASSES]
16
        self.functionality_classes.append(WEBDAV_CLASS(webdav_requester, json_output=json_output))
17
18
        for functionality_class in self.functionality_classes:
19
            for potential_method in dir(functionality_class):
20
                if(
21
                    potential_method.startswith('_')
22
                    or not callable(getattr(functionality_class, potential_method))
23
                ):
24
                    continue
25
                setattr(self, potential_method, getattr(functionality_class, potential_method))
26
27
    def get_connection_issues(self):
28
        """
29
        Return Falsy falue if everything is OK, or string representing
30
        the connection problem (bad hostname, password, whatever)
31
        """
32
        try:
33
            response = self.get_user(self.user)
34
        except Exception as e:
35
            return str(e)
36
37
        if not response.is_ok:
38
            return response.meta["message"]
39