コード例 #1
0
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
コード例 #2
0
ファイル: message.py プロジェクト: Pushjet/Pushjet-Server-Api
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
コード例 #3
0
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()})
コード例 #4
0
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()})
コード例 #5
0
ファイル: message.py プロジェクト: leeming/Pushjet-Server-Api
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)