Skip to content

Commit

Permalink
forms app: add wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
loelkes committed Oct 8, 2020
1 parent 4fd4031 commit 9d8ab72
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/nextcloud/api_wrappers/__init__.py
Expand Up @@ -10,8 +10,9 @@
from .user import User
from .user_ldap import UserLDAP
from .webdav import WebDAV
from .forms import Forms

OCS_API_CLASSES = [Activity, Apps, Capabilities, FederatedCloudShare, Group, GroupFolders,
OCS_API_CLASSES = [Activity, Apps, Capabilities, FederatedCloudShare, Forms, Group, GroupFolders,
Notifications, Share, User, UserLDAP]

WEBDAV_CLASS = WebDAV
78 changes: 78 additions & 0 deletions src/nextcloud/api_wrappers/forms.py
@@ -0,0 +1,78 @@
# -*- coding: utf-8 -*-
from nextcloud.base import WithRequester
import json

class Forms(WithRequester):

API_URL = "/ocs/v2.php/apps/forms/api/v1"
SUCCESS_CODE = 200

"""Deal the the API for the Forms app.
The App does not return OCS compliant responses. Until this is fixed, this wrapped aims to
implement an OCS-like behaviour for the Forms App API.
This is a work in progress.
"""

def get_forms(self):
"""Return a list of all configured forms"""

json_ouput_state = self._requester.json_output
self._requester.json_output = False # Disbale temporarly

response = self.requester.get('forms')

try:
# Why not return {'forms' [...]} like for submissions?
response.data = {'forms': json.loads(response.data)}
except json.JSONDecodeError:
response.is_ok = False
response.data = {'message': 'Unable to parse JSON response'}
else:
response.is_ok = True

self._requester.json_output = json_ouput_state # Set previous state

return response

def get_form(self, form_id):
"""Return an individual form"""

json_ouput_state = self._requester.json_output
self._requester.json_output = False # Disbale temporarly

response = self.requester.get(f'form/{form_id}')

try:
response.data = json.loads(response.data)
except json.JSONDecodeError:
response.is_ok = False
response.data = {'message': 'Unable to parse JSON response'}
else:
response.is_ok = True

self._requester.json_output = json_ouput_state # Set previous state

return response

def get_form_submissions(self, submission_hash):
"""Return an individual form submission"""

json_ouput_state = self._requester.json_output
self._requester.json_output = False # Disbale temporarly

response = self.requester.get(f'submissions/{submission_hash}')

try:
response.data = json.loads(response.data)
except json.JSONDecodeError:
response.is_ok = False
response.data = {'message': 'Unable to parse JSON response'}
else:
response.is_ok = True

self._requester.json_output = json_ouput_state # Set previous state

return response

0 comments on commit 9d8ab72

Please sign in to comment.