def message_send(service): text = request.form.get('message') if not text: return Error.ARGUMENT_MISSING('message') subscribers = Subscription.query.filter_by(service=service).count() if subscribers == 0: # Pretend we did something even though we didn't # Nobody is listening so it doesn't really matter return Error.NONE level = (request.form.get('level') or '3')[0] level = int(level) if level in "12345" else 3 title = request.form.get('title', '').strip()[:255] link = request.form.get('link', '').strip() msg = Message(service, text, title, level, link) db.session.add(msg) db.session.commit() if google_api_key or current_app.config['TESTING']: Gcm.send_message(msg) if apns_cert_path or current_app.config['TESTING']: Apns.send_message(msg) if zeromq_relay_uri: queue_zmq_message(json_encode({"message": msg.as_dict()})) service.cleanup() db.session.commit() return Error.NONE
def message_send(service): text = request.form.get('message') if not text: return Error.ARGUMENT_MISSING('message') subscribers = Subscription.query.filter_by(service=service).count() if subscribers == 0: # Pretend we did something even though we didn't # Nobody is listening so it doesn't really matter return Error.NONE level = (request.form.get('level') or '3')[0] level = int(level) if level in "12345" else 3 title = request.form.get('title', '').strip()[:255] link = request.form.get('link', '').strip() msg = Message(service, text, title, level, link) db.session.add(msg) db.session.commit() if google_api_key or current_app.config['TESTING']: Gcm.send_message(msg) if zeromq_relay_uri: queue_zmq_message(json_encode({"message": msg.as_dict()})) service.cleanup() db.session.commit() return Error.NONE
def subscription_post(client, service): exists = Subscription.query.filter_by(device=client).filter_by(service=service).first() is not None if exists: return Error.DUPLICATE_LISTEN subscription_new = Subscription(client, service) db.session.add(subscription_new) db.session.commit() if zeromq_relay_uri: queue_zmq_message(json_encode({'subscription': subscription_new.as_dict()})) return jsonify({'service': service.as_dict()})
def subscription_post(client, service): exists = Subscription.query.filter_by(device=client).filter_by( service=service).first() is not None if exists: return jsonify(Error.DUPLICATE_LISTEN) subscription_new = Subscription(client, service) db.session.add(subscription_new) db.session.commit() if zeromq_relay_uri: queue_zmq_message( json_encode({'subscription': subscription_new.as_dict()})) return jsonify({'service': service.as_dict()})
def message_send(service): text = request.form.get('message') if not text: return jsonify(Error.ARGUMENT_MISSING('message')) level = (request.form.get('level') or '3')[0] level = int(level) if level in "12345" else 3 title = request.form.get('title', '').strip()[:255] link = request.form.get('link', '').strip() msg = Message(service, text, title, level, link) db.session.add(msg) db.session.commit() if google_api_key: Gcm.send_message(msg) if zeromq_relay_uri: queue_zmq_message(json_encode({"message": msg.as_dict()})) service.cleanup() db.session.commit() return jsonify(Error.NONE)