diff --git a/example_conf.json b/example_conf.json new file mode 100644 index 0000000..b435e6e --- /dev/null +++ b/example_conf.json @@ -0,0 +1,41 @@ +{ + "port": 7077, + "autoprovision": [ + { + "app_id": "sandbox:com.ficture.ficturebeta", + "cert": "/Users/sam/dev/ficture/push_certs/development-com.ficture.ficturebeta.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 index 2faccd2..3e24e6b 100644 --- a/example_tac.tac +++ b/example_tac.tac @@ -1,12 +1,36 @@ +# 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 +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() -resource.putChild('', pyapns.server.APNSServer()) +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(7077, site) +server = twisted.application.internet.TCPServer(port, site) server.setServiceParent(application) -