示例#1
0
from birdseye.jobs import image_to_observation
import birdseye.models as bm

api = Api(app)
representations.json.settings = {'indent': 4}


def api_route(self, *args, **kwargs):
    def wrapper(cls):
        self.add_resource(cls, *args, **kwargs)
        return cls

    return wrapper


api.route = types.MethodType(api_route, api)


def _success(status_code=200, **message):
    return dict(status='success', **message), status_code


def _success_item(item, status_code=200):
    return _success(status_code=status_code, count='1', data=[item])


def _success_data(data, count, status_code=200):
    return _success(status_code=status_code, count=str(count), data=data)


def _error(message, status_code):
示例#2
0
# Im using sqlite3 for this application
iotApp.config.from_object('web.config')


def apiRoute(self, addNewUri):
    """Wrapper for flask api.route"""

    def wrapper(cls):
        registerUri = baseApiUri + addNewUri
        self.add_resource(cls, registerUri)
        return cls
    return wrapper


# Add route wrapper to api object
iotApi.route = MethodType(apiRoute, iotApi)


@iotApp.errorhandler(400)
def badRequest(errcode):
    """Wrapper to set a default errorhandler for bad request."""
    return make_response(errcode, 400)


@iotApp.errorhandler(404)
def notFound(errcode):
    """Wrapper to set a default errorhandler for resources not found."""
    return make_response(errcode, 404)


@iotApp.after_request
示例#3
0
  Author: Razen Chris Marling
  Date: Feb 04, 2018
  Project Name: Rocka Village Inventory System - API
  Description for this file: this is the brain of the project
"""

from sqlalchemy import create_engine
from flask import Flask
from flask_restful import Api
from .tools import Tools
import types

app = Flask(__name__, static_url_path='')
api = Api(app)
app.config.from_object('config')
api.route = types.MethodType(Tools.api_route, api)

# ===========================SET UP LOGGER==================================
Tools.initialize_logger(app.config['LOG_PATH'])
# ===============================END========================================

# =====================SET UP DATABASE IF NEEDED============================
try:
    # open connection
    engine = create_engine(app.config['CONNSTR'])
    # check if DB exist - create if not
    Tools.check_db_exist(engine)
    # check if DB tables is same with object tables
    Tools.inspect_tables(engine)
    # check if will add new column to the database
    Tools.inspect_columns(engine, app.config['DB_TYPE'])
示例#4
0
import types
from flask import Blueprint
from flask_restful import Api, reqparse


def api_route(self, *args, **kwargs):
    def wrapper(cls):
        self.add_resource(cls, *args, **kwargs)
        return cls

    return wrapper


default_per_page = 5
parser = reqparse.RequestParser()
parser.add_argument('per_page', type=int, location='args')
parser.add_argument('page', type=int, location='args')

api_bp = Blueprint('api', __name__, url_prefix='/api')
api = Api(api_bp)

api.route = types.MethodType(api_route, api)

from . import user, book, comment, log, tag