This commit is contained in:
Maxim Khomutov 2022-03-16 02:08:16 +03:00
parent ff604e5a61
commit 17b9e6acc8
2 changed files with 41 additions and 5 deletions

View File

@ -1,5 +1,5 @@
__title__ = "gitflic"
__version__ = "0.0.1"
__version__ = "1.0"
__description__ = "GitflicApi wrapper"
__author__ = "SantaSpeen"
__author_email__ = "dir@sssr.dev"

View File

@ -1,9 +1,45 @@
import requests
from .auth import GitflicAuth
from .exceptions import NotFound, NoRights, GitflicExceptions
API_URL = 'https://api.gitflic.ru/'
API_URL = 'https://api.gitflic.ru'
class Gitflic:
def __init__(self):
pass
def __init__(self, gf_session: GitflicAuth):
"""
:param gf_session:
"""
self.session = gf_session.session
@staticmethod
def _response_handler(response):
code = response.status_code
if code == 200:
return response.json()
url = response.url
if code == 403:
raise NoRights(f"No rights for '{url}'")
elif code == 404:
raise NotFound(f"Response '{url}' not found")
raise GitflicExceptions(f"Gitflic send error: {code}. {response.text}")
def call(self, method, *args, **kwargs):
"""
:param method:
:param args:
:param kwargs:
:return:
"""
response = self.session.get(API_URL + method, *args, **kwargs)
return self._response_handler(response)
def reg_call(self, method: str):
l = lambda *_args, **_kwargs: self.call(method, *_args, **_kwargs)
l.__name__ = method.replace("/", "_")
return l