diff --git a/NextCloud.py b/NextCloud.py index a455a9a..b263bed 100644 --- a/NextCloud.py +++ b/NextCloud.py @@ -77,10 +77,10 @@ def nextcloud_method(method_to_wrap): class NextCloud(object): - def __init__(self, endpoint, user, passwd, js=False): + def __init__(self, endpoint, user, password, js=False): self.query_components = [] - requester = Requester(endpoint, user, passwd, js) + requester = Requester(endpoint, user, password, js) self.functionality = { "Apps": Apps(requester), diff --git a/docs/source/NextCloud.rst b/docs/source/NextCloud.rst new file mode 100644 index 0000000..0c3c883 --- /dev/null +++ b/docs/source/NextCloud.rst @@ -0,0 +1,7 @@ +NextCloud module +================ + +.. automodule:: NextCloud + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/conf.py b/docs/source/conf.py index 6ff36a7..a137b07 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -12,10 +12,9 @@ # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # -# import os -# import sys -# sys.path.insert(0, os.path.abspath('.')) - +import os +import sys +sys.path.insert(0, os.path.abspath('../../')) # -- Project information ----------------------------------------------------- @@ -39,7 +38,7 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.doctest', + 'sphinx.ext.doctest', 'sphinx.ext.autodoc', 'sphinx.ext.napoleon', ] # Add any paths that contain templates here, relative to this directory. @@ -75,7 +74,7 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'alabaster' +html_theme = 'default' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the diff --git a/docs/source/examples.rst b/docs/source/examples.rst new file mode 100644 index 0000000..b759f98 --- /dev/null +++ b/docs/source/examples.rst @@ -0,0 +1,8 @@ +Examples +======== + +Users API methods +----------------- + +.. include:: ../../example.py + :literal: diff --git a/docs/source/index.rst b/docs/source/index.rst index 81079d3..6882c3e 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -5,11 +5,6 @@ Welcome to nextcloud-API's documentation! :maxdepth: 2 :caption: Contents: - - -Indices and tables -================== - -* :ref:`genindex` -* :ref:`modindex` -* :ref:`search` + introduction + examples + modules \ No newline at end of file diff --git a/docs/source/introduction.rst b/docs/source/introduction.rst new file mode 100644 index 0000000..ddf0df8 --- /dev/null +++ b/docs/source/introduction.rst @@ -0,0 +1,46 @@ +Introduction +============ + +Nextcloud-API is Python (2 and 3) wrapper for NextCloud's API. With it you can manage your +NextCloud instances from Python scripts. + +If you have any question, remark or if you find a bug, don't hesitate to +`open an issue `_. + + + + +Quick start +----------- + +First, create your NextCloud instance: + +.. include:: ../../example.py + :literal: + :end-before: # Quick start + +Then you can work with NextCloud objects: + +.. include:: ../../example.py + :literal: + :start-after: # Quick start + :end-before: # End quick start + +Download and install +-------------------- + +TBD + +License +------- + +Nextcloud-API is licensed under the GNU General Public License v3.0. + + +What's next ? +------------- + +Check :doc:`examples` and :doc:`modules`. + + + diff --git a/docs/source/modules.rst b/docs/source/modules.rst new file mode 100644 index 0000000..dc5731f --- /dev/null +++ b/docs/source/modules.rst @@ -0,0 +1,8 @@ +Nextcloud-API +============= + +.. toctree:: + :maxdepth: 4 + + NextCloud + diff --git a/example.py b/example.py index 2591939..67b3e58 100644 --- a/example.py +++ b/example.py @@ -1,13 +1,33 @@ +import os + import NextCloud -import json -url = "INPUT_YOUR_CLOUD" -userid = "INPUT_YOUR_USERNAME" -passwd = "INPUT_YOUR_PASSWORD" +NEXTCLOUD_URL = "http://{}:80".format(os.environ['NEXTCLOUD_HOST']) +NEXTCLOUD_USERNAME = os.environ.get('NEXTCLOUD_USERNAME') +NEXTCLOUD_PASSWORD = os.environ.get('NEXTCLOUD_PASSWORD') + +# True if you want to get response as JSON +# False if you want to get response as XML +to_js = True + +nxc = NextCloud.NextCloud(endpoint=NEXTCLOUD_URL, user=NEXTCLOUD_USERNAME, password=NEXTCLOUD_PASSWORD, js=to_js) + +# Quick start +nxc.get_users() +new_user_id = "new_user_username" +add_user_res = nxc.add_user(new_user_id, "new_user_password321_123") +group_name = "new_group_name" +add_group_res = nxc.add_group(group_name) +add_to_group_res = nxc.add_to_group(new_user_id, group_name) +# End quick start -#True if you want to get response as JSON -#False if you want to get response as XML -tojs = True +assert add_group_res['ocs']['meta']['statuscode'] == 100 +assert new_user_id in nxc.get_group(group_name)['ocs']['data']['users'] +assert add_user_res['ocs']['meta']['statuscode'] == 100 +assert add_to_group_res['ocs']['meta']['statuscode'] == 100 -nxc = NextCloud.NextCloud(url, userid, passwd, tojs) -print(nxc.get_users()) +# remove user +remove_user_res = nxc.delete_user(new_user_id) +assert remove_user_res['ocs']['meta']['statuscode'] == 100 +user_res = nxc.get_user(new_user_id) +assert user_res['ocs']['meta']['statuscode'] == 404 diff --git a/tests/README.md b/tests/README.md index 647d430..3173c1a 100644 --- a/tests/README.md +++ b/tests/README.md @@ -15,4 +15,8 @@ Enable NextCloud groupfolders application: Run tests: - docker-compose run --rm python-api pytest \ No newline at end of file + docker-compose run --rm python-api pytest + +Run examples: + + docker-compose run --rm python-api python examples.py