|
3 | 3 | handy getter methods, but otherwise you can just use a .json property to access the |
4 | 4 | raw json passed back by the client. |
5 | 5 | """ |
6 | | -from typing import Any, Dict, Optional, Callable |
| 6 | +from typing import Any, Dict, Optional, Callable, Union |
7 | 7 | from urllib.parse import quote_plus |
8 | 8 |
|
9 | 9 | from feedly.protocol import APIClient |
@@ -197,21 +197,53 @@ def _get_category_or_tag(self, stream_id:StreamIdBase, cache:Dict[str,Streamable |
197 | 197 |
|
198 | 198 | return factory({'id': stream_id.id}, self._client) |
199 | 199 |
|
200 | | - def get_category(self, name:str): |
201 | | - id_ = UserStreamId(parts=[STREAM_SOURCE_USER, self.id, 'category', name]) |
| 200 | + def get_category(self, key:Union[str, UserStreamId]): |
| 201 | + """ |
| 202 | + :param key: the id of the category (e.g. "recipes"), or stream ID object |
| 203 | + :return: the category |
| 204 | + """ |
| 205 | + if isinstance(key, str): |
| 206 | + id_ = UserStreamId(parts=[STREAM_SOURCE_USER, self.id, 'category', key]) |
| 207 | + else: |
| 208 | + id_ = key |
202 | 209 |
|
203 | 210 | return self._get_category_or_tag(id_, self._categories, UserCategory, False) |
204 | 211 |
|
205 | | - def get_tag(self, name:str) -> 'UserTag': |
206 | | - id_ = UserStreamId(parts=[STREAM_SOURCE_USER, self.id, 'tag', name]) |
| 212 | + def get_tag(self, key:Union[str, UserStreamId]) -> 'UserTag': |
| 213 | + """ |
| 214 | + :param key: the id of the tag (e.g. "recipes"), or stream ID object |
| 215 | + :return: the category |
| 216 | + """ |
| 217 | + if isinstance(key, str): |
| 218 | + id_ = UserStreamId(parts=[STREAM_SOURCE_USER, self.id, 'tag', key]) |
| 219 | + else: |
| 220 | + id_ = key |
207 | 221 |
|
208 | 222 | return self._get_category_or_tag(id_, self._tags, UserTag, True) |
209 | 223 |
|
210 | | - def get_enterprise_category(self, stream_id:EnterpriseStreamId) -> 'EnterpriseCategory': |
211 | | - return self._get_category_or_tag(stream_id, self._tags, EnterpriseCategory, False) |
212 | | - |
213 | | - def get_enterprise_tag(self, stream_id:EnterpriseStreamId) -> 'EnterpriseTag': |
214 | | - return self._get_category_or_tag(stream_id, self._tags, EnterpriseTag, False) |
| 224 | + def get_enterprise_category(self, key:Union[str, EnterpriseStreamId]) -> 'EnterpriseCategory': |
| 225 | + """ |
| 226 | + :param key: the UUID of the category (dash separated hex numbers), or a stream ID object) |
| 227 | + :return: the category |
| 228 | + """ |
| 229 | + if isinstance(key, str): |
| 230 | + id_ = EnterpriseStreamId(parts=[STREAM_SOURCE_ENTERPRISE, self.enterprise_name, 'category', key]) |
| 231 | + else: |
| 232 | + id_ = key |
| 233 | + |
| 234 | + return self._get_category_or_tag(id_, self._enterprise_categories, EnterpriseCategory, False) |
| 235 | + |
| 236 | + def get_enterprise_tag(self, key:Union[str, EnterpriseStreamId]) -> 'EnterpriseTag': |
| 237 | + """ |
| 238 | + :param key: the UUID of the tag (dash separated hex numbers), or a stream ID object) |
| 239 | + :return: the category |
| 240 | + """ |
| 241 | + if isinstance(key, str): |
| 242 | + id_ = EnterpriseStreamId(parts=[STREAM_SOURCE_ENTERPRISE, self.enterprise_name, 'tag', key]) |
| 243 | + else: |
| 244 | + id_ = key |
| 245 | + |
| 246 | + return self._get_category_or_tag(id_, self._enterprise_tags, EnterpriseTag, False) |
215 | 247 |
|
216 | 248 |
|
217 | 249 |
|
0 commit comments