forked from Dosugamea/NEXT-OCS-API-forPy
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathNextCloud.py
More file actions
38 lines (30 loc) · 1.42 KB
/
NextCloud.py
File metadata and controls
38 lines (30 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
from .requester import OCSRequester, WebDAVRequester
from .api_wrappers import OCS_API_CLASSES, WEBDAV_CLASS
class NextCloud(object):
def __init__(self, endpoint, user, password, json_output=True):
self.user = user
self.query_components = []
ocs_requester = OCSRequester(endpoint, user, password, json_output)
webdav_requester = WebDAVRequester(endpoint, user, password)
self.functionality_classes = [api_class(ocs_requester) for api_class in OCS_API_CLASSES]
self.functionality_classes.append(WEBDAV_CLASS(webdav_requester, json_output=json_output))
for functionality_class in self.functionality_classes:
for potential_method in dir(functionality_class):
if(
potential_method.startswith('_')
or not callable(getattr(functionality_class, potential_method))
):
continue
setattr(self, potential_method, getattr(functionality_class, potential_method))
def get_connection_issues(self):
"""
Return Falsy falue if everything is OK, or string representing
the connection problem (bad hostname, password, whatever)
"""
try:
response = self.get_user(self.user)
except Exception as e:
return str(e)
if not response.is_ok:
return response.meta["message"]