# Path: yams_api/api.py
# def validation_error(e):
# def bad_request_error(e):
# def not_found_error(e):
# def status():
# def set_endpoints():
# def endpoints(url_filter=None):
# 
# Path: config.py
# class API:
# 
#     LISTEN_HOST = chain_load_setting("API_HOST", "YAMS_API_HOST", "127.0.0.1")
#     LISTEN_PORT = chain_load_setting("API_PORT", "YAMS_API_PORT", default=1111)
#     LISTEN_URL = "http://%s:%s" % (LISTEN_HOST, LISTEN_PORT)
#     # ----------------------------------------- #
#     # ---- Socket API ---- #
#     LISTEN_PORT_SOCKET = chain_load_setting("API_SOCKET_PORT", "YAMS_API_SOCKET_PORT", default=1112)
# 
#     # Yield epsilon is to avoid busy-waiting.  0 denotes yielding to any ready thread.  See scheduler docs.
#     # I've found 0 to fully utilize a core, so defaults to a longer interval to save electricity.
#     YIELD_TO_READY_THREADS=0
#     SOCKET_THREAD_YIELD_EPSILON = 0.25
#     SOCKET_TIMEOUT_SECONDS = 30
#     SOCKET_RX_BUFFER_BYTES = 4096
# 
#     # ----------------------------------------- #
# 
#     DEBUG = chain_load_setting("DEBUG", "YAMS_API_DEBUG", True)
# 
#     API_VERSION_CORE = chain_load_setting("API_VERSION_CORE", "YAMS_API_VERSION_CORE", default="dev")
#     API_VERSION_PLUGINS = chain_load_setting("API_VERSION_PLUGINS", "YAMS_API_VERSION_PLUGINS", default="dev")
# 
#     default_datadir = os.path.join(basedir, "yams_api", "data")
#     DATADIR = chain_load_setting("API_DATADIR", "YAMS_API_DATADIR", default=default_datadir)
# 
#     default_database = "sqlite:///" + os.path.join(basedir, "yams_api.sqlite")
#     SQLALCHEMY_DATABASE_URI = chain_load_setting("API_DATABASE_URI", "YAMS_API_DATABASE_URI", default=default_database)
# 
# 
#     # If we have redis, we have rate limiting available
#     try:
#         r = redis.Redis()
#         r.ping()
#         USE_RATE_LIMITS = True
#     except redis.ConnectionError:
#         USE_RATE_LIMITS = False


from flask.ext.script import Manager, Server
from yams_api.api import api
from config import API

api.config.from_object(API)
#manager_api = Manager(api, usage="API Management")
manager_api = Manager(api)


# using the flask-script Server() command was binding to the wrong Flask instance.
# this server only gets used for dev/testing, so this is 'fine'
def run_api():
    api.run(
        debug=API.DEBUG,
        host=API.LISTEN_HOST,

# Path: yams_api/api.py
# def validation_error(e):
# def bad_request_error(e):
# def not_found_error(e):
# def status():
# def set_endpoints():
# def endpoints(url_filter=None):
# 
# Path: config.py
# class API:
# 
#     LISTEN_HOST = chain_load_setting("API_HOST", "YAMS_API_HOST", "127.0.0.1")
#     LISTEN_PORT = chain_load_setting("API_PORT", "YAMS_API_PORT", default=1111)
#     LISTEN_URL = "http://%s:%s" % (LISTEN_HOST, LISTEN_PORT)
#     # ----------------------------------------- #
#     # ---- Socket API ---- #
#     LISTEN_PORT_SOCKET = chain_load_setting("API_SOCKET_PORT", "YAMS_API_SOCKET_PORT", default=1112)
# 
#     # Yield epsilon is to avoid busy-waiting.  0 denotes yielding to any ready thread.  See scheduler docs.
#     # I've found 0 to fully utilize a core, so defaults to a longer interval to save electricity.
#     YIELD_TO_READY_THREADS=0
#     SOCKET_THREAD_YIELD_EPSILON = 0.25
#     SOCKET_TIMEOUT_SECONDS = 30
#     SOCKET_RX_BUFFER_BYTES = 4096
# 
#     # ----------------------------------------- #
# 
#     DEBUG = chain_load_setting("DEBUG", "YAMS_API_DEBUG", True)
# 
#     API_VERSION_CORE = chain_load_setting("API_VERSION_CORE", "YAMS_API_VERSION_CORE", default="dev")
#     API_VERSION_PLUGINS = chain_load_setting("API_VERSION_PLUGINS", "YAMS_API_VERSION_PLUGINS", default="dev")
# 
#     default_datadir = os.path.join(basedir, "yams_api", "data")
#     DATADIR = chain_load_setting("API_DATADIR", "YAMS_API_DATADIR", default=default_datadir)
# 
#     default_database = "sqlite:///" + os.path.join(basedir, "yams_api.sqlite")
#     SQLALCHEMY_DATABASE_URI = chain_load_setting("API_DATABASE_URI", "YAMS_API_DATABASE_URI", default=default_database)
# 
# 
#     # If we have redis, we have rate limiting available
#     try:
#         r = redis.Redis()
#         r.ping()
#         USE_RATE_LIMITS = True
#     except redis.ConnectionError:
#         USE_RATE_LIMITS = False


# Path: manage_api.py
from flask.ext.script import Manager, Server
from yams_api.api import api
from config import API


api.config.from_object(API)
#manager_api = Manager(api, usage="API Management")
manager_api = Manager(api)


# using the flask-script Server() command was binding to the wrong Flask instance.
# this server only gets used for dev/testing, so this is 'fine'
def run_api():
    api.run(
        debug=API.DEBUG,
        host=API.LISTEN_HOST,

        port=API.LISTEN_PORT