forked from Dosugamea/NEXT-OCS-API-forPy
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring in order to ease creation of new wrappers outside this li…
…b (custom apps) + python2 compatibility + addition of a wrapper for SystemTags + some lints and documentation
- Loading branch information
Showing
34 changed files
with
1,398 additions
and
585 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
requests | ||
pytest | ||
requests>=2.0.1 | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,84 @@ | ||
# -*- coding: utf-8 -*- | ||
from .NextCloud import NextCloud | ||
from .session import Session | ||
from .api_wrappers import API_WRAPPER_CLASSES | ||
|
||
|
||
class NextCloud(object): | ||
""" | ||
A NextCloud/OwnCloud client. | ||
Provides cookie persistence, connection-pooling, and configuration. | ||
Basic Usage:: | ||
>>> from nextcloud import nextcloud | ||
>>> s = Nextcloud('https://nextcloud.mysite.com', user='admin', password='admin') | ||
>>> # or using use another auth method | ||
>>> from requests.auth import HTTPBasicAuth | ||
>>> s = Nextcloud('https://nextcloud.mysite.com', auth=HTTPBasicAuth('admin', 'admin')) | ||
>>> # | ||
>>> s.list_folders('/') | ||
<Response [200] data={} is_ok=True> | ||
For a persistent session:: | ||
>>> s.login() # if no user, password, or auth in parameter use existing | ||
>>> # some actions # | ||
>>> s.logout() | ||
Or as a context manager:: | ||
>>> with Nextcloud('https://nextcloud.mysite.com', | ||
... user='admin', password='admin') as nxc: | ||
... # some actions # | ||
""" | ||
|
||
def __init__(self, endpoint, user=None, password=None, json_output=True, auth=None, session_kwargs=None): | ||
self.query_components = [] | ||
self._session = Session( | ||
url=endpoint, user=user, password=password, auth=auth, | ||
session_kwargs=session_kwargs | ||
) | ||
self.json_output = json_output | ||
for functionality_class in API_WRAPPER_CLASSES: | ||
json_able = getattr(functionality_class, 'JSON_ABLE', False) | ||
require_client = getattr( | ||
functionality_class, 'REQUIRE_CLIENT', False) | ||
functionality_instance = functionality_class( | ||
self._session, | ||
json_output=(json_able and json_output), | ||
client=(require_client and self)) | ||
for potential_method in dir(functionality_instance): | ||
if not potential_method.startswith('_'): | ||
if not callable(getattr(functionality_instance, potential_method)): | ||
pass | ||
else: | ||
setattr(self, potential_method, getattr( | ||
functionality_instance, potential_method)) | ||
|
||
@property | ||
def user(self): | ||
return self._session.user | ||
|
||
@property | ||
def url(self): | ||
return self._session.url | ||
|
||
def __enter__(self): | ||
self.login() | ||
return self | ||
|
||
def __exit__(self, *args): | ||
self.logout() | ||
|
||
def login(self, user=None, password=None, auth=None): | ||
self.logout() | ||
self._session.login(user=user, password=password, auth=auth) | ||
|
||
def with_auth(self, auth=None, **kwargs): | ||
init_kwargs = {'session_kwargs': self._session._session_kwargs, | ||
'json_output': self.json_output} | ||
init_kwargs.update(kwargs) | ||
return (self.__class__)(self._session.url, auth=auth, **init_kwargs) | ||
|
||
def logout(self): | ||
if self._session.session: | ||
self._session.logout() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.