Skip to content

Commit 6536f16

Browse files
authored
Merge pull request #73 from emergentmethods/async-get-articles
fix: Use query for article_ids and add async
2 parents 3911d11 + d39e636 commit 6536f16

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

asknews_sdk/api/news.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ def get_articles(
6060
response = self.client.request(
6161
method="GET",
6262
endpoint="/v1/news",
63-
params={"article_ids": article_ids},
63+
query={"article_ids": article_ids},
6464
headers=http_headers,
6565
accept=[(ArticleResponse.__content_type__, 1.0)],
6666
)
67-
return ArticleResponse.model_validate(response.content)
67+
return [ArticleResponse.model_validate(item) for item in response.content]
6868

6969
def search_news(
7070
self,
@@ -370,6 +370,30 @@ async def get_article(
370370
)
371371
return ArticleResponse.model_validate(response.content)
372372

373+
async def get_articles(
374+
self, article_ids: Union[List[str], List[UUID]], *, http_headers: Optional[Dict] = None
375+
) -> List[ArticleResponse]:
376+
"""
377+
Get news articles by their UUIDs.
378+
379+
https://docs.asknews.app/en/reference#get-/v1/news
380+
381+
:param article_ids: The UUIDs of the articles.
382+
:type article_ids: Union[List[str], List[UUID]]
383+
:param http_headers: Additional HTTP headers.
384+
:type http_headers: Optional[Dict]
385+
:return: The articles response.
386+
:rtype: List[ArticleResponse]
387+
"""
388+
response = await self.client.request(
389+
method="GET",
390+
endpoint="/v1/news",
391+
query={"article_ids": article_ids},
392+
headers=http_headers,
393+
accept=[(ArticleResponse.__content_type__, 1.0)],
394+
)
395+
return [ArticleResponse.model_validate(item) for item in response.content]
396+
373397
async def search_news(
374398
self,
375399
query: str = "",

0 commit comments

Comments
 (0)