platform login is working
This commit is contained in:
parent
44a04f451e
commit
93bd81ecea
8 changed files with 174 additions and 32 deletions
|
@ -2,21 +2,53 @@ import logging
|
|||
|
||||
from aiohttp import ClientSession, ClientResponse
|
||||
|
||||
from resa_padel.gestion_sports_payload_builder import GestionSportsPayloadBuilder
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
HEADERS = {
|
||||
"Connection": "keep-alive",
|
||||
"Accept-Language": "en-US,en;q=0.5",
|
||||
"Accept-Encoding": "gzip, deflate, br",
|
||||
"DNT": "1",
|
||||
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||
"Accept": "application/json, text/javascript, */*; q=0.01",
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
"Sec-Fetch-Dest": "empty",
|
||||
"Sec-Fetch-Mode": "cors",
|
||||
"Sec-Fetch-Site": "same-origin",
|
||||
}
|
||||
|
||||
|
||||
class GestionSportsConnector:
|
||||
|
||||
def __init__(self, url: str):
|
||||
def __init__(self, session: ClientSession, url: str):
|
||||
LOGGER.info("Initializing connection to GestionSports API")
|
||||
self.url = url
|
||||
self.session = ClientSession()
|
||||
self.session = session
|
||||
self.payload_builder = GestionSportsPayloadBuilder()
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.session.close()
|
||||
|
||||
async def connect(self) -> ClientResponse:
|
||||
LOGGER.info("Connecting to GestionSports API")
|
||||
async with self.session.get(self.url) as response:
|
||||
connection_url = self.url + "/connexion.php?"
|
||||
async with self.session.get(connection_url) as response:
|
||||
await response.text()
|
||||
return response
|
||||
|
||||
async def login(self, user: str, password: str, club_id: str) -> ClientResponse:
|
||||
payload = (
|
||||
self.payload_builder.login(user)
|
||||
.password(password)
|
||||
.club_id(club_id)
|
||||
.build_login_payload()
|
||||
)
|
||||
|
||||
login_url = f"{self.url}/connexion.php?"
|
||||
|
||||
async with self.session.post(
|
||||
login_url, data=payload, headers=HEADERS
|
||||
) as response:
|
||||
await response.text()
|
||||
return response
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue