- Notifications
You must be signed in to change notification settings - Fork673
Open
Description
This shows how to usereclosedev/requests-cache and could be added to the FAQs. Want a PR?
importgitlabasglapiGITLAB_URL="https://…"classGitLab(glapi.Gitlab):""" GitLab API. * https://python-gitlab.readthedocs.io/en/stable/api/gitlab.html * https://docs.gitlab.com/ce/api/#resources """API_BASEURL=GITLAB_URLCACHE_EXPIRATION=2*60*60# secondsdef__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)withsession.cache_disabled():super().__init__(self.API_BASEURL,private_token=token,session=session)defauth(self):""" Performs a non-cached authentication. """withself.session.cache_disabled():returnsuper().auth()