Open
Description
This shows how to use reclosedev/requests-cache and could be added to the FAQs. Want a PR?
import gitlab as glapi
GITLAB_URL = "https://…"
class GitLab(glapi.Gitlab):
""" GitLab API.
* https://python-gitlab.readthedocs.io/en/stable/api/gitlab.html
* https://docs.gitlab.com/ce/api/#resources
"""
API_BASEURL = GITLAB_URL
CACHE_EXPIRATION = 2 * 60 * 60 # seconds
def __init__(self):
account, token = security.Credentials(self.API_BASEURL).auth_pair()
session = requests_cache.CachedSession(
cache_name=config.cache_file(type(self).__name__),
expire_after=self.CACHE_EXPIRATION)
with session.cache_disabled():
super().__init__(self.API_BASEURL, private_token=token, session=session)
def auth(self):
""" Performs a non-cached authentication.
"""
with self.session.cache_disabled():
return super().auth()