Skip to content

Commit a183969

Browse files
Update q param to take list of str (#85)
* Update client and utils so q can take list of strings * Bump version * Update error strings
1 parent 98b2755 commit a183969

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

newsapi/newsapi_client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
from newsapi import const
66
from newsapi.newsapi_auth import NewsApiAuth
77
from newsapi.newsapi_exception import NewsAPIException
8-
from newsapi.utils import is_valid_string, stringify_date_param
8+
from newsapi.utils import (
9+
is_valid_string, is_valid_string_or_list, stringify_date_param
10+
)
911

1012

1113
class NewsApiClient(object):
@@ -88,10 +90,10 @@ def get_top_headlines( # noqa: C901
8890

8991
# Keyword/Phrase
9092
if q is not None:
91-
if is_valid_string(q):
93+
if is_valid_string_or_list(q):
9294
payload["q"] = q
9395
else:
94-
raise TypeError("keyword/phrase q param should be of type str")
96+
raise TypeError("keyword/phrase q param should be of type str or list of type str")
9597

9698
# Keyword/Phrase in Title
9799
if qintitle is not None:
@@ -246,10 +248,10 @@ def get_everything( # noqa: C901
246248

247249
# Keyword/Phrase
248250
if q is not None:
249-
if is_valid_string(q):
251+
if is_valid_string_or_list(q):
250252
payload["q"] = q
251253
else:
252-
raise TypeError("keyword/phrase q param should be of type str")
254+
raise TypeError("keyword/phrase q param should be of type str or list of type str")
253255

254256
# Keyword/Phrase in Title
255257
if qintitle is not None:

newsapi/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ def validate_datetime_str(datetimestr):
5454

5555
if PY3:
5656

57+
def is_valid_string_or_list(var):
58+
if isinstance(var, list):
59+
return all((is_valid_string(item) for item in var))
60+
61+
else:
62+
return is_valid_string(var)
63+
5764
def is_valid_string(var):
5865
return isinstance(var, str)
5966

@@ -63,6 +70,13 @@ def is_valid_num(var):
6370

6471
elif PY2:
6572

73+
def is_valid_string_or_list(var):
74+
if isinstance(var, list):
75+
return all((is_valid_string(item) for item in var))
76+
77+
else:
78+
return is_valid_string(var)
79+
6680
def is_valid_string(var):
6781
return isinstance(var, basestring) # noqa
6882

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from setuptools import setup
1414

15-
VERSION = "0.2.6"
15+
VERSION = "0.2.7"
1616
INSTALL_REQUIRES = ["requests<3.0.0"]
1717
TESTS_REQUIRE = ["pytest"]
1818

0 commit comments

Comments
 (0)