From 08814d6d9e152cc02e831ae47cfe66fbb670be5f Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Wed, 18 May 2016 15:54:28 -0600 Subject: [PATCH] Add simple API for getting OFXSources We'll use this in the API to show a list of accounts before adding a new one --- vanth/api/ofxsource.py | 22 ++++++++++++++++++++++ vanth/platform/ofxsource.py | 20 ++++++++++++++++++++ vanth/server.py | 8 +++++--- 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 vanth/api/ofxsource.py create mode 100644 vanth/platform/ofxsource.py diff --git a/vanth/api/ofxsource.py b/vanth/api/ofxsource.py new file mode 100644 index 0000000..3ef2c4b --- /dev/null +++ b/vanth/api/ofxsource.py @@ -0,0 +1,22 @@ +import sepiida.endpoints +import sepiida.fields + +import vanth.platform.ofxsource + + +class OFXSource(sepiida.endpoints.APIEndpoint): + ENDPOINT = '/ofxsource/' + SIGNATURE = sepiida.fields.JSONObject(s={ + 'name' : sepiida.fields.String(), + 'fid' : sepiida.fields.String(), + 'bankid' : sepiida.fields.String(), + 'uri' : sepiida.fields.URI('ofxsource'), + }) + @staticmethod + def list(): + return vanth.platform.ofxsource.by_filter({}) + + + @staticmethod + def get(uuid): + return vanth.platform.ofxsource.by_filter({'uuid': [str(uuid)]})[0] diff --git a/vanth/platform/ofxsource.py b/vanth/platform/ofxsource.py new file mode 100644 index 0000000..eca0b7d --- /dev/null +++ b/vanth/platform/ofxsource.py @@ -0,0 +1,20 @@ +import logging + +import chryso.connection +import sepiida.routing + +import vanth.tables + +LOGGER = logging.getLogger(__name__) + +def by_filter(filters): + engine = chryso.connection.get() + LOGGER.debug("Getting ofxsources by filter %s", filters) + query = vanth.tables.OFXSource.select() + results = engine.execute(query).fetchall() + return [{ + 'name' : result[vanth.tables.OFXSource.c.name], + 'fid' : result[vanth.tables.OFXSource.c.fid], + 'bankid' : result[vanth.tables.OFXSource.c.bankid], + 'uri' : sepiida.routing.uri('ofxsource', result[vanth.tables.OFXSource.c.uuid]), + } for result in results] diff --git a/vanth/server.py b/vanth/server.py index 7fdf962..8ce50f7 100644 --- a/vanth/server.py +++ b/vanth/server.py @@ -7,6 +7,7 @@ import sepiida.cors import sepiida.endpoints import vanth.api.about +import vanth.api.ofxsource import vanth.api.session import vanth.api.user import vanth.auth @@ -63,8 +64,9 @@ def create_app(config): app.route('/login/', methods=['GET', 'POST', 'DELETE'])(login) app.route('/logout/', methods=['POST'])(logout) - sepiida.endpoints.add_resource(app, vanth.api.about.About, endpoint='about') - sepiida.endpoints.add_resource(app, vanth.api.user.User, endpoint='user') - sepiida.endpoints.add_resource(app, vanth.api.session.Session, endpoint='session') + sepiida.endpoints.add_resource(app, vanth.api.about.About, endpoint='about') + sepiida.endpoints.add_resource(app, vanth.api.ofxsource.OFXSource, endpoint='ofxsource') + sepiida.endpoints.add_resource(app, vanth.api.session.Session, endpoint='session') + sepiida.endpoints.add_resource(app, vanth.api.user.User, endpoint='user') return app