forked from go2sh/nextcloud-API
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
80 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |