diff --git a/newsapi/newsapi_client.py b/newsapi/newsapi_client.py index 6d32037..68dd620 100644 --- a/newsapi/newsapi_client.py +++ b/newsapi/newsapi_client.py @@ -178,6 +178,7 @@ def get_everything( # noqa: C901 self, q=None, qintitle=None, + searchIn=None, sources=None, domains=None, exclude_domains=None, @@ -200,6 +201,10 @@ def get_everything( # noqa: C901 `documentation `_ for search syntax and examples. :type q: str or None + :param searchIn: The fields to restrict your q search to. Should be either title, content, or description. See the official News API + `documentation `_ for search syntax and examples. + :type q: str or None + :param sources: A comma-seperated string of identifiers for the news sources or blogs you want headlines from. Use :meth:`NewsApiClient.get_sources` to locate these programmatically, or look at the `sources index `_. @@ -262,6 +267,16 @@ def get_everything( # noqa: C901 else: raise TypeError("keyword/phrase qintitle param should be of type str") + # SearchIn + if searchIn is not None: + if is_valid_string(searchIn): + if searchIn in ["title", "content", "description"]: + payload["searchIn"] = searchIn + else: + raise ValueError( + f"searchIn param should be either title, content, or description. {searchIn} is given. " + ) + # Sources if sources is not None: if is_valid_string(sources): diff --git a/tests/test_newsapi_client.py b/tests/test_newsapi_client.py index e04dff9..e382f99 100644 --- a/tests/test_newsapi_client.py +++ b/tests/test_newsapi_client.py @@ -146,6 +146,11 @@ def test_api_get_everything(self): with self.assertRaises(ValueError): self.api.get_everything(page=page) + # Raises a ValueError if searchIn param is not equal to either title, description, or content + searchIn = "date" + with self.assertRaises(ValueError): + self.api.get_everything(searchIn=searchIn) + def test_api_get_sources(self): # Raise TypeError if language param is not of type str language = 0