Skip to content

add searchIn param to payload #95

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions newsapi/newsapi_client.py
Original file line number Diff line number Diff line change
@@ -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 <https://newsapi.org/docs/endpoints/everything>`_ 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 <https://newsapi.org/docs/endpoints/everything>`_ 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 <https://newsapi.org/sources>`_.
@@ -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):
5 changes: 5 additions & 0 deletions tests/test_newsapi_client.py
Original file line number Diff line number Diff line change
@@ -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