From aff11069098bf4d8f9ccc9d11b7c47c0e57e9a15 Mon Sep 17 00:00:00 2001 From: Samuel Sutch Date: Fri, 25 Jan 2013 15:34:05 -0800 Subject: [PATCH] example tac is now the tac you should use; updated * updated conf * updated pyapns.tac --- example_conf.json | 35 +++----------------------- example_tac.tac | 36 --------------------------- pyapns.tac | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 68 deletions(-) delete mode 100644 example_tac.tac create mode 100644 pyapns.tac diff --git a/example_conf.json b/example_conf.json index b435e6e..eb2c262 100644 --- a/example_conf.json +++ b/example_conf.json @@ -1,41 +1,12 @@ { "port": 7077, + "rest_port": 8088, "autoprovision": [ { - "app_id": "sandbox:com.ficture.ficturebeta", - "cert": "/Users/sam/dev/ficture/push_certs/development-com.ficture.ficturebeta.pem", + "app_id": "com.example.myapp", + "cert": "/path/to/cert.pem", "environment": "sandbox", "timeout": 15 }, - { - "app_id": "production:com.ficture.ficturebeta", - "cert": "/Users/sam/dev/ficture/push_certs/production-com.ficture.ficturebeta.pem", - "environment": "production", - "timeout": 15 - }, - { - "app_id": "sandbox:com.ficture.ficturebeta2", - "cert": "/Users/sam/dev/ficture/push_certs/development-com.ficture.ficturebeta2.pem", - "environment": "sandbox", - "timeout": 15 - }, - { - "app_id": "production:com.ficture.ficturebeta2", - "cert": "/Users/sam/dev/ficture/push_certs/production-com.ficture.ficturebeta2.pem", - "environment": "production", - "timeout": 15 - }, - { - "app_id": "sandbox:com.ficture.ficturebeta3", - "cert": "/Users/sam/dev/ficture/push_certs/development-com.ficture.ficturebeta3.pem", - "environment": "sandbox", - "timeout": 15 - }, - { - "app_id": "production:com.ficture.ficturebeta3", - "cert": "/Users/sam/dev/ficture/push_certs/production-com.ficture.ficturebeta3.pem", - "environment": "production", - "timeout": 15 - } ] } diff --git a/example_tac.tac b/example_tac.tac deleted file mode 100644 index 3e24e6b..0000000 --- a/example_tac.tac +++ /dev/null @@ -1,36 +0,0 @@ -# CONFIG FILE LOCATION -# relative to this file or absolute path - -config_file = 'example_conf.json' - -# you don't need to change anything below this line really - -import twisted.application, twisted.web, twisted.application.internet -import pyapns.server, pyapns._json -import os - -with open(os.path.abspath(config_file)) as f: - config = pyapns._json.loads(f.read()) - -application = twisted.application.service.Application("pyapns application") - -resource = twisted.web.resource.Resource() -service = pyapns.server.APNSServer() - -# get automatic provisioning -if 'autoprovision' in config: - for app in config['autoprovision']: - service.xmlrpc_provision(app['app_id'], app['cert'], app['environment'], - app['timeout']) - -# get port from config or 7077 -if 'port' in config: - port = config['port'] -else: - port = 7077 - -resource.putChild('', service) -site = twisted.web.server.Site(resource) - -server = twisted.application.internet.TCPServer(port, site) -server.setServiceParent(application) diff --git a/pyapns.tac b/pyapns.tac new file mode 100644 index 0000000..621ce3a --- /dev/null +++ b/pyapns.tac @@ -0,0 +1,62 @@ +# CONFIG FILE LOCATION +# relative to this file or absolute path + +config_file = '/path/to/config/pyapns_conf.json' + +# you don't need to change anything below this line really + +import twisted.application, twisted.web, twisted.application.internet +import pyapns.server, pyapns._json +import pyapns.rest_service, pyapns.model +import os + +config = {} + +if os.path.exists(os.path.abspath(config_file)): + with open(os.path.abspath(config_file)) as f: + config.update(pyapns._json.loads(f.read())) +else: + print 'No config file loaded. Alter the `config_file` variable at', \ + 'the top of this file to set one.' + +xml_service = pyapns.server.APNSServer() + +# get automatic provisioning +if 'autoprovision' in config: + for app in config['autoprovision']: + # for XML-RPC + xml_service.xmlrpc_provision(app['app_id'], app['cert'], + app['environment'], app['timeout']) + # for REST + pyapns.model.AppRegistry.put( + app['app_id'], app['environment'], app['cert'], + timeout=app['timeout'] + ) + +application = twisted.application.service.Application("pyapns application") + +# XML-RPC server support ------------------------------------------------------ + +if 'port' in config: + port = config['port'] +else: + port = 7077 + +resource = twisted.web.resource.Resource() +resource.putChild('', xml_service) + +site = twisted.web.server.Site(resource) + +server = twisted.application.internet.TCPServer(port, site) +server.setServiceParent(application) + +# rest service support -------------------------------------------------------- +if 'rest_port' in config: + rest_port = config['rest_port'] +else: + rest_port = 8088 + +site = twisted.web.server.Site(pyapns.rest_service.default_resource) + +server = twisted.application.internet.TCPServer(rest_port, site) +server.setServiceParent(application)