helloasso-paheko-adapter/helloasso_paheko_adapter/helloasso/__init__.py

44 lines
1.3 KiB
Python
Raw Normal View History

2023-11-06 10:14:16 +00:00
from requests_oauth2client import OAuth2Client, OAuth2ClientCredentialsAuth, ApiClient
class HelloassoAppClient:
def __init__(self, client_id, client_secret):
self.client_id = client_id
self.client_secret = client_secret
self.oauth2client = OAuth2Client(
token_endpoint="https://api.helloasso.com/oauth2/token",
client_id=self.client_id,
client_secret=self.client_secret
)
self.auth = OAuth2ClientCredentialsAuth(self.oauth2client)
self.client = ApiClient(
"https://api.helloasso.com/v5",
auth=self.auth
)
class HelloassoUserClient:
def __init__(self, email, password):
self.email = email
self.password = password
self.client = ApiClient(
"https://api.helloasso.com/v5",
headers = {"User-Agent": "Mozilla/5.0", "accept-language": "en-US,en"}
)
def login(self):
self.client.post("/auth/login", data={})
class Organization():
client: HelloassoClient
slug: str
def __init__(self, client, slug):
self.client = client
self.slug = slug
def list_payments(self):
res = self.client.client.get(f"/organizations/{self.slug}/payments")
# FIXME : ahndle pagination , cannot test right now because of not enought ppl
return res.json()