Skip to content
This repository has been archived by the owner on Jan 26, 2023. It is now read-only.

Commit

Permalink
Add /gcm route to get the sender id
Browse files Browse the repository at this point in the history
  • Loading branch information
Mechazawa committed Aug 31, 2016
1 parent 163c511 commit fea92a7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
11 changes: 10 additions & 1 deletion application.py
Expand Up @@ -15,8 +15,17 @@
from controllers import *
from utils import Error

gcm_enabled = True
if config.google_api_key == '':
stderr.write("WARNING: GCM disabled, please enter the google api key for gcm")
gcm_enabled = False
if not isinstance(config.google_gcm_sender_id, int):
stderr.write("WARNING: GCM disabled, sender id is not an integer")
gcm_enabled = False
elif config.google_gcm_sender_id == 0:
stderr.write('WARNING: GCM disabled, invalid sender id found')
gcm_enabled = False


app = Flask(__name__)
app.debug = config.debug or int(getenv('FLASK_DEBUG', 0)) > 0
Expand Down Expand Up @@ -50,7 +59,7 @@ def limit_rate(e):
app.register_blueprint(subscription)
app.register_blueprint(message)
app.register_blueprint(service)
if config.google_api_key is not "":
if gcm_enabled:
app.register_blueprint(gcm)

if __name__ == '__main__':
Expand Down
1 change: 1 addition & 0 deletions config.example.py
Expand Up @@ -7,6 +7,7 @@

# Google Cloud Messaging configuration (required for android!)
google_api_key = ''
google_gcm_sender_id = 509878466986 # Change this to your gcm sender id

# Message Queueing, this should be the relay. A "sane" value
# for this would be something like ipc:///tmp/pushjet-relay.ipc
Expand Down
7 changes: 7 additions & 0 deletions controllers/gcm.py
Expand Up @@ -2,6 +2,7 @@
from utils import has_uuid, Error
from models import Gcm
from shared import db
from config import google_gcm_sender_id

gcm = Blueprint('gcm', __name__)

Expand Down Expand Up @@ -31,3 +32,9 @@ def gcm_unregister(client):
db.session.commit()
return jsonify(Error.NONE)


@gcm.route("/gcm", methods=["GET"])
def gcm_sender_id():
data = dict(sender_id=google_gcm_sender_id)
return jsonify(data)

5 changes: 2 additions & 3 deletions tests.py
Expand Up @@ -2,8 +2,6 @@
from __future__ import unicode_literals

import os

from application import app
from uuid import uuid4
import unittest
import string
Expand All @@ -17,11 +15,12 @@
sys.exit('Please copy config.example.py to config.py and configure it')



class PushjetTestCase(unittest.TestCase):
def setUp(self):
config.google_api_key = config.google_api_key or 'PLACEHOLDER'

self.uuid = str(uuid4())
from application import app

app.config['TESTING'] = True
app.config['TESTING_GCM'] = []
Expand Down

0 comments on commit fea92a7

Please sign in to comment.