def api_comments(): if request.method == 'OPTIONS': # We're dealing with a pre-flight request return jsonify(status='OK', _allow_origin_cb=allow_all_origins) if request.method == 'POST': post_data = json.loads(request.data) item = Item.query.filter_by(id=post_data['item']).first() if not item: return abort(404) comment = post_comment(item, post_data, g.user) return jsonify( comment=comment.as_dict(), status='OK', _allow_origin_cb=allow_all_origins) if not request.args.get('item_url'): return abort(404) item = get_or_add_item( request.args.get('item_url'), request.args.get('item_title')) return_data = get_context(item) return jsonify(_allow_origin_cb=allow_all_origins, **return_data)
def salmon_all(): ''' Salmon endpoint. See http://www.salmon-protocol.org/ ''' # Parse the salmon slap envelope = Envelope(document=request.data, mime_type=request.headers['content-type']) # Get the xml.etree.ElementTree for the published entry slap_xml = envelope.GetParsedData() slap_xml = etree.parse(StringIO(ElementTree.tostring(slap_xml.getroot()))) root_em = slap_xml.getroot() ATOM_NS = '{http://www.w3.org/2005/Atom}' comment = { 'author_name': root_em.find(ATOM_NS + 'author').find(ATOM_NS + 'name').text, 'author_uri': root_em.find(ATOM_NS + 'author').find(ATOM_NS + 'uri').text, 'id': root_em.find(ATOM_NS + 'id').text, 'content': root_em.find(ATOM_NS + 'content').text, 'title': root_em.find(ATOM_NS + 'title').text, 'updated': root_em.find(ATOM_NS + 'updated').text } return jsonify(_allow_origin_cb=allow_all_origins, **comment)
def salmon_all(): ''' Salmon endpoint. See http://www.salmon-protocol.org/ ''' # Parse the salmon slap envelope = Envelope( document=request.data, mime_type=request.headers['content-type']) # Get the xml.etree.ElementTree for the published entry slap_xml = envelope.GetParsedData() slap_xml = etree.parse( StringIO(ElementTree.tostring(slap_xml.getroot()))) root_em = slap_xml.getroot() ATOM_NS = '{http://www.w3.org/2005/Atom}' comment = { 'author_name': root_em.find(ATOM_NS + 'author').find( ATOM_NS + 'name').text, 'author_uri': root_em.find(ATOM_NS + 'author').find( ATOM_NS + 'uri').text, 'id': root_em.find(ATOM_NS + 'id').text, 'content': root_em.find(ATOM_NS + 'content').text, 'title': root_em.find(ATOM_NS + 'title').text, 'updated': root_em.find(ATOM_NS + 'updated').text} return jsonify(_allow_origin_cb=allow_all_origins, **comment)
def check_login(): if g.user: return jsonify(status='OK', _allow_origin_cb=allow_all_origins) else: return jsonify(status=False, _allow_origin_cb=allow_all_origins)