|
9 | 9 |
|
10 | 10 | from ._exceptions import check_error |
11 | 11 | from ._misc import check_capabilities, clear_from_params_empty, require_capabilities |
12 | | -from ._session import AsyncNcSessionBasic, NcSessionBasic |
| 12 | +from ._session import AsyncNcSessionBasic |
13 | 13 |
|
14 | 14 |
|
15 | 15 | @dataclasses.dataclass |
@@ -91,144 +91,6 @@ class NotesSettings(typing.TypedDict): |
91 | 91 | """Newly created note's files will have this file suffix. Default is **.txt**.""" |
92 | 92 |
|
93 | 93 |
|
94 | | -class _NotesAPI: |
95 | | - """Class implementing Nextcloud Notes API.""" |
96 | | - |
97 | | - _ep_base: str = "/index.php/apps/notes/api/v1" # without `index.php` we will get 405 error. |
98 | | - last_etag: str |
99 | | - """Used by ``get_list``, when **etag** param is ``True``.""" |
100 | | - |
101 | | - def __init__(self, session: NcSessionBasic): |
102 | | - self._session = session |
103 | | - self.last_etag = "" |
104 | | - |
105 | | - @property |
106 | | - def available(self) -> bool: |
107 | | - """Returns True if the Nextcloud instance supports this feature, False otherwise.""" |
108 | | - return not check_capabilities("notes", self._session.capabilities) |
109 | | - |
110 | | - def get_list( |
111 | | - self, |
112 | | - category: str | None = None, |
113 | | - modified_since: int | None = None, |
114 | | - limit: int | None = None, |
115 | | - cursor: str | None = None, |
116 | | - no_content: bool = False, |
117 | | - etag: bool = False, |
118 | | - ) -> list[Note]: |
119 | | - """Get information of all Notes. |
120 | | -
|
121 | | - :param category: Filter the result by category name. Notes with another category are not included in the result. |
122 | | - :param modified_since: When provided only results newer than given Unix timestamp are returned. |
123 | | - :param limit: Limit response to contain no more than the given number of notes. |
124 | | - If there are more notes, then the result is chunked and the HTTP response header |
125 | | - **X-Notes-Chunk-Cursor** is sent with a string value. |
126 | | -
|
127 | | - .. note:: Use :py:attr:`~nc_py_api.nextcloud.Nextcloud.response_headers` property to achieve that. |
128 | | - :param cursor: You should use the string value from the last request's HTTP response header |
129 | | - ``X-Notes-Chunk-Cursor`` in order to get the next chunk of notes. |
130 | | - :param no_content: Flag indicating should ``content`` field be excluded from response. |
131 | | - :param etag: Flag indicating should ``ETag`` from last call be used. Default = **False**. |
132 | | - """ |
133 | | - require_capabilities("notes", self._session.capabilities) |
134 | | - params = { |
135 | | - "category": category, |
136 | | - "pruneBefore": modified_since, |
137 | | - "exclude": "content" if no_content else None, |
138 | | - "chunkSize": limit, |
139 | | - "chunkCursor": cursor, |
140 | | - } |
141 | | - clear_from_params_empty(list(params.keys()), params) |
142 | | - headers = {"If-None-Match": self.last_etag} if self.last_etag and etag else {} |
143 | | - r = _res_to_json(self._session.adapter.get(self._ep_base + "/notes", params=params, headers=headers)) |
144 | | - self.last_etag = self._session.response_headers["ETag"] |
145 | | - return [Note(i) for i in r] |
146 | | - |
147 | | - def by_id(self, note: Note) -> Note: |
148 | | - """Get updated information about :py:class:`~nc_py_api.notes.Note`.""" |
149 | | - require_capabilities("notes", self._session.capabilities) |
150 | | - r = _res_to_json( |
151 | | - self._session.adapter.get( |
152 | | - self._ep_base + f"/notes/{note.note_id}", headers={"If-None-Match": f'"{note.etag}"'} |
153 | | - ) |
154 | | - ) |
155 | | - return Note(r) if r else note |
156 | | - |
157 | | - def create( |
158 | | - self, |
159 | | - title: str, |
160 | | - content: str | None = None, |
161 | | - category: str | None = None, |
162 | | - favorite: bool | None = None, |
163 | | - last_modified: int | str | datetime.datetime | None = None, |
164 | | - ) -> Note: |
165 | | - """Create new Note.""" |
166 | | - require_capabilities("notes", self._session.capabilities) |
167 | | - params = { |
168 | | - "title": title, |
169 | | - "content": content, |
170 | | - "category": category, |
171 | | - "favorite": favorite, |
172 | | - "modified": last_modified, |
173 | | - } |
174 | | - clear_from_params_empty(list(params.keys()), params) |
175 | | - return Note(_res_to_json(self._session.adapter.post(self._ep_base + "/notes", json=params))) |
176 | | - |
177 | | - def update( |
178 | | - self, |
179 | | - note: Note, |
180 | | - title: str | None = None, |
181 | | - content: str | None = None, |
182 | | - category: str | None = None, |
183 | | - favorite: bool | None = None, |
184 | | - overwrite: bool = False, |
185 | | - ) -> Note: |
186 | | - """Updates Note. |
187 | | -
|
188 | | - ``overwrite`` specifies should be or not the Note updated even if it was changed on server(has different ETag). |
189 | | - """ |
190 | | - require_capabilities("notes", self._session.capabilities) |
191 | | - headers = {"If-Match": f'"{note.etag}"'} if not overwrite else {} |
192 | | - params = { |
193 | | - "title": title, |
194 | | - "content": content, |
195 | | - "category": category, |
196 | | - "favorite": favorite, |
197 | | - } |
198 | | - clear_from_params_empty(list(params.keys()), params) |
199 | | - if not params: |
200 | | - raise ValueError("Nothing to update.") |
201 | | - return Note( |
202 | | - _res_to_json( |
203 | | - self._session.adapter.put(self._ep_base + f"/notes/{note.note_id}", json=params, headers=headers) |
204 | | - ) |
205 | | - ) |
206 | | - |
207 | | - def delete(self, note: int | Note) -> None: |
208 | | - """Deletes a Note.""" |
209 | | - require_capabilities("notes", self._session.capabilities) |
210 | | - note_id = note.note_id if isinstance(note, Note) else note |
211 | | - check_error(self._session.adapter.delete(self._ep_base + f"/notes/{note_id}")) |
212 | | - |
213 | | - def get_settings(self) -> NotesSettings: |
214 | | - """Returns Notes App settings.""" |
215 | | - require_capabilities("notes", self._session.capabilities) |
216 | | - r = _res_to_json(self._session.adapter.get(self._ep_base + "/settings")) |
217 | | - return {"notes_path": r["notesPath"], "file_suffix": r["fileSuffix"]} |
218 | | - |
219 | | - def set_settings(self, notes_path: str | None = None, file_suffix: str | None = None) -> None: |
220 | | - """Change specified setting(s).""" |
221 | | - if notes_path is None and file_suffix is None: |
222 | | - raise ValueError("No setting to change.") |
223 | | - require_capabilities("notes", self._session.capabilities) |
224 | | - params = { |
225 | | - "notesPath": notes_path, |
226 | | - "fileSuffix": file_suffix, |
227 | | - } |
228 | | - clear_from_params_empty(list(params.keys()), params) |
229 | | - check_error(self._session.adapter.put(self._ep_base + "/settings", json=params)) |
230 | | - |
231 | | - |
232 | 94 | class _AsyncNotesAPI: |
233 | 95 | """Class implements Async Nextcloud Notes API.""" |
234 | 96 |
|
|
0 commit comments