Added WrapperError class

This commit is contained in:
spla 2022-10-03 11:58:02 +02:00
pare e5bc961f4e
commit ebb75401a1

Veure arxiu

@ -1,25 +1,12 @@
import requests
import json
import uuid
from typing import (
Optional,
Any,
Union,
List,
Tuple,
Set,
)
from urllib.parse import urlparse, urlencode
import pdb
class MisskeyAPI:
name = 'Python Wrapper for Misskey API'
__DEFAULT_BASE_URL = 'https://mk.catala.digital'
__CALLBACK = f'{__DEFAULT_BASE_URL}/callback'
__DEFAULT_TIMEOUT = 300
__DEFAULT_SCOPES = ['read', 'write']
__SCOPE_SETS = [
'read:account',
'read:blocks',
@ -56,16 +43,20 @@ class MisskeyAPI:
def __init__(
self,
api_base_url=__DEFAULT_BASE_URL,
callback=__CALLBACK,
permission=__SCOPE_SETS,
name: str = 'login',
request_timeout=__DEFAULT_TIMEOUT,
session=None,
api_base_url = None,
callback = None,
permission = __SCOPE_SETS,
name: str = None,
request_timeout = __DEFAULT_TIMEOUT,
session = None,
):
self.api_base_url = api_base_url
self.callback = callback
if self.api_base_url == None:
raise WrapperError("A Misskey instance's URL is required!")
if self.api_base_url != None:
self.callback = f'{self.api_base_url}/callback'
self.permission = permission
self.request_timeout = request_timeout
@ -106,7 +97,6 @@ class MisskeyAPI:
response = ret.json()
else:
response = requests.post(self.api_base_url + '/api/app/create', json=params, timeout=self.request_timeout)
#response = response.json()
except Exception as e:
@ -115,7 +105,7 @@ class MisskeyAPI:
return response
def app_show(self, app_id=None, session=None):
params = {
'appId': app_id
}
@ -273,6 +263,9 @@ class MisskeyAPI:
##
# Exceptions
##
class WrapperError(Exception):
"""Wrapper base class"""
class MisskeyAPIConfigError(Exception):
"""This class exception"""