Python flask.ext.restful.Resource() Examples
The following are 5
code examples of flask.ext.restful.Resource().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask.ext.restful
, or try the search function
.
Example #1
Source File: server.py From landmarkerio-server with BSD 3-Clause "New" or "Revised" License | 6 votes |
def add_template_endpoints(api, adapter): class Template(Resource): def get(self, lm_id): err = "{} template does not exist".format(lm_id) return safe_send(adapter.load_template(lm_id), err) class TemplateList(Resource): def get(self): return adapter.template_ids() templates_url = partial(url, Endpoints.templates) api.add_resource(TemplateList, templates_url()) api.add_resource(Template, templates_url('<string:lm_id>'))
Example #2
Source File: server.py From landmarkerio-server with BSD 3-Clause "New" or "Revised" License | 6 votes |
def add_collection_endpoints(api, adapter): class Collection(Resource): def get(self, collection_id): err = "{} collection not exist".format(collection_id) return safe_send(adapter.collection(collection_id), err) class CollectionList(Resource): def get(self): return adapter.collection_ids() collections_url = partial(url, Endpoints.collections) api.add_resource(CollectionList, collections_url()) api.add_resource(Collection, collections_url('<string:collection_id>'))
Example #3
Source File: server.py From landmarkerio-server with BSD 3-Clause "New" or "Revised" License | 5 votes |
def add_mode_endpoint(api, mode): if mode not in ['image', 'mesh']: raise ValueError("Mode can only be 'image' or 'mesh', " "not {}".format(mode)) class Mode(Resource): def get(self): return mode api.add_resource(Mode, url(Endpoints.mode))
Example #4
Source File: server.py From landmarkerio-server with BSD 3-Clause "New" or "Revised" License | 5 votes |
def add_image_endpoints(api, adapter): r""" Generate a Flask App that will serve images, landmarks and templates to landmarker.io Parameters ---------- adapter: :class:`ImageLandmarkerIOAdapter` Concrete implementation of the Image adapter. Will be queried for all data to pass to landmarker.io. """ class ImageList(Resource): def get(self): return adapter.asset_ids() class Texture(Resource): def get(self, asset_id): err = "{} does not have a texture".format(asset_id) return image_file(adapter.texture_file(asset_id), err) class Thumbnail(Resource): def get(self, asset_id): err = "{} does not have a thumbnail".format(asset_id) return image_file(adapter.thumbnail_file(asset_id), err) image_url = partial(url, Endpoints.images) texture_url = partial(url, Endpoints.textures) thumbnail_url = partial(url, Endpoints.thumbnail) api.add_resource(ImageList, image_url()) api.add_resource(Texture, asset(texture_url)()) api.add_resource(Thumbnail, asset(thumbnail_url)())
Example #5
Source File: server.py From landmarkerio-server with BSD 3-Clause "New" or "Revised" License | 4 votes |
def add_lm_endpoints(api, lm_adapter, template_adapter): r""" Generate a Flask App that will serve meshes landmarks and templates to landmarker.io Parameters ---------- adapter: :class:`LandmarkerIOAdapter` Concrete implementation of the LandmarkerIOAdapter. Will be queried for all data to pass to landmarker.io. dev: `bool`, optional If True, listen to anyone for CORS. Returns ------- api, app, api_endpoint """ class Landmark(Resource): def get(self, asset_id, lm_id): err = "{} does not have {} landmarks".format(asset_id, lm_id) try: return lm_adapter.load_lm(asset_id, lm_id) except Exception as e: try: return template_adapter.load_template(lm_id) except Exception as e: return abort(404, message=err) def put(self, asset_id, lm_id): try: return lm_adapter.save_lm(asset_id, lm_id, request.json) except Exception as e: print(e) return abort(409, message="{}:{} unable to " "save".format(asset_id, lm_id)) # Need this here to enable CORS put see http://mzl.la/1rCDkWX def options(self, asset_id, lm_id): pass class LandmarkList(Resource): def get(self): return lm_adapter.asset_id_to_lm_id() class LandmarkListForId(Resource): def get(self, asset_id): return lm_adapter.lm_ids(asset_id) lm_url = partial(url, Endpoints.landmarks) api.add_resource(LandmarkList, lm_url()) api.add_resource(LandmarkListForId, asset(lm_url)()) api.add_resource(Landmark, asset(lm_url)('<string:lm_id>'))