34 lines
986 B
Python
34 lines
986 B
Python
|
import requests
|
||
|
from . import settings
|
||
|
|
||
|
class API:
|
||
|
def __init__(self, prefix, params={}):
|
||
|
self.prefix=prefix
|
||
|
self.default_params=params
|
||
|
|
||
|
def get(self, url, *args, **kwargs):
|
||
|
params = kwargs.get('params', {})
|
||
|
for k,v in self.default_params.items():
|
||
|
if k not in params:
|
||
|
params[k] = v
|
||
|
kwargs['params'] = params
|
||
|
|
||
|
return requests.get(self.prefix + url, *args, **kwargs)
|
||
|
|
||
|
def post(self, url, *args, **kwargs):
|
||
|
params = kwargs.get('params', {})
|
||
|
for k,v in self.default_params.items():
|
||
|
if k not in params:
|
||
|
params[k] = v
|
||
|
kwargs['params'] = params
|
||
|
|
||
|
return requests.post(self.prefix + url, *args, **kwargs)
|
||
|
|
||
|
class GiteaAPI(API):
|
||
|
def __init__(self, token):
|
||
|
super().__init__(settings.GITEA_API, {'token': token})
|
||
|
|
||
|
class GitlabAPI(API):
|
||
|
def __init__(self, token):
|
||
|
super().__init__(settings.GITLAB_API, {'private_token': token})
|