Beispiel #1
0
                                help="Name of the Discord server to collect "
                                     "messages from")
connections_parser.add_argument('messages_number', type=int,
                                default=DEFAULT_MESSAGES_NUMBER,
                                help="Number of Discord messages to collect")
connections_parser.add_argument('timeout', type=float,
                                default=DEFAULT_TIMEOUT,
                                help="Time to collect Discord messages before "
                                     "stopping")

connections_model = API.schema_model('Connections', {
    "type": "array",
    "items": {
        "type": "array",
        "minItems": 2,
        "maxItems": 2,
        "items": {
            "type": "string"
        }
    }
})


@API.route('/api/connections')
@API.expect(connections_parser)
class GetConnections(Resource):
    @API.marshal_with(connections_model, code=201, description='Object created')
    def post(self):
        args = connections_parser.parse_args()
        server_data = scrape_server(
            token=args['token'],
Beispiel #2
0
from flask_restplus import Api, Resource, fields
from notas.utils import abort_invalid_student, get_json

app = Flask(__name__)
api = Api(
    app,
    version="1.0",
    title="NotasIV API",
    description=
    "API para el microservicio de la asignatura Infraestructura Virtual (2019-2020)"
)

status_ns = api.namespace('Status', path="/")
students_ns = api.namespace("NotasIV", path="/api/v1")

student_schema = api.schema_model('Student Schema', get_json("schema.json"))
student_list_schema = api.model(
    'Students List Schema',
    {'data': fields.List(fields.Nested(student_schema))})


@status_ns.route('/status')
class CheckStatus(Resource):
    @api.response(200, 'Success')
    def get(self):
        return get_json('status.json')


@students_ns.route("/students")
class StudentsList(Resource):
    @api.response(200, 'Success', student_list_schema)
Beispiel #3
0
    @ns.marshal_with(todo)
    def put(self, id):
        '''Update a task given its identifier'''
        return DAO.update(id, api.payload)


bob = api.schema_model(
    'Bob',
    {
        #   'properties': {
        #       'id': {
        #           'type': 'string'
        #       },
        #       'task': {
        #           'type': 'string'
        #       }
        #   },
        'type': 'object',
        'example': {
            'iq': 23,
            'db_info': {
                'host': 'locahost'
            }
        }
    })


@ns2.route('/cool')
class Cool(Resource):
    '''Shows a list of all todos, and lets you POST to add new tasks'''
    @ns2.doc('Huh')
Beispiel #4
0
import ptr_api.auth
from flask_restplus import Api, Resource, fields
from flask_cors import CORS

application = Flask(__name__)
api = Api(app=application)
cors = CORS(application, resources={r"/*": {"origins": "*"}})

model = api.schema_model(
    'Status', {
        'required': ['address'],
        'properties': {
            'mnt<id>_air': {
                'type': 'number',
                'description': 'Airmass of current pointing.'
            },
            'foc<id>_foc_moving': {
                'type': 'string',
                'description': 'True or False'
            },
            'etc...': {}
        },
        'type': 'object'
    })

#-----------------------------------------------------------------------------#


# API Homepage
class Home(Resource):
    def get(self):
        return {'about': 'Flask API home page'}
Beispiel #5
0
                return obj.total_seconds()
        except TypeError:
            pass
        return json.JSONEncoder.default(self, obj)


class AnyJson(fields.Raw):
    def format(self, value):
        if type(value) == dict:
            return value
        else:
            return json.loads(value)


# Loads event and bucket schema from JSONSchema in aw_core
event = api.schema_model('Event', schema.get_json_schema("event"))
bucket = api.schema_model('Bucket', schema.get_json_schema("bucket"))
buckets_export = api.schema_model('Export', schema.get_json_schema("export"))

# TODO: Construct all the models from JSONSchema?
#       A downside to contructing from JSONSchema: flask-restplus does not have marshalling support

info = api.model(
    'Info', {
        'hostname': fields.String(),
        'version': fields.String(),
        'testing': fields.Boolean(),
    })

create_bucket = api.model(
    'CreateBucket', {
Beispiel #6
0
            'task': 'format task',
            'desc': '冗余数据',
        }
        return api.marshal(v, order_model, ordered=True)


# 使用JSON 格式来定义模型, 注意, 下面方式只能用于expect和response
address_schema = api.schema_model(
    'Address Schema', {
        'required': [
            'number',
        ],
        'properties': {
            'road': {
                'type': 'string'
            },
            'number': {
                'type': 'integer'
            },
            'country': {
                'type': 'string'
            }
        },
        'type': 'object'
    })


@api.route('/todo/schema', endpoint='schema_ep')
class TodoSchema(Resource):
    @api.response(200, "ok", address_schema)
    def get(self):
        return {
Beispiel #7
0
app.json_encoder = CustomJSONEncoder

app.register_blueprint(blueprint)
app.api  # type: api.ServerAPI


class AnyJson(fields.Raw):
    def format(self, value):
        if type(value) == dict:
            return value
        else:
            return json.loads(value)


# Loads event schema from JSONSchema in aw_core
event = api.schema_model('Event', schema.get_json_schema("event"))

# TODO: Construct all the models from JSONSchema?
#       A downside to contructing from JSONSchema: flask-restplus does not have marshalling support
info = api.model('Info', {
    'hostname': fields.String(),
    'testing': fields.Boolean(),
})

bucket = api.model('Bucket', {
    'id': fields.String(required=True, description='The buckets unique id'),
    'name': fields.String(required=False, description='The buckets readable and renameable name'),
    'type': fields.String(required=True, description='The buckets event type'),
    'client': fields.String(required=True, description='The name of the watcher client'),
    'hostname': fields.String(required=True, description='The hostname of the client that the bucket belongs to'),
    'created': fields.DateTime(required=True, description='The creation datetime of the bucket'),
Beispiel #8
0
######################################################################
# Configure Swagger before initializing it.
######################################################################
api = Api(  # pylint: disable=invalid-name
    app,
    version='1.0.0',
    title='Payment Demo REST API Service',
    description='This is a sample server Payment store server.',
    default='payments',
    default_label='Payment operations',
    doc='/apidocs/',
    authorizations=AUTHORIZATIONS)

# Define the model so that the docs reflect what can be sent.
PAYMENT_MODEL_DOC = api.schema_model('Payment_doc', PAYMENT_SCHEMA_DOC)

# Query string arguments.
payment_args = reqparse.RequestParser()  # pylint: disable=invalid-name
payment_args.add_argument('order_id',
                          type=int,
                          required=False,
                          help='List Payments by order id')
payment_args.add_argument('customer_id',
                          type=int,
                          required=False,
                          help='List Payments by customer id')
payment_args.add_argument('available',
                          type=inputs.boolean,
                          required=False,
                          help='List Payments by availability')
Beispiel #9
0
        """
        Get the values to populate the filter form
        """
        return get_alert_form(config['filter_form_values_path'])


@api.route('/form')
class MessageFormat(Resource):
    def get(self):
        """
        Get the format of an alert
        """
        return get_alert_form(config['format_path'])


alert = api.schema_model('Alert', get_alert_form(config['format_path']))


@api.route('/number_of_alerts')
class TotalAlerts(Resource):
    def get(self):
        """
        Get the total number of alerts
        """
        return {'number_of_alerts': number_of_alerts()}


@api.route('/newest_alert')
class NewestAlert(Resource):
    def get(self):
        """
                return obj.total_seconds()
        except TypeError:
            pass
        return json.JSONEncoder.default(self, obj)


class AnyJson(fields.Raw):
    def format(self, value):
        if type(value) == dict:
            return value
        else:
            return json.loads(value)


# Loads event and bucket schema from JSONSchema in aw_core
event = api.schema_model('Event', schema.get_json_schema("event"))
bucket = api.schema_model('Bucket', schema.get_json_schema("bucket"))
buckets_export = api.schema_model('Export', schema.get_json_schema("export"))

# TODO: Construct all the models from JSONSchema?
#       A downside to contructing from JSONSchema: flask-restplus does not have marshalling support

info = api.model('Info', {
    'hostname': fields.String(),
    'version': fields.String(),
    'testing': fields.Boolean(),
})

create_bucket = api.model('CreateBucket', {
    'client': fields.String(required=True),
    'type': fields.String(required=True),
address_response = api.schema_model(
    'AddressResponse', {
        "properties": {
            "primary_number": {
                "type": "string"
            },
            "street_name": {
                "type": "string"
            },
            "street_postdirection": {
                "type": "string"
            },
            "street_suffix": {
                "type": "string"
            },
            "city_name": {
                "type": "string"
            },
            "default_city_name": {
                "type": "string"
            },
            "state_abbreviation": {
                "type": "string"
            },
            "zipcode": {
                "type": "string"
            },
            "plus4_code": {
                "type": "string"
            },
            "delivery_point": {
                "type": "string"
            },
            "delivery_point_check_digit": {
                "type": "string"
            },
            "deliver_point_barcode": {
                "type": "string"
            }
        },
        "required": [
            "primary_number", "street_name", "street_postdirection",
            "street_suffix", "city_name", "default_city_name",
            "state_abbreviation", "zipcode", "plus4_code", "delivery_point",
            "delivery_point_check_digit", "deliver_point_barcode"
        ]
    })
Beispiel #12
0
from flask_login import current_user
from flask_login import logout_user

from route_decorators import user_required
from tqueue_add_tasks import add_example_task
from schemas import validate_input
from schemas import validate_output
from schemas import PROFILE_IN_SCHEMA
from schemas import PROFILE_OUT_SCHEMA
from models import User
import settings

api_bp = flask.Blueprint('api', __name__)
api = Api(api_bp, doc='/swagger/')

TEST_USER_IN = api.schema_model('TestUserRequest', PROFILE_IN_SCHEMA)
TEST_USER_OUT = api.schema_model('TestUserResponse', PROFILE_OUT_SCHEMA)

info_fields = api.model('Info', {
    'name': fields.String,
})


@api.route('/info')
class Info(Resource):
    @ndb.synctasklet
    @api.expect(info_fields)
    @api.marshal_with(info_fields, as_list=True)
    def get(self):
        raise ndb.Return({}, httplib.OK)
Beispiel #13
0
# named Blueprint object, so as to be registered by the app factory
blueprint = Blueprint(
    'images', __name__, url_prefix='/images')
api = Api(blueprint)


variation = api.schema_model('Variation', {
    'required': ['id'],
    'properties': {
        'id': {
            'type': 'integer'
        },
        'name': {
            'type': 'string'
        },
        'width': {
            'type': 'integer'
        },
        'height': {
            'type': 'integer'
        }
    },
    'type': 'object'
})


image = api.schema_model('Image', {
    'required': ['id'],
    'properties': {
        'id': {
            'type': 'integer'