# Path: honeybadger/contrib/flask.py
# class FlaskHoneybadger(object):
#     """
#     Flask extension for Honeybadger. Initializes Honeybadger and adds a request information to payload.
#     """
#     CONFIG_PREFIX = 'HONEYBADGER_'
# 
#     def __init__(self, app=None, report_exceptions=False, reset_context_after_request=False):
#         """
#         Initialize Honeybadger.
#         :param flask.Application app: the application to wrap for the exception.
#         :param bool report_exceptions: whether to automatically report exceptions raised by Flask on requests
#          (i.e. by calling abort) or not.
#         :param bool reset_context_after_request: whether to reset honeybadger context after each request.
#         """
#         self.app = app
#         self.report_exceptions = False
#         self.reset_context_after_request = False
#         default_plugin_manager.register(FlaskPlugin())
#         if app is not None:
#             self.init_app(app,
#                           report_exceptions=report_exceptions,
#                           reset_context_after_request=reset_context_after_request)
# 
#     def init_app(self, app, report_exceptions=False, reset_context_after_request=False):
#         """
#         Initialize honeybadger and listen for errors.
#         :param Flask app: the Flask application object.
#         :param bool report_exceptions: whether to automatically report exceptions raised by Flask on  requests
#          (i.e. by calling abort) or not.
#         :param bool reset_context_after_request: whether to reset honeybadger context after each request.
#         """
#         from flask import request_tearing_down, got_request_exception
# 
#         self.app = app
# 
#         self.app.logger.info('Initializing Honeybadger')
# 
#         self.report_exceptions = report_exceptions
#         self.reset_context_after_request = reset_context_after_request
#         self._initialize_honeybadger(app.config)
# 
#         # Add hooks
#         if self.report_exceptions:
#             self._register_signal_handler('auto-reporting exceptions',
#                                           got_request_exception,
#                                           self._handle_exception)
# 
#         if self.reset_context_after_request:
#             self._register_signal_handler('auto clear context on request end',
#                                           request_tearing_down,
#                                           self._reset_context)
# 
#         logger.info('Honeybadger helper installed')
# 
#     def _register_signal_handler(self, description, signal, handler):
#         """
#         Registers a handler for the given signal.
#         :param description: a short description of the signal to handle.
#         :param signal: the signal to handle.
#         :param handler: the function to use for handling the signal.
#         """
#         from flask import signals
# 
#         if not signals.signals_available:
#             self.app.logger.warn('blinker needs to be installed in order to support %s'.format(description))
#         self.app.logger.info('Enabling {}'.format(description))
#         # Weak references won't work if handlers are methods rather than functions.
#         signal.connect(handler, sender=self.app, weak=False)
# 
#     def _initialize_honeybadger(self, config):
#         """
#         Initializes honeybadger using the given config object.
#         :param dict config: a dict or dict-like object that contains honeybadger configuration properties.
#         """
#         if config.get('DEBUG', False):
#             honeybadger.configure(environment='development')
# 
#         honeybadger_config = {}
#         for key, value in iteritems(config):
#             if key.startswith(self.CONFIG_PREFIX):
#                 honeybadger_config[key[len(self.CONFIG_PREFIX):].lower()] = value
# 
#         honeybadger.configure(**honeybadger_config)
#         honeybadger.config.set_12factor_config()  # environment should override Flask settings
# 
#     def _reset_context(self, *args, **kwargs):
#         """
#         Resets context when request is done.
#         """
#         honeybadger.reset_context()
# 
#     def _handle_exception(self, sender, exception=None):
#         """
#         Actual code handling the exception and sending it to honeybadger if it's enabled.
#         :param T sender: the object sending the exception event.
#         :param Exception exception: the exception to handle.
#         """
#         honeybadger.notify(exception)
#         if self.reset_context_after_request:
#             self._reset_context()


import logging
from flask import Flask
from honeybadger.contrib import FlaskHoneybadger
from flask_restplus import Resource, Api, reqparse



logger = logging.getLogger(__name__)

app = Flask(__name__)
app.config['HONEYBADGER_ENVIRONMENT'] = 'honeybadger-example'
app.config['HONEYBADGER_API_KEY'] = '<your key>'
app.config['HONEYBADGER_PARAMS_FILTERS'] = 'password, secret, credit-card'
FlaskHoneybadger(app, report_exceptions=True)

api = Api(app)

parser = reqparse.RequestParser()
parser.add_argument('a', type=int, help='Numerator')
parser.add_argument('b', type=int, help='Denominator')


@api.route('/fraction')
class Fraction(Resource):
    def get(self):
        args = parser.parse_args()
        logger.info('Dividing two numbers {} {}'.format(args.a, args.b))

# Path: honeybadger/contrib/flask.py
# class FlaskHoneybadger(object):
#     """
#     Flask extension for Honeybadger. Initializes Honeybadger and adds a request information to payload.
#     """
#     CONFIG_PREFIX = 'HONEYBADGER_'
# 
#     def __init__(self, app=None, report_exceptions=False, reset_context_after_request=False):
#         """
#         Initialize Honeybadger.
#         :param flask.Application app: the application to wrap for the exception.
#         :param bool report_exceptions: whether to automatically report exceptions raised by Flask on requests
#          (i.e. by calling abort) or not.
#         :param bool reset_context_after_request: whether to reset honeybadger context after each request.
#         """
#         self.app = app
#         self.report_exceptions = False
#         self.reset_context_after_request = False
#         default_plugin_manager.register(FlaskPlugin())
#         if app is not None:
#             self.init_app(app,
#                           report_exceptions=report_exceptions,
#                           reset_context_after_request=reset_context_after_request)
# 
#     def init_app(self, app, report_exceptions=False, reset_context_after_request=False):
#         """
#         Initialize honeybadger and listen for errors.
#         :param Flask app: the Flask application object.
#         :param bool report_exceptions: whether to automatically report exceptions raised by Flask on  requests
#          (i.e. by calling abort) or not.
#         :param bool reset_context_after_request: whether to reset honeybadger context after each request.
#         """
#         from flask import request_tearing_down, got_request_exception
# 
#         self.app = app
# 
#         self.app.logger.info('Initializing Honeybadger')
# 
#         self.report_exceptions = report_exceptions
#         self.reset_context_after_request = reset_context_after_request
#         self._initialize_honeybadger(app.config)
# 
#         # Add hooks
#         if self.report_exceptions:
#             self._register_signal_handler('auto-reporting exceptions',
#                                           got_request_exception,
#                                           self._handle_exception)
# 
#         if self.reset_context_after_request:
#             self._register_signal_handler('auto clear context on request end',
#                                           request_tearing_down,
#                                           self._reset_context)
# 
#         logger.info('Honeybadger helper installed')
# 
#     def _register_signal_handler(self, description, signal, handler):
#         """
#         Registers a handler for the given signal.
#         :param description: a short description of the signal to handle.
#         :param signal: the signal to handle.
#         :param handler: the function to use for handling the signal.
#         """
#         from flask import signals
# 
#         if not signals.signals_available:
#             self.app.logger.warn('blinker needs to be installed in order to support %s'.format(description))
#         self.app.logger.info('Enabling {}'.format(description))
#         # Weak references won't work if handlers are methods rather than functions.
#         signal.connect(handler, sender=self.app, weak=False)
# 
#     def _initialize_honeybadger(self, config):
#         """
#         Initializes honeybadger using the given config object.
#         :param dict config: a dict or dict-like object that contains honeybadger configuration properties.
#         """
#         if config.get('DEBUG', False):
#             honeybadger.configure(environment='development')
# 
#         honeybadger_config = {}
#         for key, value in iteritems(config):
#             if key.startswith(self.CONFIG_PREFIX):
#                 honeybadger_config[key[len(self.CONFIG_PREFIX):].lower()] = value
# 
#         honeybadger.configure(**honeybadger_config)
#         honeybadger.config.set_12factor_config()  # environment should override Flask settings
# 
#     def _reset_context(self, *args, **kwargs):
#         """
#         Resets context when request is done.
#         """
#         honeybadger.reset_context()
# 
#     def _handle_exception(self, sender, exception=None):
#         """
#         Actual code handling the exception and sending it to honeybadger if it's enabled.
#         :param T sender: the object sending the exception event.
#         :param Exception exception: the exception to handle.
#         """
#         honeybadger.notify(exception)
#         if self.reset_context_after_request:
#             self._reset_context()


# Path: examples/flask-restplus/app.py
import logging
from flask import Flask
from honeybadger.contrib import FlaskHoneybadger
from flask_restplus import Resource, Api, reqparse




logger = logging.getLogger(__name__)

app = Flask(__name__)
app.config['HONEYBADGER_ENVIRONMENT'] = 'honeybadger-example'
app.config['HONEYBADGER_API_KEY'] = '<your key>'
app.config['HONEYBADGER_PARAMS_FILTERS'] = 'password, secret, credit-card'
FlaskHoneybadger(app, report_exceptions=True)

api = Api(app)

parser = reqparse.RequestParser()
parser.add_argument('a', type=int, help='Numerator')
parser.add_argument('b', type=int, help='Denominator')


@api.route('/fraction')
class Fraction(Resource):
    def get(self):
        args = parser.parse_args()
        logger.info('Dividing two numbers {} {}'.format(args.a, args.b))

        return {'result': args.a / args.b}