Skip to content

Commit

Permalink
fork from PyAPNS
Browse files Browse the repository at this point in the history
  • Loading branch information
KJ committed Mar 7, 2013
1 parent 2fbabd5 commit 5adc04e
Show file tree
Hide file tree
Showing 8 changed files with 613 additions and 4 deletions.
4 changes: 4 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apns.py
setup.py
tests.py
README.markdown
57 changes: 57 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# PyAPNs

A Python library for interacting with the Apple Push Notification service
(APNs)

## Installation

Either download the source from GitHub or use easy_install:

$ easy_install apns

## Sample usage

```python
from apns import APNs, Payload

apns = APNs(use_sandbox=True, cert_file='cert.pem', key_file='key.pem')

# Send a notification
token_hex = 'b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b87'
payload = Payload(alert="Hello World!", sound="default", badge=1)
apns.gateway_server.send_notification(token_hex, payload)

# Get feedback messages
for (token_hex, fail_time) in apns.feedback_server.items():
# do stuff with token_hex and fail_time
```

For more complicated alerts including custom buttons etc, use the PayloadAlert
class. Example:

```python
alert = PayloadAlert("Hello world!", action_loc_key="Click me")
payload = Payload(alert=alert, sound="default")
```

To send custom payload arguments, pass a dictionary to the custom kwarg
of the Payload constructor.

```python
payload = Payload(alert="Hello World!", custom={'sekrit_number':123})
```

## Travis Build Status

[![Build Status](https://secure.travis-ci.org/simonwhitaker/PyAPNs.png?branch=master)](http://travis-ci.org/simonwhitaker/PyAPNs)

## Further Info

[iOS Reference Library: Local and Push Notification Programming Guide][a1]

## Credits

Written and maintained by Simon Whitaker at [Goo Software Ltd][goo].

[a1]:http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008194-CH1-SW1
[goo]:http://www.goosoftware.co.uk/
4 changes: 0 additions & 4 deletions README.md

This file was deleted.

54 changes: 54 additions & 0 deletions apns-send
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python

from apns import APNs, Payload

import optparse

from tornado import ioloop

parser = optparse.OptionParser()

parser.add_option("-c", "--certificate-file",
dest="certificate_file",
help="Path to .pem certificate file")

parser.add_option("-k", "--key-file",
dest="key_file",
help="Path to .pem key file")

parser.add_option("-p", "--push-token",
dest="push_token",
help="Push token")

parser.add_option("-m", "--message",
dest="message",
help="Message")

options, args = parser.parse_args()

if options.certificate_file is None:
parser.error('Must provide --certificate-file')

if options.key_file is None:
parser.error('Must provide --key-file')

if options.push_token is None:
parser.error('Must provide --push-token')

if options.message is None:
parser.error('Must provide --message')

apns = APNs(cert_file=options.certificate_file, key_file=options.key_file, use_sandbox=True)

def success():
print("Sent push message to APNS gateway.")
ioloop.IOLoop.instance().stop()

def send():
apns.gateway_server.send_notification(options.push_token, payload, success)

# Send a notification
payload = Payload(alert=options.message, sound="default", badge=1)
apns.gateway_server.connect(send)

ioloop.IOLoop.instance().start()
Loading

0 comments on commit 5adc04e

Please sign in to comment.