Skip to content

Instantly share code, notes, and snippets.

@craigderington
Last active December 13, 2018 19:22
Show Gist options
  • Save craigderington/b626085602cf479839a9557f572b184f to your computer and use it in GitHub Desktop.
Save craigderington/b626085602cf479839a9557f572b184f to your computer and use it in GitHub Desktop.
Flask REST Mailgun Webhook app scaffold
from from import Flask, render_template, Response, jsonify, url_for, flash
from flask_sqlalchemy import SQLAlchemy
from flask_httpauth import HTTPBasicAuth
from models import User, Lead, Company
import config
app = Flask(__name__)
db = SQLAlchemy(app)
auth = HTTPBasicAuth()
DEBUG = True
@app.route('/api', methods=['GET'])
@app.route('/api/v1', methods=['GET'])
@app.route('/api/v1/index', methods=['GET'])
def index():
"""
The default API view. List all webhook routes:
:return: dict
"""
api_routes = {}
api_routes['delivered'] = '/api/v1/wh/mg/lead/email/delivered'
api_routes['dropped'] = '/api/v1/wh/mg/lead/email/dropped'
api_routes['bounced'] = '/api/v1/wh/mg/lead/email/bounced'
api_routes['complaint'] = '/api/v1/wh/mg/lead/email/spam/complaint'
api_routes['unsubscribe'] = '/api/v1/wh/mg/lead/email/unsubscribe'
api_routes['clicks'] = '/api/v1/wh/mg/lead/email/click'
api_routes['opens'] = '/api/v1/wh/mg/lead/email/open'
# return the response
return jsonify(api_routes), 200
if __name__ == '__main__':
app.run(
port=5000,
debug=DEBUG
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment