(self, credentials: BundleCredentials)
| 6 | |
| 7 | class NewsApi(BundleHandler): |
| 8 | async def verify(self, credentials: BundleCredentials): |
| 9 | country: str = "us" |
| 10 | category: str = "business" |
| 11 | count: int = 10 |
| 12 | |
| 13 | news_api_key: str = credentials.credentials.get("NEWS_API_API_KEY") |
| 14 | |
| 15 | url = ( |
| 16 | f"https://newsapi.org/v2/top-headlines?country={country}&apiKey={news_api_key}&pageSize={count}&page=1" |
| 17 | + (f"&category={category}" if category else "") |
| 18 | ) |
| 19 | |
| 20 | if category is not None and category not in [ |
| 21 | "business", |
| 22 | "entertainment", |
| 23 | "general", |
| 24 | "health", |
| 25 | "science", |
| 26 | "sports", |
| 27 | "technology", |
| 28 | ]: |
| 29 | raise_http_error(ErrorCode.REQUEST_VALIDATION_ERROR, "Invalid category") |
| 30 | |
| 31 | async with ClientSession() as session: |
| 32 | async with session.get(url=url, proxy=CONFIG.PROXY) as response: |
| 33 | if response.status == 200: |
| 34 | pass |
| 35 | else: |
| 36 | raise_credentials_validation_error() |
nothing calls this directly
no test coverage detected