Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions NextCloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
7 changes: 7 additions & 0 deletions docs/source/NextCloud.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
NextCloud module
================

.. automodule:: NextCloud
:members:
:undoc-members:
:show-inheritance:
11 changes: 5 additions & 6 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 -----------------------------------------------------

Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Examples
========

Users API methods
-----------------

.. include:: ../../example.py
:literal:
11 changes: 3 additions & 8 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
46 changes: 46 additions & 0 deletions docs/source/introduction.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/EnterpriseyIntranet/nextcloud-API/issues>`_.




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`.



8 changes: 8 additions & 0 deletions docs/source/modules.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Nextcloud-API
=============

.. toctree::
:maxdepth: 4

NextCloud

38 changes: 29 additions & 9 deletions example.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ Enable NextCloud groupfolders application:

Run tests:

docker-compose run --rm python-api pytest
docker-compose run --rm python-api pytest

Run examples:

docker-compose run --rm python-api python examples.py