CodeExchanger = require "../codeExchanger"

class CodeExchangerMW

    configure: ({app: app, callback: callback}) ->
        # loading and reading configuration variables
        Config = require "#{__dirname}/../config"
        Config.load()
        endPoint = Config.get "endPoint"
        clientId = Config.get "clientId"
        secret = Config.get "appSecret"
        instanceId = Config.get "instanceId"
        @codeExchanger = new CodeExchanger()
        @codeExchanger.init endPoint, clientId, secret, instanceId
        app.use(@codeExchanger.requestsHandler())

        callback()

module.exports = CodeExchangerMW
