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