#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import, unicode_literals


from flask import Flask

from .middleware.me import me
from .middleware import github, keybase, medium
from .cache import cache


def create_app(config):
    app = Flask(__name__)
    app.config.from_object(config)
    cache.init_app(app)

    modules = config.modules['modules']
    blueprints = {
        'github': github.github_api,
        'keybase': keybase.keybase_api,
        'medium': medium.medium_api
    }

    app.register_blueprint(me)
    for module in modules.keys():
        app.register_blueprint(blueprints[module])

    return app

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import, unicode_literals


from flask import Flask

from .middleware.me import me
from .cache import cache


def _register_module(app, module):
    if module == 'github':
        from .middleware import github
        app.register_blueprint(github.github_api)
    elif module == 'keybase':
        from .middleware import keybase
        app.register_blueprint(keybase.keybase_api)
    elif module == 'medium':
        from .middleware import medium
        app.register_blueprint(medium.medium_api)


def create_app(config):
    app = Flask(__name__)
    app.config.from_object(config)
    cache.init_app(app)

    modules = config.modules['modules']
    app.register_blueprint(me)
    for module in modules.keys():
        _register_module(app, module)

    return app

Fix giant bug: crash when don't config all modules
Fix giant bug: crash when don't config all modules

that's bacause you import all the modules
> from .middleware import github, keybase, medium
while each module need to get configurations from modules.json, e.g.
> config = Config.modules['modules']['github']
but can't get anything at all, so it will crash.

that's not the correct behaviour, so we just import the desired module
and then register it. The solution isn't very elegant.
