Skip to content

Commit

Permalink
ci: try to fix exclude
Browse files Browse the repository at this point in the history
  • Loading branch information
DraftProducts committed Jul 30, 2024
1 parent cb3e955 commit 8021c52
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ __pycache__/
dist/
poetry.lock
.env
.pytest_cache/
.pytest_cache/
.venv/
2 changes: 1 addition & 1 deletion blagues_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .main import BlaguesAPI, BlagueType, CountJoke, Blague
from .main import Blague, BlaguesAPI, BlagueType, CountJoke

__all__ = ["BlaguesAPI", "BlagueType", "CountJoke", "Blague"]
22 changes: 9 additions & 13 deletions blagues_api/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from enum import Enum
from typing import List

import aiohttp
import pydantic
from typing import List
from enum import Enum


class BlagueType(str, Enum):
Expand Down Expand Up @@ -31,41 +32,36 @@ class BlaguesAPI:
def __init__(self, token: str):
self.token = token
self.base_url = "https://www.blagues-api.fr/api"
self.headers = {'Authorization': f'Bearer {self.token}'}
self.headers = {"Authorization": f"Bearer {self.token}"}

async def _get(self, url: str, params: dict = None) -> dict:
async with aiohttp.ClientSession(raise_for_status=True) as session:
async with session.get(
self.base_url + url,
headers=self.headers,
params=params
self.base_url + url, headers=self.headers, params=params
) as resp:
return await resp.json()

async def random(self, *, disallow: List[str] = None) -> Blague:
endpoint = "/random"
params = {"disallow": disallow} if disallow else {}
data = await self._get(endpoint, params)

return Blague.model_validate(data)

return Blague.model_validate(data)

async def random_categorized(self, category: str) -> Blague:
endpoint = f"/type/{category}/random"
data = await self._get(endpoint)

return Blague.model_validate(data)

return Blague.model_validate(data)

async def from_id(self, id: int) -> Blague:
endpoint = f"/id/{id}"
data = await self._get(endpoint)

return Blague.model_validate(data)

async def count(self) -> CountJoke:
endpoint = "/count"
data = await self._get(endpoint)

return CountJoke.model_validate(data)

return CountJoke.model_validate(data)
5 changes: 3 additions & 2 deletions tests/test_blagues_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from dotenv import dotenv_values
from blagues_api import BlaguesAPI, BlagueType, CountJoke, Blague

from blagues_api import Blague, BlaguesAPI, BlagueType, CountJoke

pytestmark = pytest.mark.asyncio

Expand All @@ -11,6 +11,7 @@ def token():
env = dotenv_values(".env")
return env["TOKEN"]


@pytest.fixture
def client(token):
return BlaguesAPI(token)
Expand Down

0 comments on commit 8021c52

Please sign in to comment.