diff --git a/miniflux.py b/miniflux.py index fefd9a0..0b49bdb 100644 --- a/miniflux.py +++ b/miniflux.py @@ -128,8 +128,8 @@ def discover(self, website_url: str, **kwargs) -> Dict: return response.json() raise ClientError(response) - def get_category_feeds(self, feed_id: int) -> List[Dict]: - endpoint = self._get_endpoint(f"/categories/{feed_id}/feeds") + def get_category_feeds(self, category_id: int) -> List[Dict]: + endpoint = self._get_endpoint(f"/categories/{category_id}/feeds") response = requests.get( endpoint, headers=self._headers, auth=self._auth, timeout=self._timeout ) @@ -333,6 +333,29 @@ def get_categories(self) -> List[Dict]: return response.json() raise ClientError(response) + def get_category_entry(self, category_id: int, entry_id: int) -> Dict: + endpoint = self._get_endpoint(f"/categories/{category_id}/entries/{entry_id}") + response = requests.get( + endpoint, headers=self._headers, auth=self._auth, timeout=self._timeout + ) + if response.status_code == 200: + return response.json() + raise ClientError(response) + + def get_category_entries(self, category_id: int, **kwargs) -> Dict: + endpoint = self._get_endpoint(f"/categories/{category_id}/entries") + params = self._get_params(**kwargs) + response = requests.get( + endpoint, + headers=self._headers, + auth=self._auth, + params=params, + timeout=self._timeout, + ) + if response.status_code == 200: + return response.json() + raise ClientError(response) + def create_category(self, title: str) -> Dict: endpoint = self._get_endpoint("/categories") data = {"title": title} diff --git a/tests/test_client.py b/tests/test_client.py index e995df8..da2b274 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -510,6 +510,28 @@ def test_refresh_category(self): assert result == expected_result + def test_get_feed_entry(self): + requests = _get_request_mock() + expected_result = {} + + response = mock.Mock() + response.status_code = 200 + response.json.return_value = expected_result + + requests.get.return_value = response + + client = miniflux.Client("http://localhost", "username", "password") + result = client.get_feed_entry(123, 456) + + requests.get.assert_called_once_with( + "http://localhost/v1/feeds/123/entries/456", + headers=None, + auth=("username", "password"), + timeout=30, + ) + + assert result == expected_result + def test_get_feed_entries(self): requests = _get_request_mock() expected_result = [] @@ -874,6 +896,51 @@ def test_save_entry(self): ) assert result == expected_result + def test_get_category_entry(self): + requests = _get_request_mock() + expected_result = {} + + response = mock.Mock() + response.status_code = 200 + response.json.return_value = expected_result + + requests.get.return_value = response + + client = miniflux.Client("http://localhost", "username", "password") + result = client.get_category_entry(123, 456) + + requests.get.assert_called_once_with( + "http://localhost/v1/categories/123/entries/456", + headers=None, + auth=("username", "password"), + timeout=30, + ) + + assert result == expected_result + + def test_get_category_entries(self): + requests = _get_request_mock() + expected_result = [] + + response = mock.Mock() + response.status_code = 200 + response.json.return_value = expected_result + + requests.get.return_value = response + + client = miniflux.Client("http://localhost", "username", "password") + result = client.get_category_entries(123) + + requests.get.assert_called_once_with( + "http://localhost/v1/categories/123/entries", + headers=None, + auth=("username", "password"), + params=None, + timeout=30, + ) + + assert result == expected_result + def _get_request_mock(): patcher = mock.patch("miniflux.requests")