From 10e5910a910963d5f1fd11bd242d8e358313e4cf Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Fri, 18 May 2018 08:29:55 +0200 Subject: [PATCH] Initial non-working version --- flask_matrix/__init__.py | 0 flask_matrix/base.py | 25 +++++++++++++++++++++++++ requirements.txt | 2 ++ 3 files changed, 27 insertions(+) create mode 100644 flask_matrix/__init__.py create mode 100644 flask_matrix/base.py create mode 100644 requirements.txt diff --git a/flask_matrix/__init__.py b/flask_matrix/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/flask_matrix/base.py b/flask_matrix/base.py new file mode 100644 index 0000000..3e4e9eb --- /dev/null +++ b/flask_matrix/base.py @@ -0,0 +1,25 @@ +class FlaskMatrix(object): + def __init__(self, app=None): + self.api = None + self.app = None + + if app: + self.init_app(app) + + def init_app(self, app): + app.config.setdefault('MATRIX_BASE_URL', None) + app.config.setdefault('MATRIX_USERNAME', None) + app.config.setdefault('MATRIX_PASSWORD', None) + app.config.setdefault('MATRIX_TOKEN', None) + + if app.config['MATRIX_USERNAME'] is None and app.config['MATRIX_PASSWORD'] is None \ + app.config['MATRIX_TOKEN'] is None: + raise ValueError('You must specify at least MATRIX_TOKEN or both MATRIX_USERNAME and MATRIX_PASSWORD') + + if app.config['MATRIX_BASE_URL'] is None: + raise ValueError('MATRD]IX_BASE_URL is not set!') + + self.username = app.config['MATRIX_USERNAME'] + self.password = app.config['MATRIX_PASSWORD'] + + self.client = MatrixHttpApi(app.config['MATRIX_BASE_URL'], token=app.config['MATRIX_TOKEN']) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..97f6f44 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask==0.12.2 +matrix-client==0.0.6