def handle(*args, **kwargs): method = kwargs.get("method") path = kwargs.get("path") endpoint = kwargs.get("endpoint") fn, middlewares = router.CustomRouter.get_instance().get_handler( method, endpoint) if not fn: raise NotImplemented( "This server does not support the action you requested.") mwargs = args mwkwargs = kwargs for middleware in middlewares: mwargs, mwkwargs = middleware(*mwargs, **mwkwargs) if "errors" in mwkwargs and len(mwkwargs.get("errors")): return response.as_json(status_code=417, data={ "success": False, "context": "ValidationError", "errors": mwkwargs.get("errors") }) result = fn(*mwargs, **mwkwargs) return response.as_json(data=result.as_dict())
def index(self, request): """ The root url of your ressources. Should present a list of ressources if method is GET. Should create a ressource if method is POST :param request: :type request: :class:`werkzeug.wrappers.Request` if self.auth is set call :meth:`.authentication.Authentication.check_auth` :return: :meth:`.ApiController.get_list` if request.method is GET, :meth:`.ApiController.create` if request.method is POST """ if request.method == "HEAD": verbs = list( set(self.controller['list_verbs'] + self.controller['unique_verbs'])) return self.view(headers={"Allow": ",".join(verbs)}, status=200) if self.authorization: self.authorization.check_auth(request) if self.ratelimit: self.ratelimit.check_limit(request) verb_available = { 'GET': 'get_list', 'POST': 'create', 'PUT': 'update_list' } try: return getattr(self, verb_available[request.method])(request) except KeyError: raise NotImplemented()
def manage_service_id(): logging.info('Se hace una petición %s al endpoint /api/service/id', request.method) if request.method == 'GET': return _manage_service_get_id() else: raise NotImplemented('Method not valid')
def toggle(selector): """ Turn off lights if any of them are on, or turn them on if they are all off. All lights matched by the selector will share the same power state after this action. Physically powered off lights are ignored. Parameters: selector: string The selector to limit which lights are toggled. Required. Data: duration: string The time is seconds to spend perfoming the power toggle. """ prop, value = validate_selector(selector) if prop != "id": raise NotImplemented( "Selector type %s not implemented" % prop) light = get_light_or_404(value) power = light["power"] light["power"] = "off" if power == "on" else "on" response_data = { "id": light["id"], "label": light["id"], "status": "ok", } return to_json_response(response_data)
def put(self, application_guid): now_application_identity = NOWApplicationIdentity.find_by_guid( application_guid) if not now_application_identity: raise NotFound('No identity record for this application guid.') if now_application_identity.now_application_id is None: raise NotImplemented( 'This application has not been imported. Please import an application before making changes.' ) data = request.json lead_inspector_party_guid = data.get('lead_inspector_party_guid', None) if lead_inspector_party_guid is not None: now_application_identity.now_application.lead_inspector_party_guid = lead_inspector_party_guid now_application_status_code = data.get('now_application_status_code', None) if now_application_status_code is not None and now_application_identity.now_application.now_application_status_code != now_application_status_code: now_application_identity.now_application.status_updated_date = datetime.today( ) if data.get('mine_guid', None): mine = Mine.find_by_mine_guid(data['mine_guid']) if not mine: raise BadRequest('mine not found') current_app.logger.info( f'Assigning {now_application_identity} to {mine}') now_application_identity.mine = mine now_application_identity.save() now_application_identity.now_application.deep_update_from_dict(data) return now_application_identity.now_application
def delete_dataset(datasetId): """ Deletes a dataset. Args: datasetId: the dataset to delete """ raise NotImplemented()
def manage_worker(): logging.info('Se hace una petición %s al endpoint /api/chats', request.method) if request.method == 'GET': return _manage_chats_get() else: raise NotImplemented('Method not valid')
def delete_data_pointer(datasetId, dataPointerId): """ Deletes a data pointer. Args: datasetId: the parent dataset dataPointerId: the data pointer to delete """ raise NotImplemented()
def manage_user_config_id(): logging.info( 'Se hace una petición %s al endpoint /api/user/info/config/id', request.method) if request.method == 'GET': return _manage_user_get_config_id() else: raise NotImplemented('Method not valid')
def delete_individual(datasetId, individualId): """ Deletes an individual. Args: datasetId: the parent dataset individualId: the individual to delete """ raise NotImplemented()
def manage_message(): logging.info('Se hace una petición %s al endpoint /api/message', request.method) if request.method == 'GET': return _manage_messages_get() elif request.method == 'POST': return _manage_messages_post() else: raise NotImplemented('Method not valid')
def manage_user_info(): logging.info('Se hace una petición %s al endpoint /api/user/info', request.method) if request.method == 'GET': return _manage_user_get_info() elif request.method == 'PATCH': return _manage_user_patch_info() else: raise NotImplemented('Method not valid')
def update_job_labels(id, body): """Update labels on a job. Args: id (str): Job ID to update body (dict): JSON request body Returns: UpdateJobLabelsResponse: Response - never actually returned """ raise NotImplemented('Label updates not supported by dsub.')
def manage_service(): logging.info('Se hace una petición %s al endpoint /api/service', request.method) if request.method == 'GET': return _manage_service_get() if request.method == 'POST': return _manage_service_post() if request.method == 'PATCH': return _manage_service_patch() else: raise NotImplemented('Method not valid')
def get_dataset(datasetId): """ Gets a dataset. Args: datasetId: the dataset to retrieve Returns: a dictionary representation of a Dataset """ raise NotImplemented()
def get_data_pointer(datasetId, dataPointerId): """ Gets a data pointer. Args: datasetId: the parent dataset dataPointerId: the data pointer to retrieve Returns: a dictionary representation of a DataPointer """ raise NotImplemented()
def get_individual(datasetId, individualId): """ Gets an individual. Args: datasetId: the parent dataset individualId: the data pointer to retrieve Returns: a dictionary representation of a Individual """ raise NotImplemented()
def post(self): event = self.event(request) if not hasattr(self, event): raise NotImplemented('No method implemented for event %s.' % event) # Get a dict of POSTed data data = {k: d[k] for d in [request.json, request.form, request.args] for k in six.iterkeys(d or {})} self.logger.debug('Received %s event with the following data:\n %s' % (event, repr(data))) # Call the method with the json as parameter return getattr(self, event)(data)
def login_2fa(*args, **kwargs): if kwargs.get("data").get("login_by") == "mobile_no": raise NotImplemented("mobile_no not yet supported.") email = kwargs.get("data").get("email") authenticate_for_2factor(email) return { "message": "Verification code has been sent to your email.", "data": { "tmp_id": frappe.local.response['tmp_id'] } }
def create_individual(datasetId, body): """ Create an individual. Args: datasetId: the parent dataset body: the JSON request body Returns: a dictionary representing a Individual """ if connexion.request.is_json: body = Individual.from_dict(connexion.request.get_json()) raise NotImplemented()
def get_job_aggregations(timeFrame, projectId=None): """ Query for aggregated jobs in the given time frame. Args: timeFrame (str): Time Frame to aggregate over param projectId (str): The ID of the project to query Returns: AggregationResponse: Response contains aggregation of jobs """ raise NotImplemented('function not implemented yet.')
def create_dataset(body): """ Create a dataset. Args: body: the dataset JSON Returns: a dictionary representing a Dataset """ if connexion.request.is_json: body = Dataset.from_dict(connexion.request.get_json()) raise NotImplemented()
def create_data_pointer(datasetId, body): """ Create a data pointer. Args: datasetId: the parent dataset body: the JSON request body Returns: a dictionary representing a DataPointer """ if connexion.request.is_json: body = DataPointer.from_dict(connexion.request.get_json()) raise NotImplemented()
def __call__(self, environ, start_response): if self.request.method not in self.allowed_methods: raise NotImplemented() if self.request.method == 'GET' and 'wsgi.websocket' in environ: self.ws = environ['wsgi.websocket'] self.ws.add_close_callback(self.cleanup) handler = self.websocket else: handler = getattr(self, self.request.method.lower()) resp = handler(**self.params) return resp(environ, start_response)
def manage_user_admin(): logging.info('Se hace una petición %s al endpoint /api/user/admin', request.method) if request.method == 'POST': return _manage_user_post_config() if request.method == 'GET': return _manage_user_get_admin() if request.method == 'DELETE': return _manage_user_delete_config() if request.method == 'PATCH': return _manage_user_patch_config() else: raise NotImplemented('Method not valid')
def update_dataset(datasetId, body): """ Updates a dataset. Args: datasetId: the dataset to update body: JSON representation of the updated Dataset Returns: a JSON representation of the updated Dataset """ if connexion.request.is_json: body = Dataset.from_dict(connexion.request.get_json()) raise NotImplemented()
def _parse_session_id(): """Read and check the session id""" if 'sid' not in request.values: raise BadRequest('`sid` parameter is missing.') try: session_id = int(request.values['sid']) except ValueError: raise BadRequest('`sid` must be an integer.') if session_id & 0x80000000 == 0: raise NotImplemented('Unregistered users are not supported.') return session_id
def update_individual(datasetId, individualId, body): """ Updates a data pointer. Args: datasetId: the parent dataset individualId: the individual to update body: JSON representation of the updated Individual Returns: a JSON representation of the updated Individual """ if connexion.request.is_json: body = Individual.from_dict(connexion.request.get_json()) raise NotImplemented()
def update_data_pointer(datasetId, dataPointerId, body): """ Updates a data pointer. Args: datasetId: the parent dataset dataPointerId: the data pointer to update body: JSON representation of the updated DataPointer Returns: a JSON representation of the updated DataPointer """ if connexion.request.is_json: body = DataPointer.from_dict(connexion.request.get_json()) raise NotImplemented()
def dispatch_request(self, *args, **kwargs): """ :param args: :param kwargs: """ methods = self._model.__methods__ if request.method not in methods: raise MethodNotAllowed(valid_methods=list(methods)) controller = getattr(self, request.method.lower(), None) if controller is None: raise NotImplemented() return controller(*args, **kwargs)