mirror of
https://gitflic.ru/project/santaspeen/gitflic.git
synced 2025-07-02 10:15:24 +00:00
1.0
This commit is contained in:
parent
ff604e5a61
commit
17b9e6acc8
@ -1,5 +1,5 @@
|
|||||||
__title__ = "gitflic"
|
__title__ = "gitflic"
|
||||||
__version__ = "0.0.1"
|
__version__ = "1.0"
|
||||||
__description__ = "GitflicApi wrapper"
|
__description__ = "GitflicApi wrapper"
|
||||||
__author__ = "SantaSpeen"
|
__author__ = "SantaSpeen"
|
||||||
__author_email__ = "dir@sssr.dev"
|
__author_email__ = "dir@sssr.dev"
|
||||||
|
@ -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:
|
class Gitflic:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, gf_session: GitflicAuth):
|
||||||
pass
|
"""
|
||||||
|
|
||||||
|
: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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user