Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Small improvement #6

Merged
merged 3 commits into from
Nov 12, 2022
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ The above are then the methods available to you, for example:
>>> books_list['data'][0]['name']
'Mathematics'
```

And to POST you can follow this example:

```python
>>> api.post_books_create({'name': 'Sample Book', 'description': 'Sample Description', 'tags': [{ 'name': 'Sample-Name', 'value': 'Sample-Value' }] })
```
23 changes: 13 additions & 10 deletions src/bookstack/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,20 @@ def _get_api(self):

def _create_api_method(self, method_info):
def request_method(*args):
response = self._session.request(
method_info['method'],
method_info['uri'].format(*args)
) if method_info['method'] != "POST" else self._session.request(
method_info['method'],
method_info['uri'],
*args
)

uri = method_info['uri']
arg = args
if method_info['method'] != "POST":
try:
uri = uri.replace('{id}', str(args[0]['id']))
del arg[0]["id"]
except:
pass
response = self._session.request(method_info['method'], uri.format(arg))
if method_info['method'] == "POST" or method_info['method'] == "PUT":
self._session.request(method_info['method'], uri, json=arg[0])
else:
self._session.request(method_info['method'], uri.format(arg))
return self._get_response_content(response)

return request_method

@staticmethod
Expand Down