Skip to content

Commit aff1106

Browse files
author
Samuel Sutch
committed
example tac is now the tac you should use; updated
* updated conf * updated pyapns.tac
1 parent a7bdc7a commit aff1106

File tree

3 files changed

+65
-68
lines changed

3 files changed

+65
-68
lines changed

example_conf.json

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,12 @@
11
{
22
"port": 7077,
3+
"rest_port": 8088,
34
"autoprovision": [
45
{
5-
"app_id": "sandbox:com.ficture.ficturebeta",
6-
"cert": "/Users/sam/dev/ficture/push_certs/development-com.ficture.ficturebeta.pem",
6+
"app_id": "com.example.myapp",
7+
"cert": "/path/to/cert.pem",
78
"environment": "sandbox",
89
"timeout": 15
910
},
10-
{
11-
"app_id": "production:com.ficture.ficturebeta",
12-
"cert": "/Users/sam/dev/ficture/push_certs/production-com.ficture.ficturebeta.pem",
13-
"environment": "production",
14-
"timeout": 15
15-
},
16-
{
17-
"app_id": "sandbox:com.ficture.ficturebeta2",
18-
"cert": "/Users/sam/dev/ficture/push_certs/development-com.ficture.ficturebeta2.pem",
19-
"environment": "sandbox",
20-
"timeout": 15
21-
},
22-
{
23-
"app_id": "production:com.ficture.ficturebeta2",
24-
"cert": "/Users/sam/dev/ficture/push_certs/production-com.ficture.ficturebeta2.pem",
25-
"environment": "production",
26-
"timeout": 15
27-
},
28-
{
29-
"app_id": "sandbox:com.ficture.ficturebeta3",
30-
"cert": "/Users/sam/dev/ficture/push_certs/development-com.ficture.ficturebeta3.pem",
31-
"environment": "sandbox",
32-
"timeout": 15
33-
},
34-
{
35-
"app_id": "production:com.ficture.ficturebeta3",
36-
"cert": "/Users/sam/dev/ficture/push_certs/production-com.ficture.ficturebeta3.pem",
37-
"environment": "production",
38-
"timeout": 15
39-
}
4011
]
4112
}

example_tac.tac

Lines changed: 0 additions & 36 deletions
This file was deleted.

pyapns.tac

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# CONFIG FILE LOCATION
2+
# relative to this file or absolute path
3+
4+
config_file = '/path/to/config/pyapns_conf.json'
5+
6+
# you don't need to change anything below this line really
7+
8+
import twisted.application, twisted.web, twisted.application.internet
9+
import pyapns.server, pyapns._json
10+
import pyapns.rest_service, pyapns.model
11+
import os
12+
13+
config = {}
14+
15+
if os.path.exists(os.path.abspath(config_file)):
16+
with open(os.path.abspath(config_file)) as f:
17+
config.update(pyapns._json.loads(f.read()))
18+
else:
19+
print 'No config file loaded. Alter the `config_file` variable at', \
20+
'the top of this file to set one.'
21+
22+
xml_service = pyapns.server.APNSServer()
23+
24+
# get automatic provisioning
25+
if 'autoprovision' in config:
26+
for app in config['autoprovision']:
27+
# for XML-RPC
28+
xml_service.xmlrpc_provision(app['app_id'], app['cert'],
29+
app['environment'], app['timeout'])
30+
# for REST
31+
pyapns.model.AppRegistry.put(
32+
app['app_id'], app['environment'], app['cert'],
33+
timeout=app['timeout']
34+
)
35+
36+
application = twisted.application.service.Application("pyapns application")
37+
38+
# XML-RPC server support ------------------------------------------------------
39+
40+
if 'port' in config:
41+
port = config['port']
42+
else:
43+
port = 7077
44+
45+
resource = twisted.web.resource.Resource()
46+
resource.putChild('', xml_service)
47+
48+
site = twisted.web.server.Site(resource)
49+
50+
server = twisted.application.internet.TCPServer(port, site)
51+
server.setServiceParent(application)
52+
53+
# rest service support --------------------------------------------------------
54+
if 'rest_port' in config:
55+
rest_port = config['rest_port']
56+
else:
57+
rest_port = 8088
58+
59+
site = twisted.web.server.Site(pyapns.rest_service.default_resource)
60+
61+
server = twisted.application.internet.TCPServer(rest_port, site)
62+
server.setServiceParent(application)

0 commit comments

Comments
 (0)